Return-Path: From: Wang Mingyu Date: Wed, 21 Nov 2018 00:08:55 -0800 Message-ID: <1542787735-36170-7-git-send-email-wangmy@cn.fujitsu.com> In-Reply-To: <1542787735-36170-1-git-send-email-wangmy@cn.fujitsu.com> References: <1542787735-36170-1-git-send-email-wangmy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Fuego] [PATCH] Add test cases of service sshd. List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org OpenSSH is the premier connectivity tool for remote login with the SSH protocol. This test set is used to check the pidfile, process and syslog of service sshd. Signed-off-by: Wang Mingyu --- engine/tests/Functional.openssh/fuego_test.sh | 18 ++++++++ engine/tests/Functional.openssh/openssh_test.sh | 4 ++ engine/tests/Functional.openssh/parser.py | 22 +++++++++ engine/tests/Functional.openssh/spec.json | 7 +++ .../Functional.openssh/tests/openssh_pidfile.sh | 52 ++++++++++++++++++++++ .../tests/Functional.openssh/tests/openssh_ps.sh | 43 ++++++++++++++++++ .../Functional.openssh/tests/openssh_syslog.sh | 49 ++++++++++++++++++++ 7 files changed, 195 insertions(+) create mode 100644 engine/tests/Functional.openssh/fuego_test.sh create mode 100755 engine/tests/Functional.openssh/openssh_test.sh create mode 100644 engine/tests/Functional.openssh/parser.py create mode 100644 engine/tests/Functional.openssh/spec.json create mode 100644 engine/tests/Functional.openssh/tests/openssh_pidfile.sh create mode 100644 engine/tests/Functional.openssh/tests/openssh_ps.sh create mode 100644 engine/tests/Functional.openssh/tests/openssh_syslog.sh diff --git a/engine/tests/Functional.openssh/fuego_test.sh b/engine/tests/Functional.openssh/fuego_test.sh new file mode 100644 index 0000000..8892415 --- /dev/null +++ b/engine/tests/Functional.openssh/fuego_test.sh @@ -0,0 +1,18 @@ +function test_pre_check { + assert_has_program sshd +} + +function test_deploy { + put $TEST_HOME/openssh_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;\ + ./openssh_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +} diff --git a/engine/tests/Functional.openssh/openssh_test.sh b/engine/tests/Functional.openssh/openssh_test.sh new file mode 100755 index 0000000..dd5ce37 --- /dev/null +++ b/engine/tests/Functional.openssh/openssh_test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +done diff --git a/engine/tests/Functional.openssh/parser.py b/engine/tests/Functional.openssh/parser.py new file mode 100644 index 0000000..d85abd7 --- /dev/null +++ b/engine/tests/Functional.openssh/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.openssh/spec.json b/engine/tests/Functional.openssh/spec.json new file mode 100644 index 0000000..e6a2ec2 --- /dev/null +++ b/engine/tests/Functional.openssh/spec.json @@ -0,0 +1,7 @@ +{ + "testName": "Functional.opensshd", + "specs": { + "default": {} + } +} + diff --git a/engine/tests/Functional.openssh/tests/openssh_pidfile.sh b/engine/tests/Functional.openssh/tests/openssh_pidfile.sh new file mode 100644 index 0000000..8efc653 --- /dev/null +++ b/engine/tests/Functional.openssh/tests/openssh_pidfile.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# In the target start sshd, and check if the /var/run/sshd.pid is exist. + +test="pidfile" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target sshd stop + +exec_service_on_target sshdgenkeys restart + +if exec_service_on_target sshd start +then + echo " -> start sshd succeeded." +else + echo " -> start sshd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +sleep 5 + +if ls /var/run/sshd.pid +then + echo " -> /var/run/sshd.pid is exist." +else + echo " -> /var/run/sshd.pid is not exist." + echo " -> $test: TEST-FAIL" + exec_service_on_target sshd stop + exit +fi + +if exec_service_on_target sshd stop +then + echo " -> stop sshd succeeded." +else + echo " -> stop sshd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +sleep 5 + +if test ! -f /var/run/sshd.pid +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi diff --git a/engine/tests/Functional.openssh/tests/openssh_ps.sh b/engine/tests/Functional.openssh/tests/openssh_ps.sh new file mode 100644 index 0000000..aad3f7a --- /dev/null +++ b/engine/tests/Functional.openssh/tests/openssh_ps.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# In the target start sshd, and confirm the process condition by command ps. +# check the keyword "sshd". + +test="ps" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target sshd stop +exec_service_on_target sshdgenkeys restart + +if exec_service_on_target sshd start +then + echo " -> start of sshd succeeded." +else + echo " -> start of sshd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +sleep 5 + +if ps aux | grep "[/]usr/sbin/sshd" +then + echo " -> get the pid of sshd." +else + echo " -> can't get the pid of sshd." + echo " -> $test: TEST-FAIL" + exec_service_on_target sshd stop + exit +fi + +exec_service_on_target sshd stop + +if ps aux | grep "[/]usr/sbin/sshd" +then + echo " -> $test: TEST-FAIL" +else + echo " -> $test: TEST-PASS" +fi diff --git a/engine/tests/Functional.openssh/tests/openssh_syslog.sh b/engine/tests/Functional.openssh/tests/openssh_syslog.sh new file mode 100644 index 0000000..bd6c76f --- /dev/null +++ b/engine/tests/Functional.openssh/tests/openssh_syslog.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# In the target start sshd, and check the messages of /var/log/syslog. +# check the keyword "sshd". + +test="syslog" + +. ./fuego_board_function_lib.sh + +set_init_manager +logger_service=$(detect_logger_service) + +exec_service_on_target sshd 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 sshd start +then + echo " -> start of sshd succeeded." +else + echo " -> start of sshd failed." + echo " -> $test: TEST-FAIL" + restore_target + exit +fi + +sleep 5 + +if cat /var/log/syslog | grep "sshd" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +restore_target -- 1.8.3.1