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

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


ripd is a routing component that works with the Quagga routing engine.
This test set is used to check the generation of logfile, pidfile, process and syslog of service ripd.

Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
---
 engine/tests/Functional.ripd/data/ripd.conf        |  13 +++
 engine/tests/Functional.ripd/data/zebra.conf       |  22 ++++
 engine/tests/Functional.ripd/fuego_test.sh         |  22 ++++
 engine/tests/Functional.ripd/parser.py             |  22 ++++
 engine/tests/Functional.ripd/ripd_test.sh          |   4 +
 engine/tests/Functional.ripd/spec.json             |   7 ++
 engine/tests/Functional.ripd/tests/ripd_logfile.sh | 111 ++++++++++++++++++++
 engine/tests/Functional.ripd/tests/ripd_pidfile.sh |  98 ++++++++++++++++++
 engine/tests/Functional.ripd/tests/ripd_ps.sh      | 115 +++++++++++++++++++++
 engine/tests/Functional.ripd/tests/ripd_syslog.sh  | 109 +++++++++++++++++++
 10 files changed, 523 insertions(+)
 create mode 100644 engine/tests/Functional.ripd/data/ripd.conf
 create mode 100644 engine/tests/Functional.ripd/data/zebra.conf
 create mode 100644 engine/tests/Functional.ripd/fuego_test.sh
 create mode 100644 engine/tests/Functional.ripd/parser.py
 create mode 100755 engine/tests/Functional.ripd/ripd_test.sh
 create mode 100644 engine/tests/Functional.ripd/spec.json
 create mode 100644 engine/tests/Functional.ripd/tests/ripd_logfile.sh
 create mode 100644 engine/tests/Functional.ripd/tests/ripd_pidfile.sh
 create mode 100644 engine/tests/Functional.ripd/tests/ripd_ps.sh
 create mode 100644 engine/tests/Functional.ripd/tests/ripd_syslog.sh

diff --git a/engine/tests/Functional.ripd/data/ripd.conf b/engine/tests/Functional.ripd/data/ripd.conf
new file mode 100644
index 0000000..ca0b51f
--- /dev/null
+++ b/engine/tests/Functional.ripd/data/ripd.conf
@@ -0,0 +1,13 @@
+!
+! Zebra configuration saved from vty
+!   2000/01/01 02:15:35
+!
+hostname ripd
+password zebra
+log file /var/log/quagga/ripd.log
+log syslog informational
+!
+router rip
+!
+line vty
+!
diff --git a/engine/tests/Functional.ripd/data/zebra.conf b/engine/tests/Functional.ripd/data/zebra.conf
new file mode 100644
index 0000000..730e7cf
--- /dev/null
+++ b/engine/tests/Functional.ripd/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.ripd/fuego_test.sh b/engine/tests/Functional.ripd/fuego_test.sh
new file mode 100644
index 0000000..d835b35
--- /dev/null
+++ b/engine/tests/Functional.ripd/fuego_test.sh
@@ -0,0 +1,22 @@
+function test_pre_check {
+    assert_has_program ripd
+    assert_has_program zebra
+}
+
+function test_deploy {
+    put $TEST_HOME/ripd_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"
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./ripd_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.ripd/parser.py b/engine/tests/Functional.ripd/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.ripd/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.ripd/ripd_test.sh b/engine/tests/Functional.ripd/ripd_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.ripd/ripd_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/engine/tests/Functional.ripd/spec.json b/engine/tests/Functional.ripd/spec.json
new file mode 100644
index 0000000..7cad99e
--- /dev/null
+++ b/engine/tests/Functional.ripd/spec.json
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.ripd",
+    "specs": {
+        "default": {}
+    }
+}
+
diff --git a/engine/tests/Functional.ripd/tests/ripd_logfile.sh b/engine/tests/Functional.ripd/tests/ripd_logfile.sh
new file mode 100644
index 0000000..520ff44
--- /dev/null
+++ b/engine/tests/Functional.ripd/tests/ripd_logfile.sh
@@ -0,0 +1,111 @@
+#!/bin/sh
+
+#  In the target start ripd, and confirm the ripd log.
+
+test="logfile"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+zebra_status=0
+ripd_status=0
+if exec_service_on_target ripd status | grep "running"
+then
+    ripd_status=1
+fi
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target ripd stop
+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/ripd.log ]
+then
+    mv /var/log/quagga/ripd.log /var/log/quagga/ripd.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
+
+if [ -f /etc/quagga/ripd.conf ]
+then
+    mv /etc/quagga/ripd.conf /etc/quagga/ripd.conf_bak
+fi
+cp data/ripd.conf /etc/quagga/ripd.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 /etc/quagga/ripd.conf_bak ]
+    then
+        mv /etc/quagga/ripd.conf_bak /etc/quagga/ripd.conf
+    else
+        rm /etc/quagga/ripd.conf
+    fi
+    if [ -f /var/log/quagga/ripd.log_bak ]
+    then
+        mv /var/log/quagga/ripd.log_bak /var/log/quagga/ripd.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
+
+if exec_service_on_target ripd start
+then
+    echo " -> start of ripd succeeded."
+else
+    echo " -> start of ripd failed."
+    echo " -> $test: TEST-FAIL"
+    if zebra_status=0
+    then
+        exec_service_on_target zebra stop
+    fi
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if [ -f /var/log/quagga/ripd.log ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> can't get the logfile of ripd."
+    echo " -> $test: TEST-FAIL"
+fi
+
+if zebra_status=0
+then
+    exec_service_on_target zebra stop
+fi
+if ripd_status=0
+then
+    exec_service_on_target ripd stop
+fi
+restore_target
diff --git a/engine/tests/Functional.ripd/tests/ripd_pidfile.sh b/engine/tests/Functional.ripd/tests/ripd_pidfile.sh
new file mode 100644
index 0000000..cc98fc9
--- /dev/null
+++ b/engine/tests/Functional.ripd/tests/ripd_pidfile.sh
@@ -0,0 +1,98 @@
+#!/bin/sh
+
+#  In the target start ripd, and confirm the process condition by command ps.
+
+test="pidfile"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+zebra_status=0
+ripd_status=0
+if exec_service_on_target ripd status | grep "running"
+then
+    ripd_status=1
+fi
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target ripd stop
+exec_service_on_target zebra stop
+
+rm -f /var/run/quagga/ripd.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
+
+if [ -f /etc/quagga/ripd.conf ]
+then
+    mv /etc/quagga/ripd.conf /etc/quagga/ripd.conf_bak
+fi
+cp data/ripd.conf /etc/quagga/ripd.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 /etc/quagga/ripd.conf_bak ]
+    then
+        mv /etc/quagga/ripd.conf_bak /etc/quagga/ripd.conf
+    else
+        rm /etc/quagga/ripd.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
+
+if exec_service_on_target ripd start
+then
+    echo " -> start of ripd succeeded."
+else
+    echo " -> start of ripd failed."
+    echo " -> $test: TEST-FAIL"
+    if zebra_status=0
+    then
+        exec_service_on_target zebra stop
+    fi
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if [ -f /var/run/quagga/ripd.pid ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> can't get the pidfile of ripd."
+    echo " -> $test: TEST-FAIL"
+fi
+
+if zebra_status=0
+then
+    exec_service_on_target zebra stop
+fi
+if ripd_status=0
+then
+    exec_service_on_target ripd stop
+fi
+restore_target
diff --git a/engine/tests/Functional.ripd/tests/ripd_ps.sh b/engine/tests/Functional.ripd/tests/ripd_ps.sh
new file mode 100644
index 0000000..81c9c52
--- /dev/null
+++ b/engine/tests/Functional.ripd/tests/ripd_ps.sh
@@ -0,0 +1,115 @@
+#!/bin/sh
+
+#  In the target start ripd, and confirm the process condition by command ps.
+
+test="ps"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+zebra_status=0
+ripd_status=0
+if exec_service_on_target ripd status | grep "running"
+then
+    ripd_status=1
+fi
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target ripd stop
+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
+
+if [ -f /etc/quagga/ripd.conf ]
+then
+    mv /etc/quagga/ripd.conf /etc/quagga/ripd.conf_bak
+fi
+cp data/ripd.conf /etc/quagga/ripd.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 /etc/quagga/ripd.conf_bak ]
+    then
+        mv /etc/quagga/ripd.conf_bak /etc/quagga/ripd.conf
+    else
+        rm /etc/quagga/ripd.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
+
+if exec_service_on_target ripd start
+then
+    echo " -> start of ripd succeeded."
+else
+    echo " -> start of ripd failed."
+    echo " -> $test: TEST-FAIL"
+    if zebra_status=0
+    then
+        exec_service_on_target zebra stop
+    fi
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if ps aux | grep "[/]usr/sbin/ripd"
+then
+    echo " -> get the process of ripd."
+else
+    echo " -> can't get the process of ripd."
+    echo " -> $test: TEST-FAIL"
+    if zebra_status=0
+    then
+        exec_service_on_target zebra stop
+    fi
+    if ripd_status=0
+    then
+        exec_service_on_target ripd stop
+    fi
+    restore_target
+    exit
+fi
+
+exec_service_on_target ripd stop
+exec_service_on_target zebra stop
+
+if ps aux | grep "[/]usr/sbin/ripd"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi
+if zebra_status=1
+then
+    exec_service_on_target zebra start
+fi
+if ripd_status=1
+then
+    exec_service_on_target ripd start
+fi
+restore_target
diff --git a/engine/tests/Functional.ripd/tests/ripd_syslog.sh b/engine/tests/Functional.ripd/tests/ripd_syslog.sh
new file mode 100644
index 0000000..f03db0b
--- /dev/null
+++ b/engine/tests/Functional.ripd/tests/ripd_syslog.sh
@@ -0,0 +1,109 @@
+#!/bin/sh
+
+#  In the target start ripd, and confirm the log file.
+
+test="syslog"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+logger_service=$(detect_logger_service)
+
+zebra_status=0
+ripd_status=0
+if exec_service_on_target ripd status | grep "running"
+then
+    ripd_status=1
+fi
+if exec_service_on_target zebra status | grep "running"
+then
+    zebra_status=1
+fi
+
+exec_service_on_target ripd stop
+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
+
+if [ -f /etc/quagga/ripd.conf ]
+then
+    mv /etc/quagga/ripd.conf /etc/quagga/ripd.conf_bak
+fi
+cp data/ripd.conf /etc/quagga/ripd.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 /etc/quagga/ripd.conf_bak ]
+    then
+        mv /etc/quagga/ripd.conf_bak /etc/quagga/ripd.conf
+    else
+        rm /etc/quagga/ripd.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
+
+if exec_service_on_target ripd start
+then
+    echo " -> start of ripd succeeded."
+else
+    echo " -> start of ripd failed."
+    echo " -> $test: TEST-FAIL"
+    if zebra_status=0
+    then
+        exec_service_on_target zebra stop
+    fi
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if tail /var/log/syslog | grep "ripd"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> can't get the syslog of ripd."
+    echo " -> $test: TEST-FAIL"
+fi
+
+if zebra_status=0
+then
+    exec_service_on_target zebra stop
+fi
+if ripd_status=0
+then
+    exec_service_on_target ripd stop
+fi
+restore_target
-- 
1.8.3.1





More information about the Fuego mailing list