[Fuego] [PATCH v3] bgpd: add test cases for bgpd.

Tim.Bird at sony.com Tim.Bird at sony.com
Fri Nov 9 01:41:02 UTC 2018



> -----Original Message-----
> From: Zheng Ruoqin on Friday, September 28, 2018 8:29 AM
> 
> Before using these cases, you need to set some value in your
> board file, for example:
> 
> $ cat myboard.board
> IFETH="eth0"
> ROUTER_ID="192.168.0.15"
> ROUTER="192.168.246.0"

These should all be documented in the test.yaml file.

> 
> Signed-off-by: Zheng Ruoqin <zhengrq.fnst at cn.fujitsu.com>
> ---
>  engine/tests/Functional.bgpd/bgpd_test.sh          |  4 ++
>  engine/tests/Functional.bgpd/data/bgpd.conf        | 15 +++++
>  engine/tests/Functional.bgpd/data/zebra.conf       | 22 +++++++
>  engine/tests/Functional.bgpd/fuego_test.sh         | 25 ++++++++
>  engine/tests/Functional.bgpd/parser.py             | 22 +++++++
>  engine/tests/Functional.bgpd/spec.json             |  6 ++
>  engine/tests/Functional.bgpd/test.yaml             | 30 ++++++++++
>  engine/tests/Functional.bgpd/tests/bgpd_logfile.sh | 65
> +++++++++++++++++++++
>  engine/tests/Functional.bgpd/tests/bgpd_pidfile.sh | 63
> ++++++++++++++++++++
>  engine/tests/Functional.bgpd/tests/bgpd_ps.sh      | 62
> ++++++++++++++++++++
>  engine/tests/Functional.bgpd/tests/bgpd_syslog.sh  | 67
> ++++++++++++++++++++++
>  11 files changed, 381 insertions(+)
>  create mode 100644 engine/tests/Functional.bgpd/bgpd_test.sh
>  create mode 100644 engine/tests/Functional.bgpd/data/bgpd.conf
>  create mode 100644 engine/tests/Functional.bgpd/data/zebra.conf
>  create mode 100644 engine/tests/Functional.bgpd/fuego_test.sh
>  create mode 100644 engine/tests/Functional.bgpd/parser.py
>  create mode 100644 engine/tests/Functional.bgpd/spec.json
>  create mode 100644 engine/tests/Functional.bgpd/test.yaml
>  create mode 100644 engine/tests/Functional.bgpd/tests/bgpd_logfile.sh
>  create mode 100644 engine/tests/Functional.bgpd/tests/bgpd_pidfile.sh
>  create mode 100644 engine/tests/Functional.bgpd/tests/bgpd_ps.sh
>  create mode 100644 engine/tests/Functional.bgpd/tests/bgpd_syslog.sh
> 
> diff --git a/engine/tests/Functional.bgpd/bgpd_test.sh
> b/engine/tests/Functional.bgpd/bgpd_test.sh
> new file mode 100644
> index 0000000..dd5ce37
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/bgpd_test.sh
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +for i in tests/*.sh; do
> +    sh $i
> +done
> diff --git a/engine/tests/Functional.bgpd/data/bgpd.conf
> b/engine/tests/Functional.bgpd/data/bgpd.conf
> new file mode 100644
> index 0000000..e623631
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/data/bgpd.conf
> @@ -0,0 +1,15 @@
> +!
> +! Zebra configuration saved from vty
> +!   2000/01/01 02:27:41
> +!
> +hostname bgpd
> +password zebra
> +log file /var/log/quagga/bgpd.log
> +log syslog informational
> +!
> +router bgp 7675
> +bgp router-id xxx
> +!
> +line vty
> +!
> +
> diff --git a/engine/tests/Functional.bgpd/data/zebra.conf
> b/engine/tests/Functional.bgpd/data/zebra.conf
> new file mode 100644
> index 0000000..730e7cf
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/data/zebra.conf
> @@ -0,0 +1,22 @@
> +!
> +! Zebra configuration saved from vty
> +!   2000/01/01 01:54:01
> +!
> +hostname Router
> +password zebra
> +enable password zebra
> +log file /var/log/quagga/zebra.log
> +log syslog informational
> +!
> +!interface bmap
> +!
> +!interface xxx
> +!
> +interface lo
> +!
> +ip route xxx/24 xxx reject
> +!
> +!ipv6 forwarding
> +!
> +line vty
> +!
> diff --git a/engine/tests/Functional.bgpd/fuego_test.sh
> b/engine/tests/Functional.bgpd/fuego_test.sh
> new file mode 100644
> index 0000000..7e25b2c
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/fuego_test.sh
> @@ -0,0 +1,25 @@
> +function test_pre_check {
> +    is_on_target_path bgpd PROGRAM_BGPD
> +    assert_define PROGRAM_BGPD "Missing 'BGPD' program on target
> board"
> +    is_on_target_path zebra PROGRAM_ZEBRA
> +    assert_define PROGRAM_ZEBRA "Missing 'zebra' program on target
> board"
> +}
> +
> +function test_deploy {
> +    put $TEST_HOME/bgpd_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
> +    put $FUEGO_CORE/engine/scripts/fuego_board_function_lib.sh
> $BOARD_TESTDIR/fuego.$TESTDIR
> +    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
> +    put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
> +    cmd "sed -i 's/!interface xxx/interface $IFETH/'
> $BOARD_TESTDIR/fuego.$TESTDIR/data/zebra.conf"
> +    cmd "sed -i 's/ip route xxx\/24 xxx reject/ip route $ROUTER\/24 $IFETH
> reject/' $BOARD_TESTDIR/fuego.$TESTDIR/data/zebra.conf"
> +    cmd "sed -i 's/bgp router-id xxx/bgp router-id $ROUTER_ID/'
> $BOARD_TESTDIR/fuego.$TESTDIR/data/bgpd.conf"
> +}
> +
> +function test_run {
> +    report "cd $BOARD_TESTDIR/fuego.$TESTDIR; \
> +        sh bgpd_test.sh"
> +}
> +
> +function test_processing {
> +    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
> +}
> diff --git a/engine/tests/Functional.bgpd/parser.py
> b/engine/tests/Functional.bgpd/parser.py
> new file mode 100644
> index 0000000..d85abd7
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/parser.py
> @@ -0,0 +1,22 @@
> +#!/usr/bin/python
> +# See common.py for description of command-line arguments
> +
> +import os, sys, collections
> +
> +sys.path.insert(0, os.environ['FUEGO_CORE'] + '/engine/scripts/parser')
> +import common as plib
> +
> +measurements = {}
> +measurements = collections.OrderedDict()
> +
> +regex_string = '^ -> (.*): TEST-(.*)$'
> +matches = plib.parse_log(regex_string)
> +
> +if matches:
> +    for m in matches:
> +        measurements['default.' + m[0]] = 'PASS' if m[1] == 'PASS' else 'FAIL'
> +
> +# split the output for each testcase
> +plib.split_output_per_testcase(regex_string, measurements)
> +
> +sys.exit(plib.process(measurements))
> diff --git a/engine/tests/Functional.bgpd/spec.json
> b/engine/tests/Functional.bgpd/spec.json
> new file mode 100644
> index 0000000..b297307
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/spec.json
> @@ -0,0 +1,6 @@
> +{
> +    "testName": "Functional.bgpd",
> +    "specs": {
> +        "default": {}
> +    }
> +}
> diff --git a/engine/tests/Functional.bgpd/test.yaml
> b/engine/tests/Functional.bgpd/test.yaml
> new file mode 100644
> index 0000000..90e35e2
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/test.yaml
> @@ -0,0 +1,30 @@
> +fuego_package_version: 1
> +name: Functional.bgpd
> +description: |
> +      OpenBGPD is a FREE implementation of the Border Gateway Protocol,
> +      Version 4. It allows ordinary machines to be used as routers
> +      exchanging routes with other systems speaking the BGP protocol.
> +      This is a simple test to examine whether bpgd cat start
> +      successfully and obtain the log. And zebra is the pre-service of bgpd.
> +license: Unknown
> +author: The OpenBSD Project
> +maintainer: Zheng Ruoqin <zhengrq.fnst at cn.fujitsu.com>
> +version: 1.00
> +fuego_release: 1
> +type: Functional
> +tags: ['router']
> +params:
> +      IFETH="the eth interface in your target board" Defined in board file
This is not how test variables are described in the test.yaml file.
Please see http://fuegotest.org/wiki/test.yaml
> +data_files:
> + - bgpd_test.sh
> + - data
> + - ├── bgpd.conf
> + - └── zebra.conf
These extra characters should not be here (the ascii line-draw chars).
These lines are used when creating a test package (they are passed
as argument to the 'tar' command).

If all of the files in the 'data' directory should be included in the test
package, it is sufficient to just list the directory ('data'), and not 
the individual files.

You can test that this section of the test.yaml file is correct by trying to 
package this test, with "ftc package-test Functional.bgpd"

> + - fuego_test.sh
> + - parser.py
> + - spec.json
> + - tests
> + - ├── bgpd_01.sh
> + - ├── bgpd_02.sh
> + - ├── bgpd_03.sh
> + - └── bgpd_04.sh
Same issue here as with the files in the data directory.  You should not use
line-draw chars, and you can probably just lists the 'tests' directory without
listing all the individual files in it.

> diff --git a/engine/tests/Functional.bgpd/tests/bgpd_logfile.sh
> b/engine/tests/Functional.bgpd/tests/bgpd_logfile.sh
> new file mode 100644
> index 0000000..b46472f
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_logfile.sh
> @@ -0,0 +1,65 @@
> +#!/bin/sh
> +
> +#  In the target start bgpd and zebra, then confirm the log file.
> +#  check the /var/log/quagga/bgpd.log file.
> +
> +test="logfile"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target bgpd stop
> +exec_service_on_target zebra stop
> +if [ -f /var/log/quagga/bgpd.log ]
> +then
> +    mv /var/log/quagga/bgpd.log /var/log/quagga/bgpd.log.bck
> +fi
> +
> +#Backup the config file
> +mv /etc/quagga/bgpd.conf /etc/quagga/bgpd.conf.bck
> +mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf.bck
> +
> +cp data/bgpd.conf /etc/quagga/bgpd.conf
> +cp data/zebra.conf /etc/quagga/zebra.conf
> +chown quagga:quagga /etc/quagga/*.conf
> +
> +if exec_service_on_target zebra start
> +then
> +    echo " -> start of zebra succeeded."
> +else
> +    echo " -> start of zebra failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if exec_service_on_target bgpd start
> +then
> +    echo " -> start of bgpd succeeded."
> +else
> +    echo " -> start of bgpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if ls /var/log/quagga/bgpd.log
> +then
> +    echo " -> get log file of bgpd."
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> can't get log file of bgpd."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +exec_service_on_target bgpd stop
> +exec_service_on_target zebra stop
> +
> +#Restore the config file
> +mv /etc/quagga/bgpd.conf.bck /etc/quagga/bgpd.conf
> +mv /etc/quagga/zebra.conf.bck /etc/quagga/zebra.conf
> +
> +if [ -f /var/log/quagga/bgpd.log.bck ]
> +then
> +    mv /var/log/quagga/bgpd.log.bck /var/log/quagga/bgpd.log
> +fi
> diff --git a/engine/tests/Functional.bgpd/tests/bgpd_pidfile.sh
> b/engine/tests/Functional.bgpd/tests/bgpd_pidfile.sh
> new file mode 100644
> index 0000000..14db31a
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_pidfile.sh
> @@ -0,0 +1,63 @@
> +#!/bin/sh
> +
> +#  In the target start bgpd and zebra, then confirm the process condition by
> /var/run/quagga/bgpd.pid file.
> +#  check the keyword "bgpd".
> +
> +test="pidfile"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target bgpd stop
> +exec_service_on_target zebra stop
> +rm -f /var/run/quagga/bgpd.pid
> +
> +#Backup the config file
> +mv /etc/quagga/bgpd.conf /etc/quagga/bgpd.conf.bck
> +mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf.bck
> +
> +cp data/bgpd.conf /etc/quagga/bgpd.conf
> +cp data/zebra.conf /etc/quagga/zebra.conf
> +chown quagga:quagga /etc/quagga/*.conf
> +
> +if exec_service_on_target zebra start
> +then
> +    echo " -> start of zebra succeeded."
> +else
> +    echo " -> start of zebra failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if exec_service_on_target bgpd start
> +then
> +    echo " -> start of bgpd succeeded."
> +else
> +    echo " -> start of bgpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if ls /var/run/quagga/bgpd.pid
> +then
> +    echo " -> get the pid of bgpd."
> +else
> +    echo " -> can't get the pid of bgpd."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +exec_service_on_target bgpd stop
> +exec_service_on_target zebra stop
> +
> +if ls /var/run/quagga/bgpd.pid
> +then
> +    echo " -> $test: TEST-FAIL"
> +else
> +    echo " -> $test: TEST-PASS"
> +fi
> +
> +#Restore the config file
> +mv /etc/quagga/bgpd.conf.bck /etc/quagga/bgpd.conf
> +mv /etc/quagga/zebra.conf.bck /etc/quagga/zebra.conf
> diff --git a/engine/tests/Functional.bgpd/tests/bgpd_ps.sh
> b/engine/tests/Functional.bgpd/tests/bgpd_ps.sh
> new file mode 100644
> index 0000000..bbee1b8
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_ps.sh
> @@ -0,0 +1,62 @@
> +#!/bin/sh
> +
> +#  In the target start bgpd and zebra, then confirm the process condition by
> command ps.
> +#  check the keyword "quagga/bgpd".
> +
> +test="ps"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target bgpd stop
> +exec_service_on_target zebra stop
> +
> +#Backup the config file
> +mv /etc/quagga/bgpd.conf /etc/quagga/bgpd.conf.bck
> +mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf.bck
> +
> +cp data/bgpd.conf /etc/quagga/bgpd.conf
> +cp data/zebra.conf /etc/quagga/zebra.conf
> +chown quagga:quagga /etc/quagga/*.conf
> +
> +if exec_service_on_target zebra start
> +then
> +    echo " -> start of zebra succeeded."
> +else
> +    echo " -> start of zebra failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if exec_service_on_target bgpd start
> +then
> +    echo " -> start of bgpd succeeded."
> +else
> +    echo " -> start of bgpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if ps -N a | grep "quagga/[b]gpd"
> +then
> +    echo " -> get the pid of bgpd."
> +else
> +    echo " -> can't get the pid of bgpd."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +exec_service_on_target bgpd stop
> +exec_service_on_target zebra stop
> +
> +if ps -N a | grep "quagga/[b]gpd"
> +then
> +    echo " -> $test: TEST-FAIL"
> +else
> +    echo " -> $test: TEST-PASS"
> +fi
> +
> +#Restore the config file
> +mv /etc/quagga/bgpd.conf.bck /etc/quagga/bgpd.conf
> +mv /etc/quagga/zebra.conf.bck /etc/quagga/zebra.conf
> diff --git a/engine/tests/Functional.bgpd/tests/bgpd_syslog.sh
> b/engine/tests/Functional.bgpd/tests/bgpd_syslog.sh
> new file mode 100644
> index 0000000..a793e8c
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_syslog.sh
> @@ -0,0 +1,67 @@
> +#!/bin/sh
> +
> +#  In the target start bgpd and zebra.
> +#  At the same time, start syslog-ng and check the keyword "bgpd" in
> syslog.
> +
> +test="syslog"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target bgpd stop
> +exec_service_on_target zebra stop
> +exec_service_on_target syslog-ng stop
> +
> +rm -f /var/run/quagga/bgpd.pid
> +#Backup the config file
> +mv /etc/quagga/bgpd.conf /etc/quagga/bgpd.conf.bck
> +mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf.bck
> +
> +cp data/bgpd.conf /etc/quagga/bgpd.conf
> +cp data/zebra.conf /etc/quagga/zebra.conf
> +chown quagga:quagga /etc/quagga/*.conf
> +
> +if exec_service_on_target syslog-ng restart
> +then
> +    echo " -> restart of syslog-ng succeeded."
> +else
> +    echo " -> restart of syslog-ng failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if exec_service_on_target zebra start
> +then
> +    echo " -> start of zebra succeeded."
> +else
> +    echo " -> start of zebra failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if exec_service_on_target bgpd start
> +then
> +    echo " -> start of bgpd succeeded."
> +else
> +    echo " -> start of bgpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if tail -n 20 /var/log/syslog | grep "bgpd"
> +then
> +    echo " -> get the syslog of bgpd."
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> can't get the syslog of bgpd."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +exec_service_on_target bgpd stop
> +exec_service_on_target zebra stop
> +
> +#Restore the config file
> +mv /etc/quagga/bgpd.conf.bck /etc/quagga/bgpd.conf
> +mv /etc/quagga/zebra.conf.bck /etc/quagga/zebra.conf
> --
> 1.8.3.1

Thanks for the improvements.  Please make the requested changes,
and re-submit.

Regards,
 -- Tim


More information about the Fuego mailing list