Skip to contentSkip to conversation

Add test cases of service nscd.

PATCH Superseded Wang Mingyu 2 participants 4 messages Feb 19, 2019 – Feb 27, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add test cases of service nscd.

The nscd is a daemon that provides a cache for the most common name service requests. This test set is used to check if the ps, pidfile and syslog of the service can be generated successfully.

---
 tests/Functional.nscd/fuego_test.sh         | 18 ++++++++++
 tests/Functional.nscd/nscd_test.sh          |  7 ++++
 tests/Functional.nscd/parser.py             | 22 ++++++++++++
 tests/Functional.nscd/spec.json             |  6 ++++
 tests/Functional.nscd/tests/nscd_pidfile.sh | 53 +++++++++++++++++++++++++++++
 tests/Functional.nscd/tests/nscd_ps.sh      | 47 +++++++++++++++++++++++++
 tests/Functional.nscd/tests/nscd_syslog.sh  | 52 ++++++++++++++++++++++++++++
 7 files changed, 205 insertions(+)
 create mode 100644 tests/Functional.nscd/fuego_test.sh
 create mode 100755 tests/Functional.nscd/nscd_test.sh
 create mode 100644 tests/Functional.nscd/parser.py
 create mode 100644 tests/Functional.nscd/spec.json
 create mode 100644 tests/Functional.nscd/tests/nscd_pidfile.sh
 create mode 100644 tests/Functional.nscd/tests/nscd_ps.sh
 create mode 100644 tests/Functional.nscd/tests/nscd_syslog.sh
tests/Functional.nscd/fuego_test.sh new file +18 -0
new file mode 100644
index 0000000..f27e1d0
@@ -0,0 +1,18 @@
+function test_pre_check {
+    assert_has_program nscd
+}
+
+function test_deploy {
+    put $TEST_HOME/nscd_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/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./nscd_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.nscd/nscd_test.sh new file +7 -0
new file mode 100755
index 0000000..95c34db
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ./fuego_board_function_lib.sh
+set_init_manager
+
+for i in tests/*.sh; do
+    source $i
+done
tests/Functional.nscd/parser.py new file +22 -0
new file mode 100644
index 0000000..d85abd7
@@ -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))
tests/Functional.nscd/spec.json new file +6 -0
new file mode 100644
index 0000000..7c7f785
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.nscd",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.nscd/tests/nscd_pidfile.sh new file +53 -0

53 lines not on this page · raw message

tests/Functional.nscd/tests/nscd_ps.sh new file +47 -0

47 lines not on this page · raw message

tests/Functional.nscd/tests/nscd_syslog.sh new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 Add the function get_service_status to get status of service.

Add the variable service_status to store the status of the service.

---
 scripts/fuego_board_function_lib.sh | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
scripts/fuego_board_function_lib.sh +24 -2
index 4c29bf3..41b94ba 100644
@@ -11,6 +11,7 @@
 
 init_manager="init_manager-not-set"
 logger_service="logger_service-not-set"
+service_status="unknown"
 
 # set_init_manager:
 #   detects and sets the init_manager variable, which indicates which
@@ -43,8 +44,29 @@ detect_logger_service() {
 exec_service_on_target() {
     if [ "$init_manager" = "systemd" ]
     then
-        systemctl $2 $1
+            systemctl $2 $1
     else
-        /etc/init.d/$1 $2
+            service $1 $2
     fi
 }
+
+# get_service_status:
+#  get status of service 
+# returns: status of service
+get_service_status() {
+    if [ "$init_manager" = "systemd" ]
+    then
+        service_status=$(systemctl is-active $1)
+    else
+        if service $1 status | grep "is running"
+        then
+            service_status="active"
+        else
+            if service $1 status | grep "is stopped"
+            then
+                service_status="inactive"
+            fi
+        fi
+    fi
+    echo $service_status
+}
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [Fuego] [PATCH] Add the function get_service_status to get status of service.

See comments inline below.

Quoted 24 lines

-----Original Message-----
From: Wang Mingyu

Add the variable service_status to store the status of the service.

---
 scripts/fuego_board_function_lib.sh | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
scripts/fuego_board_function_lib.sh +1 -0
index 4c29bf3..41b94ba 100644
@@ -11,6 +11,7 @@
 
 init_manager="init_manager-not-set"
 logger_service="logger_service-not-set"
+service_status="unknown"
 
 # set_init_manager:
 #   detects and sets the init_manager variable, which indicates which

scripts/fuego_board_function_lib.sh detect_logger_service() { · line 47

Quoted 5 lines
scripts/fuego_board_function_lib.sh +1 -1
@@ -43,8 +44,29 @@ detect_logger_service() {
 exec_service_on_target() {
     if [ "$init_manager" = "systemd" ]
     then
-        systemctl $2 $1
+            systemctl $2 $1

I'm not sure why you are changing the indentation level here. I'm omitting this part of the patch.

scripts/fuego_board_function_lib.sh detect_logger_service() { · line 49

Quoted 3 lines
scripts/fuego_board_function_lib.sh +1 -1
     else
-        /etc/init.d/$1 $2
+            service $1 $2

OK - but I kept the indentation level the same (4 spaces).

scripts/fuego_board_function_lib.sh detect_logger_service() { · line 56

Quoted 7 lines
scripts/fuego_board_function_lib.sh +5 -0
     fi
 }
+
+# get_service_status:
+#  get status of service
+# returns: status of service
+get_service_status() {

get_service_status might be called more than once, and with different services. I decided to reset $service_status to "unknown" every time this function is called, to avoid getting the result from a previous call.

Quoted 17 lines
scripts/fuego_board_function_lib.sh +16 -1
+    if [ "$init_manager" = "systemd" ]
+    then
+        service_status=$(systemctl is-active $1)
+    else
+        if service $1 status | grep "is running"
+        then
+            service_status="active"
+        else
+            if service $1 status | grep "is stopped"
+            then
+                service_status="inactive"
+            fi
+        fi
+    fi
+    echo $service_status
+}
--
Quoted 1 line

1.8.3.1

Applied, with some slight modifications. Thanks.
-- Tim

#3 lore raw
In reply to Wang Mingyu

I had already applied the previous version of this patch in my next branch. In order to apply the new changes, I had to apply pieces of this patch (the new parts) manually.

Please make sure that patches are against the fuegotest fuego-core 'next' branch, and hand-editing the changes is a lot of work.

Quoted 62 lines

-----Original Message-----
From: Wang Mingyu

The nscd is a daemon that provides a cache for the most common name service requests.
This test set is used to check if the ps, pidfile and syslog of the service can be generated successfully.

---
 tests/Functional.nscd/fuego_test.sh         | 18 ++++++++++
 tests/Functional.nscd/nscd_test.sh          |  7 ++++
 tests/Functional.nscd/parser.py             | 22 ++++++++++++
 tests/Functional.nscd/spec.json             |  6 ++++
 tests/Functional.nscd/tests/nscd_pidfile.sh | 53
+++++++++++++++++++++++++++++
 tests/Functional.nscd/tests/nscd_ps.sh      | 47
+++++++++++++++++++++++++
 tests/Functional.nscd/tests/nscd_syslog.sh  | 52
++++++++++++++++++++++++++++
 7 files changed, 205 insertions(+)
 create mode 100644 tests/Functional.nscd/fuego_test.sh
 create mode 100755 tests/Functional.nscd/nscd_test.sh
 create mode 100644 tests/Functional.nscd/parser.py
 create mode 100644 tests/Functional.nscd/spec.json
 create mode 100644 tests/Functional.nscd/tests/nscd_pidfile.sh
 create mode 100644 tests/Functional.nscd/tests/nscd_ps.sh
 create mode 100644 tests/Functional.nscd/tests/nscd_syslog.sh
tests/Functional.nscd/fuego_test.sh new file +7 -0
new file mode 100644
index 0000000..f27e1d0
@@ -0,0 +1,18 @@
+function test_pre_check {
+    assert_has_program nscd
+}
+
+function test_deploy {
+    put $TEST_HOME/nscd_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put $FUEGO_CORE/engine/scripts/fuego_board_function_lib.sh

$BOARD_TESTDIR/fuego.$TESTDIR

tests/Functional.nscd/fuego_test.sh new file +11 -0
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./nscd_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.nscd/nscd_test.sh new file +0 -0
new file mode 100755
index 0000000..95c34db

tests/Functional.nscd/nscd_test.sh line 6

Quoted 6 lines
tests/Functional.nscd/nscd_test.sh new file +6 -0
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ./fuego_board_function_lib.sh
+set_init_manager
+
+for i in tests/*.sh; do
+    source $i

This is a rather big change from 'sh $i'.
I'll comment more on this below.

Quoted 8 lines
tests/Functional.nscd/nscd_test.sh new file +1 -0
+done
tests/Functional.nscd/parser.py new file +0 -0
new file mode 100644
index 0000000..d85abd7

tests/Functional.nscd/parser.py line 6

Quoted 6 lines
tests/Functional.nscd/parser.py new file +6 -0
@@ -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')

I removed the above line as it is no longer needed.

Quoted 36 lines
tests/Functional.nscd/parser.py new file +16 -0
+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))
tests/Functional.nscd/spec.json new file +6 -0
new file mode 100644
index 0000000..7c7f785
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.nscd",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.nscd/tests/nscd_pidfile.sh new file +0 -0
new file mode 100644
index 0000000..42225bb

tests/Functional.nscd/tests/nscd_pidfile.sh line 8

Quoted 8 lines
tests/Functional.nscd/tests/nscd_pidfile.sh new file +8 -0
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+#  In the target start nscd, and check if the /var/run/nscd.pid is exist
+#  check the keyword "nscd".
+
+test="pidfile"
+
+nscd_status=$(get_service_status)

You are missing the service name here ('nscd'). I added it.

Quoted 5 lines
tests/Functional.nscd/tests/nscd_pidfile.sh new file +5 -0
+
+exec_service_on_target nscd stop
+
+if [ -f /run/nscd/nscd.pid ]
+then

tests/Functional.nscd/tests/nscd_pidfile.sh line 23

Quoted 10 lines
tests/Functional.nscd/tests/nscd_pidfile.sh new file +10 -0
+    rm -f /run/nscd/nscd.pid
+fi
+
+if exec_service_on_target nscd start
+then
+    echo " -> start of nscd succeeded."
+else
+    echo " -> start of nscd failed."
+    echo " -> $test: TEST-FAIL"
+    exit

I believe this will exit the shell before other tests can execute. I'm not sure this structure works when you use 'source' instead of 'sh' to execute the sub-tests.
I believe that if you get a single failure, the other tests will fail to execute.

This is an issue with all uses of 'exit' in all the sub-test scripts, I believe.

Quoted 17 lines
tests/Functional.nscd/tests/nscd_pidfile.sh new file +17 -0
+fi
+
+sleep 10
+
+if test -f /run/nscd/nscd.pid
+then
+    echo " -> get the pidfile of nscd."
+else
+    echo " -> can't get the pidfile of nscd."
+    echo " -> $test: TEST-FAIL"
+    if [ "$nscd_status" = "inactive" ]
+    then
+        exec_service_on_target nscd stop
+    fi
+    exit
+fi
+

tests/Functional.nscd/tests/nscd_pidfile.sh line 50

Quoted 10 lines
tests/Functional.nscd/tests/nscd_pidfile.sh new file +10 -0
+exec_service_on_target nscd stop
+
+if test ! -f /run/nscd/nscd.pid
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+if [ "$nscd_status" = "active" ] || [ "$nscd_status" = "unknown" ]

|| might not be supported. I converted this to '-o' instead.

Quoted 14 lines
tests/Functional.nscd/tests/nscd_pidfile.sh new file +3 -0
+then
+    exec_service_on_target nscd start
+fi
tests/Functional.nscd/tests/nscd_ps.sh new file +3 -0
new file mode 100644
index 0000000..8529924
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+#  In the target start nscd, and confirm the process condition by command

ps.

tests/Functional.nscd/tests/nscd_ps.sh line 7

Quoted 4 lines
tests/Functional.nscd/tests/nscd_ps.sh new file +4 -0
+
+test="ps"
+
+nscd_status=$(get_service_status)

This call is missing the service name ('nscd'). I added it.

Quoted 27 lines
tests/Functional.nscd/tests/nscd_ps.sh new file +27 -0
+
+exec_service_on_target nscd stop
+
+if exec_service_on_target nscd start
+then
+    echo " -> start of nscd succeeded."
+else
+    echo " -> start of nscd failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+sleep 5
+
+if ps aux | grep "[/]usr/sbin/nscd"
+then
+    echo " -> get the process of nscd."
+else
+    echo " -> can't get the process of nscd."
+    echo " -> $test: TEST-FAIL"
+    if [ "$nscd_status" = "inactive" ]
+    then
+        exec_service_on_target nscd stop
+    fi
+    exit
+fi
+

tests/Functional.nscd/tests/nscd_ps.sh line 44

Quoted 10 lines
tests/Functional.nscd/tests/nscd_ps.sh new file +10 -0
+exec_service_on_target nscd stop
+
+if ps aux | grep "[/]usr/sbin/nscd"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi
+
+if [ "$nscd_status" = "active" ] || [ "$nscd_status" = "unknown" ]

|| might not be supported. I switched this to '-o' instead.

Quoted 10 lines
tests/Functional.nscd/tests/nscd_ps.sh new file +3 -0
+then
+    exec_service_on_target nscd start
+fi
tests/Functional.nscd/tests/nscd_syslog.sh new file +0 -0
new file mode 100644
index 0000000..e8141fb

tests/Functional.nscd/tests/nscd_syslog.sh line 10

Quoted 10 lines
tests/Functional.nscd/tests/nscd_syslog.sh new file +10 -0
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+#  In the target start nscd, and check the messages of /var/log/syslog.
+#  check the keyword "nscd".
+
+test="syslog"
+
+logger_service=$(detect_logger_service)
+
+nscd_status=$(get_service_status)

This was missing the service name. I added it.

Quoted 43 lines
tests/Functional.nscd/tests/nscd_syslog.sh new file +42 -1
+
+exec_service_on_target nscd stop
+exec_service_on_target $logger_service stop
+
+if [ -f /var/log/syslog ]
+then
+    mv /var/log/syslog /var/log/syslog_bak
+fi
+
+restore_target(){
+    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 nscd start
+then
+    echo " -> start of nscd succeeded."
+else
+    echo " -> start of nscd failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 10
+
+if cat /var/log/syslog | grep "starting up"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+if [ "$nscd_status" = "inactive" ]
+then
+    exec_service_on_target nscd stop
+fi
+restore_target
--
Quoted 1 line

1.8.3.1

I had to make some changes, but this patch was applied.

Please check out my changes in the fuegotest fuego-core 'next' branch and let me know if anything I did broke something in this test.

Thanks,
-- Tim