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

Tim.Bird at sony.com Tim.Bird at sony.com
Fri Nov 16 00:06:03 UTC 2018


> -----Original Message-----
> From: Zheng Ruoqin
> 
> Test cases for bgpd.
> 
> 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             | 32 ++++++++++
>  engine/tests/Functional.bgpd/tests/bgpd_logfile.sh | 69
> +++++++++++++++++++++
>  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  | 71
> ++++++++++++++++++++++
>  11 files changed, 391 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"

These should be "assert_has_program".  I'll change them.

> +}
> +
> +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"

It is preferable not to make target-specific changes to the data
in 'deploy'.  We're working on having a binary cache of test packages,
with packages usable on lots of different boards and in different labs.

These customizing operations should be done in 'test_run'.

If it's possible to avoid using sed on target, that would be good.
However, I don't know of a different program, that is also
commonly available, for substituting strings in files.

> +}
> +
> +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..51d4506
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/test.yaml
> @@ -0,0 +1,32 @@
> +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 can start
> +      successfully and obtain the log. And zebra is the pre-service of bgpd.
> +license: BSD-3-Clause
> +author: Zheng Ruoqin <zhengrq.fnst at cn.fujitsu.com>
> +maintainer: Tim Bird <tim.bird at sony.com>
This field is for the test maintainer, which I'd argue is you. :-)
> +version: 1.00
> +fuego_release: 1
> +type: Functional
> +tags: ['router']
> +params:
> +    - IFETH:
> +        description: eth interface in your target board, defined in board file
> +        example: eth0
> +    - ROUTER_ID:
> +        description: ip address of router for bgpd.conf, defined in board file
> +        example: 192.168.0.15
> +    - ROUTER:
> +        description: ip address of router for zebra.conf, defined in board file
> +        example: 192.168.246.0
> +data_files:
> + - bgpd_test.sh
> + - data
> + - fuego_test.sh
> + - parser.py
> + - spec.json
> + - tests
Nice job.  It's good to have a yaml file for a test.

> 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..dccf8c0
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_logfile.sh
> @@ -0,0 +1,69 @@
> +#!/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
> +   mkdir /var/log/quagga
> +   chown -R quagga:quagga /var/log/quagga
> +fi
> +
> +mv /var/log/quagga/bgpd.log /var/log/quagga/bgpd.log.bck
> +
> +#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..2003063
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_syslog.sh
> @@ -0,0 +1,71 @@
> +#!/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
> +#Backup the syslog file
> +mv /var/log/syslog /var/log/syslog.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 cat /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
> +#Restore the syslog file
> +mv /var/log/syslog.bck /var/log/syslog
> --
> 1.8.3.1

Thanks.  Applied with some changes.
 -- Tim



More information about the Fuego mailing list