Add test cases of service nscd.
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 | 4 ++ tests/Functional.nscd/parser.py | 22 +++++++++++ tests/Functional.nscd/spec.json | 7 ++++ tests/Functional.nscd/tests/nscd_pidfile.sh | 57 +++++++++++++++++++++++++++++ tests/Functional.nscd/tests/nscd_ps.sh | 51 ++++++++++++++++++++++++++ tests/Functional.nscd/tests/nscd_syslog.sh | 55 ++++++++++++++++++++++++++++ 7 files changed, 214 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
@@ -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 +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +done
tests/Functional.nscd/parser.py new file +22 -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') +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 +7 -0
@@ -0,0 +1,7 @@ +{ + "testName": "Functional.nscd", + "specs": { + "default": {} + } +} +
tests/Functional.nscd/tests/nscd_pidfile.sh new file +57 -0
57 lines not on this page · raw message
tests/Functional.nscd/tests/nscd_ps.sh new file +51 -0
51 lines not on this page · raw message
tests/Functional.nscd/tests/nscd_syslog.sh new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 1/1 Modify the function exec_service_on_target to get status of service.
--- scripts/fuego_board_function_lib.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
scripts/fuego_board_function_lib.sh +19 -2
@@ -11,6 +11,7 @@ init_manager="init_manager-not-set" logger_service="logger_service-not-set" +service_status="service-not-running" # set_init_manager: # detects and sets the init_manager variable, which indicates which
@@ -40,11 +41,27 @@ detect_logger_service() { # $1: service name # $2: action to perform (e.g. start, stop, restart) # relies on $init_manager being set prior to call +# returns: status of service exec_service_on_target() { if [ "$init_manager" = "systemd" ] then - systemctl $2 $1 + if [ "$2" = "status" ] + then + service_status=$(systemctl is-active $1) + else + systemctl $2 $1 + fi else - /etc/init.d/$1 $2 + if [ "$2" = "status" ] + then + if /etc/init.d/$1 status | grep "is running" + then + service_status="active" + fi + else +# service $1 $2 + /etc/init.d/$1 $2 + fi fi + echo $service_status }
Signature · 1 line
1.8.3.1
Re: [Fuego] [PATCH] Modify the function exec_service_on_target to get status of service.
Thank you for this update. Please see comments inline below.
Quoted 3 lines
-----Original Message-----
From: Wang Mingyu
This patch needs a message for the body of the commit, explaining what the patch does.
Quoted 11 lines
Signed-off-by Wang Mingyu <[email protected]>--- scripts/fuego_board_function_lib.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)scripts/fuego_board_function_lib.sh +0
-0
scripts/fuego_board_function_lib.sh line 14
Quoted 4 lines
scripts/fuego_board_function_lib.sh +1
-0@@ -11,6 +11,7 @@ init_manager="init_manager-not-set" logger_service="logger_service-not-set" +service_status="service-not-running"
This should be "unknown" or something like that.
It is not correct to assume the service is not running, if, for example, the service rc script doesn't support the 'status' operation.
More comments on this below.
Quoted 8 lines
scripts/fuego_board_function_lib.sh +1
-0# set_init_manager: # detects and sets the init_manager variable, which indicates which@@ -40,11 +41,27 @@ detect_logger_service() { # $1: service name # $2: action to perform (e.g. start, stop, restart) # relies on $init_manager being set prior to call +# returns: status of service
scripts/fuego_board_function_lib.sh detect_logger_service() { · line 53
Quoted 10 lines
scripts/fuego_board_function_lib.sh +6
-1exec_service_on_target() { if [ "$init_manager" = "systemd" ] then - systemctl $2 $1 + if [ "$2" = "status" ] + then + service_status=$(systemctl is-active $1) + else + systemctl $2 $1 + fi
This is a nice improvement. Thanks.
scripts/fuego_board_function_lib.sh detect_logger_service() { · line 62
Quoted 10 lines
scripts/fuego_board_function_lib.sh +8
-1else - /etc/init.d/$1 $2 + if [ "$2" = "status" ] + then + if /etc/init.d/$1 status | grep "is running" + then + service_status="active" + fi + else +# service $1 $2
What is the purpose of this comment?
scripts/fuego_board_function_lib.sh detect_logger_service() { · line 66
Quoted 4 lines
scripts/fuego_board_function_lib.sh +3
-0+ /etc/init.d/$1 $2 + fi fi + echo $service_status
Is this right? Is it correct to echo the service status if the action was start or stop?
Quoted 3 lines
scripts/fuego_board_function_lib.sh +0
-1} --1.8.3.1
Two things here:
1) there's no code that uses 'service'. This seems like it was the successor to directly calling the rc script, and the predecessor to systemctl. I don't know if there are very many systems out there that use service, but don't allow directly calling the rc script (that aren't also system-based). That is to say, it's hard to know if making a third option for the init_manager is worthwhile or not. But that's independent, I think, of the current patch.
2) we should use 'unknown' when the status is unknown.
In general, I think that if the rc script does not support the 'status' operation, then we should return 'unknown' for the status, and then let the script decide whether to abort or continue, based on that status.
Please let me know what you think.
-- Tim
Applied to fuegotest/fuego-core next branch.
Thanks. There are some comments inline below.
-- Tim
Quoted 7 lines
-----Original Message-----
From: Wang MingyuThe 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.
I word-wrapped this a bit better.
Quoted 95 lines
Signed-off-by Wang Mingyu <[email protected]>--- tests/Functional.nscd/fuego_test.sh | 18 +++++++++ tests/Functional.nscd/nscd_test.sh | 4 ++ tests/Functional.nscd/parser.py | 22 +++++++++++ tests/Functional.nscd/spec.json | 7 ++++ tests/Functional.nscd/tests/nscd_pidfile.sh | 57 +++++++++++++++++++++++++++++ tests/Functional.nscd/tests/nscd_ps.sh | 51 ++++++++++++++++++++++++++ tests/Functional.nscd/tests/nscd_syslog.sh | 55 ++++++++++++++++++++++++++++ 7 files changed, 214 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.shtests/Functional.nscd/fuego_test.sh new file +7
-0@@ -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 +4
-0@@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +donetests/Functional.nscd/parser.py new file +22
-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') +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 +0
-0
tests/Functional.nscd/spec.json line 7
Quoted 7 lines
tests/Functional.nscd/spec.json new file +7
-0@@ -0,0 +1,7 @@ +{ + "testName": "Functional.nscd", + "specs": { + "default": {} + } +} +
I removed this extra newline at the end of the spec.json file.
Quoted 130 lines
tests/Functional.nscd/tests/nscd_pidfile.sh new file +57
-0@@ -0,0 +1,57 @@ +#!/bin/sh + +# In the target start nscd, and check if the /var/run/nscd.pid is exist +# check the keyword "nscd". + +test="pidfile" + +. ./fuego_board_function_lib.sh + +set_init_manager + +nscd_status=$(exec_service_on_target nscd status) + +exec_service_on_target nscd stop + +if [ -f /run/nscd/nscd.pid ] +then + 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 +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" != "active" ] + then + exec_service_on_target nscd stop + fi + exit +fi + +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" ] +then + exec_service_on_target nscd start +fitests/Functional.nscd/tests/nscd_ps.sh new file +3
-0@@ -0,0 +1,51 @@ +#!/bin/sh + +# In the target start nscd, and confirm the process condition by commandps.
tests/Functional.nscd/tests/nscd_ps.sh new file +48
-0+ +test="ps" + +. ./fuego_board_function_lib.sh + +set_init_manager + +nscd_status=$(exec_service_on_target nscd status) + +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" != "active" ] + then + exec_service_on_target nscd stop + fi + exit +fi + +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" ] +then + exec_service_on_target nscd start +fitests/Functional.nscd/tests/nscd_syslog.sh new file +0
-0
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,55 @@ +#!/bin/sh + +# In the target start nscd, and check the messages of /var/log/syslog. +# check the keyword "nscd". + +test="syslog" + +. ./fuego_board_function_lib.sh + +set_init_manager
If we're going to use set_init_manager in every sub-test script, it might be more efficient to just call it once in nscd_test.sh and pass the value of 'init_manager as a shell variable to all the sub-test scripts.
Quoted 34 lines
tests/Functional.nscd/tests/nscd_syslog.sh new file +34
-0+ +nscd_status=$(exec_service_on_target nscd status) + +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
tests/Functional.nscd/tests/nscd_syslog.sh line 55
Quoted 10 lines
tests/Functional.nscd/tests/nscd_syslog.sh new file +10
-0+ echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +if [ "$nscd_status" != "active" ] +then + exec_service_on_target nscd stop +fi +restore_target
This will stop the service, if the status is "unknown", which might not be correct. However, I'm fine leaving this as is for now.
Quoted 2 lines
--
1.8.3.1
Thanks.
-- Tim