[Fuego] [PATCH] Add test cases of service zebra.

Wang Mingyu wangmy at cn.fujitsu.com
Wed Nov 21 08:08:54 UTC 2018


Zebra is a routing software package that provides TCP/IP based routing services with routing protocols support.
This test set is used to check the logfile, pidfild, process, syslog and IPv4/IPv6 routing protocols of zebra.

Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
---
 engine/tests/Functional.zebra/data/zebra.conf      | 22 +++++++
 engine/tests/Functional.zebra/data/zebra.conf.ipv4 | 25 +++++++
 engine/tests/Functional.zebra/data/zebra.conf.ipv6 | 28 ++++++++
 engine/tests/Functional.zebra/fuego_test.sh        | 26 ++++++++
 engine/tests/Functional.zebra/parser.py            | 22 +++++++
 engine/tests/Functional.zebra/spec.json            |  7 ++
 engine/tests/Functional.zebra/test.yaml            | 33 ++++++++++
 .../tests/Functional.zebra/tests/zebra_logfile.sh  | 75 +++++++++++++++++++++
 .../tests/Functional.zebra/tests/zebra_pidfile.sh  | 77 ++++++++++++++++++++++
 engine/tests/Functional.zebra/tests/zebra_ps.sh    | 74 +++++++++++++++++++++
 .../Functional.zebra/tests/zebra_route_ipv4.sh     | 59 +++++++++++++++++
 .../Functional.zebra/tests/zebra_route_ipv6.sh     | 62 +++++++++++++++++
 .../tests/Functional.zebra/tests/zebra_syslog.sh   | 73 ++++++++++++++++++++
 engine/tests/Functional.zebra/zebra_test.sh        |  4 ++
 14 files changed, 587 insertions(+)
 create mode 100644 engine/tests/Functional.zebra/data/zebra.conf
 create mode 100644 engine/tests/Functional.zebra/data/zebra.conf.ipv4
 create mode 100644 engine/tests/Functional.zebra/data/zebra.conf.ipv6
 create mode 100644 engine/tests/Functional.zebra/fuego_test.sh
 create mode 100644 engine/tests/Functional.zebra/parser.py
 create mode 100644 engine/tests/Functional.zebra/spec.json
 create mode 100644 engine/tests/Functional.zebra/test.yaml
 create mode 100644 engine/tests/Functional.zebra/tests/zebra_logfile.sh
 create mode 100644 engine/tests/Functional.zebra/tests/zebra_pidfile.sh
 create mode 100644 engine/tests/Functional.zebra/tests/zebra_ps.sh
 create mode 100644 engine/tests/Functional.zebra/tests/zebra_route_ipv4.sh
 create mode 100644 engine/tests/Functional.zebra/tests/zebra_route_ipv6.sh
 create mode 100644 engine/tests/Functional.zebra/tests/zebra_syslog.sh
 create mode 100755 engine/tests/Functional.zebra/zebra_test.sh

diff --git a/engine/tests/Functional.zebra/data/zebra.conf b/engine/tests/Functional.zebra/data/zebra.conf
new file mode 100644
index 0000000..730e7cf
--- /dev/null
+++ b/engine/tests/Functional.zebra/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.zebra/data/zebra.conf.ipv4 b/engine/tests/Functional.zebra/data/zebra.conf.ipv4
new file mode 100644
index 0000000..10a7569
--- /dev/null
+++ b/engine/tests/Functional.zebra/data/zebra.conf.ipv4
@@ -0,0 +1,25 @@
+!
+! Zebra configuration saved from vty
+!   2005/11/30 03:02:45
+!
+hostname Router
+password zebra
+enable password zebra
+log file /var/log/quagga/zebra.log
+!
+interface xxx
+! ipv6 nd suppress-ra
+!
+interface lo
+!
+!interface sit0
+! ipv6 nd suppress-ra
+!
+! ip route xxx/24 xxx reject
+
+! p2020 special setting
+ip route xxx/24 xxx reject
+!
+!
+line vty
+!
diff --git a/engine/tests/Functional.zebra/data/zebra.conf.ipv6 b/engine/tests/Functional.zebra/data/zebra.conf.ipv6
new file mode 100644
index 0000000..a299b1a
--- /dev/null
+++ b/engine/tests/Functional.zebra/data/zebra.conf.ipv6
@@ -0,0 +1,28 @@
+!
+! Zebra configuration saved from vty
+!   2005/11/30 04:47:01
+!
+hostname Router
+password zebra
+enable password zebra
+log file /var/log/quagga/zebra.log
+!
+interface xxx
+ ipv6 nd suppress-ra
+!
+interface lo
+!
+interface sit0
+ ipv6 nd suppress-ra
+!
+ipv6 route xxx/48 xxx reject
+
+! p2020 special setting 
+!ipv6 route xxx/48 xxx reject
+!
+! p1020,p2020,e300(8313) special setting
+!ipv6 route xxx/48 xxx reject
+!
+!
+line vty
+!
diff --git a/engine/tests/Functional.zebra/fuego_test.sh b/engine/tests/Functional.zebra/fuego_test.sh
new file mode 100644
index 0000000..58fc287
--- /dev/null
+++ b/engine/tests/Functional.zebra/fuego_test.sh
@@ -0,0 +1,26 @@
+function test_pre_check {
+    assert_has_program zebra
+}
+
+function test_deploy {
+    put $TEST_HOME/zebra_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/!interface xxx/interface $IFETH/' $BOARD_TESTDIR/fuego.$TESTDIR/data/zebra.conf.ipv4"
+    cmd "sed -i 's/!interface xxx/interface $IFETH/' $BOARD_TESTDIR/fuego.$TESTDIR/data/zebra.conf.ipv6"
+    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/ip route xxx\/24 xxx reject/ip route $ROUTER\/24 $IFETH reject/' $BOARD_TESTDIR/fuego.$TESTDIR/data/zebra.conf.ipv4"
+    cmd "sed -i 's/ipv6 route xxx\/48 xxx reject/ipv6 route $ROUTER_IPV6\/48 $IFETH reject/' $BOARD_TESTDIR/fuego.$TESTDIR/data/zebra.conf.ipv6"
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    export test_route=$ROUTER;\
+    ./zebra_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.zebra/parser.py b/engine/tests/Functional.zebra/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.zebra/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.zebra/spec.json b/engine/tests/Functional.zebra/spec.json
new file mode 100644
index 0000000..38c8eb2
--- /dev/null
+++ b/engine/tests/Functional.zebra/spec.json
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.zebra",
+    "specs": {
+        "default": {}
+    }
+}
+
diff --git a/engine/tests/Functional.zebra/test.yaml b/engine/tests/Functional.zebra/test.yaml
new file mode 100644
index 0000000..08e4a37
--- /dev/null
+++ b/engine/tests/Functional.zebra/test.yaml
@@ -0,0 +1,33 @@
+fuego_package_version: 1
+name: Functional.zebra
+description: |
+      zebra is a routing manager that implements the zebra route engine.
+      This test is used to check if zebra can start successfully and obtain the log.
+license: Unknown
+author: Wang Mingyu <wangmy at cn.fujitsu.com>
+maintainer: Tim Bird <tim.bird at sony.com>
+version: 1.00
+fuego_release: 1
+type: Functional
+tags: ['router']
+params:
+ - ROUTER:
+   description: the static route of your target board, defined in board file
+   example: 192.168.246.0
+data_files:
+ - zebra_test.sh
+ - data
+    zebra.conf
+    zebra.conf.ipv4
+    zebra.conf.ipv6
+ - test.yaml
+ - fuego_test.sh
+ - parser.py
+ - spec.json
+ - tests
+    zebra_logfile.sh
+    zebra_pidfile.sh
+    zebra_ps.sh
+    zebra_route_ipv4.sh
+    zebra_route_ipv6.sh
+    zebra_syslog.sh
diff --git a/engine/tests/Functional.zebra/tests/zebra_logfile.sh b/engine/tests/Functional.zebra/tests/zebra_logfile.sh
new file mode 100644
index 0000000..f6f4139
--- /dev/null
+++ b/engine/tests/Functional.zebra/tests/zebra_logfile.sh
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+#  In the target start zebra, and confirm the zebra log.
+
+test="logfile"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+zebra_status=0
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target zebra stop
+
+if [ ! -d /var/log/quagga ]
+then
+   mkdir /var/log/quagga
+   chown -R quagga:quagga /var/log/quagga
+fi
+
+if [ -f /var/log/quagga/zebra.log ]
+then
+    mv /var/log/quagga/zebra.log /var/log/quagga/zebra.log_bak
+fi
+
+if [ -f /etc/quagga/zebra.conf ]
+then
+    mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf_bak
+fi
+cp data/zebra.conf /etc/quagga/zebra.conf
+
+chown quagga:quagga /etc/quagga/*.conf
+
+restore_target() {
+    if [ -f /etc/quagga/zebra.conf_bak ]
+    then
+        mv /etc/quagga/zebra.conf_bak /etc/quagga/zebra.conf
+    else
+        rm /etc/quagga/zebra.conf
+    fi
+    if [ -f /var/log/quagga/zebra.log_bak ]
+    then
+        mv /var/log/quagga/zebra.log_bak /var/log/quagga/zebra.log
+    fi
+}
+
+if exec_service_on_target zebra start
+then
+    echo " -> start of zebra succeeded."
+else
+    echo " -> start of zebra failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if [ -f /var/log/quagga/zebra.log ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> can't get the logfile of zebra."
+    echo " -> $test: TEST-FAIL"
+fi
+
+if zebra_status=0
+then
+    exec_service_on_target zebra stop
+fi
+restore_target
diff --git a/engine/tests/Functional.zebra/tests/zebra_pidfile.sh b/engine/tests/Functional.zebra/tests/zebra_pidfile.sh
new file mode 100644
index 0000000..71b55dd
--- /dev/null
+++ b/engine/tests/Functional.zebra/tests/zebra_pidfile.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+#  In the target start zebra, and confirm the process condition by command ps.
+
+test="pidfile"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+zebra_status=0
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target zebra stop
+
+rm -f /var/run/quagga/zebra.pid
+
+if [ -f /etc/quagga/zebra.conf ]
+then
+    mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf_bak
+fi
+cp data/zebra.conf /etc/quagga/zebra.conf
+
+chown quagga:quagga /etc/quagga/*.conf
+
+restore_target() {
+    if [ -f /etc/quagga/zebra.conf_bak ]
+    then
+        mv /etc/quagga/zebra.conf_bak /etc/quagga/zebra.conf
+    else
+        rm /etc/quagga/zebra.conf
+    fi
+}
+
+if exec_service_on_target zebra start
+then
+    echo " -> start of zebra succeeded."
+else
+    echo " -> start of zebra failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if [ -f /var/run/quagga/zebra.pid ]
+then
+    echo " -> get the pidfile of zebra."
+else
+    echo " -> can't get the pidfile of zebra."
+    echo " -> $test: TEST-FAIL"
+    if zebra_status=0
+    then
+        exec_service_on_target zebra stop
+    fi
+    restore_target
+    exit
+fi
+
+exec_service_on_target zebra stop
+
+if [ ! -f /var/run/quagga/zebra.pid ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+if zebra_status=1
+then
+    exec_service_on_target zebra start
+fi
+restore_target
diff --git a/engine/tests/Functional.zebra/tests/zebra_ps.sh b/engine/tests/Functional.zebra/tests/zebra_ps.sh
new file mode 100644
index 0000000..e5f669e
--- /dev/null
+++ b/engine/tests/Functional.zebra/tests/zebra_ps.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+#  In the target start zebra, and confirm the process condition by command ps.
+
+test="ps"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+zebra_status=0
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target zebra stop
+
+if [ -f /etc/quagga/zebra.conf ]
+then
+    mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf_bak
+fi
+cp data/zebra.conf /etc/quagga/zebra.conf
+
+chown quagga:quagga /etc/quagga/*.conf
+
+restore_target() {
+    if [ -f /etc/quagga/zebra.conf_bak ]
+    then
+        mv /etc/quagga/zebra.conf_bak /etc/quagga/zebra.conf
+    else
+        rm /etc/quagga/zebra.conf
+    fi
+}
+
+if exec_service_on_target zebra start
+then
+    echo " -> start of zebra succeeded."
+else
+    echo " -> start of zebra failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if ps aux | grep "[/]usr/sbin/zebra"
+then
+    echo " -> get the process of zebra."
+else
+    echo " -> can't get the process of zebra."
+    echo " -> $test: TEST-FAIL"
+    if zebra_status=0
+    then
+        exec_service_on_target zebra stop
+    fi
+    restore_target
+    exit
+fi
+
+exec_service_on_target zebra stop
+
+if ps aux | grep "[/]usr/sbin/zebra"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi
+if zebra_status=1
+then
+    exec_service_on_target zebra start
+fi
+restore_target
diff --git a/engine/tests/Functional.zebra/tests/zebra_route_ipv4.sh b/engine/tests/Functional.zebra/tests/zebra_route_ipv4.sh
new file mode 100644
index 0000000..ba7520c
--- /dev/null
+++ b/engine/tests/Functional.zebra/tests/zebra_route_ipv4.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+#  In the target start zebra, and set the static route.
+
+test="route_ipv4"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+zebra_status=0
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target zebra stop
+
+if [ -f /etc/quagga/zebra.conf ]
+then
+    mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf_bak
+fi
+cp data/zebra.conf.ipv4 /etc/quagga/zebra.conf
+
+chown quagga:quagga /etc/quagga/*.conf
+
+restore_target() {
+    if [ -f /etc/quagga/zebra.conf_bak ]
+    then
+        mv /etc/quagga/zebra.conf_bak /etc/quagga/zebra.conf
+    else
+        rm /etc/quagga/zebra.conf
+    fi
+}
+
+if exec_service_on_target zebra start
+then
+    echo " -> start of zebra succeeded."
+else
+    echo " -> start of zebra failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if netstat -rn | grep "$test_route"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+if zebra_status=0
+then
+    exec_service_on_target zebra stop
+fi
+restore_target
diff --git a/engine/tests/Functional.zebra/tests/zebra_route_ipv6.sh b/engine/tests/Functional.zebra/tests/zebra_route_ipv6.sh
new file mode 100644
index 0000000..83a44c5
--- /dev/null
+++ b/engine/tests/Functional.zebra/tests/zebra_route_ipv6.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+#  In the target start zebra, and set the static route.
+
+test="route_ipv6"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+zebra_status=0
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target zebra stop
+
+modprobe ipv6
+
+if [ -f /etc/quagga/zebra.conf ]
+then
+    mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf_bak
+fi
+cp data/zebra.conf.ipv6 /etc/quagga/zebra.conf
+
+chown quagga:quagga /etc/quagga/*.conf
+
+restore_target() {
+    if [ -f /etc/quagga/zebra.conf_bak ]
+    then
+        mv /etc/quagga/zebra.conf_bak /etc/quagga/zebra.conf
+    else
+        rm /etc/quagga/zebra.conf
+    fi
+}
+
+if exec_service_on_target zebra start
+then
+    echo " -> start of zebra succeeded."
+else
+    echo " -> start of zebra failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if ip -6 route list | grep "$test_ipv6_net"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+if zebra_status=0
+then
+    exec_service_on_target zebra stop
+fi
+modprobe -r ipv6
+restore_target
diff --git a/engine/tests/Functional.zebra/tests/zebra_syslog.sh b/engine/tests/Functional.zebra/tests/zebra_syslog.sh
new file mode 100644
index 0000000..02495c1
--- /dev/null
+++ b/engine/tests/Functional.zebra/tests/zebra_syslog.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+#  In the target start zebra, and confirm the log file.
+
+test="syslog"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+logger_service=$(detect_logger_service)
+
+zebra_status=0
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target zebra stop
+exec_service_on_target $logger_service stop
+
+if [ -f /var/log/syslog ]
+then
+    mv /var/log/syslog /var/log/syslog_bak
+fi
+
+if [ -f /etc/quagga/zebra.conf ]
+then
+    mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf_bak
+fi
+cp data/zebra.conf /etc/quagga/zebra.conf
+
+chown quagga:quagga /etc/quagga/*.conf
+
+restore_target() {
+    if [ -f /etc/quagga/zebra.conf_bak ]
+    then
+        mv /etc/quagga/zebra.conf_bak /etc/quagga/zebra.conf
+    else
+        rm /etc/quagga/zebra.conf
+    fi
+    if [ -f /var/log/syslog_bak ]
+    then
+        mv /var/log/syslog_bak /var/log/syslog
+    fi
+}
+
+exec_service_on_target $logger_service restart
+
+if exec_service_on_target zebra start
+then
+    echo " -> start of zebra succeeded."
+else
+    echo " -> start of zebra failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if tail /var/log/syslog | grep "zebra"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> can't get the syslog of zebra."
+    echo " -> $test: TEST-FAIL"
+fi
+
+if zebra_status=0
+then
+    exec_service_on_target zebra stop
+fi
+restore_target
diff --git a/engine/tests/Functional.zebra/zebra_test.sh b/engine/tests/Functional.zebra/zebra_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.zebra/zebra_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
-- 
1.8.3.1





More information about the Fuego mailing list