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

Tim.Bird at sony.com Tim.Bird at sony.com
Mon Sep 24 23:40:42 UTC 2018



> -----Original Message-----
> From: Zheng Ruoqin
> 
> Before using these cases, you need to set remote_ifeth value in your
> board file, for example:
> 
> $ cat myboard.board
> remote_ifeth="eth0"
Our convention is to use uppercase for board-defined test variables.

This patch is missing a test.yaml file, to document the variable, so I'm not sure
what it's used for. The language here makes it sound mandatory (not optional).
That is also something that is described in the test.yaml file.

The test.yaml file would also help explain what this is a test of.
I am not familiar with 'bgpd' or 'zebra'.  I assume 'bgpd' is 
border gateway protocol daemon, and that 'zebra' refers to 
routing software, described here: https://www.nonngnu.org/quagga.

In general, if you introduce new board variables, there needs to be a test.yaml
file documenting the variables.  Please add one for this test.

> 
> 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    | 23 ++++++++++
>  engine/tests/Functional.bgpd/parser.py        | 22 +++++++++
>  engine/tests/Functional.bgpd/spec.json        |  6 +++
>  engine/tests/Functional.bgpd/tests/bgpd_01.sh | 62
> +++++++++++++++++++++++++
>  engine/tests/Functional.bgpd/tests/bgpd_02.sh | 66
> +++++++++++++++++++++++++++
>  engine/tests/Functional.bgpd/tests/bgpd_03.sh | 63
> +++++++++++++++++++++++++
>  engine/tests/Functional.bgpd/tests/bgpd_04.sh | 65
> ++++++++++++++++++++++++++
>  10 files changed, 348 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/tests/bgpd_01.sh
>  create mode 100644 engine/tests/Functional.bgpd/tests/bgpd_02.sh
>  create mode 100644 engine/tests/Functional.bgpd/tests/bgpd_03.sh
>  create mode 100644 engine/tests/Functional.bgpd/tests/bgpd_04.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..76000a9
> --- /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 192.168.0.15
Will these values work in other people's labs?  If not, they need to be
parameterized with board variables, or autodected if possible.

> +!
> +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..7c8c216
> --- /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 192.168.246.0/24 eth0 reject
Will this address work in someone else's lab?  If not, this needs to 
be parameterized.

> +!
> +!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..a30f850
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/fuego_test.sh
> @@ -0,0 +1,23 @@
> +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/
> +}
> +
> +function test_run {
> +    report "sed -i 's/!interface xxx/interface $remote_ifeth/'
> $BOARD_TESTDIR/fuego.$TESTDIR/data/zebra.conf"
Changing the config should be done as part of the deploy step.
I'm not sure output for this step should go to the testlog.
Please use 'cmd' instead of 'report' here.

> +    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/tests/bgpd_01.sh
> b/engine/tests/Functional.bgpd/tests/bgpd_01.sh
> new file mode 100644
> index 0000000..43f564a
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_01.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="bgpd01"
I really wish this had a more descriptive testcase name.
> +
> +. ./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 bgpd | grep ".*quagga/bgpd.*" | grep -v grep
You can eliminate the use of 'grep -v grep', by using a regular
expression in the first grep, like so:

if ps -N a | grep [b]gpd | grep ".*quagga/bgpd.*"

Also, these greps are redundant. One is a strict subset of the other. 
Also the extra .* on both sides of the regular expression have no
effect. So this could be further simplified to:
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 bgpd | grep ".*quagga/bgpd.*" | grep -v grep
Can use the same simplification here.

> +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_02.sh
> b/engine/tests/Functional.bgpd/tests/bgpd_02.sh
> new file mode 100644
> index 0000000..b820198
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_02.sh
> @@ -0,0 +1,66 @@
> +#!/bin/sh
> +
> +#  In the target start bgpd and zebra.
> +#  At the same time, start syslog-ng and check the keyword "bgpd" in
> syslog.
> +
> +test="bgpd02"
> +
> +. ./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
> +
> +#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.*"
This assumes that the logger output is in syslog.  That depends
on the logging system being used.  Maybe we need a function
library command that retrieves the tail of the system log,
in a distro-independent manner?

grep "bgpd" is the same as 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
> diff --git a/engine/tests/Functional.bgpd/tests/bgpd_03.sh
> b/engine/tests/Functional.bgpd/tests/bgpd_03.sh
> new file mode 100644
> index 0000000..ffaff4c
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_03.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="bgpd03"
> +
> +. ./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_04.sh
> b/engine/tests/Functional.bgpd/tests/bgpd_04.sh
> new file mode 100644
> index 0000000..9123111
> --- /dev/null
> +++ b/engine/tests/Functional.bgpd/tests/bgpd_04.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="bgpd04"
> +
> +. ./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
> --
> 1.8.3.1

These tests check that the indicated services are present, can be started
and stopped, and that they produce some log data.  These are all good,
but will there be additional tests that actually test bgpd and zebra functionality?

Thanks,
 -- Tim



More information about the Fuego mailing list