[Fuego] [PATCH] samba:: Add test cases for samba.
Tim.Bird at sony.com
Tim.Bird at sony.com
Sat Aug 10 00:13:02 UTC 2019
> -----Original Message-----
> From: Wang Mingyu
>
> This is a simple test to check the ps/pid/syslog of samba and use smbclient to
> implement a simple ftp-like client.
>
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> ---
> tests/Functional.samba/data/smb04.conf | 20 +++++
> tests/Functional.samba/data/test1 | 1 +
> tests/Functional.samba/fuego_test.sh | 21 +++++
> tests/Functional.samba/samba_test.sh | 7 ++
> tests/Functional.samba/spec.json | 6 ++
> tests/Functional.samba/test.yaml | 22 +++++
> tests/Functional.samba/tests/test_samba01.sh | 48 +++++++++++
> tests/Functional.samba/tests/test_samba02.sh | 55 +++++++++++++
> tests/Functional.samba/tests/test_samba03.sh | 47 +++++++++++
> tests/Functional.samba/tests/test_samba04.sh | 84
> ++++++++++++++++++++
> 10 files changed, 311 insertions(+)
> create mode 100644 tests/Functional.samba/data/smb04.conf
> create mode 100644 tests/Functional.samba/data/test1
> create mode 100644 tests/Functional.samba/fuego_test.sh
> create mode 100644 tests/Functional.samba/samba_test.sh
> create mode 100644 tests/Functional.samba/spec.json
> create mode 100644 tests/Functional.samba/test.yaml
> create mode 100644 tests/Functional.samba/tests/test_samba01.sh
> create mode 100644 tests/Functional.samba/tests/test_samba02.sh
> create mode 100644 tests/Functional.samba/tests/test_samba03.sh
> create mode 100644 tests/Functional.samba/tests/test_samba04.sh
>
> diff --git a/tests/Functional.samba/data/smb04.conf
> b/tests/Functional.samba/data/smb04.conf
> new file mode 100644
> index 0000000..94acbbc
> --- /dev/null
> +++ b/tests/Functional.samba/data/smb04.conf
> @@ -0,0 +1,20 @@
> +[global]
> + workgroup = MYGROUP
> + server string = Samba Server
> + security = user
> + hosts allow = 127.0.0.1 test_target
> + load printers = yes
> + log file = /var/log/samba/log.%m
> + max log size = 50
> + max protocol = SMB3_10
> + min protocol = SMB2
> + interfaces = 127.0.0.1 test_target
> + dns proxy = no
> +
> +[test]
> + comment = samba server
> + path = /home/test_for_fuego/samba
> + writable = yes
> + browseable = yes
> + guest ok = yes
> + public = yes
> diff --git a/tests/Functional.samba/data/test1
> b/tests/Functional.samba/data/test1
> new file mode 100644
> index 0000000..3b18e51
> --- /dev/null
> +++ b/tests/Functional.samba/data/test1
> @@ -0,0 +1 @@
> +hello world
> diff --git a/tests/Functional.samba/fuego_test.sh
> b/tests/Functional.samba/fuego_test.sh
> new file mode 100644
> index 0000000..63a247f
> --- /dev/null
> +++ b/tests/Functional.samba/fuego_test.sh
> @@ -0,0 +1,21 @@
> +function test_pre_check {
> + assert_has_program expect
> + assert_has_program smbclient
> +}
> +
> +function test_deploy {
> + put $TEST_HOME/samba_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
> + put $FUEGO_CORE/scripts/fuego_board_function_lib.sh
> $BOARD_TESTDIR/fuego.$TESTDIR
> + put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
> + put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
> +}
> +
> +function test_run {
> + report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
> + export test_target=$IPADDR;\
> + ./samba_test.sh"
This is picky, but I wish these were indented.
> +}
> +
> +function test_processing {
> + log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
> +}
> diff --git a/tests/Functional.samba/samba_test.sh
> b/tests/Functional.samba/samba_test.sh
> new file mode 100644
> index 0000000..95c34db
> --- /dev/null
> +++ b/tests/Functional.samba/samba_test.sh
> @@ -0,0 +1,7 @@
> +#!/bin/sh
> +. ./fuego_board_function_lib.sh
> +set_init_manager
> +
> +for i in tests/*.sh; do
> + source $i
> +done
> diff --git a/tests/Functional.samba/spec.json
> b/tests/Functional.samba/spec.json
> new file mode 100644
> index 0000000..2f3d0b6
> --- /dev/null
> +++ b/tests/Functional.samba/spec.json
> @@ -0,0 +1,6 @@
> +{
> + "testName": "Functional.sambad",
> + "specs": {
> + "default": {}
> + }
> +}
> diff --git a/tests/Functional.samba/test.yaml
> b/tests/Functional.samba/test.yaml
> new file mode 100644
> index 0000000..ac81666
> --- /dev/null
> +++ b/tests/Functional.samba/test.yaml
> @@ -0,0 +1,22 @@
> +fuego_package_version: 1
> +name: Functional.samba
> +description: |
> + The Samba software suite is a collection of programs that implements
> the Server Message Block protocol for UNIX systems.
> + This is a simple test to check the ps/pid/syslog of samba and use
> smbclient to implement a simple ftp-like client.
These lines are too long. And there was trailing whitespace on one of them.
> +license: BSD-3-Clause
There was trailing whitespace on this line also.
> +author: Wang Mingyu <wangmy at cn.fujitsu.com>
> +maintainer: Wang Mingyu <wangmy at cn.fujitsu.com>
> +version: 1.00
> +fuego_release: 1
> +type: Functional
> +tags: ['samba']
> +params:
> + IPADDR:
> + description: the IP address of your target board - Defined in board file
> +data_files:
> + - samba_test.sh
> + - fuego_test.sh
> + - spec.json
> + - test.yaml
> + - data
> + - tests
Thanks for including a test.yaml file!!
> diff --git a/tests/Functional.samba/tests/test_samba01.sh
> b/tests/Functional.samba/tests/test_samba01.sh
> new file mode 100644
> index 0000000..102261b
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba01.sh
> @@ -0,0 +1,48 @@
> +#!/bin/sh
> +
> +# In the target start samba, and confirm the process condition by command
> ps.
> +# check the keyword "smbd".
> +
> +test="samba01"
> +
> +service_status=$(get_service_status smb)
> +
> +exec_service_on_target smb stop
> +
> +if exec_service_on_target smb start
> +then
> + echo " -> start of smb succeeded."
> +else
> + echo " -> start of smb failed."
> + echo " -> $test: TEST-FAIL"
> + exit
> +fi
> +
> +sleep 5
> +
> +if ps aux | grep "[/]usr/sbin/smbd"
> +then
> + echo " -> get the pid of smbd."
> +else
> + echo " -> can't get the pid of smbd."
> + echo " -> $test: TEST-FAIL"
> + if [ "$service_status" = "inactive" ]
> + then
> + exec_service_on_target smb stop
> + fi
> + exit
> +fi
> +
> +exec_service_on_target smb stop
> +
> +if ps aux | grep "[/]usr/sbin/smbd"
> +then
> + echo " -> $test: TEST-FAIL"
> +else
> + echo " -> $test: TEST-PASS"
> +fi
> +
> +if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
> +then
> + exec_service_on_target smb start
> +fi
> diff --git a/tests/Functional.samba/tests/test_samba02.sh
> b/tests/Functional.samba/tests/test_samba02.sh
> new file mode 100644
> index 0000000..0a1c492
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba02.sh
> @@ -0,0 +1,55 @@
> +#!/bin/sh
> +
> +# In the target start samba, and check if the /var/run/smb.pid is exist.
> +
> +test="samba02"
> +
> +service_status=$(get_service_status smb)
> +exec_service_on_target smb stop
> +
> +if exec_service_on_target smb start
> +then
> + echo " -> start smb succeeded."
> +else
> + echo " -> start smb failed."
> + echo " -> $test: TEST-FAIL"
> + exit
> +fi
> +
> +sleep 5
> +
> +if test -f /var/run/smbd.pid
> +then
> + echo " -> /var/run/smbd.pid is exist."
> +else
> + echo " -> /var/run/smbd.pid is not exist."
> + echo " -> $test: TEST-FAIL"
> + if [ "$service_status" = "inactive" ]
> + then
> + exec_service_on_target smb stop
> + fi
> + exit
> +fi
> +
> +if exec_service_on_target smb stop
> +then
> + echo " -> stop smb succeeded."
> +else
> + echo " -> stop smb failed."
> + echo " -> $test: TEST-FAIL"
> + exit
> +fi
> +
> +sleep 5
> +
> +if test ! -f /var/run/smbd.pid
> +then
> + echo " -> $test: TEST-PASS"
> +else
> + echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
> +then
> + exec_service_on_target smb start
> +fi
> diff --git a/tests/Functional.samba/tests/test_samba03.sh
> b/tests/Functional.samba/tests/test_samba03.sh
> new file mode 100644
> index 0000000..aed1afd
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba03.sh
> @@ -0,0 +1,47 @@
> +#!/bin/sh
> +
> +# In the target start samba, and check if the logfile of samba is exist.
> +
> +test="samba03"
> +
> +service_status=$(get_service_status smb)
> +exec_service_on_target smb stop
> +
> +if [ -e /var/log/samba/log.smbd ]
> +then
> + mv /var/log/samba/log.smbd /var/log/samba/log.smbd_bak
> +fi
> +
> +restore_target(){
> + if [ -f /var/log/samba/log.smbd_bak ]
> + then
> + mv /var/log/samba/log.smbd_bak /var/log/samba/log.smbd
> + fi
> +}
> +
> +if exec_service_on_target smb start
> +then
> + echo " -> start smb succeeded."
> +else
> + echo " -> start smb failed."
> + echo " -> $test: TEST-FAIL"
> + restore_target
> + exit
> +fi
> +
> +sleep 5
> +
> +if test -f /var/log/samba/log.smbd
> +then
> + echo " -> /var/log/samba/log.smbd exists."
> + echo " -> $test: TEST-PASS"
> +else
> + echo " -> /var/log/samba/log.smbd dose not exist."
> + echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$service_status" = "inactive" ]
> +then
> + exec_service_on_target smb stop
> +fi
> +restore_target
> diff --git a/tests/Functional.samba/tests/test_samba04.sh
> b/tests/Functional.samba/tests/test_samba04.sh
> new file mode 100644
> index 0000000..2ad6e59
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba04.sh
> @@ -0,0 +1,84 @@
> +#!/bin/sh
> +
> +# Set the server to access the target even if you don't have a password
> from the server, and make sure the server can access the target.
> +
> +test="smbd04"
> +
> +smb_status=$(get_service_status smb)
> +iptables_status=$(get_service_status iptables)
> +
> +exec_service_on_target smb stop
> +exec_service_on_target iptables stop
> +
> +useradd test_for_fuego
> +
> +mkdir -p /home/test_for_fuego/samba
> +mkdir -p /home/test_for_fuego/samba_test
> +
> +cp data/test1 /home/test_for_fuego/samba/
> +
> +chown nobody:nobody -R /home/test_for_fuego/samba
> +
> +if [ -f /etc/samba/smb.conf ]
> +then
> + mv /etc/samba/smb.conf /etc/samba/smb.conf_bak
> +fi
> +
> +restore_target(){
> + if [ -f /etc/samba/smb.conf_bak ]
> + then
> + mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
> + fi
> + mv data/smb04.conf_bak data/smb04.conf
> + rm -fr /home/test_for_fuego
> + userdel test_for_fuego
> + if [ "$iptables_status" = "active" -o "$iptables_status" = "unknown" ]
> + then
> + exec_service_on_target iptables start
> + fi
> + if [ "$smb_status" = "inactive" ]
> + then
> + exec_service_on_target smb stop
> + fi
> +}
> +
> +cp data/smb04.conf data/smb04.conf_bak
> +sed -i 's/test_target/'"$test_target"'/g' data/smb04.conf
We might not have 'sed' on the target. Should probably put
an "assert_has_program sed" in test_pre_check
> +cp data/smb04.conf /etc/samba/smb.conf
> +
> +if exec_service_on_target smb start
> +then
> + echo " -> start of smb succeeded."
> +else
> + echo " -> start of smb failed."
> + echo " -> $test: TEST-FAIL"
> + restore_target
> + exit
> +fi
> +
> +sleep 5
> +
> +expect <<-EOF
> +spawn smbclient //$test_target/test -N
> +expect {
> + -re ".*smb: .*" {
> + send "get test1 /home/test_for_fuego/samba_test/test1\n"
> + }
> + default { send_user "Can not log into the board.\n"} }
> +expect {
> + -re ".*smb: .*" {
> + send "\n"
> + }
> + default { send_user "Can not log into the board.\n"} }
> +send "exit\n"
> +expect eof
> +EOF
> +
> +if ls /home/test_for_fuego/samba_test/test1
> +then
> + echo " -> $test: TEST-PASS"
> +else
> + echo " -> $test: TEST-FAIL"
> +fi
> +
> +restore_target
> --
There were a few minor nits, but overall this looks good.
I applied it as is. I may do a fixup patch myself based on the few items
in my review, but I may just let it be. I don't have a system with smb configured,
so I can't test this here. I've applied this to the fuegotest 'next' branch.
There were a few whitespace errors in the test.yaml file. Please check for those
before submitting, by doing 'grep -R " $" *'
Thanks. This looks like a nice test.
-- Tim
More information about the Fuego
mailing list