Re: [Fuego] [PATCH] samba: Add test case to access the server on target from host.

<[email protected]>
Newsgroups dev.linux.lists.fuego
Message-ID <[email protected]>

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

This patch is missing a description in the commit body.
Please make sure every patch has a description, in addition
to the summary line.

> 
> Signed-off-by: Wang Mingyu <[email protected]>
> ---
>  tests/Functional.samba/data/smb04.conf        |   8 +-
>  tests/Functional.samba/data/smb05.conf        |  19 ++++
>  tests/Functional.samba/data/smb06.conf        |  18 ++++
>  tests/Functional.samba/fuego_test.sh          |  19 +++-
>  tests/Functional.samba/samba_test.sh          |   8 +-
>  tests/Functional.samba/test.yaml              |   8 +-
>  .../Functional.samba/tests/restore_target.sh  |  23 ++++
>  tests/Functional.samba/tests/test_samba04.sh  |  22 ++--
>  tests/Functional.samba/tests/test_samba05.sh  | 102
> ++++++++++++++++++
>  tests/Functional.samba/tests/test_samba06.sh  |  53 +++++++++
>  .../tests/test_samba06_host.sh                |  22 ++++
>  11 files changed, 275 insertions(+), 27 deletions(-)
>  create mode 100644 tests/Functional.samba/data/smb05.conf
>  create mode 100644 tests/Functional.samba/data/smb06.conf
>  mode change 100644 => 100755 tests/Functional.samba/fuego_test.sh
>  create mode 100644 tests/Functional.samba/tests/restore_target.sh
>  create mode 100644 tests/Functional.samba/tests/test_samba05.sh
>  create mode 100644 tests/Functional.samba/tests/test_samba06.sh
>  create mode 100644 tests/Functional.samba/tests/test_samba06_host.sh
> 
> diff --git a/tests/Functional.samba/data/smb04.conf
> b/tests/Functional.samba/data/smb04.conf
> index 94acbbc..fb59410 100644
> --- a/tests/Functional.samba/data/smb04.conf
> +++ b/tests/Functional.samba/data/smb04.conf
> @@ -2,18 +2,16 @@
>     workgroup = MYGROUP
>     server string = Samba Server
>     security = user
> -   hosts allow = 127.0.0.1 test_target
> +   hosts allow = 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
> +   interfaces = localhost
>     dns proxy = no
> 
>  [test]
>     comment = samba server
> -   path = /home/test_for_fuego/samba
> +   path = /home/test/samba
>     writable = yes
>     browseable = yes
>     guest ok = yes
> diff --git a/tests/Functional.samba/data/smb05.conf
> b/tests/Functional.samba/data/smb05.conf
> new file mode 100644
> index 0000000..d52163d
> --- /dev/null
> +++ b/tests/Functional.samba/data/smb05.conf
> @@ -0,0 +1,19 @@
> +[global]
> +   workgroup = MYGROUP
> +   server string = Samba Server
> +   security = user
> +   passdb backend = tdbsam
> +   hosts allow = test_target
> +   load printers = no
> +   log file = /var/log/samba/log.%m
> +   max log size = 50
> +   max protocol = SMB3_10
> +   min protocol = SMB2
> +   interfaces = localhost
> +   dns proxy = no
> +
> +[test]
> +   comment = samba server
> +   path = /home/test/samba
> +   writable = yes
> +   browseable = yes
> diff --git a/tests/Functional.samba/data/smb06.conf
> b/tests/Functional.samba/data/smb06.conf
> new file mode 100644
> index 0000000..1bbacd4
> --- /dev/null
> +++ b/tests/Functional.samba/data/smb06.conf
> @@ -0,0 +1,18 @@
> +[global]
> +   workgroup = MYGROUP
> +   server string = Samba Server
> +   security = user
> +   hosts allow = 127.0.0.1 test_host
> +   load printers = yes
> +   log file = /var/log/samba/log.%m
> +   max log size = 50
> +   interfaces = 127.0.0.1 test_target
> +   dns proxy = no
> +
> +[test]
> +   comment = samba server
> +   path = /home/test/samba
> +   writable = yes
> +   browseable = yes
> +   guest ok = yes
> +   public = yes
> diff --git a/tests/Functional.samba/fuego_test.sh
> b/tests/Functional.samba/fuego_test.sh
> old mode 100644
> new mode 100755
> index 1f694ef..b840dc1
> --- a/tests/Functional.samba/fuego_test.sh
> +++ b/tests/Functional.samba/fuego_test.sh
> @@ -1,4 +1,7 @@
> +NEED_ROOT=1
> +
>  function test_pre_check {
> +    assert_has_program samba
>      assert_has_program expect
>      assert_has_program smbclient
>      assert_has_program sed
> @@ -12,9 +15,19 @@ function test_deploy {
>  }
> 
>  function test_run {
> -    report "cd $BOARD_TESTDIR/fuego.$TESTDIR; \
> -        export test_target=$IPADDR; \
> -        ./samba_test.sh"
> +    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
> +    export test_target=$IPADDR;\
> +    export test_host=$SRV_IP;\
> +    ./samba_test.sh"
> +
> +    service_file=/tmp/test_for_fuego
> +    report_append "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
> +    sh tests/test_samba06.sh $SRV_IP $IPADDR $service_file"
> +
> +    log_this "cd $TEST_HOME; sh tests/test_samba06_host.sh $IPADDR"
> +
> +    cmd "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
> +    sh tests/restore_target.sh $service_file"
>  }
> 
>  function test_processing {
> diff --git a/tests/Functional.samba/samba_test.sh
> b/tests/Functional.samba/samba_test.sh
> index 95c34db..93b0740 100644
> --- a/tests/Functional.samba/samba_test.sh
> +++ b/tests/Functional.samba/samba_test.sh
> @@ -2,6 +2,8 @@
>  . ./fuego_board_function_lib.sh
>  set_init_manager
> 
> -for i in tests/*.sh; do
> -    source $i
> -done
> +source tests/test_samba01.sh
> +source tests/test_samba02.sh
> +source tests/test_samba03.sh
> +source tests/test_samba04.sh
> +source tests/test_samba05.sh
> diff --git a/tests/Functional.samba/test.yaml
> b/tests/Functional.samba/test.yaml
> index bd61de6..9b1ac0c 100644
> --- a/tests/Functional.samba/test.yaml
> +++ b/tests/Functional.samba/test.yaml
> @@ -1,11 +1,11 @@
>  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.
> +      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.
> -license: BSD-3-Clause
> +license: BSD-3-Clause
>  author: Wang Mingyu <[email protected]>
>  maintainer: Wang Mingyu <[email protected]>
>  version: 1.00
> @@ -15,6 +15,8 @@ tags: ['samba']
>  params:
>      IPADDR:
>          description: the IP address of your target board - Defined in board file
> +    SRV_IP:
> +        description: the IP address of your host - Defined in board file
>  data_files:
>   - samba_test.sh
>   - fuego_test.sh
> diff --git a/tests/Functional.samba/tests/restore_target.sh
> b/tests/Functional.samba/tests/restore_target.sh
> new file mode 100644
> index 0000000..4883480
> --- /dev/null
> +++ b/tests/Functional.samba/tests/restore_target.sh
> @@ -0,0 +1,23 @@
> +#!/bin/sh
> +
> +# restore the status of target when test finished.
> +
> +. ./fuego_board_function_lib.sh
> +set_init_manager
> +
> +if [ -f /etc/samba/smb.conf_bak ]
> +then
> +    mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
> +fi
> +mv data/smb06.conf_bak data/smb06.conf
> +
> +if [ "$(tail -n 1 $1)" = "active" -o "$(tail -n 1 $1)" = "unknown" ]
> +then
> +    exec_service_on_target iptables start
> +fi
> +if [ "$(head -n 1 $1)" = "inactive" ]
> +then
> +    exec_service_on_target smb stop
> +fi
> +
> +rm -fr $1
> diff --git a/tests/Functional.samba/tests/test_samba04.sh
> b/tests/Functional.samba/tests/test_samba04.sh
> index 2ad6e59..cacc6c0 100644
> --- a/tests/Functional.samba/tests/test_samba04.sh
> +++ b/tests/Functional.samba/tests/test_samba04.sh
> @@ -1,6 +1,8 @@
>  #!/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.
> +#  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"
> 
> @@ -10,14 +12,12 @@ 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/samba
> +mkdir -p /home/test/samba_test
> 
> -mkdir -p /home/test_for_fuego/samba
> -mkdir -p /home/test_for_fuego/samba_test
> +cp data/test1 /home/test/samba/
> 
> -cp data/test1 /home/test_for_fuego/samba/
> -
> -chown nobody:nobody -R /home/test_for_fuego/samba
> +chown nobody:nobody -R /home/test/samba
> 
>  if [ -f /etc/samba/smb.conf ]
>  then
> @@ -29,9 +29,6 @@ restore_target(){
>      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
> @@ -42,7 +39,6 @@ restore_target(){
>      fi
>  }
> 
> -cp data/smb04.conf data/smb04.conf_bak
>  sed -i 's/test_target/'"$test_target"'/g' data/smb04.conf
>  cp data/smb04.conf /etc/samba/smb.conf
> 
> @@ -62,7 +58,7 @@ expect <<-EOF
>  spawn smbclient //$test_target/test -N
>  expect {
>   -re ".*smb: .*" {
> -           send "get test1 /home/test_for_fuego/samba_test/test1\n"
> +           send "get test1 /home/test/samba_test/test1\n"
>            }
>   default { send_user "Can not log into the board.\n"}  }
>  expect {
> @@ -74,7 +70,7 @@ send "exit\n"
>  expect eof
>  EOF
> 
> -if ls /home/test_for_fuego/samba_test/test1
> +if ls /home/test/samba_test/test1
>  then
>      echo " -> $test: TEST-PASS"
>  else
> diff --git a/tests/Functional.samba/tests/test_samba05.sh
> b/tests/Functional.samba/tests/test_samba05.sh
> new file mode 100644
> index 0000000..fe55560
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba05.sh
> @@ -0,0 +1,102 @@
> +#!/bin/sh
> +
> +#  In the target start samba, set the server to access
> +#  the target having password from the server,
> +#  and make sure the server can access the target.
> +
> +test="samba05"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +useradd test_for_fuego
> +
> +expect <<-EOF
> +spawn smbpasswd -a test_for_fuego
> +expect "SMB password:"
> +send "goodluck\r"
> +expect "Retype new SMB password:"
> +send "goodluck\r"
> +expect "Added user root."
> +EOF
> +
> +smb_status=$(get_service_status smb)
> +iptables_status=$(get_service_status iptables)
> +
> +exec_service_on_target smb stop
> +exec_service_on_target iptables stop
> +
> +mkdir -p /home/test/samba
> +
> +cp data/test1 /home/test/samba/
> +
> +chown nobody:nobody -R /home/test/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
> +    smbpasswd -x test_for_fuego
> +    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
> +}
> +
> +sed -i 's/test_target/'"$test_target"'/g' data/smb05.conf
> +cp data/smb05.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 sh
> +expect ".*"
> +send "smbclient //$test_target/test --user=test_for_fuego\r"
> +expect {
> + -re ".*Enter.*password:.*" {
> +           send "goodluck\r"
> +          }
> + default { send_user "Can not access the board.\n"}  }
> +expect {
> + -re ".*Password:.*" {
> +           send "goodluck\r"
> +          }
> + default { send_user "Password is wrong.\n"}  }
> +expect {
> + -re ".*smb:.*" {
> +           send "ls\r"
> +          }
> + default { send_user "Can not log into the board.\n"}  }
> +expect {
> + -re ".*test1.*" {
> +           send_user " -> $test: TEST-PASS\n"
> +          }
> + default { send_user " -> $test: TEST-FAIL\n"}  }
> +send "exit\n"
> +expect eof
> +EOF
> +
> +restore_target
> diff --git a/tests/Functional.samba/tests/test_samba06.sh
> b/tests/Functional.samba/tests/test_samba06.sh
> new file mode 100644
> index 0000000..000d3ec
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba06.sh
> @@ -0,0 +1,53 @@
> +#!/bin/sh
> +
> +#  Start the service samba and keep it running on the target
> +
> +. ./fuego_board_function_lib.sh
> +set_init_manager
> +
> +echo $(get_service_status smb) > $3
> +echo $(get_service_status iptables) >> $3
> +
> +exec_service_on_target smb stop
> +exec_service_on_target iptables stop
> +
> +mkdir -p /home/test/samba
> +
> +cp data/test1 /home/test/samba/
> +
> +chown nobody:nobody -R /home/test/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
> +    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
> +}
> +
> +sed -i 's/test_target/'"$2"'/g' data/smb06.conf
> +sed -i 's/test_host/'"$1"'/g' data/smb06.conf
> +cp data/smb06.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"
> +    exit
> +fi
> +
> +sleep 5
> diff --git a/tests/Functional.samba/tests/test_samba06_host.sh
> b/tests/Functional.samba/tests/test_samba06_host.sh
> new file mode 100644
> index 0000000..e04dac3
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba06_host.sh
> @@ -0,0 +1,22 @@
> +#!/bin/sh
> +
> +# Access the samba server on the target from the host
> +
> +test="samba06"
> +expect <<-EOF
> +spawn sh
> +expect ".*"
> +send "smbclient //$1/test -N\r"
> +expect {
> + -re ".*smb:.*" {
> +           send "ls\r"
> +          }
> + default { send_user "Can't connect to the board"\n"}  }
> +expect {
> + -re ".*test1.*" {
> +           send_user " -> $test: TEST-PASS\n"
> +          }
> + default { send_user " -> $test: TEST-FAIL\n"}  }
> +send "exit\n"
> +expect eof
> +EOF
> --
> 2.17.1

I had to remove whitespace at the end of some lines.

Please check for trailing whitespace using something like:
'grep -R " $" *'
before submitting.

~/f/fuego-core/tests/Functional.samba$ grep -R " $" *
tests/restore_target.sh:# restore the status of target when test finished. 
tests/test_samba05.sh:    echo " -> $test: TEST-FAIL"    
tests/test_samba05.sh: default { send_user "Can not log into the board.\n"}  } 
test.yaml:license: BSD-3-Clause 

I fixed the whitespace this time, but please check this before submitting
in the future.

Thanks for the patch. It looks good.  I have applied it.
 -- Tim
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.