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

Zheng Ruoqin zhengrq.fnst at cn.fujitsu.com
Thu Nov 15 18:00:34 UTC 2018


ospfd is an Open Shortest Path First (OSPF) daemon which manages routing tables.

Signed-off-by: Zheng Ruoqin <zhengrq.fnst at cn.fujitsu.com>
---
 engine/tests/Functional.ospfd/data/ospfd.conf      | 23 +++++++
 engine/tests/Functional.ospfd/data/zebra.conf      | 22 +++++++
 engine/tests/Functional.ospfd/fuego_test.sh        | 23 +++++++
 engine/tests/Functional.ospfd/ospfd_test.sh        |  4 ++
 engine/tests/Functional.ospfd/parser.py            | 22 +++++++
 engine/tests/Functional.ospfd/spec.json            |  6 ++
 engine/tests/Functional.ospfd/test.yaml            | 26 ++++++++
 .../tests/Functional.ospfd/tests/ospfd_logfile.sh  | 72 +++++++++++++++++++++
 .../tests/Functional.ospfd/tests/ospfd_pidfile.sh  | 63 +++++++++++++++++++
 engine/tests/Functional.ospfd/tests/ospfd_ps.sh    | 62 ++++++++++++++++++
 .../tests/Functional.ospfd/tests/ospfd_syslog.sh   | 73 ++++++++++++++++++++++
 11 files changed, 396 insertions(+)
 create mode 100644 engine/tests/Functional.ospfd/data/ospfd.conf
 create mode 100644 engine/tests/Functional.ospfd/data/zebra.conf
 create mode 100644 engine/tests/Functional.ospfd/fuego_test.sh
 create mode 100644 engine/tests/Functional.ospfd/ospfd_test.sh
 create mode 100644 engine/tests/Functional.ospfd/parser.py
 create mode 100644 engine/tests/Functional.ospfd/spec.json
 create mode 100644 engine/tests/Functional.ospfd/test.yaml
 create mode 100644 engine/tests/Functional.ospfd/tests/ospfd_logfile.sh
 create mode 100644 engine/tests/Functional.ospfd/tests/ospfd_pidfile.sh
 create mode 100644 engine/tests/Functional.ospfd/tests/ospfd_ps.sh
 create mode 100644 engine/tests/Functional.ospfd/tests/ospfd_syslog.sh

diff --git a/engine/tests/Functional.ospfd/data/ospfd.conf b/engine/tests/Functional.ospfd/data/ospfd.conf
new file mode 100644
index 0000000..ea0f155
--- /dev/null
+++ b/engine/tests/Functional.ospfd/data/ospfd.conf
@@ -0,0 +1,23 @@
+!
+! Zebra configuration saved from vty
+!   2000/01/01 02:22:47
+!
+hostname ospfd
+password zebra
+log file /var/log/quagga/ospfd.log
+log syslog informational
+!
+!
+!
+interface bmap
+!
+interface eth0
+!
+interface eth1
+!
+interface eth2
+!
+interface lo
+!
+line vty
+!
diff --git a/engine/tests/Functional.ospfd/data/zebra.conf b/engine/tests/Functional.ospfd/data/zebra.conf
new file mode 100644
index 0000000..7c8c216
--- /dev/null
+++ b/engine/tests/Functional.ospfd/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
+!
+!ipv6 forwarding
+!
+line vty
+!
diff --git a/engine/tests/Functional.ospfd/fuego_test.sh b/engine/tests/Functional.ospfd/fuego_test.sh
new file mode 100644
index 0000000..2721778
--- /dev/null
+++ b/engine/tests/Functional.ospfd/fuego_test.sh
@@ -0,0 +1,23 @@
+function test_pre_check {
+    is_on_target_path ospfd PROGRAM_OSPFD
+    assert_define PROGRAM_OSPFD "Missing 'ospfd' 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/ospfd_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"
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR; \
+        sh ospfd_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.ospfd/ospfd_test.sh b/engine/tests/Functional.ospfd/ospfd_test.sh
new file mode 100644
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.ospfd/ospfd_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/engine/tests/Functional.ospfd/parser.py b/engine/tests/Functional.ospfd/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.ospfd/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.ospfd/spec.json b/engine/tests/Functional.ospfd/spec.json
new file mode 100644
index 0000000..8800b6d
--- /dev/null
+++ b/engine/tests/Functional.ospfd/spec.json
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.ospfd",
+    "specs": {
+        "default": {}
+    }
+}
diff --git a/engine/tests/Functional.ospfd/test.yaml b/engine/tests/Functional.ospfd/test.yaml
new file mode 100644
index 0000000..988f612
--- /dev/null
+++ b/engine/tests/Functional.ospfd/test.yaml
@@ -0,0 +1,26 @@
+fuego_package_version: 1
+name: Functional.ospfd
+description: |
+      ospfd is an Open Shortest Path First (OSPF) daemon which manages routing tables. 
+      This implementation supports OSPF version 2, thus it is only capable of 
+      maintaining IPv4 routing tables.
+      This is a simple test to examine whether ospfd can start 
+      successfully and obtain the log. And zebra is the pre-service of ospfd.
+license: BSD-3-Clause
+author: Zheng Ruoqin <zhengrq.fnst at cn.fujitsu.com>
+maintainer: Tim Bird <tim.bird at sony.com>
+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
+data_files:
+ - ospfd_test.sh
+ - data
+ - fuego_test.sh
+ - parser.py
+ - spec.json
+ - tests
diff --git a/engine/tests/Functional.ospfd/tests/ospfd_logfile.sh b/engine/tests/Functional.ospfd/tests/ospfd_logfile.sh
new file mode 100644
index 0000000..d7ebc9d
--- /dev/null
+++ b/engine/tests/Functional.ospfd/tests/ospfd_logfile.sh
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+#  In the target start ospfd and zebra, then confirm the log file.
+#  check the /var/log/quagga/ospfd.log file.
+
+test="logfile"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target ospfd 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/ospfd.log ]
+then
+   mv /var/log/quagga/ospfd.log /var/log/quagga/ospfd.log.bck
+fi
+
+#Backup the config file
+mv /etc/quagga/ospfd.conf /etc/quagga/ospfd.conf.bck
+mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf.bck
+
+cp data/ospfd.conf /etc/quagga/ospfd.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 ospfd start
+then
+    echo " -> start of ospfd succeeded."
+else
+    echo " -> start of ospfd failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if ls /var/log/quagga/ospfd.log
+then
+    echo " -> get log file of ospfd."
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> can't get log file of ospfd."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+exec_service_on_target ospfd stop
+exec_service_on_target zebra stop
+
+#Restore the config file
+mv /etc/quagga/ospfd.conf.bck /etc/quagga/ospfd.conf
+mv /etc/quagga/zebra.conf.bck /etc/quagga/zebra.conf
+
+if [ -f /var/log/quagga/ospfd.log.bck ]
+then
+    mv /var/log/quagga/ospfd.log.bck /var/log/quagga/ospfd.log
+fi
diff --git a/engine/tests/Functional.ospfd/tests/ospfd_pidfile.sh b/engine/tests/Functional.ospfd/tests/ospfd_pidfile.sh
new file mode 100644
index 0000000..e447c54
--- /dev/null
+++ b/engine/tests/Functional.ospfd/tests/ospfd_pidfile.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+#  In the target start ospfd and zebra, then confirm the process condition by /var/run/quagga/ospfd.pid file.
+#  check the keyword "ospfd".
+
+test="pidfile"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target ospfd stop
+exec_service_on_target zebra stop
+rm -f /var/run/quagga/ospfd.pid
+
+#Backup the config file
+mv /etc/quagga/ospfd.conf /etc/quagga/ospfd.conf.bck
+mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf.bck
+
+cp data/ospfd.conf /etc/quagga/ospfd.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 ospfd start
+then
+    echo " -> start of ospfd succeeded."
+else
+    echo " -> start of ospfd failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if ls /var/run/quagga/ospfd.pid
+then
+    echo " -> get the pid of ospfd."
+else
+    echo " -> can't get the pid of ospfd."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+exec_service_on_target ospfd stop
+exec_service_on_target zebra stop
+
+if ls /var/run/quagga/ospfd.pid
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi
+
+#Restore the config file
+mv /etc/quagga/ospfd.conf.bck /etc/quagga/ospfd.conf
+mv /etc/quagga/zebra.conf.bck /etc/quagga/zebra.conf
diff --git a/engine/tests/Functional.ospfd/tests/ospfd_ps.sh b/engine/tests/Functional.ospfd/tests/ospfd_ps.sh
new file mode 100644
index 0000000..f9ab4a5
--- /dev/null
+++ b/engine/tests/Functional.ospfd/tests/ospfd_ps.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+#  In the target start ospfd and zebra, then confirm the process condition by command ps.
+#  check the keyword "quagga/ospfd".
+
+test="ps"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target ospfd stop
+exec_service_on_target zebra stop
+
+#Backup the config file
+mv /etc/quagga/ospfd.conf /etc/quagga/ospfd.conf.bck
+mv /etc/quagga/zebra.conf /etc/quagga/zebra.conf.bck
+
+cp data/ospfd.conf /etc/quagga/ospfd.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 ospfd start
+then
+    echo " -> start of ospfd succeeded."
+else
+    echo " -> start of ospfd failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if ps -N a | grep "quagga/[o]spfd"
+then
+    echo " -> get the pid of ospfd."
+else
+    echo " -> can't get the pid of ospfd."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+exec_service_on_target ospfd stop
+exec_service_on_target zebra stop
+
+if ps -N a | grep "quagga/[o]spfd"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi
+
+#Restore the config file
+mv /etc/quagga/ospfd.conf.bck /etc/quagga/ospfd.conf
+mv /etc/quagga/zebra.conf.bck /etc/quagga/zebra.conf
diff --git a/engine/tests/Functional.ospfd/tests/ospfd_syslog.sh b/engine/tests/Functional.ospfd/tests/ospfd_syslog.sh
new file mode 100644
index 0000000..19ccab3
--- /dev/null
+++ b/engine/tests/Functional.ospfd/tests/ospfd_syslog.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+#  In the target start ospfd and zebra.
+#  At the same time, start syslog-ng and check the keyword "ospfd" in syslog.
+
+test="syslog"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target ospfd stop
+exec_service_on_target zebra stop
+exec_service_on_target syslog-ng stop
+
+rm -f /var/run/quagga/ospfd.pid
+#Backup the config file
+mv /etc/quagga/ospfd.conf /etc/quagga/ospfd.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/ospfd.conf /etc/quagga/ospfd.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 ospfd start
+then
+    echo " -> start of ospfd succeeded."
+else
+    echo " -> start of ospfd failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if cat /var/log/syslog | grep "OSPF"
+then
+    echo " -> get the syslog of ospfd."
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> can't get the syslog of ospfd."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+exec_service_on_target ospfd stop
+exec_service_on_target zebra stop
+
+#Restore the config file
+mv /etc/quagga/ospfd.conf.bck /etc/quagga/ospfd.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





More information about the Fuego mailing list