[Fuego] [PATCH v2] dhcpd: Add test cases of service dhcpd.
Wang Mingyu
wangmy at cn.fujitsu.com
Thu Apr 18 23:39:10 UTC 2019
DHCP allows hosts on a TCP/IP network to request and be assigned IP addresses, and also to discover information about the network to which they are attached.
This is a simple test to check the service can start successfully.
Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
---
tests/Functional.dhcpd/data/change_dhcpd.conf | 5 ++
tests/Functional.dhcpd/data/dhcpd.conf | 18 ++++++
tests/Functional.dhcpd/dhcpd_test.sh | 4 ++
tests/Functional.dhcpd/fuego_test.sh | 21 ++++++
tests/Functional.dhcpd/parser.py | 20 ++++++
tests/Functional.dhcpd/spec.json | 6 ++
tests/Functional.dhcpd/test.yaml | 26 ++++++++
tests/Functional.dhcpd/tests/dhcpd_pidfile.sh | 93 +++++++++++++++++++++++++++
tests/Functional.dhcpd/tests/dhcpd_ps.sh | 88 +++++++++++++++++++++++++
tests/Functional.dhcpd/tests/dhcpd_syslog.sh | 90 ++++++++++++++++++++++++++
10 files changed, 371 insertions(+)
create mode 100644 tests/Functional.dhcpd/data/change_dhcpd.conf
create mode 100644 tests/Functional.dhcpd/data/dhcpd.conf
create mode 100644 tests/Functional.dhcpd/dhcpd_test.sh
create mode 100644 tests/Functional.dhcpd/fuego_test.sh
create mode 100644 tests/Functional.dhcpd/parser.py
create mode 100644 tests/Functional.dhcpd/spec.json
create mode 100644 tests/Functional.dhcpd/test.yaml
create mode 100644 tests/Functional.dhcpd/tests/dhcpd_pidfile.sh
create mode 100644 tests/Functional.dhcpd/tests/dhcpd_ps.sh
create mode 100644 tests/Functional.dhcpd/tests/dhcpd_syslog.sh
diff --git a/tests/Functional.dhcpd/data/change_dhcpd.conf b/tests/Functional.dhcpd/data/change_dhcpd.conf
new file mode 100644
index 0000000..8e79207
--- /dev/null
+++ b/tests/Functional.dhcpd/data/change_dhcpd.conf
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+echo " subnet 192.168.246.0 netmask 255.255.255.0 {" >> /etc/dhcp/dhcpd.conf
+echo " range 192.168.246.200 192.168.246.210;" >> /etc/dhcp/dhcpd.conf
+echo " } " >> /etc/dhcp/dhcpd.conf
diff --git a/tests/Functional.dhcpd/data/dhcpd.conf b/tests/Functional.dhcpd/data/dhcpd.conf
new file mode 100644
index 0000000..2ce38b8
--- /dev/null
+++ b/tests/Functional.dhcpd/data/dhcpd.conf
@@ -0,0 +1,18 @@
+# /etc/dhcpd.conf
+
+ddns-update-style none;
+#deny unknown-clients;
+#allow bootp;
+
+# subnet 192.168.0.0 netmask 255.255.255.0 {
+subnet 192.168.246.0 netmask 255.255.255.0 {
+
+ range 192.168.246.100 192.168.246.110;
+# option routers 192.168.0.1;
+ option broadcast-address 192.168.246.255;
+
+ default-lease-time 3600; # 1h
+ max-lease-time 7200; # 2h
+
+}
+
diff --git a/tests/Functional.dhcpd/dhcpd_test.sh b/tests/Functional.dhcpd/dhcpd_test.sh
new file mode 100644
index 0000000..dd5ce37
--- /dev/null
+++ b/tests/Functional.dhcpd/dhcpd_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+ sh $i
+done
diff --git a/tests/Functional.dhcpd/fuego_test.sh b/tests/Functional.dhcpd/fuego_test.sh
new file mode 100644
index 0000000..7710bf6
--- /dev/null
+++ b/tests/Functional.dhcpd/fuego_test.sh
@@ -0,0 +1,21 @@
+function test_pre_check {
+ is_on_target_path dhcpd PROGRAM_DHCPD
+ assert_define PROGRAM_DHCPD "Missing 'dhcpd' program on target board"
+}
+
+function test_deploy {
+ put $TEST_HOME/dhcpd_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+ put $FUEGO_CORE/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 "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+ export remote_ifeth=$IFETH;\
+ ./dhcpd_test.sh"
+}
+
+function test_processing {
+ log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/tests/Functional.dhcpd/parser.py b/tests/Functional.dhcpd/parser.py
new file mode 100644
index 0000000..f25a608
--- /dev/null
+++ b/tests/Functional.dhcpd/parser.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+# See common.py for description of command-line arguments
+
+import os, sys, collections
+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/tests/Functional.dhcpd/spec.json b/tests/Functional.dhcpd/spec.json
new file mode 100644
index 0000000..1cf5e10
--- /dev/null
+++ b/tests/Functional.dhcpd/spec.json
@@ -0,0 +1,6 @@
+{
+ "testName": "Functional.dhcpd",
+ "specs": {
+ "default": {}
+ }
+}
diff --git a/tests/Functional.dhcpd/test.yaml b/tests/Functional.dhcpd/test.yaml
new file mode 100644
index 0000000..8af6bd6
--- /dev/null
+++ b/tests/Functional.dhcpd/test.yaml
@@ -0,0 +1,26 @@
+fuego_package_version: 1
+name: Functional.dhcpd
+description: |
+ The Internet Systems Consortium DHCP Server, dhcpd, implements the Dynamic Host Configuration Protocol (DHCP) and the Internet Bootstrap Protocol (BOOTP).
+ DHCP allows hosts on a TCP/IP network to request and be assigned IP addresses, and also to discover information about the network to which they are attached.
+ BOOTP provides similar functionality, with certain restrictions.
+ This is a simple test to check the service can start successfully.
+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: ['vlan']
+params:
+ IFETH="the eth interface in your target board" Defined in board file
+data_files:
+ - dhcpd_test.sh
+ - fuego_test.sh
+ - parser.py
+ - spec.json
+ - test.yaml
+ - tests
+ dhcpd_ps.sh
+ dhcpd_pidfile.sh
+ dhcpd_syslog.sh
diff --git a/tests/Functional.dhcpd/tests/dhcpd_pidfile.sh b/tests/Functional.dhcpd/tests/dhcpd_pidfile.sh
new file mode 100644
index 0000000..4970ee6
--- /dev/null
+++ b/tests/Functional.dhcpd/tests/dhcpd_pidfile.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+# In the target start dhcpd, and check if the /var/run/dhcpd.pid is exist
+# check the keyword "dhcpd".
+
+test="pidfile"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+dhcpd_status=$(exec_service_on_target dhcpd is-active)
+dnsmasq_status=$(exec_service_on_target dnsmasq is-active)
+
+exec_service_on_target dhcpd stop
+exec_service_on_target dnsmasq stop
+
+if [ -f /var/run/dhcpd.pid ]
+then
+ rm -f /var/run/dhcpd.pid
+fi
+
+if [ -f /etc/dhcp/dhcpd.conf ]
+then
+ cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf_bak
+fi
+
+if [ -e /etc/default/dhcp-server ]
+then
+ cp /etc/default/dhcp-server /etc/default/dhcp-server_bak
+fi
+
+echo "INTERFACES="$remote_ifeth"" > /etc/default/dhcp-server
+
+cp data/change_dhcpd.conf /etc/
+
+chmod +x /etc/change_dhcpd.conf
+
+restore_target(){
+ rm -f /etc/change_dhcpd.conf
+ if [ -f /etc/dhcp/dhcpd.conf_bak ]
+ then
+ mv /etc/dhcp/dhcpd.conf_bak /etc/dhcp/dhcpd.conf
+ fi
+
+ if [ -e /etc/default/dhcp-server ]
+ then
+ mv /etc/default/dhcp-server_bak /etc/default/dhcp-server
+ fi
+ if [ "$dnsmasq_status" = "active" ]
+ then
+ exec_service_on_target dnsmasq start
+ fi
+ if [ "$dhcpd_status" = "active" ]
+ then
+ exec_service_on_target dhcpd start
+ fi
+}
+
+/etc/change_dhcpd.conf
+
+if exec_service_on_target dhcpd start
+then
+ echo " -> start of dhcpd succeeded."
+else
+ echo " -> start of dhcpd failed."
+ echo " -> $test: TEST-FAIL"
+ restore_target
+ exit
+fi
+
+sleep 10
+
+if test -f /var/run/dhcpd.pid
+then
+ echo " -> get the pidfile of dhcpd."
+else
+ echo " -> can't get the pidfile of dhcpd."
+ echo " -> $test: TEST-FAIL"
+ exec_service_on_target dhcpd stop
+ restore_target
+ exit
+fi
+
+exec_service_on_target dhcpd stop
+
+if test ! -f /var/run/dhcpd.pid
+then
+ echo " -> $test: TEST-PASS"
+else
+ echo " -> $test: TEST-FAIL"
+fi
+restore_target
diff --git a/tests/Functional.dhcpd/tests/dhcpd_ps.sh b/tests/Functional.dhcpd/tests/dhcpd_ps.sh
new file mode 100644
index 0000000..2896ba1
--- /dev/null
+++ b/tests/Functional.dhcpd/tests/dhcpd_ps.sh
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+# In the target start dhcpd, and confirm the process condition by command ps.
+# check the keyword "dhcpd".
+
+test="ps"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+dhcpd_status=$(exec_service_on_target dhcpd is-active)
+dnsmasq_status=$(exec_service_on_target dnsmasq is-active)
+
+exec_service_on_target dhcpd stop
+exec_service_on_target dnsmasq stop
+
+if [ -e /etc/default/dhcp-server ]
+then
+ cp /etc/default/dhcp-server /etc/default/dhcp-server_bak
+fi
+
+echo "INTERFACES="$remote_ifeth"" > /etc/default/dhcp-server
+
+if [ -e /etc/dhcp/dhcpd.conf ]
+then
+ mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf_bak
+fi
+
+cp data/change_dhcpd.conf /etc/
+
+restore_target(){
+ rm -f /etc/change_dhcpd.conf
+ if [ -f /etc/dhcp/dhcpd.conf_bak ]
+ then
+ mv /etc/dhcp/dhcpd.conf_bak /etc/dhcp/dhcpd.conf
+ fi
+
+ if [ -e /etc/default/dhcp-server ]
+ then
+ mv /etc/default/dhcp-server_bak /etc/default/dhcp-server
+ fi
+ if [ "$dnsmasq_status" = "active" ]
+ then
+ exec_service_on_target dnsmasq start
+ fi
+ if [ "$dhcpd_status" = "active" ]
+ then
+ exec_service_on_target dhcpd start
+ fi
+}
+
+chmod +x /etc/change_dhcpd.conf
+
+/etc/change_dhcpd.conf
+
+if exec_service_on_target dhcpd start
+then
+ echo " -> start of dhcpd succeeded."
+else
+ echo " -> start of dhcpd failed."
+ echo " -> $test: TEST-FAIL"
+ restore_target
+ exit
+fi
+
+sleep 10
+
+if ps aux | grep "[/]usr/sbin/dhcpd"
+then
+ echo " -> get the pid of dhcpd."
+else
+ echo " -> can't get the pid of dhcpd."
+ echo " -> $test: TEST-FAIL"
+ exec_service_on_target dhcpd stop
+ restore_target
+ exit
+fi
+
+exec_service_on_target dhcpd stop
+
+if ps aux | grep "[/]usr/sbin/dhcpd"
+then
+ echo " -> $test: TEST-FAIL"
+else
+ echo " -> $test: TEST-PASS"
+fi
+restore_target
diff --git a/tests/Functional.dhcpd/tests/dhcpd_syslog.sh b/tests/Functional.dhcpd/tests/dhcpd_syslog.sh
new file mode 100644
index 0000000..e53dd69
--- /dev/null
+++ b/tests/Functional.dhcpd/tests/dhcpd_syslog.sh
@@ -0,0 +1,90 @@
+#!/bin/sh
+
+# In the target start dhcpd, and check the messages of /var/log/syslog.
+# check the keyword "dhcpd".
+
+test="syslog"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+logger_service=$(detect_logger_service)
+
+dhcpd_status=$(exec_service_on_target dhcpd is-active)
+dnsmasq_status=$(exec_service_on_target dnsmasq is-active)
+
+exec_service_on_target dhcpd stop
+exec_service_on_target $logger_service stop
+
+if [ -f /var/log/syslog ]
+then
+ mv /var/log/syslog /var/log/syslog_bak
+fi
+
+if [ -e /etc/default/dhcp-server ]
+then
+ cp /etc/default/dhcp-server /etc/default/dhcp-server_bak
+fi
+
+echo "INTERFACES="$remote_ifeth"" > /etc/default/dhcp-server
+
+if [ -f /etc/dhcp/dhcpd.conf ]
+then
+ cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf_bak
+fi
+
+cp data/change_dhcpd.conf /etc/
+
+restore_target(){
+ rm -f /etc/change_dhcpd.conf
+ if [ -f /etc/dhcp/dhcpd.conf_bak ]
+ then
+ mv /etc/dhcp/dhcpd.conf_bak /etc/dhcp/dhcpd.conf
+ fi
+
+ if [ -e /etc/default/dhcp-server ]
+ then
+ mv /etc/default/dhcp-server_bak /etc/default/dhcp-server
+ fi
+
+ if [ -f /var/log/syslog_bak ]
+ then
+ mv /var/log/syslog_bak /var/log/syslog
+ fi
+ if [ "$dnsmasq_status" = "active" ]
+ then
+ exec_service_on_target dnsmasq start
+ fi
+ if [ "$dhcpd_status" = "active" ]
+ then
+ exec_service_on_target dhcpd start
+ fi
+}
+
+chmod +x /etc/change_dhcpd.conf
+
+/etc/change_dhcpd.conf
+
+exec_service_on_target $logger_service restart
+
+if exec_service_on_target dhcpd start
+then
+ echo " -> start of dhcpd succeeded."
+else
+ echo " -> start of dhcpd failed."
+ echo " -> $test: TEST-FAIL"
+ restore_target
+ exit
+fi
+
+sleep 10
+
+if cat /var/log/syslog | grep "dhcpd"
+then
+ echo " -> $test: TEST-PASS"
+else
+ echo " -> $test: TEST-FAIL"
+fi
+
+exec_service_on_target dhcpd stop
+restore_target
--
1.8.3.1
More information about the Fuego
mailing list