Skip to contentSkip to conversation

logrotate: Add test cases for command logrotate.

PATCH In review Wang Mingyu 2 participants 8 messages Nov 5, 2019 – Nov 25, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 logrotate: Add test cases for command logrotate.

Logrotate is designed to ease administration of systems that generate large numbers of log files. This test set is used to check if rotate file can be created.

---
 tests/Functional.logrotate/data/test.conf     |   8 ++++
 tests/Functional.logrotate/data/testlog.sh    |   5 ++
 tests/Functional.logrotate/data/testlog100k   | Bin 0 -> 105984 bytes
 tests/Functional.logrotate/fuego_test.sh      |  19 ++++++++
 tests/Functional.logrotate/logrotate_test.sh  |   4 ++
 tests/Functional.logrotate/spec.json          |   6 +++
 tests/Functional.logrotate/test.yaml          |  23 ++++++++++
 .../tests/logrotate_01.sh                     |  13 ++++++
 .../tests/logrotate_02.sh                     |  23 ++++++++++
 .../tests/logrotate_03.sh                     |  19 ++++++++
 .../tests/logrotate_04.sh                     |  43 ++++++++++++++++++
 .../tests/logrotate_05.sh                     |  30 ++++++++++++
 12 files changed, 193 insertions(+)
 create mode 100644 tests/Functional.logrotate/data/test.conf
 create mode 100644 tests/Functional.logrotate/data/testlog.sh
 create mode 100644 tests/Functional.logrotate/data/testlog100k
 create mode 100644 tests/Functional.logrotate/fuego_test.sh
 create mode 100755 tests/Functional.logrotate/logrotate_test.sh
 create mode 100644 tests/Functional.logrotate/spec.json
 create mode 100644 tests/Functional.logrotate/test.yaml
 create mode 100644 tests/Functional.logrotate/tests/logrotate_01.sh
 create mode 100644 tests/Functional.logrotate/tests/logrotate_02.sh
 create mode 100644 tests/Functional.logrotate/tests/logrotate_03.sh
 create mode 100644 tests/Functional.logrotate/tests/logrotate_04.sh
 create mode 100644 tests/Functional.logrotate/tests/logrotate_05.sh
tests/Functional.logrotate/data/test.conf new file +8 -0
new file mode 100644
index 0000000..a346adf
@@ -0,0 +1,8 @@
+/var/log/testlog {
+        create 600 root root
+        ifempty
+        daily
+        nocompress
+        missingok
+        rotate 1
+}
tests/Functional.logrotate/data/testlog.sh new file +5 -0
new file mode 100644
index 0000000..da7a877
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+ddch=`date --date ' 1 days ago' '+%Y-%m-%d'`
+echo "logrotate state -- version 2" >> /var/lib/logrotate.status
+echo "\"/var/log/testlog\" $ddch" >> /var/lib/logrotate.status
tests/Functional.logrotate/data/testlog100k new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..1dc679f54731568a9cbda775a663b7ea51595fe3
GIT binary patch
tests/Functional.logrotate/fuego_test.sh new file +19 -0
new file mode 100644
index 0000000..64a83b2
@@ -0,0 +1,19 @@
+function test_pre_check {
+    assert_has_program logrotate
+}
+
+function test_deploy {
+    put $TEST_HOME/logrotate_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    export test_host=$SRV_IP;\
+    ./logrotate_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.logrotate/logrotate_test.sh new file +4 -0
new file mode 100755
index 0000000..dd5ce37
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
tests/Functional.logrotate/spec.json new file +6 -0
new file mode 100644
index 0000000..cfd6646
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.logrotate",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.logrotate/test.yaml new file +23 -0
new file mode 100644
index 0000000..1b2d2d9
@@ -0,0 +1,23 @@
+fuego_package_version: 1
+name: Functional.logrotate
+description: |
+      Logrotate is designed to ease administration of systems that generate large numbers of log files.
+      It allows automatic rotation, compression, removal, and mailing of log files.
+      This is a simple test to check the common options and features of logrotate.
+license: BSD-3-Clause
+author: Wang Mingyu <[email protected]>
+maintainer: Wang Mingyu <[email protected]>
+version: 1.00
+fuego_release: 1
+type: Functional
+tags: ['logrotate']
+params:
+    SRV_IP:
+        description: the IP address of your host - Defined in board file
+data_files:
+ - logrotate_test.sh
+ - fuego_test.sh
+ - spec.json
+ - test.yaml
+ - data
+ - tests
tests/Functional.logrotate/tests/logrotate_01.sh new file +13 -0
new file mode 100644
index 0000000..5aed3e3
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate and confirm the result.
+#  option : --help
+
+test="logrotate1"
+
+if logrotate --help | grep "Usage"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
tests/Functional.logrotate/tests/logrotate_02.sh new file +23 -0
new file mode 100644
index 0000000..4e16d0b
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate and confirm the result.
+#  option : -dv
+
+test="logrotate2"
+
+if [ -f /var/lib/logrotate.status ]
+then
+    rm -f /var/lib/logrotate.status
+fi
+
+cp data/test.conf /etc/logrotate.d/test.conf
+
+chown root /etc/logrotate.d/test.conf
+
+if logrotate -dv /etc/logrotate.d/test.conf
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f /etc/logrotate.d/test.conf
tests/Functional.logrotate/tests/logrotate_03.sh new file +19 -0
new file mode 100644
index 0000000..98a850d
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate and confirm the result.
+#  option : -v
+
+test="logrotate3"
+
+cp data/test.conf /etc/logrotate.d/test.conf
+
+logrotate -v /etc/logrotate.d/test.conf
+
+if tail /var/lib/logrotate.status | grep testlog
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f /etc/logrotate.d/test.conf
+sed -i '/testlog/d' /var/lib/logrotate.status
tests/Functional.logrotate/tests/logrotate_04.sh new file +43 -0

43 lines not on this page · raw message

tests/Functional.logrotate/tests/logrotate_05.sh new file +30 -0
new file mode 100644
index 0000000..a5f61dc
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate.Verify that the rotate file is created in the specified directory(Specify the file size).
+#  option : -v
+
+test="logrotate5"
+
+if [ -f /var/log/testlog* ]
+then
+    rm -f /var/log/testlog*
+fi
+
+cp data/test.conf /etc/logrotate.d/test.conf
+
+cp data/testlog100k /var/log/testlog
+
+chmod +x data/testlog.sh
+data/testlog.sh
+chown root /etc/logrotate.d/test.conf
+logrotate -v /etc/logrotate.d/test.conf
+if ls /var/log/testlog.1
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+rm -f /etc/logrotate.d/test.conf
+rm -f /var/log/testlog*
+sed -i '/testlog/d' /var/lib/logrotate.status
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 samba: Add test case to access the target from host using samba.

---
 tests/Functional.samba/data/smb04.conf        |   4 +-
 tests/Functional.samba/data/smb05.conf        |  19 ++++
 tests/Functional.samba/data/smb06.conf        |  18 +++
 tests/Functional.samba/fuego_test.sh          |  20 +++-
 tests/Functional.samba/samba_test.sh          |   8 +-
 tests/Functional.samba/test.yaml              |  10 +-
 .../Functional.samba/tests/restore_target.sh  |  24 ++++
 tests/Functional.samba/tests/test_samba04.sh  |  16 +--
 tests/Functional.samba/tests/test_samba05.sh  | 103 ++++++++++++++++++
 tests/Functional.samba/tests/test_samba06.sh  |  58 ++++++++++
 .../tests/test_samba06_host.sh                |  23 ++++
 11 files changed, 278 insertions(+), 25 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/samba_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
tests/Functional.samba/data/smb04.conf +1 -3
index 94acbbc..c836021 100644
@@ -6,14 +6,12 @@
    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
+   path = /home/test/samba
    writable = yes
    browseable = yes
    guest ok = yes
tests/Functional.samba/data/smb05.conf new file +19 -0
new file mode 100644
index 0000000..63d3d02
@@ -0,0 +1,19 @@
+[global]
+   workgroup = MYGROUP
+   server string = Samba Server
+   security = user
+   passdb backend = tdbsam
+   hosts allow = 127.0.0.1 test_target
+   load printers = no
+   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/samba
+   writable = yes
+   browseable = yes
tests/Functional.samba/data/smb06.conf new file +18 -0
new file mode 100644
index 0000000..1bbacd4
@@ -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
tests/Functional.samba/fuego_test.sh +16 -4
index 1f694ef..63e0cef 100644
@@ -1,7 +1,9 @@
+NEED_ROOT=1
+
 function test_pre_check {
+    assert_has_program samba
     assert_has_program expect
     assert_has_program smbclient
-    assert_has_program sed
 }
 
 function test_deploy {
@@ -12,9 +14,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"
+
+    report_append "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    sh tests/restore_target.sh $service_file"
 }
 
 function test_processing {
tests/Functional.samba/samba_test.sh +5 -3
old mode 100644
new mode 100755
index 95c34db..93b0740
@@ -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
tests/Functional.samba/test.yaml +5 -5
index bd61de6..f38dcf9 100644
@@ -1,11 +1,9 @@
 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.
-license: BSD-3-Clause
+      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 
 author: Wang Mingyu <[email protected]>
 maintainer: Wang Mingyu <[email protected]>
 version: 1.00
@@ -15,6 +13,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
tests/Functional.samba/tests/restore_target.sh new file +24 -0
new file mode 100644
index 0000000..6610923
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+#  In the target start samba, and confirm the process condition by command ps.
+#  check the keyword "smbd".
+
+. ./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
tests/Functional.samba/tests/test_samba04.sh +6 -10
index 2ad6e59..c1dac10 100644
@@ -10,14 +10,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
@@ -30,8 +28,6 @@ restore_target(){
         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
@@ -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
tests/Functional.samba/tests/test_samba05.sh new file +103 -0

103 lines not on this page · raw message

tests/Functional.samba/tests/test_samba06.sh new file +58 -0

58 lines not on this page · raw message

tests/Functional.samba/tests/test_samba06_host.sh new file +23 -0
new file mode 100644
index 0000000..77ff7a5
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+#  In the target start samba, and confirm the process condition by command ps.
+#  check the keyword "smbd".
+
+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
Signature · 1 line
2.17.1
#2 lore raw

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

This looks like a nice upgrade, but I have a couple of comments.

Quoted 104 lines

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

---
 tests/Functional.samba/data/smb04.conf        |   4 +-
 tests/Functional.samba/data/smb05.conf        |  19 ++++
 tests/Functional.samba/data/smb06.conf        |  18 +++
 tests/Functional.samba/fuego_test.sh          |  20 +++-
 tests/Functional.samba/samba_test.sh          |   8 +-
 tests/Functional.samba/test.yaml              |  10 +-
 .../Functional.samba/tests/restore_target.sh  |  24 ++++
 tests/Functional.samba/tests/test_samba04.sh  |  16 +--
 tests/Functional.samba/tests/test_samba05.sh  | 103
++++++++++++++++++
 tests/Functional.samba/tests/test_samba06.sh  |  58 ++++++++++
 .../tests/test_samba06_host.sh                |  23 ++++
 11 files changed, 278 insertions(+), 25 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/samba_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
tests/Functional.samba/data/smb04.conf +1 -3
index 94acbbc..c836021 100644
@@ -6,14 +6,12 @@
    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
+   path = /home/test/samba
    writable = yes
    browseable = yes
    guest ok = yes
tests/Functional.samba/data/smb05.conf new file +19 -0
new file mode 100644
index 0000000..63d3d02
@@ -0,0 +1,19 @@
+[global]
+   workgroup = MYGROUP
+   server string = Samba Server
+   security = user
+   passdb backend = tdbsam
+   hosts allow = 127.0.0.1 test_target
+   load printers = no
+   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/samba
+   writable = yes
+   browseable = yes
tests/Functional.samba/data/smb06.conf new file +18 -0
new file mode 100644
index 0000000..1bbacd4
@@ -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
tests/Functional.samba/fuego_test.sh +0 -0
index 1f694ef..63e0cef 100644

tests/Functional.samba/fuego_test.sh line 4

Quoted 7 lines
tests/Functional.samba/fuego_test.sh +3 -1
@@ -1,7 +1,9 @@
+NEED_ROOT=1
+
 function test_pre_check {
+    assert_has_program samba
     assert_has_program expect
     assert_has_program smbclient
-    assert_has_program sed

You use 'sed' below. I'm not sure why you are removing this assertion. 'sed' is not one of the programs required by Fuego, so you should check for it.

Quoted 13 lines
tests/Functional.samba/fuego_test.sh +3 -3
 }
 
 function test_deploy {
@@ -12,9 +14,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;\

tests/Functional.samba/fuego_test.sh function test_deploy { · line 29

Quoted 10 lines
tests/Functional.samba/fuego_test.sh +10 -0
+    ./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"
+
+    report_append "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    sh tests/restore_target.sh $service_file"

Does this need to be a 'report_append'? Is there something from restore_target.sh that needs to go into the test log? I can't see anything.
Please convert this to just 'cmd'.

Quoted 37 lines
tests/Functional.samba/fuego_test.sh +0 -0
 }
 
 function test_processing {
tests/Functional.samba/samba_test.sh +5 -3
old mode 100644
new mode 100755
index 95c34db..93b0740
@@ -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
tests/Functional.samba/test.yaml +1 -5
index bd61de6..f38dcf9 100644
@@ -1,11 +1,9 @@
 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.
-license: BSD-3-Clause
+      The Samba software suite is a collection of programs that implements
Quoted 3 lines

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.

Please keep descriptions to 80 columns.

Quoted 23 lines
tests/Functional.samba/test.yaml +3 -0
+license: BSD-3-Clause
 author: Wang Mingyu <[email protected]>
 maintainer: Wang Mingyu <[email protected]>
 version: 1.00
@@ -15,6 +13,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
tests/Functional.samba/tests/restore_target.sh new file +3 -0
new file mode 100644
index 0000000..6610923
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+#  In the target start samba, and confirm the process condition by command
Quoted 2 lines

ps.
+# check the keyword "smbd".

This comment appears to be a copy-paste bug. It does not describe this file. Please update it.

Quoted 82 lines
tests/Functional.samba/tests/restore_target.sh new file +20 -0
+
+. ./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
tests/Functional.samba/tests/test_samba04.sh +6 -10
index 2ad6e59..c1dac10 100644
@@ -10,14 +10,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
@@ -30,8 +28,6 @@ restore_target(){
         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
@@ -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
tests/Functional.samba/tests/test_samba05.sh new file +4 -0
new file mode 100644
index 0000000..f66a92f
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+#  In the target start samba,
+#  Set the server to access the target having password from the server, and
Quoted 1 line

make sure the server can access the target.

Please keep comments (and code where possible) to 80 columns width.

Also - just to clarify - is this test (samba05) doing all operations on the board. The description is a bit confusing.

Quoted 33 lines
tests/Functional.samba/tests/test_samba05.sh new file +33 -0
+
+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

tests/Functional.samba/tests/test_samba05.sh line 47

Quoted 10 lines
tests/Functional.samba/tests/test_samba05.sh new file +10 -0
+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
+    mv data/smb05.conf_bak data/smb05.conf

Normally, the entire fuego.Functional.samba directory is removed after the test. I don't think it's necessary to save off the smb05.bak and restore it here. (Unless it's used more than once per test run, but I don't see that anywhere.)

tests/Functional.samba/tests/test_samba05.sh line 59

Quoted 12 lines
tests/Functional.samba/tests/test_samba05.sh new file +12 -0
+    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/smb05.conf data/smb05.conf_bak

See above. I don't think you need to save a copy of this file.

Quoted 1 line

+sed -i 's/test_target/'"$test_target"'/g' data/smb05.conf

Is there some reason this can't use 'localhost' or '127.0.0.1' instead of $test_target here?

Quoted 8 lines
tests/Functional.samba/tests/test_samba05.sh new file +8 -0
+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"

tests/Functional.samba/tests/test_samba05.sh line 78

Quoted 10 lines
tests/Functional.samba/tests/test_samba05.sh new file +10 -0
+    restore_target
+    exit
+fi
+
+sleep 5
+
+expect <<-EOF
+spawn sh
+expect ".*"
+send "smbclient //$test_target/test --user=test_for_fuego\r"

Same thing here. Is $test_target needed, or could it be 'localhost' or '127.0.0.1'? (Maybe it's needed. I'm not an smb expert. But this could be simplified you could use a generic address for the local machine.)

Quoted 55 lines
tests/Functional.samba/tests/test_samba05.sh new file +25 -0
+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
tests/Functional.samba/tests/test_samba06.sh new file +3 -0
new file mode 100644
index 0000000..29c1dd1
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+#  In the target start samba, and confirm the process condition by command

ps.

tests/Functional.samba/tests/test_samba06.sh new file +19 -0
+#  check the keyword "smbd".
+
+
+. ./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 ]

tests/Functional.samba/tests/test_samba06.sh line 32

Quoted 10 lines
tests/Functional.samba/tests/test_samba06.sh new file +10 -0
+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/smb06.conf_bak data/smb06.conf

I don't think smb06.conf needs to be backed up or restored.

tests/Functional.samba/tests/test_samba06.sh line 44

Quoted 12 lines
tests/Functional.samba/tests/test_samba06.sh new file +12 -0
+    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/smb06.conf data/smb06.conf_bak

I don't think smb06.conf needs to be backed up or restored. This could be remove, IMHO.

Or are you trying to make it so this test can be run manually multiple times (outside of Fuego's CI context?)

Quoted 24 lines
tests/Functional.samba/tests/test_samba06.sh new file +14 -0
+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
tests/Functional.samba/tests/test_samba06_host.sh new file +3 -0
new file mode 100644
index 0000000..77ff7a5
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+#  In the target start samba, and confirm the process condition by command
Quoted 2 lines

ps.
+# check the keyword "smbd".

This description doesn't seem right. isn't this a test on the host against the server running on the target?

Please update this comment, or explain why it's accurate.

Quoted 20 lines
tests/Functional.samba/tests/test_samba06_host.sh new file +19 -1
+
+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
--
Quoted 1 line

2.17.1

This is pretty nice. It's very nice to see a test that uses Fuego's inherent host/target capabilities to perform a test. And it's nice to see a test of actual samba functionality.

Please fix the items mentioned, and/or respond to comments and resubmit.

Thanks,
-- Tim

#3 lore raw

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

Hi,
Tim

Quoted 3 lines
Quoted 1 line

+sed -i 's/test_target/'"$test_target"'/g' data/smb05.conf

Is there some reason this can't use 'localhost' or '127.0.0.1' instead of $test_target here?

The host_allow in samba.conf is used to set the ip address that can access the samba server.
In the test, the target accesses the samba server established on itself, still needs to specify the ip address of the target. Specified as localhost cannot access samba server.

The interfaces can be specified to localhost.

Other items have been fixed, and I will resubmit the patch later.

Thanks,
-- Wangmy

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Tuesday, November 19, 2019 11:37 PM
To: Wang, Mingyu/王 鸣瑜 <[email protected]>; [email protected]
Subject: RE: [Fuego] [PATCH] samba: Add test case to access the target from host using samba.

This looks like a nice upgrade, but I have a couple of comments.

Quoted 104 lines

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

---
 tests/Functional.samba/data/smb04.conf        |   4 +-
 tests/Functional.samba/data/smb05.conf        |  19 ++++
 tests/Functional.samba/data/smb06.conf        |  18 +++
 tests/Functional.samba/fuego_test.sh          |  20 +++-
 tests/Functional.samba/samba_test.sh          |   8 +-
 tests/Functional.samba/test.yaml              |  10 +-
 .../Functional.samba/tests/restore_target.sh  |  24 ++++  
tests/Functional.samba/tests/test_samba04.sh  |  16 +--  
tests/Functional.samba/tests/test_samba05.sh  | 103
++++++++++++++++++
 tests/Functional.samba/tests/test_samba06.sh  |  58 ++++++++++
 .../tests/test_samba06_host.sh                |  23 ++++
 11 files changed, 278 insertions(+), 25 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/samba_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
tests/Functional.samba/data/smb04.conf +1 -3
index 94acbbc..c836021 100644
@@ -6,14 +6,12 @@
    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
+   path = /home/test/samba
    writable = yes
    browseable = yes
    guest ok = yes
tests/Functional.samba/data/smb05.conf new file +19 -0
new file mode 100644
index 0000000..63d3d02
@@ -0,0 +1,19 @@
+[global]
+   workgroup = MYGROUP
+   server string = Samba Server
+   security = user
+   passdb backend = tdbsam
+   hosts allow = 127.0.0.1 test_target
+   load printers = no
+   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/samba
+   writable = yes
+   browseable = yes
tests/Functional.samba/data/smb06.conf new file +18 -0
new file mode 100644
index 0000000..1bbacd4
@@ -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
tests/Functional.samba/fuego_test.sh +0 -0
index 1f694ef..63e0cef 100644

tests/Functional.samba/fuego_test.sh line 4

Quoted 7 lines
tests/Functional.samba/fuego_test.sh +3 -1
@@ -1,7 +1,9 @@
+NEED_ROOT=1
+
 function test_pre_check {
+    assert_has_program samba
     assert_has_program expect
     assert_has_program smbclient
-    assert_has_program sed

You use 'sed' below. I'm not sure why you are removing this assertion. 'sed' is not one of the programs required by Fuego, so you should check for it.

Quoted 12 lines
tests/Functional.samba/fuego_test.sh +3 -3
 }
 
 function test_deploy {
@@ -12,9 +14,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;\

tests/Functional.samba/fuego_test.sh function test_deploy { } · line 28

Quoted 10 lines
tests/Functional.samba/fuego_test.sh +10 -0
+    ./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"
+
+    report_append "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    sh tests/restore_target.sh $service_file"

Does this need to be a 'report_append'? Is there something from restore_target.sh that needs to go into the test log? I can't see anything. Please convert this to just 'cmd'.

Quoted 38 lines
tests/Functional.samba/fuego_test.sh +0 -0
 }
 
 function test_processing {
tests/Functional.samba/samba_test.sh +5 -3
old mode 100644
new mode 100755
index 95c34db..93b0740
@@ -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
tests/Functional.samba/test.yaml +2 -5
index bd61de6..f38dcf9 100644
@@ -1,11 +1,9 @@
 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.
-license: BSD-3-Clause
+      The Samba software suite is a collection of programs that 
+ implements
Quoted 4 lines

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.

Please keep descriptions to 80 columns.

Quoted 26 lines
tests/Functional.samba/test.yaml +1 -0
+license: BSD-3-Clause
 author: Wang Mingyu <[email protected]>
 maintainer: Wang Mingyu <[email protected]>
 version: 1.00
@@ -15,6 +13,8 @@ tags: ['samba']
 params:
     IPADDR:
         description: the IP address of your target board - Defined in 

board file

tests/Functional.samba/test.yaml +3 -0
+    SRV_IP:
+        description: the IP address of your host - Defined in board 
+ file
 data_files:
  - samba_test.sh
  - fuego_test.sh
tests/Functional.samba/tests/restore_target.sh new file +4 -0
new file mode 100644
index 0000000..6610923
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+#  In the target start samba, and confirm the process condition by 
+command
Quoted 2 lines

ps.
+# check the keyword "smbd".

This comment appears to be a copy-paste bug. It does not describe this file. Please update it.

Quoted 76 lines
tests/Functional.samba/tests/restore_target.sh new file +17 -0
+
+. ./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
tests/Functional.samba/tests/test_samba04.sh +0 -0
index 2ad6e59..c1dac10 100644
@@ -10,14 +10,12 @@ iptables_status=$(get_service_status iptables)  

exec_service_on_target smb stop exec_service_on_target iptables stop

tests/Functional.samba/tests/test_samba04.sh +4 -8
-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
@@ -30,8 +28,6 @@ restore_target(){
         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 @@ -62,7 +58,7 @@ 

expect <<-EOF spawn smbclient //$test_target/test -N expect {
-re ".*smb: .*" {

tests/Functional.samba/tests/test_samba04.sh +2 -3
-           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
tests/Functional.samba/tests/test_samba05.sh new file +5 -0
new file mode 100644
index 0000000..f66a92f
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+#  In the target start samba,
+#  Set the server to access the target having password from the 
+server, and
Quoted 1 line

make sure the server can access the target.

Please keep comments (and code where possible) to 80 columns width.

Also - just to clarify - is this test (samba05) doing all operations on the board. The description is a bit confusing.

Quoted 32 lines
tests/Functional.samba/tests/test_samba05.sh new file +32 -0
+
+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

tests/Functional.samba/tests/test_samba05.sh line 47

Quoted 10 lines
tests/Functional.samba/tests/test_samba05.sh new file +10 -0
+    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
+    mv data/smb05.conf_bak data/smb05.conf

Normally, the entire fuego.Functional.samba directory is removed after the test. I don't think it's necessary to save off the smb05.bak and restore it here. (Unless it's used more than once per test run, but I don't see that anywhere.)

tests/Functional.samba/tests/test_samba05.sh line 59

Quoted 12 lines
tests/Functional.samba/tests/test_samba05.sh new file +12 -0
+    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/smb05.conf data/smb05.conf_bak

See above. I don't think you need to save a copy of this file.

Quoted 1 line

+sed -i 's/test_target/'"$test_target"'/g' data/smb05.conf

Is there some reason this can't use 'localhost' or '127.0.0.1' instead of $test_target here?

Quoted 8 lines
tests/Functional.samba/tests/test_samba05.sh new file +8 -0
+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"

tests/Functional.samba/tests/test_samba05.sh line 78

Quoted 10 lines
tests/Functional.samba/tests/test_samba05.sh new file +10 -0
+    restore_target
+    exit
+fi
+
+sleep 5
+
+expect <<-EOF
+spawn sh
+expect ".*"
+send "smbclient //$test_target/test --user=test_for_fuego\r"

Same thing here. Is $test_target needed, or could it be 'localhost'
or '127.0.0.1'? (Maybe it's needed. I'm not an smb expert. But this could be simplified you could use a generic address for the local machine.)

Quoted 51 lines
tests/Functional.samba/tests/test_samba05.sh new file +21 -0
+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
tests/Functional.samba/tests/test_samba06.sh new file +4 -0
new file mode 100644
index 0000000..29c1dd1
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+#  In the target start samba, and confirm the process condition by 
+command

ps.

tests/Functional.samba/tests/test_samba06.sh new file +18 -0
+#  check the keyword "smbd".
+
+
+. ./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
+

tests/Functional.samba/tests/test_samba06.sh line 32

Quoted 10 lines
tests/Functional.samba/tests/test_samba06.sh new file +10 -0
+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/smb06.conf_bak data/smb06.conf

I don't think smb06.conf needs to be backed up or restored.

tests/Functional.samba/tests/test_samba06.sh line 44

Quoted 12 lines
tests/Functional.samba/tests/test_samba06.sh new file +12 -0
+    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/smb06.conf data/smb06.conf_bak

I don't think smb06.conf needs to be backed up or restored. This could be remove, IMHO.

Or are you trying to make it so this test can be run manually multiple times (outside of Fuego's CI context?)

Quoted 25 lines
tests/Functional.samba/tests/test_samba06.sh new file +14 -0
+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
tests/Functional.samba/tests/test_samba06_host.sh new file +4 -0
new file mode 100644
index 0000000..77ff7a5
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+#  In the target start samba, and confirm the process condition by 
+command
Quoted 2 lines

ps.
+# check the keyword "smbd".

This description doesn't seem right. isn't this a test on the host against the server running on the target?

Please update this comment, or explain why it's accurate.

Quoted 18 lines
tests/Functional.samba/tests/test_samba06_host.sh new file +17 -1
+
+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
--
Quoted 1 line

2.17.1

This is pretty nice. It's very nice to see a test that uses Fuego's inherent host/target capabilities to perform a test. And it's nice to see a test of actual samba functionality.

Please fix the items mentioned, and/or respond to comments and resubmit.

Thanks,
-- Tim

#4 lore raw

PATCH v3 1/1 openvpn: Add test cases of service openvpn.

In reply to Wang Mingyu

This test set is used to check if the service openvpn can be started. And check the process file, syslog file, tap0 can be created or not.

---
 tests/Functional.openvpn/data/host-target.key | 22 ++++++
 tests/Functional.openvpn/data/testcli.conf    |  7 ++
 tests/Functional.openvpn/data/testenv.sh      | 18 +++++
 tests/Functional.openvpn/data/testsrv.conf    | 16 +++++
 tests/Functional.openvpn/fuego_test.sh        | 19 +++++
 tests/Functional.openvpn/openvpn_test.sh      |  9 +++
 tests/Functional.openvpn/spec.json            |  6 ++
 .../tests/openvpn_genkey.sh                   | 26 +++++++
 .../tests/openvpn_lport_client.sh             | 66 +++++++++++++++++
 .../tests/openvpn_lport_server.sh             | 65 +++++++++++++++++
 .../tests/openvpn_pid_client.sh               | 62 ++++++++++++++++
 .../tests/openvpn_pid_server.sh               | 63 ++++++++++++++++
 .../tests/openvpn_ps_client.sh                | 67 +++++++++++++++++
 .../tests/openvpn_ps_server.sh                | 67 +++++++++++++++++
 .../tests/openvpn_syslog-ng_client.sh         | 71 +++++++++++++++++++
 .../tests/openvpn_syslog-ng_server.sh         | 69 ++++++++++++++++++
 .../tests/openvpn_tun_client.sh               | 56 +++++++++++++++
 .../tests/openvpn_tun_server.sh               | 56 +++++++++++++++
 18 files changed, 765 insertions(+)
 create mode 100644 tests/Functional.openvpn/data/host-target.key
 create mode 100644 tests/Functional.openvpn/data/testcli.conf
 create mode 100644 tests/Functional.openvpn/data/testenv.sh
 create mode 100644 tests/Functional.openvpn/data/testsrv.conf
 create mode 100644 tests/Functional.openvpn/fuego_test.sh
 create mode 100755 tests/Functional.openvpn/openvpn_test.sh
 create mode 100644 tests/Functional.openvpn/spec.json
 create mode 100644 tests/Functional.openvpn/tests/openvpn_genkey.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_lport_client.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_lport_server.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_pid_client.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_pid_server.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_ps_client.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_ps_server.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_syslog-ng_client.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_tun_client.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_tun_server.sh
tests/Functional.openvpn/data/host-target.key new file +22 -0
new file mode 100644
index 0000000..99743bf
@@ -0,0 +1,22 @@
+#
+# 2048 bit OpenVPN static key
+#
+-----BEGIN OpenVPN Static key V1-----
+debe9557c7eb224c5cf4f3369d5211ff
+fb9c375a4784759edf6b0f6eb8f5da31
+bb280394d40382cc8e02d6cbb3e47492
+3509eac6b48965078e3d317b0791dea2
+dbcf0eddcab0fb20780fcf0908ce94cd
+7cb65a913fea73ac6bfe0ab34f085aa3
+a6c8b89a97d189e5145c3199955c4b34
+6d51f864f2b49f3252d1548c3b3510ec
+0ecd4b9f17f2039439a79f41a46f6a54
+c0385b962b2b94fcbe73e0108b224a5b
+2efae27d872f0efef67b244c7eb6f525
+581e4c2b4e6aa193fb1d37798bdb46ff
+7c6727f08e9601c10ac7478d73d731e6
+f4b652252f3e5309cd1d6d30c7a433cc
+134bd6dd50fa6a6fc7a843fdc058d38d
+fb8679b48eb09745badf004fbf4a434c
+-----END OpenVPN Static key V1-----
+
tests/Functional.openvpn/data/testcli.conf new file +7 -0
new file mode 100644
index 0000000..2c252bb
@@ -0,0 +1,7 @@
+remote  192.168.0.1
+port    5000
+dev     tap
+#dev    tun
+verb    3
+ping    60
+
tests/Functional.openvpn/data/testenv.sh new file +18 -0
new file mode 100644
index 0000000..8c01d58
@@ -0,0 +1,18 @@
+#set the variable
+if [ "$init_manager" == "systemd" ]
+then
+        service_name="[email protected]"
+        config_file="/etc/openvpn/loopback-server.conf"
+        pid_file="/var/run/openvpn/loopback-server.pid"
+else
+        service_name="openvpn"
+        if [ "$test_type" == "client" ]
+        then
+                config_file="/etc/openvpn/testcli.conf"
+                pid_file="/var/run/openvpn.testcli.pid"
+        elif [ "$test_type" == "server" ]
+        then
+                config_file="/etc/openvpn/testsrv.conf"
+                pid_file="/var/run/openvpn.testsrv.pid"
+        fi
+fi
tests/Functional.openvpn/data/testsrv.conf new file +16 -0
new file mode 100644
index 0000000..0c18a40
@@ -0,0 +1,16 @@
+#
+proto           udp
+port            5000
+
+dev             tap
+
+secret          /etc/openvpn/host-target.key
+#link-mtu       1200
+
+ping            10
+ping-restart    60
+ping-timer-rem
+persist-key
+persist-tun
+verb            3
+
tests/Functional.openvpn/fuego_test.sh new file +19 -0
new file mode 100644
index 0000000..65d2991
@@ -0,0 +1,19 @@
+function test_pre_check {
+    assert_has_program openvpn
+}
+
+function test_deploy {
+    put $TEST_HOME/openvpn_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put $FUEGO_CORE/scripts/fuego_board_function_lib.sh $BOARD_TESTDIR/fuego.$TESTDIR
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./openvpn_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.openvpn/openvpn_test.sh new file +9 -0
new file mode 100755
index 0000000..42f41ea
@@ -0,0 +1,9 @@
+#!/bin/sh
+. ./fuego_board_function_lib.sh
+set_init_manager
+
+. data/testenv.sh
+
+for i in tests/*.sh; do
+    source $i
+done
tests/Functional.openvpn/spec.json new file +6 -0
new file mode 100644
index 0000000..e9fdc5a
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.openvpn",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.openvpn/tests/openvpn_genkey.sh new file +26 -0
new file mode 100644
index 0000000..cef533e
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+#  In target, run command openvpn.
+#  option: --genkey
+
+test="genkey"
+
+if [ -f /etc/openvpn/host-target.key ]
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+
+openvpn --genkey --secret /etc/openvpn/host-target.key
+if ls /etc/openvpn/host-target.key
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f /etc/openvpn/host-target.key
+
+if [ -f /etc/openvpn/host-target.key_bak ]
+then
+    mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+fi
+
tests/Functional.openvpn/tests/openvpn_lport_client.sh new file +66 -0

66 lines not on this page · raw message

tests/Functional.openvpn/tests/openvpn_lport_server.sh new file +65 -0

65 lines not on this page · raw message

tests/Functional.openvpn/tests/openvpn_pid_client.sh new file +62 -0

62 lines not on this page · raw message

tests/Functional.openvpn/tests/openvpn_pid_server.sh new file +63 -0

63 lines not on this page · raw message

tests/Functional.openvpn/tests/openvpn_ps_client.sh new file +67 -0

67 lines not on this page · raw message

tests/Functional.openvpn/tests/openvpn_ps_server.sh new file +67 -0

67 lines not on this page · raw message

tests/Functional.openvpn/tests/openvpn_syslog-ng_client.sh new file +71 -0

71 lines not on this page · raw message

tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh new file +69 -0

69 lines not on this page · raw message

tests/Functional.openvpn/tests/openvpn_tun_client.sh new file +56 -0

56 lines not on this page · raw message

tests/Functional.openvpn/tests/openvpn_tun_server.sh new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.17.1
#5 lore raw

Re: [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn.

Quoted 181 lines

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

This test set is used to check if the service openvpn can be started. And check the process file, syslog file, tap0 can be created or not.

---
 tests/Functional.openvpn/data/host-target.key | 22 ++++++
 tests/Functional.openvpn/data/testcli.conf    |  7 ++
 tests/Functional.openvpn/data/testenv.sh      | 18 +++++
 tests/Functional.openvpn/data/testsrv.conf    | 16 +++++
 tests/Functional.openvpn/fuego_test.sh        | 19 +++++
 tests/Functional.openvpn/openvpn_test.sh      |  9 +++
 tests/Functional.openvpn/spec.json            |  6 ++
 .../tests/openvpn_genkey.sh                   | 26 +++++++
 .../tests/openvpn_lport_client.sh             | 66 +++++++++++++++++
 .../tests/openvpn_lport_server.sh             | 65 +++++++++++++++++
 .../tests/openvpn_pid_client.sh               | 62 ++++++++++++++++
 .../tests/openvpn_pid_server.sh               | 63 ++++++++++++++++
 .../tests/openvpn_ps_client.sh                | 67 +++++++++++++++++
 .../tests/openvpn_ps_server.sh                | 67 +++++++++++++++++
 .../tests/openvpn_syslog-ng_client.sh         | 71 +++++++++++++++++++
 .../tests/openvpn_syslog-ng_server.sh         | 69 ++++++++++++++++++
 .../tests/openvpn_tun_client.sh               | 56 +++++++++++++++
 .../tests/openvpn_tun_server.sh               | 56 +++++++++++++++
 18 files changed, 765 insertions(+)
 create mode 100644 tests/Functional.openvpn/data/host-target.key
 create mode 100644 tests/Functional.openvpn/data/testcli.conf
 create mode 100644 tests/Functional.openvpn/data/testenv.sh
 create mode 100644 tests/Functional.openvpn/data/testsrv.conf
 create mode 100644 tests/Functional.openvpn/fuego_test.sh
 create mode 100755 tests/Functional.openvpn/openvpn_test.sh
 create mode 100644 tests/Functional.openvpn/spec.json
 create mode 100644 tests/Functional.openvpn/tests/openvpn_genkey.sh
 create mode 100644
tests/Functional.openvpn/tests/openvpn_lport_client.sh
 create mode 100644
tests/Functional.openvpn/tests/openvpn_lport_server.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_pid_client.sh
 create mode 100644
tests/Functional.openvpn/tests/openvpn_pid_server.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_ps_client.sh
 create mode 100644
tests/Functional.openvpn/tests/openvpn_ps_server.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_syslog-
ng_client.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_syslog-
ng_server.sh
 create mode 100644
tests/Functional.openvpn/tests/openvpn_tun_client.sh
 create mode 100644

tests/Functional.openvpn/tests/openvpn_tun_server.sh

tests/Functional.openvpn/data/host-target.key new file +22 -0
new file mode 100644
index 0000000..99743bf
@@ -0,0 +1,22 @@
+#
+# 2048 bit OpenVPN static key
+#
+-----BEGIN OpenVPN Static key V1-----
+debe9557c7eb224c5cf4f3369d5211ff
+fb9c375a4784759edf6b0f6eb8f5da31
+bb280394d40382cc8e02d6cbb3e47492
+3509eac6b48965078e3d317b0791dea2
+dbcf0eddcab0fb20780fcf0908ce94cd
+7cb65a913fea73ac6bfe0ab34f085aa3
+a6c8b89a97d189e5145c3199955c4b34
+6d51f864f2b49f3252d1548c3b3510ec
+0ecd4b9f17f2039439a79f41a46f6a54
+c0385b962b2b94fcbe73e0108b224a5b
+2efae27d872f0efef67b244c7eb6f525
+581e4c2b4e6aa193fb1d37798bdb46ff
+7c6727f08e9601c10ac7478d73d731e6
+f4b652252f3e5309cd1d6d30c7a433cc
+134bd6dd50fa6a6fc7a843fdc058d38d
+fb8679b48eb09745badf004fbf4a434c
+-----END OpenVPN Static key V1-----
+
tests/Functional.openvpn/data/testcli.conf new file +7 -0
new file mode 100644
index 0000000..2c252bb
@@ -0,0 +1,7 @@
+remote  192.168.0.1
+port    5000
+dev     tap
+#dev    tun
+verb    3
+ping    60
+
tests/Functional.openvpn/data/testenv.sh new file +18 -0
new file mode 100644
index 0000000..8c01d58
@@ -0,0 +1,18 @@
+#set the variable
+if [ "$init_manager" == "systemd" ]
+then
+        service_name="[email protected]"
+        config_file="/etc/openvpn/loopback-server.conf"
+        pid_file="/var/run/openvpn/loopback-server.pid"
+else
+        service_name="openvpn"
+        if [ "$test_type" == "client" ]
+        then
+                config_file="/etc/openvpn/testcli.conf"
+                pid_file="/var/run/openvpn.testcli.pid"
+        elif [ "$test_type" == "server" ]
+        then
+                config_file="/etc/openvpn/testsrv.conf"
+                pid_file="/var/run/openvpn.testsrv.pid"
+        fi
+fi
tests/Functional.openvpn/data/testsrv.conf new file +16 -0
new file mode 100644
index 0000000..0c18a40
@@ -0,0 +1,16 @@
+#
+proto           udp
+port            5000
+
+dev             tap
+
+secret          /etc/openvpn/host-target.key
+#link-mtu       1200
+
+ping            10
+ping-restart    60
+ping-timer-rem
+persist-key
+persist-tun
+verb            3
+
tests/Functional.openvpn/fuego_test.sh new file +7 -0
new file mode 100644
index 0000000..65d2991
@@ -0,0 +1,19 @@
+function test_pre_check {
+    assert_has_program openvpn
+}
+
+function test_deploy {
+    put $TEST_HOME/openvpn_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put $FUEGO_CORE/scripts/fuego_board_function_lib.sh

$BOARD_TESTDIR/fuego.$TESTDIR

tests/Functional.openvpn/fuego_test.sh new file +12 -0
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./openvpn_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.openvpn/openvpn_test.sh new file +0 -0
new file mode 100755
index 0000000..42f41ea

tests/Functional.openvpn/openvpn_test.sh line 5

Quoted 5 lines
tests/Functional.openvpn/openvpn_test.sh new file +5 -0
@@ -0,0 +1,9 @@
+#!/bin/sh
+. ./fuego_board_function_lib.sh
+set_init_manager
+
+. data/testenv.sh

I don't see how this works.
This source ('.') only happens once, in this wrapper script. But the variables set by the if statement in data/testenv.sh need to change depending on $test_type, that is sourced in the loop below.

The first part of data/testenv.sh, which sets the service name can be done once per invocation of openvpn_test.sh. But the setting of config_file and pid_file needs to happen *after* the sub-test script has been sourced.

This needs to be restructured so that setting the getting the config_file and pid_file is done using a function, called by each sub-test shell script.

This code won't work in the non-systemd case at all.

Quoted 28 lines
tests/Functional.openvpn/openvpn_test.sh new file +4 -0
+
+for i in tests/*.sh; do
+    source $i
+done
tests/Functional.openvpn/spec.json new file +6 -0
new file mode 100644
index 0000000..e9fdc5a
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.openvpn",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.openvpn/tests/openvpn_genkey.sh new file +4 -0
new file mode 100644
index 0000000..cef533e
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+#  In target, run command openvpn.
+#  option: --genkey

tests/Functional.openvpn/tests/openvpn_genkey.sh line 14

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_genkey.sh new file +10 -0
+
+test="genkey"
+
+if [ -f /etc/openvpn/host-target.key ]
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+
+openvpn --genkey --secret /etc/openvpn/host-target.key
+if ls /etc/openvpn/host-target.key

should use 'if [ -f /etc/openvpn/host-target.key' here

Using test (or '[') for file existence is preferred over ls.

Quoted 23 lines
tests/Functional.openvpn/tests/openvpn_genkey.sh new file +12 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f /etc/openvpn/host-target.key
+
+if [ -f /etc/openvpn/host-target.key_bak ]
+then
+    mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+fi
+
tests/Functional.openvpn/tests/openvpn_lport_client.sh new file +4 -0
new file mode 100644
index 0000000..f8aac80
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the Listening port.
+

tests/Functional.openvpn/tests/openvpn_lport_client.sh line 14

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_lport_client.sh new file +10 -0
+test="lport_client"
+
+test_type="client"
+
+service_status=$(get_service_status $service_name)
+exec_service_on_target $service_name stop
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"

I would prefer it is you used "${config_file}_bak" instead of $config_file"_bak", throughout all these test scripts.

Starting quotes in the middle of the string is hard to read.

Quoted 16 lines
tests/Functional.openvpn/tests/openvpn_lport_client.sh new file +16 -0
+fi
+cp data/testcli.conf $config_file
+
+if [ -f /etc/openvpn/host-target.key ]
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200
+
+restore_target() {
+    rm -fr /dev/net
+    rm $config_file
+    if [ -f $config_file"_bak" ]

tests/Functional.openvpn/tests/openvpn_lport_client.sh line 40

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_lport_client.sh new file +10 -0
+    then
+        mv $config_file"_bak" $config_file
+    fi
+    rm -r /etc/openvpn/host-target.key
+    if [ -f /etc/openvpn/host-target.key_bak ]
+    then
+        mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+    fi
+
+    modprobe -r tun

There's no check whether module 'tun' was loaded before the test or not. If it was already loaded, we should not remove it.

Quoted 5 lines
tests/Functional.openvpn/tests/openvpn_lport_client.sh new file +5 -0
+}
+
+if exec_service_on_target $service_name start
+then
+    echo " -> $test: service start succeeded."

tests/Functional.openvpn/tests/openvpn_lport_client.sh line 55

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_lport_client.sh new file +10 -0
+else
+    echo " -> $test: service start failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if netstat -ln | grep ":5000"

Need to add 'assert_has_program netstat' to test_precheck in fuego_test.sh.

Quoted 36 lines
tests/Functional.openvpn/tests/openvpn_lport_client.sh new file +11 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+if [ "$service_status" = "inactive" ]
+then
+    exec_service_on_target $service_name stop
+fi
+restore_target
tests/Functional.openvpn/tests/openvpn_lport_server.sh new file +18 -0
new file mode 100644
index 0000000..0377c2d
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the Listening port.
+
+test="lport_server"
+
+test_type="server"
+
+service_status=$(get_service_status $service_name)
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"
+fi
+cp data/testsrv.conf $config_file
+
+if [ -f /etc/openvpn/host-target.key ]
+then

tests/Functional.openvpn/tests/openvpn_lport_server.sh line 28

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_lport_server.sh new file +10 -0
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200
+
+restore_target() {
+    rm -fr /dev/net

What happens if /dev/net already existed before the test?

If I ran this test on my Ubuntu machine as root, I would lose my default installation of /dev/net/tun. Please only remove this directory if it did not already exist when the test started. (You'll have to save the status of this above when you do the mkdir)

Quoted 62 lines
tests/Functional.openvpn/tests/openvpn_lport_server.sh new file +37 -0
+    rm $config_file
+    if [ -f $config_file"_bak" ]
+    then
+        mv $config_file"_bak" $config_file
+    fi
+    rm -r /etc/openvpn/host-target.key
+    if [ -f /etc/openvpn/host-target.key_bak ]
+    then
+        mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+    fi
+
+    modprobe -r tun
+}
+
+if exec_service_on_target $service_name start
+then
+    echo " -> $test: service start succeeded."
+else
+    echo " -> $test: service start failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if netstat -ln | grep ":5000"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+if [ "$service_status" = "inactive" ]
+then
+    exec_service_on_target $service_name stop
+fi
+restore_target
tests/Functional.openvpn/tests/openvpn_pid_client.sh new file +18 -0
new file mode 100644
index 0000000..a7829b2
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the pidfile.
+
+test="pid_client"
+
+test_type="client"
+
+service_status=$(get_service_status $service_name)
+exec_service_on_target $service_name stop
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"
+fi
+cp data/testcli.conf $config_file
+
+if [ -f /etc/openvpn/host-target.key ]

tests/Functional.openvpn/tests/openvpn_pid_client.sh line 28

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_pid_client.sh new file +10 -0
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200
+
+restore_target() {
+    rm -fr /dev/net

Same issue here. Please don't remove stuff unless you know you created it.

tests/Functional.openvpn/tests/openvpn_pid_client.sh line 39

Quoted 11 lines
tests/Functional.openvpn/tests/openvpn_pid_client.sh new file +11 -0
+    rm $config_file
+    if [ -f $config_file"_bak" ]
+    then
+        mv $config_file"_bak" $config_file
+    fi
+    rm -r /etc/openvpn/host-target.key
+    if [ -f /etc/openvpn/host-target.key_bak ]
+    then
+        mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+    fi
+    modprobe -r tun

Please don't remove modules unless you know you inserted them.

tests/Functional.openvpn/tests/openvpn_pid_client.sh line 52

Quoted 13 lines
tests/Functional.openvpn/tests/openvpn_pid_client.sh new file +13 -0
+}
+
+if exec_service_on_target $service_name start
+then
+    echo " -> $test: service start succeeded."
+else
+    echo " -> $test: service start failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+if ls $pid_file

Please check for presence of a file with '[ -f $pid_file'

Quoted 35 lines
tests/Functional.openvpn/tests/openvpn_pid_client.sh new file +10 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+if [ "$service_status" = "inactive" ]
+then
+    exec_service_on_target $service_name stop
+fi
+restore_target
tests/Functional.openvpn/tests/openvpn_pid_server.sh new file +18 -0
new file mode 100644
index 0000000..e2f2e7b
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the pidfile.
+
+test="pid_server"
+
+test_type="server"
+
+service_status=$(get_service_status $service_name)
+exec_service_on_target $service_name stop
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"
+fi
+cp data/testsrv.conf $config_file
+
+if [ -f /etc/openvpn/host-target.key ]

tests/Functional.openvpn/tests/openvpn_pid_server.sh line 28

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_pid_server.sh new file +10 -0
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200
+
+restore_target() {
+    rm -fr /dev/net

Same issue as above.

Quoted 14 lines
tests/Functional.openvpn/tests/openvpn_pid_server.sh new file +14 -0
+    rm $config_file
+    if [ -f $config_file"_bak" ]
+    then
+        mv $config_file"_bak" $config_file
+    fi
+    rm -r /etc/openvpn/host-target.key
+    if [ -f /etc/openvpn/host-target.key_bak ]
+    then
+        mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+    fi
+    modprobe -r tun
+}
+
+if exec_service_on_target $service_name start

tests/Functional.openvpn/tests/openvpn_pid_server.sh line 52

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_pid_server.sh new file +10 -0
+then
+    echo " -> $test: service start succeeded."
+else
+    echo " -> $test: service start failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+if ls $pid_file

please use '[ -f $pid_file' for detecting the presence of a file.

Quoted 33 lines
tests/Functional.openvpn/tests/openvpn_pid_server.sh new file +11 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+if [ "$service_status" = "inactive" ]
+then
+    exec_service_on_target $service_name stop
+fi
+restore_target
tests/Functional.openvpn/tests/openvpn_ps_client.sh new file +15 -0
new file mode 100644
index 0000000..956c2fd
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the status of process.
+
+test="ps_client"
+
+test_type="client"
+
+service_status=$(get_service_status $service_name)
+exec_service_on_target $service_name stop
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"
+fi

tests/Functional.openvpn/tests/openvpn_ps_client.sh line 25

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_ps_client.sh new file +10 -0
+cp data/testcli.conf $config_file
+
+if [ -f /etc/openvpn/host-target.key ]
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200

This pattern is repeated a lot. You should put this into a shell library and source it into all the sub-scripts.

I think you should probably structure this with a setup routine (in data/testenv.sh) and a restore routine (also in data/testenv.sh)

Quoted 201 lines
tests/Functional.openvpn/tests/openvpn_ps_client.sh new file +42 -0
+
+restore_target() {
+    rm -fr /dev/net
+    rm $config_file
+    if [ -f $config_file"_bak" ]
+    then
+        mv $config_file"_bak" $config_file
+    fi
+    rm -r /etc/openvpn/host-target.key
+    if [ -f /etc/openvpn/host-target.key_bak ]
+    then
+        mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+    fi
+    modprobe -r tun
+}
+
+exec_service_on_target $service_name start
+
+if ps aux | grep "[/]usr/sbin/openvpn"
+then
+    echo " -> $test: get the process of openvpn succeeded."
+else
+    echo " -> $test: get the process of openvpn failed."
+    echo " -> $test: TEST-FAIL"
+    exec_service_on_target $service_name stop
+    restore_target
+    exit
+fi
+
+exec_service_on_target $service_name stop
+
+if ! ps aux | grep "[/]usr/sbin/openvpn"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+restore_target
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target $service_name start
+fi
tests/Functional.openvpn/tests/openvpn_ps_server.sh new file +67 -0
new file mode 100644
index 0000000..6a6a25c
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the status of process.
+
+test="ps_server"
+
+test_type="server"
+
+service_status=$(get_service_status $service_name)
+exec_service_on_target $service_name stop
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"
+fi
+cp data/testsrv.conf $config_file
+
+if [ -f /etc/openvpn/host-target.key ]
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200
+
+restore_target() {
+    rm -fr /dev/net
+    rm $config_file
+    if [ -f $config_file"_bak" ]
+    then
+        mv $config_file"_bak" $config_file
+    fi
+    rm -r /etc/openvpn/host-target.key
+    if [ -f /etc/openvpn/host-target.key_bak ]
+    then
+        mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+    fi
+    modprobe -r tun
+}
+
+exec_service_on_target $service_name start
+
+if ps aux | grep "[/]usr/sbin/openvpn"
+then
+    echo " -> $test: get the process of openvpn succeeded."
+else
+    echo " -> $test: get the process of openvpn failed."
+    echo " -> $test: TEST-FAIL"
+    exec_service_on_target $service_name stop
+    restore_target
+    exit
+fi
+
+exec_service_on_target $service_name stop
+
+if ! ps aux | grep "[/]usr/sbin/openvpn"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+restore_target
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target $service_name start
+fi
tests/Functional.openvpn/tests/openvpn_syslog-ng_client.sh new file +71 -0
new file mode 100644
index 0000000..7b4f36c
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the message of syslog-ng.
+
+test="syslog-ng_client"
+
+test_type="client"
+
+logger_service=$(detect_logger_service)
+openvpn_logfile=$(get_service_logfile)
+service_status=$(get_service_status $service_name)
+
+exec_service_on_target $service_name stop
+exec_service_on_target $logger_service stop
+
+if [ -f $openvpn_logfile ]
+then
+    mv $openvpn_logfile $openvpn_logfile"_bak"
+fi
+
+exec_service_on_target $logger_service restart
+
+sleep 2
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"
+fi
+cp data/testcli.conf $config_file
+
+if [ -f /etc/openvpn/host-target.key ]
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200
+
+exec_service_on_target $service_name start
+
+sleep 5
+
+if cat $openvpn_logfile | grep OpenVPN
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+exec_service_on_target $service_name stop
+
+rm -fr /dev/net
+
+rm $config_file
+if [ -f $config_file"_bak" ]
+then
+    mv $config_file"_bak" $config_file
+fi
+
+rm -r /etc/openvpn/host-target.key
+if [ -f /etc/openvpn/host-target.key_bak ]
+then
+    mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+fi
+
+modprobe -r tun
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target $service_name start
+fi
tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh new file +0 -0
new file mode 100644
index 0000000..29a53b9

tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh line 6

Quoted 6 lines
tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh new file +6 -0
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the message of syslog-ng.
+
+test="syslog-ng_server"
+

This script is missing the line:
test_type="server"

This wouldn't work in the non-systemd case (even if the source of data/testenv.sh was correct)

Quoted 11 lines
tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh new file +11 -0
+logger_service=$(detect_logger_service)
+service_status=$(get_service_status $service_name)
+openvpn_logfile=$(get_service_logfile)
+
+exec_service_on_target $service_name stop
+exec_service_on_target $logger_service stop
+
+if [ -f $openvpn_logfile ]
+then
+    mv $openvpn_logfile $openvpn_logfile"_bak"
+fi

tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh line 27

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh new file +10 -0
+
+exec_service_on_target $logger_service restart
+
+sleep 2
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"
+fi
+cp data/testsrv.conf $config_file

If you restructure this with some library functions for setup and teardown, you can probably include the cp in the library setup function.
that is, something like this:
if [ "$test_type" = "client" ] ; then
cp data/testcli.conf $config_file
elif [ "$test_type" = "server" ] ; then
cp data/testsrc.conf $config_file
else

    echo " -> $test: TEST-ERROR - invalid test_type"
    return 1

fi

Quoted 68 lines
tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh new file +42 -0
+
+if [ -f /etc/openvpn/host-target.key ]
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200
+
+exec_service_on_target $service_name start
+
+sleep 5
+
+if cat $openvpn_logfile | grep OpenVPN
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+exec_service_on_target $service_name stop
+
+rm -fr /dev/net
+
+rm $config_file
+if [ -f $config_file"_bak" ]
+then
+    mv $config_file"_bak" $config_file
+fi
+
+rm -r /etc/openvpn/host-target.key
+if [ -f /etc/openvpn/host-target.key_bak ]
+then
+    mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+fi
+
+modprobe -r tun
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target $service_name start
+fi
tests/Functional.openvpn/tests/openvpn_tun_client.sh new file +19 -0
new file mode 100644
index 0000000..7bba41e
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# Verify the creation of the tun device (tap0) interface by openvpn.
+
+test="tun_client"
+
+test_type="client"
+
+service_status=$(get_service_status $service_name)
+exec_service_on_target $service_name stop
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"
+fi
+cp data/testcli.conf $config_file
+
+if [ -f /etc/openvpn/host-target.key ]
+then

tests/Functional.openvpn/tests/openvpn_tun_client.sh line 29

Quoted 10 lines
tests/Functional.openvpn/tests/openvpn_tun_client.sh new file +10 -0
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200
+
+exec_service_on_target $service_name start
+
+if ifconfig tap0

Need to add 'assert_has_program ifconfig' to test_precheck in fuego_test.sh

Quoted 91 lines
tests/Functional.openvpn/tests/openvpn_tun_client.sh new file +27 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+exec_service_on_target $service_name stop
+
+rm -fr /dev/net
+
+rm $config_file
+if [ -f $config_file"_bak" ]
+then
+    mv $config_file"_bak" $config_file
+fi
+
+rm -r /etc/openvpn/host-target.key
+if [ -f /etc/openvpn/host-target.key_bak ]
+then
+    mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+fi
+
+modprobe -r tun
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target $service_name start
+fi
tests/Functional.openvpn/tests/openvpn_tun_server.sh new file +56 -1
new file mode 100644
index 0000000..4a9aa46
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# Verify the creation of the tun device (tap0) interface by openvpn.
+
+test="tun_server"
+
+test_type="server"
+
+service_status=$(get_service_status $service_name)
+exec_service_on_target $service_name stop
+
+if [ -f $config_file ]
+then
+    mv $config_file $config_file"_bak"
+fi
+cp data/testsrv.conf $config_file
+
+if [ -f /etc/openvpn/host-target.key ]
+then
+    mv /etc/openvpn/host-target.key /etc/openvpn/host-target.key_bak
+fi
+cp data/host-target.key /etc/openvpn/host-target.key
+
+mkdir -m 755 /dev/net
+mknod /dev/net/tun c 10 200
+
+exec_service_on_target $service_name start
+
+if ifconfig tap0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+exec_service_on_target $service_name stop
+
+rm -fr /dev/net
+
+rm $config_file
+if [ -f $config_file"_bak" ]
+then
+    mv $config_file"_bak" $config_file
+fi
+
+rm -r /etc/openvpn/host-target.key
+if [ -f /etc/openvpn/host-target.key_bak ]
+then
+    mv /etc/openvpn/host-target.key_bak /etc/openvpn/host-target.key
+fi
+
+modprobe -r tun
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target $service_name start
+fi
--
Quoted 1 line

2.17.1

Thanks for the submission.
This is getting better. Please address my comments and submit it again.
-- Tim

#6 lore raw
In reply to Wang Mingyu
Quoted 59 lines

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

Logrotate is designed to ease administration of systems that generate large numbers of log files.
This test set is used to check if rotate file can be created.

---
 tests/Functional.logrotate/data/test.conf     |   8 ++++
 tests/Functional.logrotate/data/testlog.sh    |   5 ++
 tests/Functional.logrotate/data/testlog100k   | Bin 0 -> 105984 bytes
 tests/Functional.logrotate/fuego_test.sh      |  19 ++++++++
 tests/Functional.logrotate/logrotate_test.sh  |   4 ++
 tests/Functional.logrotate/spec.json          |   6 +++
 tests/Functional.logrotate/test.yaml          |  23 ++++++++++
 .../tests/logrotate_01.sh                     |  13 ++++++
 .../tests/logrotate_02.sh                     |  23 ++++++++++
 .../tests/logrotate_03.sh                     |  19 ++++++++
 .../tests/logrotate_04.sh                     |  43 ++++++++++++++++++
 .../tests/logrotate_05.sh                     |  30 ++++++++++++
 12 files changed, 193 insertions(+)
 create mode 100644 tests/Functional.logrotate/data/test.conf
 create mode 100644 tests/Functional.logrotate/data/testlog.sh
 create mode 100644 tests/Functional.logrotate/data/testlog100k
 create mode 100644 tests/Functional.logrotate/fuego_test.sh
 create mode 100755 tests/Functional.logrotate/logrotate_test.sh
 create mode 100644 tests/Functional.logrotate/spec.json
 create mode 100644 tests/Functional.logrotate/test.yaml
 create mode 100644 tests/Functional.logrotate/tests/logrotate_01.sh
 create mode 100644 tests/Functional.logrotate/tests/logrotate_02.sh
 create mode 100644 tests/Functional.logrotate/tests/logrotate_03.sh
 create mode 100644 tests/Functional.logrotate/tests/logrotate_04.sh
 create mode 100644 tests/Functional.logrotate/tests/logrotate_05.sh
tests/Functional.logrotate/data/test.conf new file +8 -0
new file mode 100644
index 0000000..a346adf
@@ -0,0 +1,8 @@
+/var/log/testlog {
+        create 600 root root
+        ifempty
+        daily
+        nocompress
+        missingok
+        rotate 1
+}
tests/Functional.logrotate/data/testlog.sh new file +0 -0
new file mode 100644
index 0000000..da7a877

tests/Functional.logrotate/data/testlog.sh line 3

Quoted 3 lines
tests/Functional.logrotate/data/testlog.sh new file +3 -0
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+ddch=`date --date ' 1 days ago' '+%Y-%m-%d'`

Hmmm. I'm not sure if we need an assert_has_program on 'date' or not. It's not in our required programs list, but maybe it should be. For now, I think it's OK to not add the 'assert_has_program date'. But there's a bigger problem.

The busybox date command does not support this '1 days ago' syntax, so this will be a problem on machines with only the busybox version of 'date'. I'm not sure what to do about that. Coming up with the correct syntax for the logrotate.status file will be quite difficult if we can't use 'date' to calculate yesterday's date string.

Let me know what you think.

Quoted 240 lines
tests/Functional.logrotate/data/testlog.sh new file +2 -0
+echo "logrotate state -- version 2" >> /var/lib/logrotate.status
+echo "\"/var/log/testlog\" $ddch" >> /var/lib/logrotate.status
tests/Functional.logrotate/data/testlog100k new file +0 -0
new file mode 100644

index 0000000000000000000000000000000000000000..1dc679f54731568a9cbda775a6 63b7ea51595fe3
GIT binary patch
literal 105984 zcmeI5d0-U9^2b*N!X;-EJdh;28zdV8yGaO9L{XdL$K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1OjK8jU>Ieo8$yB>*t^M!N{HG|{=C50Sq4|HF%>V0PcD *>M rFjK9XhUMR8{oi(p%|EDl0jAe4@xQqeuPfMaO{VH_1<yat@4x>AP`)FD

Quoted 2 lines

literal 0
HcmV?d00001

I'm shocked that this 100K file compressed down to something so small. But that's good, I guess.

tests/Functional.logrotate/fuego_test.sh

Quoted 8 lines
tests/Functional.logrotate/fuego_test.sh new file +0 -0
new file mode 100644
index 0000000..64a83b2
@@ -0,0 +1,19 @@

I think you probably need a NEED_ROOT=1 here

Quoted 54 lines
tests/Functional.logrotate/fuego_test.sh new file +19 -0
+function test_pre_check {
+    assert_has_program logrotate
+}
+
+function test_deploy {
+    put $TEST_HOME/logrotate_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    export test_host=$SRV_IP;\
+    ./logrotate_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.logrotate/logrotate_test.sh new file +4 -0
new file mode 100755
index 0000000..dd5ce37
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
tests/Functional.logrotate/spec.json new file +6 -0
new file mode 100644
index 0000000..cfd6646
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.logrotate",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.logrotate/test.yaml new file +4 -0
new file mode 100644
index 0000000..1b2d2d9
@@ -0,0 +1,23 @@
+fuego_package_version: 1
+name: Functional.logrotate
+description: |
+      Logrotate is designed to ease administration of systems that generate
Quoted 1 line

large numbers of log files.

Please keep lines in the description field in the test.yaml file to 80 chars or less.

Quoted 28 lines

+ It allows automatic rotation, compression, removal, and mailing of log
files.
+ This is a simple test to check the common options and features of
logrotate.

tests/Functional.logrotate/test.yaml new file +17 -0
+license: BSD-3-Clause
+author: Wang Mingyu <[email protected]>
+maintainer: Wang Mingyu <[email protected]>
+version: 1.00
+fuego_release: 1
+type: Functional
+tags: ['logrotate']
+params:
+    SRV_IP:
+        description: the IP address of your host - Defined in board file
+data_files:
+ - logrotate_test.sh
+ - fuego_test.sh
+ - spec.json
+ - test.yaml
+ - data
+ - tests
tests/Functional.logrotate/tests/logrotate_01.sh new file +0 -0
new file mode 100644
index 0000000..5aed3e3

tests/Functional.logrotate/tests/logrotate_01.sh line 6

Quoted 6 lines
tests/Functional.logrotate/tests/logrotate_01.sh new file +6 -0
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate and confirm the result.
+#  option : --help
+
+test="logrotate1"

These are not very descriptive testcase names.

I'd prefer something like test="logrotate-usage". but since the filename encodes the testcase number, maybe it's best to keep them the same.

Quoted 74 lines
tests/Functional.logrotate/tests/logrotate_01.sh new file +7 -0
+
+if logrotate --help | grep "Usage"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
tests/Functional.logrotate/tests/logrotate_02.sh new file +23 -0
new file mode 100644
index 0000000..4e16d0b
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate and confirm the result.
+#  option : -dv
+
+test="logrotate2"
+
+if [ -f /var/lib/logrotate.status ]
+then
+    rm -f /var/lib/logrotate.status
+fi
+
+cp data/test.conf /etc/logrotate.d/test.conf
+
+chown root /etc/logrotate.d/test.conf
+
+if logrotate -dv /etc/logrotate.d/test.conf
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f /etc/logrotate.d/test.conf
tests/Functional.logrotate/tests/logrotate_03.sh new file +19 -0
new file mode 100644
index 0000000..98a850d
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate and confirm the result.
+#  option : -v
+
+test="logrotate3"
+
+cp data/test.conf /etc/logrotate.d/test.conf
+
+logrotate -v /etc/logrotate.d/test.conf
+
+if tail /var/lib/logrotate.status | grep testlog
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f /etc/logrotate.d/test.conf
+sed -i '/testlog/d' /var/lib/logrotate.status
tests/Functional.logrotate/tests/logrotate_04.sh new file +3 -0
new file mode 100644
index 0000000..08bfbf5
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate. Verify that the rotate file is

created in the specified directory.

tests/Functional.logrotate/tests/logrotate_04.sh line 13

Quoted 10 lines
tests/Functional.logrotate/tests/logrotate_04.sh new file +10 -0
+#  option : -v
+
+test="logrotate4"
+
+if [ -f /var/log/testlog* ]
+then
+    rm -f /var/log/testlog*
+fi
+
+if [ -f /home/test/testlog.sh ]

Is this the Fuego test directory? Is this required to be present on machines, before the test starts?

tests/Functional.logrotate/tests/logrotate_04.sh line 16

Quoted 3 lines
tests/Functional.logrotate/tests/logrotate_04.sh new file +3 -0
+then
+    rm -f /home/test/testlog.sh
+fi

What is the purpose of these lines? Why is /home/test/testlog.sh being removed?

tests/Functional.logrotate/tests/logrotate_04.sh line 23

Quoted 7 lines
tests/Functional.logrotate/tests/logrotate_04.sh new file +7 -0
+
+if [ -f /var/lib/logrotate.status ]
+then
+    rm -f /var/lib/logrotate.status
+fi
+
+ntpdate $test_host

Need an assert_has_program for ntpdate as well.

Quoted 10 lines
tests/Functional.logrotate/tests/logrotate_04.sh new file +10 -0
+
+cp data/test.conf /etc/logrotate.d/test.conf
+
+touch /var/log/testlog
+
+chmod +x data/testlog.sh
+data/testlog.sh
+chown root /etc/logrotate.d/test.conf
+logrotate -v /etc/logrotate.d/test.conf
+if ls /var/log/testlog.1

tests/Functional.logrotate/tests/logrotate_04.sh line 43

Quoted 10 lines
tests/Functional.logrotate/tests/logrotate_04.sh new file +10 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+rm -f /etc/logrotate.d/test.conf
+rm -f /var/log/testlog*
+sed -i '/testlog/d' /var/lib/logrotate.status
+sed -i '/logrotate/d' /var/lib/logrotate.status

These sed lines are quite dangerous - especially the /logrotate/d one. Are you sure you want to remove all lines from logrotate.status have have logrotate in them?

Quoted 11 lines
tests/Functional.logrotate/tests/logrotate_05.sh new file +3 -0
new file mode 100644
index 0000000..a5f61dc
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate.Verify that the rotate file is

created in the specified directory(Specify the file size).

Please keep lines to 80 columns.

Quoted 28 lines
tests/Functional.logrotate/tests/logrotate_05.sh new file +27 -1
+#  option : -v
+
+test="logrotate5"
+
+if [ -f /var/log/testlog* ]
+then
+    rm -f /var/log/testlog*
+fi
+
+cp data/test.conf /etc/logrotate.d/test.conf
+
+cp data/testlog100k /var/log/testlog
+
+chmod +x data/testlog.sh
+data/testlog.sh
+chown root /etc/logrotate.d/test.conf
+logrotate -v /etc/logrotate.d/test.conf
+if ls /var/log/testlog.1
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+rm -f /etc/logrotate.d/test.conf
+rm -f /var/log/testlog*
+sed -i '/testlog/d' /var/lib/logrotate.status
--
Quoted 1 line

2.17.1

Thanks for the patch.
Please respond to the comments, and re-submit it.

-- Tim

#7 lore raw
In reply to Wang Mingyu
Quoted 6 lines

-----Original Message-----
From: Bird, Tim

Quoted 3 lines

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

...

Quoted 17 lines

tests/Functional.logrotate/data/testlog.sh line 3

Quoted 5 lines

+++ b/tests/Functional.logrotate/data/testlog.sh

tests/Functional.logrotate/data/testlog.sh new file +3 -0
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+ddch=`date --date ' 1 days ago' '+%Y-%m-%d'`

Hmmm. I'm not sure if we need an assert_has_program on 'date' or not. It's not in our required programs list, but maybe it should be. For now, I think it's OK to not add the 'assert_has_program date'. But there's a bigger problem.

The busybox date command does not support this '1 days ago' syntax, so this will be a problem on machines with only the busybox version of 'date'. I'm not sure what to do about that. Coming up with the correct syntax for the logrotate.status file will be quite difficult if we can't use 'date' to calculate yesterday's date string.

Quoted 4 lines

Let me know what you think.

tests/Functional.logrotate/data/testlog.sh line 5

Quoted 2 lines
tests/Functional.logrotate/data/testlog.sh new file +2 -0
+echo "logrotate state -- version 2" >> /var/lib/logrotate.status
+echo "\"/var/log/testlog\" $ddch" >> /var/lib/logrotate.status

OK. I thought some more about this, and I think I've found something that will work with busybox. busybox date does not support "1 day ago", but it does support working with the date in seconds format. And posix shells support arithmetic. So the following should work:

today=$(date +%s)

# there are 86000 seconds in a day
yesterday=$(( $today - 86000 ))
ddch=$(date --date "@$yesterday" "+%Y-%m-%d"

Now, this code might have boundary issues. That is, what happens
if you just happen to run the code when the target board thinks it is 1 second to midnight. It's not clear to me that the original code, or the rest of this test is free from this boundary issue either, so I think the code above should suffice. Besides, this will be a rare event, and really any test that fails should be re-run to validate the status before turning the result into a bug report. The chance of the test failing twice due to this boundary issue is, IMHO, acceptably small.

Please use this code for the calculation of '1 day ago' to put into the logrotate.status file.

Also, please use modern shell command substitution syntax:
foo=$(cmd args ...)
rather than backticks
foo=cmd args ...

for grabbing command output into variables. The backtick method is deprecated.

Thanks,
-- Tim