All of lore.kernel.org
 help / color / mirror / Atom feed
* [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate.
@ 2019-11-05  9:01 Wang Mingyu
  2019-11-05  9:01 ` [Fuego] [PATCH] samba: Add test case to access the target from host using samba Wang Mingyu
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Wang Mingyu @ 2019-11-05  9:01 UTC (permalink / raw)
  To: fuego

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.

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 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

diff --git a/tests/Functional.logrotate/data/test.conf b/tests/Functional.logrotate/data/test.conf
new file mode 100644
index 0000000..a346adf
--- /dev/null
+++ b/tests/Functional.logrotate/data/test.conf
@@ -0,0 +1,8 @@
+/var/log/testlog {
+        create 600 root root
+        ifempty
+        daily
+        nocompress
+        missingok
+        rotate 1
+}
diff --git a/tests/Functional.logrotate/data/testlog.sh b/tests/Functional.logrotate/data/testlog.sh
new file mode 100644
index 0000000..da7a877
--- /dev/null
+++ b/tests/Functional.logrotate/data/testlog.sh
@@ -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
diff --git a/tests/Functional.logrotate/data/testlog100k b/tests/Functional.logrotate/data/testlog100k
new file mode 100644
index 0000000000000000000000000000000000000000..1dc679f54731568a9cbda775a663b7ea51595fe3
GIT binary patch
literal 105984
zcmeI5d0-U9^2b*N!X;-EJdh;28zdV8yGaO9L{XdL$K@>wVs7M00!a`-{fUA^e4r2f
z0X{&`=Zyl&Q#|l~hzE+OPr(y!P(TqC1(8=ZGs|u^JKbNze|~PwA7rMhr<;7HQr%Ns
zU6bVTc!qWHcq*%_x`gQ5?O<8e*uv_n8n+rAPq1rNC?_k_H7l6i&ArxNU$S6WifZ-y
zk)EdQlWR@CZ4y=Z>I|EIwx%-6guez*l;{ECU-I)25dX$>-%vpRqnejf1A)hgf1_4M
z7;4#K*8gz@nEk0KzI>#vQI=m>IJPjWrn;)EB&)b8tE^_!NHSSj#T8kjDs{L1rDXps
zN>PjQT9E#?9bo#!nE#v+Hvb$=WtJ6=FRjv4@sw9omsS?%BszZ2C1ok<`|`us{*>!@
zv5fgIclhUODzi-ZYXC)wiirR24b5QwUpV}AlNOc<|0u|s(+c80cS&=Yzvpt>{^V)e
zWSQ{S0E!Y#CjNsqCc*q~A>+>T|L#$3#GbND#@|>f@vlD~nWEmjt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cS@juY|mvZ*sg)|#rSSI=(Ux#B$pCkTL?zX;vWYmA2|9lAOe{3Ie
z?M~o>3j%6KCoKM)`IiCvzubEhNi2b1hXhpl#n}9l`FD5bKf3ta*goXioxr%_fSNk9
zxqF2u3G=@JSbvGSMNSO_<`Vx$ZZ=eM#LPbjh=0aflUht*en~)G_Zpsm=0a!xg`^+;
zbM)sv;@@!!_Ws5CKi{$cn%A#C=RcMptrUz3sOfXDUzYjb?&!Z}`5kLaYFPw691~Cv
z`SASPX94eDf)*#RbZkJ~*%+VyoCElO@ZP27a^l}43D<ul{$Hr#1RlO4poXl(^Pl|I
z!}h;v+&>;#|C0Py;3IgH_)oqQ+ke61FTx+}TB;F&;rCGd!(M#<9kTyLz~Tf-i2qHG
z;p^}Jp{g8zCH4nrtgAUOH&b2o631Ve^S|->%THndv!+qro@a`GW_iLVpCN|V5&!)s
zHG=uCJl58KP58NoWwQTBqo7fuTk|v3yKgt)`19JR;<%@*|LYz8I{y#LgnwLw^$PDH
z{`XT-ZG=D1e;xt!zg{O&;7Z^T;$Jfh^S`nF|8OE^e@yG|vj4(<B<=cUs&Nmp{ZB4%
zeMpXg`ENbi=C51-LiYa(e;ewu!I|pPVw`_YJDb1G|H(3w{!9Fc&HwOoGS%BFt@!^+
zyTtup*8c~F*!*c3()D1OjK8jU>Ieo8$yB>*t^M!N{HG|{=C50Sq4|HF%>V0PcD*>M
rFjK9XhUMR8{oi(p%|EDl0jAe4@xQqeuPfMaO{VH_1<yat@4x>AP`)FD

literal 0
HcmV?d00001

diff --git a/tests/Functional.logrotate/fuego_test.sh b/tests/Functional.logrotate/fuego_test.sh
new file mode 100644
index 0000000..64a83b2
--- /dev/null
+++ b/tests/Functional.logrotate/fuego_test.sh
@@ -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"
+}
diff --git a/tests/Functional.logrotate/logrotate_test.sh b/tests/Functional.logrotate/logrotate_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/tests/Functional.logrotate/logrotate_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/tests/Functional.logrotate/spec.json b/tests/Functional.logrotate/spec.json
new file mode 100644
index 0000000..cfd6646
--- /dev/null
+++ b/tests/Functional.logrotate/spec.json
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.logrotate",
+    "specs": {
+        "default": {}
+    }
+}
diff --git a/tests/Functional.logrotate/test.yaml b/tests/Functional.logrotate/test.yaml
new file mode 100644
index 0000000..1b2d2d9
--- /dev/null
+++ b/tests/Functional.logrotate/test.yaml
@@ -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 <wangmy@cn.fujitsu.com>
+maintainer: Wang Mingyu <wangmy@cn.fujitsu.com>
+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
diff --git a/tests/Functional.logrotate/tests/logrotate_01.sh b/tests/Functional.logrotate/tests/logrotate_01.sh
new file mode 100644
index 0000000..5aed3e3
--- /dev/null
+++ b/tests/Functional.logrotate/tests/logrotate_01.sh
@@ -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
diff --git a/tests/Functional.logrotate/tests/logrotate_02.sh b/tests/Functional.logrotate/tests/logrotate_02.sh
new file mode 100644
index 0000000..4e16d0b
--- /dev/null
+++ b/tests/Functional.logrotate/tests/logrotate_02.sh
@@ -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
diff --git a/tests/Functional.logrotate/tests/logrotate_03.sh b/tests/Functional.logrotate/tests/logrotate_03.sh
new file mode 100644
index 0000000..98a850d
--- /dev/null
+++ b/tests/Functional.logrotate/tests/logrotate_03.sh
@@ -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
diff --git a/tests/Functional.logrotate/tests/logrotate_04.sh b/tests/Functional.logrotate/tests/logrotate_04.sh
new file mode 100644
index 0000000..08bfbf5
--- /dev/null
+++ b/tests/Functional.logrotate/tests/logrotate_04.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+#  In the target to execute command logrotate. Verify that the rotate file is created in the specified directory.
+#  option : -v
+
+test="logrotate4"
+
+if [ -f /var/log/testlog* ]
+then
+    rm -f /var/log/testlog*
+fi
+
+if [ -f /home/test/testlog.sh ]
+then
+    rm -f /home/test/testlog.sh
+fi
+
+if [ -f /var/lib/logrotate.status ]
+then
+    rm -f /var/lib/logrotate.status
+fi
+
+ntpdate $test_host
+
+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
+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
diff --git a/tests/Functional.logrotate/tests/logrotate_05.sh b/tests/Functional.logrotate/tests/logrotate_05.sh
new file mode 100644
index 0000000..a5f61dc
--- /dev/null
+++ b/tests/Functional.logrotate/tests/logrotate_05.sh
@@ -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
-- 
2.17.1




^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Fuego] [PATCH] samba: Add test case to access the target from host using samba.
  2019-11-05  9:01 [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate Wang Mingyu
@ 2019-11-05  9:01 ` Wang Mingyu
  2019-11-19 15:36   ` Tim.Bird
  2019-11-05  9:01 ` [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn Wang Mingyu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Wang Mingyu @ 2019-11-05  9:01 UTC (permalink / raw)
  To: fuego

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 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

diff --git a/tests/Functional.samba/data/smb04.conf b/tests/Functional.samba/data/smb04.conf
index 94acbbc..c836021 100644
--- a/tests/Functional.samba/data/smb04.conf
+++ b/tests/Functional.samba/data/smb04.conf
@@ -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
diff --git a/tests/Functional.samba/data/smb05.conf b/tests/Functional.samba/data/smb05.conf
new file mode 100644
index 0000000..63d3d02
--- /dev/null
+++ b/tests/Functional.samba/data/smb05.conf
@@ -0,0 +1,19 @@
+[global]
+   workgroup = MYGROUP
+   server string = Samba Server
+   security = user
+   passdb backend = tdbsam
+   hosts allow = 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
diff --git a/tests/Functional.samba/data/smb06.conf b/tests/Functional.samba/data/smb06.conf
new file mode 100644
index 0000000..1bbacd4
--- /dev/null
+++ b/tests/Functional.samba/data/smb06.conf
@@ -0,0 +1,18 @@
+[global]
+   workgroup = MYGROUP
+   server string = Samba Server
+   security = user
+   hosts allow = 127.0.0.1 test_host
+   load printers = yes
+   log file = /var/log/samba/log.%m
+   max log size = 50
+   interfaces = 127.0.0.1 test_target
+   dns proxy = no
+
+[test]
+   comment = samba server
+   path = /home/test/samba
+   writable = yes
+   browseable = yes
+   guest ok = yes
+   public = yes
diff --git a/tests/Functional.samba/fuego_test.sh b/tests/Functional.samba/fuego_test.sh
index 1f694ef..63e0cef 100644
--- a/tests/Functional.samba/fuego_test.sh
+++ b/tests/Functional.samba/fuego_test.sh
@@ -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 {
diff --git a/tests/Functional.samba/samba_test.sh b/tests/Functional.samba/samba_test.sh
old mode 100644
new mode 100755
index 95c34db..93b0740
--- a/tests/Functional.samba/samba_test.sh
+++ b/tests/Functional.samba/samba_test.sh
@@ -2,6 +2,8 @@
 . ./fuego_board_function_lib.sh
 set_init_manager
 
-for i in tests/*.sh; do
-    source $i
-done
+source tests/test_samba01.sh
+source tests/test_samba02.sh
+source tests/test_samba03.sh
+source tests/test_samba04.sh
+source tests/test_samba05.sh
diff --git a/tests/Functional.samba/test.yaml b/tests/Functional.samba/test.yaml
index bd61de6..f38dcf9 100644
--- a/tests/Functional.samba/test.yaml
+++ b/tests/Functional.samba/test.yaml
@@ -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 <wangmy@cn.fujitsu.com>
 maintainer: Wang Mingyu <wangmy@cn.fujitsu.com>
 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
diff --git a/tests/Functional.samba/tests/restore_target.sh b/tests/Functional.samba/tests/restore_target.sh
new file mode 100644
index 0000000..6610923
--- /dev/null
+++ b/tests/Functional.samba/tests/restore_target.sh
@@ -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
diff --git a/tests/Functional.samba/tests/test_samba04.sh b/tests/Functional.samba/tests/test_samba04.sh
index 2ad6e59..c1dac10 100644
--- a/tests/Functional.samba/tests/test_samba04.sh
+++ b/tests/Functional.samba/tests/test_samba04.sh
@@ -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
diff --git a/tests/Functional.samba/tests/test_samba05.sh b/tests/Functional.samba/tests/test_samba05.sh
new file mode 100644
index 0000000..f66a92f
--- /dev/null
+++ b/tests/Functional.samba/tests/test_samba05.sh
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+#  In the target start samba, 
+#  Set the server to access the target having password from the server, and make sure the server can access the target.
+
+test="samba05"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+useradd test_for_fuego
+
+expect <<-EOF
+spawn smbpasswd -a test_for_fuego
+expect "SMB password:"
+send "goodluck\r"
+expect "Retype new SMB password:"
+send "goodluck\r"
+expect "Added user root."
+EOF
+
+smb_status=$(get_service_status smb)
+iptables_status=$(get_service_status iptables)
+
+exec_service_on_target smb stop
+exec_service_on_target iptables stop
+
+mkdir -p /home/test/samba
+
+cp data/test1 /home/test/samba/
+
+chown nobody:nobody -R /home/test/samba
+
+if [ -f /etc/samba/smb.conf ]
+then
+    mv /etc/samba/smb.conf /etc/samba/smb.conf_bak
+fi
+
+restore_target(){
+    if [ -f /etc/samba/smb.conf_bak ]
+    then
+        mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
+    fi
+    smbpasswd -x test_for_fuego
+    rm -fr /home/test_for_fuego
+    mv data/smb05.conf_bak data/smb05.conf
+    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
+sed -i 's/test_target/'"$test_target"'/g' data/smb05.conf
+cp data/smb05.conf /etc/samba/smb.conf
+
+if exec_service_on_target smb start
+then
+    echo " -> start of smb succeeded."
+else
+    echo " -> start of smb failed."
+    echo " -> $test: TEST-FAIL"    
+    restore_target
+    exit
+fi
+
+sleep 5
+
+expect <<-EOF
+spawn sh
+expect ".*"
+send "smbclient //$test_target/test --user=test_for_fuego\r"
+expect {
+ -re ".*Enter.*password:.*" {
+           send "goodluck\r"
+          }
+ default { send_user "Can not access the board.\n"}  }
+expect {
+ -re ".*Password:.*" {
+           send "goodluck\r"
+          }
+ default { send_user "Password is wrong.\n"}  }
+expect {
+ -re ".*smb:.*" {
+           send "ls\r"
+          }
+ default { send_user "Can not log into the board.\n"}  } 
+expect {
+ -re ".*test1.*" {
+           send_user " -> $test: TEST-PASS\n"
+          }
+ default { send_user " -> $test: TEST-FAIL\n"}  }
+send "exit\n"
+expect eof
+EOF
+
+restore_target
diff --git a/tests/Functional.samba/tests/test_samba06.sh b/tests/Functional.samba/tests/test_samba06.sh
new file mode 100644
index 0000000..29c1dd1
--- /dev/null
+++ b/tests/Functional.samba/tests/test_samba06.sh
@@ -0,0 +1,58 @@
+#!/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
+
+echo $(get_service_status smb) > $3
+echo $(get_service_status iptables) >> $3
+
+exec_service_on_target smb stop
+exec_service_on_target iptables stop
+
+mkdir -p /home/test/samba
+
+cp data/test1 /home/test/samba/
+
+chown nobody:nobody -R /home/test/samba
+
+if [ -f /etc/samba/smb.conf ]
+then
+    mv /etc/samba/smb.conf /etc/samba/smb.conf_bak
+fi
+
+restore_target(){
+    if [ -f /etc/samba/smb.conf_bak ]
+    then
+        mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
+    fi
+    mv data/smb06.conf_bak data/smb06.conf
+    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
+sed -i 's/test_target/'"$2"'/g' data/smb06.conf
+sed -i 's/test_host/'"$1"'/g' data/smb06.conf
+cp data/smb06.conf /etc/samba/smb.conf
+
+if exec_service_on_target smb start
+then
+    echo " -> start of smb succeeded."
+else
+    echo " -> start of smb failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+sleep 5
diff --git a/tests/Functional.samba/tests/test_samba06_host.sh b/tests/Functional.samba/tests/test_samba06_host.sh
new file mode 100644
index 0000000..77ff7a5
--- /dev/null
+++ b/tests/Functional.samba/tests/test_samba06_host.sh
@@ -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
-- 
2.17.1




^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn.
  2019-11-05  9:01 [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate Wang Mingyu
  2019-11-05  9:01 ` [Fuego] [PATCH] samba: Add test case to access the target from host using samba Wang Mingyu
@ 2019-11-05  9:01 ` Wang Mingyu
  2019-11-08 13:13   ` Tim.Bird
  2019-11-06 20:37 ` [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate Tim.Bird
  2019-11-07 14:08 ` Tim.Bird
  3 siblings, 1 reply; 10+ messages in thread
From: Wang Mingyu @ 2019-11-05  9:01 UTC (permalink / raw)
  To: fuego

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.

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 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

diff --git a/tests/Functional.openvpn/data/host-target.key b/tests/Functional.openvpn/data/host-target.key
new file mode 100644
index 0000000..99743bf
--- /dev/null
+++ b/tests/Functional.openvpn/data/host-target.key
@@ -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-----
+
diff --git a/tests/Functional.openvpn/data/testcli.conf b/tests/Functional.openvpn/data/testcli.conf
new file mode 100644
index 0000000..2c252bb
--- /dev/null
+++ b/tests/Functional.openvpn/data/testcli.conf
@@ -0,0 +1,7 @@
+remote  192.168.0.1
+port    5000
+dev     tap
+#dev    tun
+verb    3
+ping    60
+
diff --git a/tests/Functional.openvpn/data/testenv.sh b/tests/Functional.openvpn/data/testenv.sh
new file mode 100644
index 0000000..8c01d58
--- /dev/null
+++ b/tests/Functional.openvpn/data/testenv.sh
@@ -0,0 +1,18 @@
+#set the variable
+if [ "$init_manager" == "systemd" ]
+then
+        service_name="openvpn@loopback-server.service"
+        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
diff --git a/tests/Functional.openvpn/data/testsrv.conf b/tests/Functional.openvpn/data/testsrv.conf
new file mode 100644
index 0000000..0c18a40
--- /dev/null
+++ b/tests/Functional.openvpn/data/testsrv.conf
@@ -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
+
diff --git a/tests/Functional.openvpn/fuego_test.sh b/tests/Functional.openvpn/fuego_test.sh
new file mode 100644
index 0000000..65d2991
--- /dev/null
+++ b/tests/Functional.openvpn/fuego_test.sh
@@ -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"
+}
diff --git a/tests/Functional.openvpn/openvpn_test.sh b/tests/Functional.openvpn/openvpn_test.sh
new file mode 100755
index 0000000..42f41ea
--- /dev/null
+++ b/tests/Functional.openvpn/openvpn_test.sh
@@ -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
diff --git a/tests/Functional.openvpn/spec.json b/tests/Functional.openvpn/spec.json
new file mode 100644
index 0000000..e9fdc5a
--- /dev/null
+++ b/tests/Functional.openvpn/spec.json
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.openvpn",
+    "specs": {
+        "default": {}
+    }
+}
diff --git a/tests/Functional.openvpn/tests/openvpn_genkey.sh b/tests/Functional.openvpn/tests/openvpn_genkey.sh
new file mode 100644
index 0000000..cef533e
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_genkey.sh
@@ -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
+
diff --git a/tests/Functional.openvpn/tests/openvpn_lport_client.sh b/tests/Functional.openvpn/tests/openvpn_lport_client.sh
new file mode 100644
index 0000000..f8aac80
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_lport_client.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the Listening port.
+
+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"
+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" ]
+    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
diff --git a/tests/Functional.openvpn/tests/openvpn_lport_server.sh b/tests/Functional.openvpn/tests/openvpn_lport_server.sh
new file mode 100644
index 0000000..0377c2d
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_lport_server.sh
@@ -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
+    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
+}
+
+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
diff --git a/tests/Functional.openvpn/tests/openvpn_pid_client.sh b/tests/Functional.openvpn/tests/openvpn_pid_client.sh
new file mode 100644
index 0000000..a7829b2
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_pid_client.sh
@@ -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 ]
+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
+}
+
+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
+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
diff --git a/tests/Functional.openvpn/tests/openvpn_pid_server.sh b/tests/Functional.openvpn/tests/openvpn_pid_server.sh
new file mode 100644
index 0000000..e2f2e7b
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_pid_server.sh
@@ -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 ]
+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
+}
+
+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
+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
diff --git a/tests/Functional.openvpn/tests/openvpn_ps_client.sh b/tests/Functional.openvpn/tests/openvpn_ps_client.sh
new file mode 100644
index 0000000..956c2fd
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_ps_client.sh
@@ -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
+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" ]
+    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
diff --git a/tests/Functional.openvpn/tests/openvpn_ps_server.sh b/tests/Functional.openvpn/tests/openvpn_ps_server.sh
new file mode 100644
index 0000000..6a6a25c
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_ps_server.sh
@@ -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
diff --git a/tests/Functional.openvpn/tests/openvpn_syslog-ng_client.sh b/tests/Functional.openvpn/tests/openvpn_syslog-ng_client.sh
new file mode 100644
index 0000000..7b4f36c
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_syslog-ng_client.sh
@@ -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
diff --git a/tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh b/tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh
new file mode 100644
index 0000000..29a53b9
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the message of syslog-ng.
+
+test="syslog-ng_server"
+
+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
+
+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 [ -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
diff --git a/tests/Functional.openvpn/tests/openvpn_tun_client.sh b/tests/Functional.openvpn/tests/openvpn_tun_client.sh
new file mode 100644
index 0000000..7bba41e
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_tun_client.sh
@@ -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
+    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
diff --git a/tests/Functional.openvpn/tests/openvpn_tun_server.sh b/tests/Functional.openvpn/tests/openvpn_tun_server.sh
new file mode 100644
index 0000000..4a9aa46
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_tun_server.sh
@@ -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
-- 
2.17.1




^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate.
  2019-11-05  9:01 [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate Wang Mingyu
  2019-11-05  9:01 ` [Fuego] [PATCH] samba: Add test case to access the target from host using samba Wang Mingyu
  2019-11-05  9:01 ` [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn Wang Mingyu
@ 2019-11-06 20:37 ` Tim.Bird
  2019-11-07 14:08 ` Tim.Bird
  3 siblings, 0 replies; 10+ messages in thread
From: Tim.Bird @ 2019-11-06 20:37 UTC (permalink / raw)
  To: wangmy, fuego



> -----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.
> 
> Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
> ---
>  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
> 
> diff --git a/tests/Functional.logrotate/data/test.conf
> b/tests/Functional.logrotate/data/test.conf
> new file mode 100644
> index 0000000..a346adf
> --- /dev/null
> +++ b/tests/Functional.logrotate/data/test.conf
> @@ -0,0 +1,8 @@
> +/var/log/testlog {
> +        create 600 root root
> +        ifempty
> +        daily
> +        nocompress
> +        missingok
> +        rotate 1
> +}
> diff --git a/tests/Functional.logrotate/data/testlog.sh
> b/tests/Functional.logrotate/data/testlog.sh
> new file mode 100644
> index 0000000..da7a877
> --- /dev/null
> +++ b/tests/Functional.logrotate/data/testlog.sh
> @@ -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.

> +echo "logrotate state -- version 2" >> /var/lib/logrotate.status
> +echo "\"/var/log/testlog\" $ddch" >> /var/lib/logrotate.status
> diff --git a/tests/Functional.logrotate/data/testlog100k
> b/tests/Functional.logrotate/data/testlog100k
> new file mode 100644
> index
> 0000000000000000000000000000000000000000..1dc679f54731568a9cbda775a6
> 63b7ea51595fe3
> GIT binary patch
> literal 105984
> zcmeI5d0-U9^2b*N!X;-EJdh;28zdV8yGaO9L{XdL$K@>wVs7M00!a`-
> {fUA^e4r2f
> z0X{&`=Zyl&Q#|l~hzE+OPr(y!P(TqC1(8=ZGs|u^JKbNze|~PwA7rMhr<;7HQr%
> Ns
> zU6bVTc!qWHcq*%_x`gQ5?O<8e*uv_n8n+rAPq1rN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&;rCGd!(M#<9kTyLz~Tf-i2qHG
> z;p^}Jp{g8zCH4nrtgAUOH&b2o631Ve^S|-
> >%THndv!+qro@a`GW_iLVpCN|V5&!)s
> zHG=uCJl58KP58NoWwQTBqo7fuTk|v3yKgt)`19JR;<%@*|LYz8I{y#LgnwLw^$
> PDH
> z{`XT-
> ZG=D1e;xt!zg{O&;7Z^T;$Jfh^S`nF|8OE^e@yG|vj4(<B<=cUs&Nmp{ZB4%
> zeMpXg`ENbi=C51-
> LiYa(e;ewu!I|pPVw`_YJDb1G|H(3w{!9Fc&HwOoGS%BFt@!^+
> zyTtup*8c~F*!*c3()D1OjK8jU>Ieo8$yB>*t^M!N{HG|{=C50Sq4|HF%>V0PcD
> *>M
> rFjK9XhUMR8{oi(p%|EDl0jAe4@xQqeuPfMaO{VH_1<yat@4x>AP`)FD
> 
> literal 0
> HcmV?d00001

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

> 
> diff --git a/tests/Functional.logrotate/fuego_test.sh
> b/tests/Functional.logrotate/fuego_test.sh
> new file mode 100644
> index 0000000..64a83b2
> --- /dev/null
> +++ b/tests/Functional.logrotate/fuego_test.sh
> @@ -0,0 +1,19 @@

I think you probably need a NEED_ROOT=1 here

> +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"
> +}
> diff --git a/tests/Functional.logrotate/logrotate_test.sh
> b/tests/Functional.logrotate/logrotate_test.sh
> new file mode 100755
> index 0000000..dd5ce37
> --- /dev/null
> +++ b/tests/Functional.logrotate/logrotate_test.sh
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +for i in tests/*.sh; do
> +    sh $i
> +done
> diff --git a/tests/Functional.logrotate/spec.json
> b/tests/Functional.logrotate/spec.json
> new file mode 100644
> index 0000000..cfd6646
> --- /dev/null
> +++ b/tests/Functional.logrotate/spec.json
> @@ -0,0 +1,6 @@
> +{
> +    "testName": "Functional.logrotate",
> +    "specs": {
> +        "default": {}
> +    }
> +}
> diff --git a/tests/Functional.logrotate/test.yaml
> b/tests/Functional.logrotate/test.yaml
> new file mode 100644
> index 0000000..1b2d2d9
> --- /dev/null
> +++ b/tests/Functional.logrotate/test.yaml
> @@ -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.
Please keep lines in the description field in the test.yaml file to 80 chars or less.

> +      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 <wangmy@cn.fujitsu.com>
> +maintainer: Wang Mingyu <wangmy@cn.fujitsu.com>
> +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
> diff --git a/tests/Functional.logrotate/tests/logrotate_01.sh
> b/tests/Functional.logrotate/tests/logrotate_01.sh
> new file mode 100644
> index 0000000..5aed3e3
> --- /dev/null
> +++ b/tests/Functional.logrotate/tests/logrotate_01.sh
> @@ -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.

> +
> +if logrotate --help | grep "Usage"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> diff --git a/tests/Functional.logrotate/tests/logrotate_02.sh
> b/tests/Functional.logrotate/tests/logrotate_02.sh
> new file mode 100644
> index 0000000..4e16d0b
> --- /dev/null
> +++ b/tests/Functional.logrotate/tests/logrotate_02.sh
> @@ -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
> diff --git a/tests/Functional.logrotate/tests/logrotate_03.sh
> b/tests/Functional.logrotate/tests/logrotate_03.sh
> new file mode 100644
> index 0000000..98a850d
> --- /dev/null
> +++ b/tests/Functional.logrotate/tests/logrotate_03.sh
> @@ -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
> diff --git a/tests/Functional.logrotate/tests/logrotate_04.sh
> b/tests/Functional.logrotate/tests/logrotate_04.sh
> new file mode 100644
> index 0000000..08bfbf5
> --- /dev/null
> +++ b/tests/Functional.logrotate/tests/logrotate_04.sh
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +
> +#  In the target to execute command logrotate. Verify that the rotate file is
> created in the specified directory.
> +#  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?
> +then
> +    rm -f /home/test/testlog.sh
> +fi

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

> +
> +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.

> +
> +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
> +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?

> diff --git a/tests/Functional.logrotate/tests/logrotate_05.sh
> b/tests/Functional.logrotate/tests/logrotate_05.sh
> new file mode 100644
> index 0000000..a5f61dc
> --- /dev/null
> +++ b/tests/Functional.logrotate/tests/logrotate_05.sh
> @@ -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.

> +#  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
> --
> 2.17.1

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

-- Tim


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate.
  2019-11-05  9:01 [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate Wang Mingyu
                   ` (2 preceding siblings ...)
  2019-11-06 20:37 ` [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate Tim.Bird
@ 2019-11-07 14:08 ` Tim.Bird
  3 siblings, 0 replies; 10+ messages in thread
From: Tim.Bird @ 2019-11-07 14:08 UTC (permalink / raw)
  To: wangmy, fuego

> -----Original Message-----
> From: Bird, Tim
> 
> > -----Original Message-----
> > From: Wang Mingyu
> >
...
> > +++ b/tests/Functional.logrotate/data/testlog.sh
> > @@ -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.
> 
> > +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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn.
  2019-11-05  9:01 ` [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn Wang Mingyu
@ 2019-11-08 13:13   ` Tim.Bird
  0 siblings, 0 replies; 10+ messages in thread
From: Tim.Bird @ 2019-11-08 13:13 UTC (permalink / raw)
  To: wangmy, fuego



> -----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.
> 
> Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
> ---
>  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
> 
> diff --git a/tests/Functional.openvpn/data/host-target.key
> b/tests/Functional.openvpn/data/host-target.key
> new file mode 100644
> index 0000000..99743bf
> --- /dev/null
> +++ b/tests/Functional.openvpn/data/host-target.key
> @@ -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-----
> +
> diff --git a/tests/Functional.openvpn/data/testcli.conf
> b/tests/Functional.openvpn/data/testcli.conf
> new file mode 100644
> index 0000000..2c252bb
> --- /dev/null
> +++ b/tests/Functional.openvpn/data/testcli.conf
> @@ -0,0 +1,7 @@
> +remote  192.168.0.1
> +port    5000
> +dev     tap
> +#dev    tun
> +verb    3
> +ping    60
> +
> diff --git a/tests/Functional.openvpn/data/testenv.sh
> b/tests/Functional.openvpn/data/testenv.sh
> new file mode 100644
> index 0000000..8c01d58
> --- /dev/null
> +++ b/tests/Functional.openvpn/data/testenv.sh
> @@ -0,0 +1,18 @@
> +#set the variable
> +if [ "$init_manager" == "systemd" ]
> +then
> +        service_name="openvpn@loopback-server.service"
> +        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
> diff --git a/tests/Functional.openvpn/data/testsrv.conf
> b/tests/Functional.openvpn/data/testsrv.conf
> new file mode 100644
> index 0000000..0c18a40
> --- /dev/null
> +++ b/tests/Functional.openvpn/data/testsrv.conf
> @@ -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
> +
> diff --git a/tests/Functional.openvpn/fuego_test.sh
> b/tests/Functional.openvpn/fuego_test.sh
> new file mode 100644
> index 0000000..65d2991
> --- /dev/null
> +++ b/tests/Functional.openvpn/fuego_test.sh
> @@ -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"
> +}
> diff --git a/tests/Functional.openvpn/openvpn_test.sh
> b/tests/Functional.openvpn/openvpn_test.sh
> new file mode 100755
> index 0000000..42f41ea
> --- /dev/null
> +++ b/tests/Functional.openvpn/openvpn_test.sh
> @@ -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.

> +
> +for i in tests/*.sh; do
> +    source $i
> +done
> diff --git a/tests/Functional.openvpn/spec.json
> b/tests/Functional.openvpn/spec.json
> new file mode 100644
> index 0000000..e9fdc5a
> --- /dev/null
> +++ b/tests/Functional.openvpn/spec.json
> @@ -0,0 +1,6 @@
> +{
> +    "testName": "Functional.openvpn",
> +    "specs": {
> +        "default": {}
> +    }
> +}
> diff --git a/tests/Functional.openvpn/tests/openvpn_genkey.sh
> b/tests/Functional.openvpn/tests/openvpn_genkey.sh
> new file mode 100644
> index 0000000..cef533e
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_genkey.sh
> @@ -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
should use 'if [ -f /etc/openvpn/host-target.key' here

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

> +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
> +
> diff --git a/tests/Functional.openvpn/tests/openvpn_lport_client.sh
> b/tests/Functional.openvpn/tests/openvpn_lport_client.sh
> new file mode 100644
> index 0000000..f8aac80
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_lport_client.sh
> @@ -0,0 +1,66 @@
> +#!/bin/sh
> +
> +#  In the target, run openvpn and check the Listening port.
> +
> +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.

> +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" ]
> +    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.

> +}
> +
> +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"

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

> +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
> diff --git a/tests/Functional.openvpn/tests/openvpn_lport_server.sh
> b/tests/Functional.openvpn/tests/openvpn_lport_server.sh
> new file mode 100644
> index 0000000..0377c2d
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_lport_server.sh
> @@ -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
> +    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)

> +    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
> diff --git a/tests/Functional.openvpn/tests/openvpn_pid_client.sh
> b/tests/Functional.openvpn/tests/openvpn_pid_client.sh
> new file mode 100644
> index 0000000..a7829b2
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_pid_client.sh
> @@ -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 ]
> +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.

> +    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.

> +}
> +
> +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'

> +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
> diff --git a/tests/Functional.openvpn/tests/openvpn_pid_server.sh
> b/tests/Functional.openvpn/tests/openvpn_pid_server.sh
> new file mode 100644
> index 0000000..e2f2e7b
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_pid_server.sh
> @@ -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 ]
> +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.

> +    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
> +
> +if ls $pid_file
please use '[ -f $pid_file' for detecting the presence of a file.

> +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
> diff --git a/tests/Functional.openvpn/tests/openvpn_ps_client.sh
> b/tests/Functional.openvpn/tests/openvpn_ps_client.sh
> new file mode 100644
> index 0000000..956c2fd
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_ps_client.sh
> @@ -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
> +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)

> +
> +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
> diff --git a/tests/Functional.openvpn/tests/openvpn_ps_server.sh
> b/tests/Functional.openvpn/tests/openvpn_ps_server.sh
> new file mode 100644
> index 0000000..6a6a25c
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_ps_server.sh
> @@ -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
> diff --git a/tests/Functional.openvpn/tests/openvpn_syslog-ng_client.sh
> b/tests/Functional.openvpn/tests/openvpn_syslog-ng_client.sh
> new file mode 100644
> index 0000000..7b4f36c
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_syslog-ng_client.sh
> @@ -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
> diff --git a/tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh
> b/tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh
> new file mode 100644
> index 0000000..29a53b9
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_syslog-ng_server.sh
> @@ -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)

> +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
> +
> +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
> +
> +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
> diff --git a/tests/Functional.openvpn/tests/openvpn_tun_client.sh
> b/tests/Functional.openvpn/tests/openvpn_tun_client.sh
> new file mode 100644
> index 0000000..7bba41e
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_tun_client.sh
> @@ -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
> +    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

> +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
> diff --git a/tests/Functional.openvpn/tests/openvpn_tun_server.sh
> b/tests/Functional.openvpn/tests/openvpn_tun_server.sh
> new file mode 100644
> index 0000000..4a9aa46
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_tun_server.sh
> @@ -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
> --
> 2.17.1

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Fuego] [PATCH] samba: Add test case to access the target from host using samba.
  2019-11-05  9:01 ` [Fuego] [PATCH] samba: Add test case to access the target from host using samba Wang Mingyu
@ 2019-11-19 15:36   ` Tim.Bird
  2019-11-25  3:21     ` Wang, Mingyu
  0 siblings, 1 reply; 10+ messages in thread
From: Tim.Bird @ 2019-11-19 15:36 UTC (permalink / raw)
  To: wangmy, fuego

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

> -----Original Message-----
> From: Wang Mingyu
> 
> Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
> ---
>  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
> 
> diff --git a/tests/Functional.samba/data/smb04.conf
> b/tests/Functional.samba/data/smb04.conf
> index 94acbbc..c836021 100644
> --- a/tests/Functional.samba/data/smb04.conf
> +++ b/tests/Functional.samba/data/smb04.conf
> @@ -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
> diff --git a/tests/Functional.samba/data/smb05.conf
> b/tests/Functional.samba/data/smb05.conf
> new file mode 100644
> index 0000000..63d3d02
> --- /dev/null
> +++ b/tests/Functional.samba/data/smb05.conf
> @@ -0,0 +1,19 @@
> +[global]
> +   workgroup = MYGROUP
> +   server string = Samba Server
> +   security = user
> +   passdb backend = tdbsam
> +   hosts allow = 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
> diff --git a/tests/Functional.samba/data/smb06.conf
> b/tests/Functional.samba/data/smb06.conf
> new file mode 100644
> index 0000000..1bbacd4
> --- /dev/null
> +++ b/tests/Functional.samba/data/smb06.conf
> @@ -0,0 +1,18 @@
> +[global]
> +   workgroup = MYGROUP
> +   server string = Samba Server
> +   security = user
> +   hosts allow = 127.0.0.1 test_host
> +   load printers = yes
> +   log file = /var/log/samba/log.%m
> +   max log size = 50
> +   interfaces = 127.0.0.1 test_target
> +   dns proxy = no
> +
> +[test]
> +   comment = samba server
> +   path = /home/test/samba
> +   writable = yes
> +   browseable = yes
> +   guest ok = yes
> +   public = yes
> diff --git a/tests/Functional.samba/fuego_test.sh
> b/tests/Functional.samba/fuego_test.sh
> index 1f694ef..63e0cef 100644
> --- a/tests/Functional.samba/fuego_test.sh
> +++ b/tests/Functional.samba/fuego_test.sh
> @@ -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.

>  }
> 
>  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"
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'.

>  }
> 
>  function test_processing {
> diff --git a/tests/Functional.samba/samba_test.sh
> b/tests/Functional.samba/samba_test.sh
> old mode 100644
> new mode 100755
> index 95c34db..93b0740
> --- a/tests/Functional.samba/samba_test.sh
> +++ b/tests/Functional.samba/samba_test.sh
> @@ -2,6 +2,8 @@
>  . ./fuego_board_function_lib.sh
>  set_init_manager
> 
> -for i in tests/*.sh; do
> -    source $i
> -done
> +source tests/test_samba01.sh
> +source tests/test_samba02.sh
> +source tests/test_samba03.sh
> +source tests/test_samba04.sh
> +source tests/test_samba05.sh
> diff --git a/tests/Functional.samba/test.yaml
> b/tests/Functional.samba/test.yaml
> index bd61de6..f38dcf9 100644
> --- a/tests/Functional.samba/test.yaml
> +++ b/tests/Functional.samba/test.yaml
> @@ -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.
Please keep descriptions to 80 columns.

> +license: BSD-3-Clause
>  author: Wang Mingyu <wangmy@cn.fujitsu.com>
>  maintainer: Wang Mingyu <wangmy@cn.fujitsu.com>
>  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
> diff --git a/tests/Functional.samba/tests/restore_target.sh
> b/tests/Functional.samba/tests/restore_target.sh
> new file mode 100644
> index 0000000..6610923
> --- /dev/null
> +++ b/tests/Functional.samba/tests/restore_target.sh
> @@ -0,0 +1,24 @@
> +#!/bin/sh
> +
> +#  In the target start samba, and confirm the process condition by command
> ps.
> +#  check the keyword "smbd".
This comment appears to be a copy-paste bug.  It does not describe
this file.  Please update it.

> +
> +. ./fuego_board_function_lib.sh
> +set_init_manager
> +
> +if [ -f /etc/samba/smb.conf_bak ]
> +then
> +    mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
> +fi
> +mv data/smb06.conf_bak data/smb06.conf
> +
> +if [ "$(tail -n 1 $1)" = "active" -o "$(tail -n 1 $1)" = "unknown" ]
> +then
> +    exec_service_on_target iptables start
> +fi
> +if [ "$(head -n 1 $1)" = "inactive" ]
> +then
> +    exec_service_on_target smb stop
> +fi
> +
> +rm -fr $1
> diff --git a/tests/Functional.samba/tests/test_samba04.sh
> b/tests/Functional.samba/tests/test_samba04.sh
> index 2ad6e59..c1dac10 100644
> --- a/tests/Functional.samba/tests/test_samba04.sh
> +++ b/tests/Functional.samba/tests/test_samba04.sh
> @@ -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
> diff --git a/tests/Functional.samba/tests/test_samba05.sh
> b/tests/Functional.samba/tests/test_samba05.sh
> new file mode 100644
> index 0000000..f66a92f
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba05.sh
> @@ -0,0 +1,103 @@
> +#!/bin/sh
> +
> +#  In the target start samba,
> +#  Set the server to access the target having password from the server, and
> make sure the server can access the target.
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.

> +
> +test="samba05"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +useradd test_for_fuego
> +
> +expect <<-EOF
> +spawn smbpasswd -a test_for_fuego
> +expect "SMB password:"
> +send "goodluck\r"
> +expect "Retype new SMB password:"
> +send "goodluck\r"
> +expect "Added user root."
> +EOF
> +
> +smb_status=$(get_service_status smb)
> +iptables_status=$(get_service_status iptables)
> +
> +exec_service_on_target smb stop
> +exec_service_on_target iptables stop
> +
> +mkdir -p /home/test/samba
> +
> +cp data/test1 /home/test/samba/
> +
> +chown nobody:nobody -R /home/test/samba
> +
> +if [ -f /etc/samba/smb.conf ]
> +then
> +    mv /etc/samba/smb.conf /etc/samba/smb.conf_bak
> +fi
> +
> +restore_target(){
> +    if [ -f /etc/samba/smb.conf_bak ]
> +    then
> +        mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
> +    fi
> +    smbpasswd -x test_for_fuego
> +    rm -fr /home/test_for_fuego
> +    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.)

> +    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.

> +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?

> +cp data/smb05.conf /etc/samba/smb.conf
> +
> +if exec_service_on_target smb start
> +then
> +    echo " -> start of smb succeeded."
> +else
> +    echo " -> start of smb failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +sleep 5
> +
> +expect <<-EOF
> +spawn sh
> +expect ".*"
> +send "smbclient //$test_target/test --user=test_for_fuego\r"

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.)

> +expect {
> + -re ".*Enter.*password:.*" {
> +           send "goodluck\r"
> +          }
> + default { send_user "Can not access the board.\n"}  }
> +expect {
> + -re ".*Password:.*" {
> +           send "goodluck\r"
> +          }
> + default { send_user "Password is wrong.\n"}  }
> +expect {
> + -re ".*smb:.*" {
> +           send "ls\r"
> +          }
> + default { send_user "Can not log into the board.\n"}  }
> +expect {
> + -re ".*test1.*" {
> +           send_user " -> $test: TEST-PASS\n"
> +          }
> + default { send_user " -> $test: TEST-FAIL\n"}  }
> +send "exit\n"
> +expect eof
> +EOF
> +
> +restore_target
> diff --git a/tests/Functional.samba/tests/test_samba06.sh
> b/tests/Functional.samba/tests/test_samba06.sh
> new file mode 100644
> index 0000000..29c1dd1
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba06.sh
> @@ -0,0 +1,58 @@
> +#!/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
> +
> +echo $(get_service_status smb) > $3
> +echo $(get_service_status iptables) >> $3
> +
> +exec_service_on_target smb stop
> +exec_service_on_target iptables stop
> +
> +mkdir -p /home/test/samba
> +
> +cp data/test1 /home/test/samba/
> +
> +chown nobody:nobody -R /home/test/samba
> +
> +if [ -f /etc/samba/smb.conf ]
> +then
> +    mv /etc/samba/smb.conf /etc/samba/smb.conf_bak
> +fi
> +
> +restore_target(){
> +    if [ -f /etc/samba/smb.conf_bak ]
> +    then
> +        mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
> +    fi
> +    mv data/smb06.conf_bak data/smb06.conf
I don't think smb06.conf needs to be backed up or restored.

> +    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?)

> +sed -i 's/test_target/'"$2"'/g' data/smb06.conf
> +sed -i 's/test_host/'"$1"'/g' data/smb06.conf
> +cp data/smb06.conf /etc/samba/smb.conf
> +
> +if exec_service_on_target smb start
> +then
> +    echo " -> start of smb succeeded."
> +else
> +    echo " -> start of smb failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +sleep 5
> diff --git a/tests/Functional.samba/tests/test_samba06_host.sh
> b/tests/Functional.samba/tests/test_samba06_host.sh
> new file mode 100644
> index 0000000..77ff7a5
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba06_host.sh
> @@ -0,0 +1,23 @@
> +#!/bin/sh
> +
> +#  In the target start samba, and confirm the process condition by command
> 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.
> +
> +test="samba06"
> +expect <<-EOF
> +spawn sh
> +expect ".*"
> +send "smbclient //$1/test -N\r"
> +expect {
> + -re ".*smb:.*" {
> +           send "ls\r"
> +          }
> + default { send_user "Can't connect to the board"\n"}  }
> +expect {
> + -re ".*test1.*" {
> +           send_user " -> $test: TEST-PASS\n"
> +          }
> + default { send_user " -> $test: TEST-FAIL\n"}  }
> +send "exit\n"
> +expect eof
> +EOF
> --
> 2.17.1

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Fuego] [PATCH] samba: Add test case to access the target from host using samba.
  2019-11-19 15:36   ` Tim.Bird
@ 2019-11-25  3:21     ` Wang, Mingyu
  0 siblings, 0 replies; 10+ messages in thread
From: Wang, Mingyu @ 2019-11-25  3:21 UTC (permalink / raw)
  To: fuego

Hi,
Tim

>> +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: Tim.Bird@sony.com [mailto:Tim.Bird@sony.com] 
Sent: Tuesday, November 19, 2019 11:37 PM
To: Wang, Mingyu/王 鸣瑜 <wangmy@cn.fujitsu.com>; fuego@lists.linuxfoundation.org
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.

> -----Original Message-----
> From: Wang Mingyu
> 
> Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
> ---
>  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
> 
> diff --git a/tests/Functional.samba/data/smb04.conf
> b/tests/Functional.samba/data/smb04.conf
> index 94acbbc..c836021 100644
> --- a/tests/Functional.samba/data/smb04.conf
> +++ b/tests/Functional.samba/data/smb04.conf
> @@ -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
> diff --git a/tests/Functional.samba/data/smb05.conf
> b/tests/Functional.samba/data/smb05.conf
> new file mode 100644
> index 0000000..63d3d02
> --- /dev/null
> +++ b/tests/Functional.samba/data/smb05.conf
> @@ -0,0 +1,19 @@
> +[global]
> +   workgroup = MYGROUP
> +   server string = Samba Server
> +   security = user
> +   passdb backend = tdbsam
> +   hosts allow = 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
> diff --git a/tests/Functional.samba/data/smb06.conf
> b/tests/Functional.samba/data/smb06.conf
> new file mode 100644
> index 0000000..1bbacd4
> --- /dev/null
> +++ b/tests/Functional.samba/data/smb06.conf
> @@ -0,0 +1,18 @@
> +[global]
> +   workgroup = MYGROUP
> +   server string = Samba Server
> +   security = user
> +   hosts allow = 127.0.0.1 test_host
> +   load printers = yes
> +   log file = /var/log/samba/log.%m
> +   max log size = 50
> +   interfaces = 127.0.0.1 test_target
> +   dns proxy = no
> +
> +[test]
> +   comment = samba server
> +   path = /home/test/samba
> +   writable = yes
> +   browseable = yes
> +   guest ok = yes
> +   public = yes
> diff --git a/tests/Functional.samba/fuego_test.sh
> b/tests/Functional.samba/fuego_test.sh
> index 1f694ef..63e0cef 100644
> --- a/tests/Functional.samba/fuego_test.sh
> +++ b/tests/Functional.samba/fuego_test.sh
> @@ -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.

>  }
> 
>  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"
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'.

>  }
> 
>  function test_processing {
> diff --git a/tests/Functional.samba/samba_test.sh
> b/tests/Functional.samba/samba_test.sh
> old mode 100644
> new mode 100755
> index 95c34db..93b0740
> --- a/tests/Functional.samba/samba_test.sh
> +++ b/tests/Functional.samba/samba_test.sh
> @@ -2,6 +2,8 @@
>  . ./fuego_board_function_lib.sh
>  set_init_manager
> 
> -for i in tests/*.sh; do
> -    source $i
> -done
> +source tests/test_samba01.sh
> +source tests/test_samba02.sh
> +source tests/test_samba03.sh
> +source tests/test_samba04.sh
> +source tests/test_samba05.sh
> diff --git a/tests/Functional.samba/test.yaml
> b/tests/Functional.samba/test.yaml
> index bd61de6..f38dcf9 100644
> --- a/tests/Functional.samba/test.yaml
> +++ b/tests/Functional.samba/test.yaml
> @@ -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.
Please keep descriptions to 80 columns.

> +license: BSD-3-Clause
>  author: Wang Mingyu <wangmy@cn.fujitsu.com>
>  maintainer: Wang Mingyu <wangmy@cn.fujitsu.com>
>  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
> diff --git a/tests/Functional.samba/tests/restore_target.sh
> b/tests/Functional.samba/tests/restore_target.sh
> new file mode 100644
> index 0000000..6610923
> --- /dev/null
> +++ b/tests/Functional.samba/tests/restore_target.sh
> @@ -0,0 +1,24 @@
> +#!/bin/sh
> +
> +#  In the target start samba, and confirm the process condition by 
> +command
> ps.
> +#  check the keyword "smbd".
This comment appears to be a copy-paste bug.  It does not describe this file.  Please update it.

> +
> +. ./fuego_board_function_lib.sh
> +set_init_manager
> +
> +if [ -f /etc/samba/smb.conf_bak ]
> +then
> +    mv /etc/samba/smb.conf_bak /etc/samba/smb.conf fi mv 
> +data/smb06.conf_bak data/smb06.conf
> +
> +if [ "$(tail -n 1 $1)" = "active" -o "$(tail -n 1 $1)" = "unknown" ] 
> +then
> +    exec_service_on_target iptables start fi if [ "$(head -n 1 $1)" = 
> +"inactive" ] then
> +    exec_service_on_target smb stop
> +fi
> +
> +rm -fr $1
> diff --git a/tests/Functional.samba/tests/test_samba04.sh
> b/tests/Functional.samba/tests/test_samba04.sh
> index 2ad6e59..c1dac10 100644
> --- a/tests/Functional.samba/tests/test_samba04.sh
> +++ b/tests/Functional.samba/tests/test_samba04.sh
> @@ -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
> diff --git a/tests/Functional.samba/tests/test_samba05.sh
> b/tests/Functional.samba/tests/test_samba05.sh
> new file mode 100644
> index 0000000..f66a92f
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba05.sh
> @@ -0,0 +1,103 @@
> +#!/bin/sh
> +
> +#  In the target start samba,
> +#  Set the server to access the target having password from the 
> +server, and
> make sure the server can access the target.
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.

> +
> +test="samba05"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +useradd test_for_fuego
> +
> +expect <<-EOF
> +spawn smbpasswd -a test_for_fuego
> +expect "SMB password:"
> +send "goodluck\r"
> +expect "Retype new SMB password:"
> +send "goodluck\r"
> +expect "Added user root."
> +EOF
> +
> +smb_status=$(get_service_status smb)
> +iptables_status=$(get_service_status iptables)
> +
> +exec_service_on_target smb stop
> +exec_service_on_target iptables stop
> +
> +mkdir -p /home/test/samba
> +
> +cp data/test1 /home/test/samba/
> +
> +chown nobody:nobody -R /home/test/samba
> +
> +if [ -f /etc/samba/smb.conf ]
> +then
> +    mv /etc/samba/smb.conf /etc/samba/smb.conf_bak fi
> +
> +restore_target(){
> +    if [ -f /etc/samba/smb.conf_bak ]
> +    then
> +        mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
> +    fi
> +    smbpasswd -x test_for_fuego
> +    rm -fr /home/test_for_fuego
> +    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.)

> +    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.

> +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?

> +cp data/smb05.conf /etc/samba/smb.conf
> +
> +if exec_service_on_target smb start
> +then
> +    echo " -> start of smb succeeded."
> +else
> +    echo " -> start of smb failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +sleep 5
> +
> +expect <<-EOF
> +spawn sh
> +expect ".*"
> +send "smbclient //$test_target/test --user=test_for_fuego\r"

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.)

> +expect {
> + -re ".*Enter.*password:.*" {
> +           send "goodluck\r"
> +          }
> + default { send_user "Can not access the board.\n"}  } expect {  -re 
> +".*Password:.*" {
> +           send "goodluck\r"
> +          }
> + default { send_user "Password is wrong.\n"}  } expect {  -re 
> +".*smb:.*" {
> +           send "ls\r"
> +          }
> + default { send_user "Can not log into the board.\n"}  } expect {  
> +-re ".*test1.*" {
> +           send_user " -> $test: TEST-PASS\n"
> +          }
> + default { send_user " -> $test: TEST-FAIL\n"}  } send "exit\n"
> +expect eof
> +EOF
> +
> +restore_target
> diff --git a/tests/Functional.samba/tests/test_samba06.sh
> b/tests/Functional.samba/tests/test_samba06.sh
> new file mode 100644
> index 0000000..29c1dd1
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba06.sh
> @@ -0,0 +1,58 @@
> +#!/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
> +
> +echo $(get_service_status smb) > $3
> +echo $(get_service_status iptables) >> $3
> +
> +exec_service_on_target smb stop
> +exec_service_on_target iptables stop
> +
> +mkdir -p /home/test/samba
> +
> +cp data/test1 /home/test/samba/
> +
> +chown nobody:nobody -R /home/test/samba
> +
> +if [ -f /etc/samba/smb.conf ]
> +then
> +    mv /etc/samba/smb.conf /etc/samba/smb.conf_bak fi
> +
> +restore_target(){
> +    if [ -f /etc/samba/smb.conf_bak ]
> +    then
> +        mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
> +    fi
> +    mv data/smb06.conf_bak data/smb06.conf
I don't think smb06.conf needs to be backed up or restored.

> +    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?)

> +sed -i 's/test_target/'"$2"'/g' data/smb06.conf sed -i 
> +'s/test_host/'"$1"'/g' data/smb06.conf cp data/smb06.conf 
> +/etc/samba/smb.conf
> +
> +if exec_service_on_target smb start
> +then
> +    echo " -> start of smb succeeded."
> +else
> +    echo " -> start of smb failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +sleep 5
> diff --git a/tests/Functional.samba/tests/test_samba06_host.sh
> b/tests/Functional.samba/tests/test_samba06_host.sh
> new file mode 100644
> index 0000000..77ff7a5
> --- /dev/null
> +++ b/tests/Functional.samba/tests/test_samba06_host.sh
> @@ -0,0 +1,23 @@
> +#!/bin/sh
> +
> +#  In the target start samba, and confirm the process condition by 
> +command
> 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.
> +
> +test="samba06"
> +expect <<-EOF
> +spawn sh
> +expect ".*"
> +send "smbclient //$1/test -N\r"
> +expect {
> + -re ".*smb:.*" {
> +           send "ls\r"
> +          }
> + default { send_user "Can't connect to the board"\n"}  } expect {  
> +-re ".*test1.*" {
> +           send_user " -> $test: TEST-PASS\n"
> +          }
> + default { send_user " -> $test: TEST-FAIL\n"}  } send "exit\n"
> +expect eof
> +EOF
> --
> 2.17.1

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






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn.
  2019-11-18 10:49 ` [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn Wang Mingyu
@ 2019-11-19 17:00   ` Tim.Bird
  0 siblings, 0 replies; 10+ messages in thread
From: Tim.Bird @ 2019-11-19 17:00 UTC (permalink / raw)
  To: wangmy, fuego



> -----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.
> 
> Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
> ---
>  scripts/fuego_board_function_lib.sh           | 14 ++++
>  tests/Functional.openvpn/data/host-target.key | 22 ++++++
>  tests/Functional.openvpn/data/testcli.conf    |  7 ++
>  tests/Functional.openvpn/data/testenv.sh      | 79 +++++++++++++++++++
>  tests/Functional.openvpn/data/testsrv.conf    | 16 ++++
>  tests/Functional.openvpn/fuego_test.sh        | 21 +++++
>  tests/Functional.openvpn/openvpn_test.sh      | 14 ++++
>  tests/Functional.openvpn/spec.json            |  6 ++
>  .../tests/openvpn_genkey.sh                   | 26 ++++++
>  .../Functional.openvpn/tests/openvpn_lport.sh | 34 ++++++++
>  tests/Functional.openvpn/tests/openvpn_pid.sh | 31 ++++++++
>  tests/Functional.openvpn/tests/openvpn_ps.sh  | 36 +++++++++
>  .../tests/openvpn_syslog-ng.sh                | 42 ++++++++++
>  tests/Functional.openvpn/tests/openvpn_tun.sh | 27 +++++++
>  14 files changed, 375 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.sh
>  create mode 100644 tests/Functional.openvpn/tests/openvpn_pid.sh
>  create mode 100644 tests/Functional.openvpn/tests/openvpn_ps.sh
>  create mode 100644 tests/Functional.openvpn/tests/openvpn_syslog-ng.sh
>  create mode 100644 tests/Functional.openvpn/tests/openvpn_tun.sh
> 
> diff --git a/scripts/fuego_board_function_lib.sh
> b/scripts/fuego_board_function_lib.sh
> index a6cd842..115c615 100644
> --- a/scripts/fuego_board_function_lib.sh
> +++ b/scripts/fuego_board_function_lib.sh
> @@ -12,6 +12,7 @@
>  init_manager="init_manager-not-set"
>  logger_service="logger_service-not-set"
>  service_status="unknown"
> +module_status="unknown"
> 
>  # set_init_manager:
>  #   detects and sets the init_manager variable, which indicates which
> @@ -100,3 +101,16 @@ get_service_logfile() {
>      fi
>      echo $service_logfile
>  }
> +
> +# get_module_status:
> +# get status of module
> +# returns: status of module
> +get_module_status() {
> +    if lsmod | grep $1
> +    then
> +        module_status="loaded"
> +    else
> +        module_status="unloaded"
> +    fi
> +    echo $module_status
> +}

This has already been applied as a separate patch.  I'll remove this
hunk.

> diff --git a/tests/Functional.openvpn/data/host-target.key
> b/tests/Functional.openvpn/data/host-target.key
> new file mode 100644
> index 0000000..99743bf
> --- /dev/null
> +++ b/tests/Functional.openvpn/data/host-target.key
> @@ -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-----
> +
> diff --git a/tests/Functional.openvpn/data/testcli.conf
> b/tests/Functional.openvpn/data/testcli.conf
> new file mode 100644
> index 0000000..2c252bb
> --- /dev/null
> +++ b/tests/Functional.openvpn/data/testcli.conf
> @@ -0,0 +1,7 @@
> +remote  192.168.0.1
Will this work on any machine?  Does this need address to be
substituted with a valid address for the board under test?
Or does it need to avoid an address already in use by the 
board?

> +port    5000
> +dev     tap
> +#dev    tun
> +verb    3
> +ping    60
> +
> diff --git a/tests/Functional.openvpn/data/testenv.sh
> b/tests/Functional.openvpn/data/testenv.sh
> new file mode 100644
> index 0000000..0d89191
> --- /dev/null
> +++ b/tests/Functional.openvpn/data/testenv.sh
> @@ -0,0 +1,79 @@
> +service_name="service_name-not-set"
> +config_file="config_file-not-set"
> +pid_file="pid_file-not-set"
> +module_status="unknown"
> +
> +#set the variable of service openvpn
> +set_service_file() {
> +    if [ "$init_manager" == "systemd" ]
> +    then
> +        service_name="openvpn@loopback-server.service"
> +        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
> +}
> +
> +setup_routine() {
> +    set_service_file
> +    service_status=$(get_service_status $service_name)
> +    module_status=$(get_module_status tun)
> +    exec_service_on_target $service_name stop
> +
> +    if [ -f $config_file ]
> +    then
> +        mv $config_file "${config_file}_bak"
> +    fi
> +
> +    test_type=$1
> +    if [ "$test_type" = "client" ]
> +    then
> +        cp data/testcli.conf $config_file
> +    elif [ "$test_type" = "server" ] ; then
> +        cp data/testsrv.conf $config_file
> +    fi
> +
> +    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
> +
> +    if [ -d /dev/net ]
> +    then
> +        mv /dev/net /dev/net_bak
> +    fi
> +    mkdir -m 755 /dev/net
> +    mknod /dev/net/tun c 10 200
> +}
> +
> +restore_routine() {
> +    if [ -d /dev/net_bak ]
> +    then
> +        mv /dev/net_bak /dev/net
> +    fi
> +    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
> +    if [ "$module_status" = "unloaded" ]
> +    then
> +        modprobe -r tun
> +    fi
> +}

Nice.  Thanks.  If we use this pattern a lot, then we might want
to add some generic functions for backing up and restoring
files, starting and stopping services, and loading and unloading
modules - and add them to fuego_board_function_lib.sh

However, let's keep these local for now and see if we get more
examples of this in additional tests.

> diff --git a/tests/Functional.openvpn/data/testsrv.conf
> b/tests/Functional.openvpn/data/testsrv.conf
> new file mode 100644
> index 0000000..0c18a40
> --- /dev/null
> +++ b/tests/Functional.openvpn/data/testsrv.conf
> @@ -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
> +
> diff --git a/tests/Functional.openvpn/fuego_test.sh
> b/tests/Functional.openvpn/fuego_test.sh
> new file mode 100644
> index 0000000..a94740e
> --- /dev/null
> +++ b/tests/Functional.openvpn/fuego_test.sh
> @@ -0,0 +1,21 @@

Probably need a NEED_ROOT=1 here.
This test does a lot of manipulation of system-wide configuration
files, loading/unloading modules and starting/stopping services.

> +function test_pre_check {
> +    assert_has_program openvpn
> +    assert_has_program netstat
> +    assert_has_program ifconfig
> +}
> +
> +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"
> +}
> diff --git a/tests/Functional.openvpn/openvpn_test.sh
> b/tests/Functional.openvpn/openvpn_test.sh
> new file mode 100755
> index 0000000..13bcf82
> --- /dev/null
> +++ b/tests/Functional.openvpn/openvpn_test.sh
> @@ -0,0 +1,14 @@
> +#!/bin/sh
> +. ./fuego_board_function_lib.sh
> +set_init_manager
> +
> +. data/testenv.sh
> +
> +for i in tests/*.sh; do
> +    if [ "$i" = "tests/openvpn_genkey.sh" ]; then
> +        source $i
> +    else
> +        source $i client
> +        source $i server
> +    fi
> +done
> diff --git a/tests/Functional.openvpn/spec.json
> b/tests/Functional.openvpn/spec.json
> new file mode 100644
> index 0000000..e9fdc5a
> --- /dev/null
> +++ b/tests/Functional.openvpn/spec.json
> @@ -0,0 +1,6 @@
> +{
> +    "testName": "Functional.openvpn",
> +    "specs": {
> +        "default": {}
> +    }
> +}
> diff --git a/tests/Functional.openvpn/tests/openvpn_genkey.sh
> b/tests/Functional.openvpn/tests/openvpn_genkey.sh
> new file mode 100644
> index 0000000..90d2474
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_genkey.sh
> @@ -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 [ -f /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
> +
> diff --git a/tests/Functional.openvpn/tests/openvpn_lport.sh
> b/tests/Functional.openvpn/tests/openvpn_lport.sh
> new file mode 100644
> index 0000000..f19659a
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_lport.sh
> @@ -0,0 +1,34 @@
> +#!/bin/sh
> +
> +#  In the target, run openvpn and check the Listening port.
> +
> +test="lport_$1"
> +
> +test_type=$1
> +
> +setup_routine $test_type
> +
> +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_routine
> +    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_routine
> diff --git a/tests/Functional.openvpn/tests/openvpn_pid.sh
> b/tests/Functional.openvpn/tests/openvpn_pid.sh
> new file mode 100644
> index 0000000..dbcb61a
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_pid.sh
> @@ -0,0 +1,31 @@
> +#!/bin/sh
> +
> +#  In the target, run openvpn and check the pidfile.
> +
> +test="pid_$1"
> +
> +test_type=$1
> +
> +setup_routine $test_type
> +
> +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_routine
> +    exit
> +fi
> +
> +if [ -f $pid_file ]
> +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_routine
> diff --git a/tests/Functional.openvpn/tests/openvpn_ps.sh
> b/tests/Functional.openvpn/tests/openvpn_ps.sh
> new file mode 100644
> index 0000000..d8b8c52
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_ps.sh
> @@ -0,0 +1,36 @@
> +#!/bin/sh
> +
> +#  In the target, run openvpn and check the status of process.
> +
> +test="ps_$1"
> +
> +test_type=$1
> +
> +setup_routine $test_type
> +
> +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_routine
> +    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_routine
> +if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
> +then
> +    exec_service_on_target $service_name start
> +fi
> diff --git a/tests/Functional.openvpn/tests/openvpn_syslog-ng.sh
> b/tests/Functional.openvpn/tests/openvpn_syslog-ng.sh
> new file mode 100644
> index 0000000..8dd84ee
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_syslog-ng.sh
> @@ -0,0 +1,42 @@
> +#!/bin/sh
> +
> +#  In the target, run openvpn and check the message of syslog-ng.
> +
> +test="syslog-ng_$1"
> +
> +test_type=$1
> +
> +setup_routine $test_type
> +logger_service=$(detect_logger_service)
> +openvpn_logfile=$(get_service_logfile)
> +
> +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
> +
> +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
> +
> +restore_routine
> +
> +if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
> +then
> +    exec_service_on_target $service_name start
> +fi
> diff --git a/tests/Functional.openvpn/tests/openvpn_tun.sh
> b/tests/Functional.openvpn/tests/openvpn_tun.sh
> new file mode 100644
> index 0000000..8902df8
> --- /dev/null
> +++ b/tests/Functional.openvpn/tests/openvpn_tun.sh
> @@ -0,0 +1,27 @@
> +#!/bin/sh
> +
> +# Verify the creation of the tun device (tap0) interface by openvpn.
> +
> +test="tun_$1"
> +
> +test_type=$1
> +
> +setup_routine $test_type
> +
> +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
> +
> +restore_routine
> +
> +if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
> +then
> +    exec_service_on_target $service_name start
> +fi
> --
> 2.17.1

OK - this looks good.

I'm going to apply it, but please respond to my comments above.
I'll go ahead and add the NEED_ROOT=1.

Let me know about the address in the configuration file (whether that
matters for this test).

Thanks,
 -- Tim


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn.
  2019-11-18 10:49 [Fuego] [PATCH v2] " Wang Mingyu
@ 2019-11-18 10:49 ` Wang Mingyu
  2019-11-19 17:00   ` Tim.Bird
  0 siblings, 1 reply; 10+ messages in thread
From: Wang Mingyu @ 2019-11-18 10:49 UTC (permalink / raw)
  To: fuego

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.

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 scripts/fuego_board_function_lib.sh           | 14 ++++
 tests/Functional.openvpn/data/host-target.key | 22 ++++++
 tests/Functional.openvpn/data/testcli.conf    |  7 ++
 tests/Functional.openvpn/data/testenv.sh      | 79 +++++++++++++++++++
 tests/Functional.openvpn/data/testsrv.conf    | 16 ++++
 tests/Functional.openvpn/fuego_test.sh        | 21 +++++
 tests/Functional.openvpn/openvpn_test.sh      | 14 ++++
 tests/Functional.openvpn/spec.json            |  6 ++
 .../tests/openvpn_genkey.sh                   | 26 ++++++
 .../Functional.openvpn/tests/openvpn_lport.sh | 34 ++++++++
 tests/Functional.openvpn/tests/openvpn_pid.sh | 31 ++++++++
 tests/Functional.openvpn/tests/openvpn_ps.sh  | 36 +++++++++
 .../tests/openvpn_syslog-ng.sh                | 42 ++++++++++
 tests/Functional.openvpn/tests/openvpn_tun.sh | 27 +++++++
 14 files changed, 375 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.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_pid.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_ps.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_syslog-ng.sh
 create mode 100644 tests/Functional.openvpn/tests/openvpn_tun.sh

diff --git a/scripts/fuego_board_function_lib.sh b/scripts/fuego_board_function_lib.sh
index a6cd842..115c615 100644
--- a/scripts/fuego_board_function_lib.sh
+++ b/scripts/fuego_board_function_lib.sh
@@ -12,6 +12,7 @@
 init_manager="init_manager-not-set"
 logger_service="logger_service-not-set"
 service_status="unknown"
+module_status="unknown"
 
 # set_init_manager:
 #   detects and sets the init_manager variable, which indicates which
@@ -100,3 +101,16 @@ get_service_logfile() {
     fi
     echo $service_logfile
 }
+
+# get_module_status:
+# get status of module
+# returns: status of module
+get_module_status() {
+    if lsmod | grep $1
+    then
+        module_status="loaded"
+    else
+        module_status="unloaded"
+    fi
+    echo $module_status
+}
diff --git a/tests/Functional.openvpn/data/host-target.key b/tests/Functional.openvpn/data/host-target.key
new file mode 100644
index 0000000..99743bf
--- /dev/null
+++ b/tests/Functional.openvpn/data/host-target.key
@@ -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-----
+
diff --git a/tests/Functional.openvpn/data/testcli.conf b/tests/Functional.openvpn/data/testcli.conf
new file mode 100644
index 0000000..2c252bb
--- /dev/null
+++ b/tests/Functional.openvpn/data/testcli.conf
@@ -0,0 +1,7 @@
+remote  192.168.0.1
+port    5000
+dev     tap
+#dev    tun
+verb    3
+ping    60
+
diff --git a/tests/Functional.openvpn/data/testenv.sh b/tests/Functional.openvpn/data/testenv.sh
new file mode 100644
index 0000000..0d89191
--- /dev/null
+++ b/tests/Functional.openvpn/data/testenv.sh
@@ -0,0 +1,79 @@
+service_name="service_name-not-set"
+config_file="config_file-not-set"
+pid_file="pid_file-not-set"
+module_status="unknown"
+
+#set the variable of service openvpn
+set_service_file() {
+    if [ "$init_manager" == "systemd" ]
+    then
+        service_name="openvpn@loopback-server.service"
+        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
+}
+
+setup_routine() {
+    set_service_file
+    service_status=$(get_service_status $service_name)
+    module_status=$(get_module_status tun)
+    exec_service_on_target $service_name stop
+
+    if [ -f $config_file ]
+    then
+        mv $config_file "${config_file}_bak"
+    fi
+
+    test_type=$1
+    if [ "$test_type" = "client" ]
+    then
+        cp data/testcli.conf $config_file
+    elif [ "$test_type" = "server" ] ; then
+        cp data/testsrv.conf $config_file
+    fi
+
+    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
+
+    if [ -d /dev/net ]
+    then
+        mv /dev/net /dev/net_bak
+    fi
+    mkdir -m 755 /dev/net
+    mknod /dev/net/tun c 10 200
+}
+
+restore_routine() {
+    if [ -d /dev/net_bak ]
+    then
+        mv /dev/net_bak /dev/net
+    fi
+    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
+    if [ "$module_status" = "unloaded" ]
+    then
+        modprobe -r tun
+    fi
+}
diff --git a/tests/Functional.openvpn/data/testsrv.conf b/tests/Functional.openvpn/data/testsrv.conf
new file mode 100644
index 0000000..0c18a40
--- /dev/null
+++ b/tests/Functional.openvpn/data/testsrv.conf
@@ -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
+
diff --git a/tests/Functional.openvpn/fuego_test.sh b/tests/Functional.openvpn/fuego_test.sh
new file mode 100644
index 0000000..a94740e
--- /dev/null
+++ b/tests/Functional.openvpn/fuego_test.sh
@@ -0,0 +1,21 @@
+function test_pre_check {
+    assert_has_program openvpn
+    assert_has_program netstat
+    assert_has_program ifconfig
+}
+
+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"
+}
diff --git a/tests/Functional.openvpn/openvpn_test.sh b/tests/Functional.openvpn/openvpn_test.sh
new file mode 100755
index 0000000..13bcf82
--- /dev/null
+++ b/tests/Functional.openvpn/openvpn_test.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+. ./fuego_board_function_lib.sh
+set_init_manager
+
+. data/testenv.sh
+
+for i in tests/*.sh; do
+    if [ "$i" = "tests/openvpn_genkey.sh" ]; then
+        source $i
+    else
+        source $i client
+        source $i server
+    fi
+done
diff --git a/tests/Functional.openvpn/spec.json b/tests/Functional.openvpn/spec.json
new file mode 100644
index 0000000..e9fdc5a
--- /dev/null
+++ b/tests/Functional.openvpn/spec.json
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.openvpn",
+    "specs": {
+        "default": {}
+    }
+}
diff --git a/tests/Functional.openvpn/tests/openvpn_genkey.sh b/tests/Functional.openvpn/tests/openvpn_genkey.sh
new file mode 100644
index 0000000..90d2474
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_genkey.sh
@@ -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 [ -f /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
+
diff --git a/tests/Functional.openvpn/tests/openvpn_lport.sh b/tests/Functional.openvpn/tests/openvpn_lport.sh
new file mode 100644
index 0000000..f19659a
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_lport.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the Listening port.
+
+test="lport_$1"
+
+test_type=$1
+
+setup_routine $test_type
+
+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_routine
+    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_routine
diff --git a/tests/Functional.openvpn/tests/openvpn_pid.sh b/tests/Functional.openvpn/tests/openvpn_pid.sh
new file mode 100644
index 0000000..dbcb61a
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_pid.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the pidfile.
+
+test="pid_$1"
+
+test_type=$1
+
+setup_routine $test_type
+
+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_routine
+    exit
+fi
+
+if [ -f $pid_file ]
+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_routine
diff --git a/tests/Functional.openvpn/tests/openvpn_ps.sh b/tests/Functional.openvpn/tests/openvpn_ps.sh
new file mode 100644
index 0000000..d8b8c52
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_ps.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the status of process.
+
+test="ps_$1"
+
+test_type=$1
+
+setup_routine $test_type
+
+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_routine
+    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_routine
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target $service_name start
+fi
diff --git a/tests/Functional.openvpn/tests/openvpn_syslog-ng.sh b/tests/Functional.openvpn/tests/openvpn_syslog-ng.sh
new file mode 100644
index 0000000..8dd84ee
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_syslog-ng.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+#  In the target, run openvpn and check the message of syslog-ng.
+
+test="syslog-ng_$1"
+
+test_type=$1
+
+setup_routine $test_type
+logger_service=$(detect_logger_service)
+openvpn_logfile=$(get_service_logfile)
+
+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
+
+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
+
+restore_routine
+
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target $service_name start
+fi
diff --git a/tests/Functional.openvpn/tests/openvpn_tun.sh b/tests/Functional.openvpn/tests/openvpn_tun.sh
new file mode 100644
index 0000000..8902df8
--- /dev/null
+++ b/tests/Functional.openvpn/tests/openvpn_tun.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# Verify the creation of the tun device (tap0) interface by openvpn.
+
+test="tun_$1"
+
+test_type=$1
+
+setup_routine $test_type
+
+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
+
+restore_routine
+
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target $service_name start
+fi
-- 
2.17.1




^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-11-25  3:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05  9:01 [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate Wang Mingyu
2019-11-05  9:01 ` [Fuego] [PATCH] samba: Add test case to access the target from host using samba Wang Mingyu
2019-11-19 15:36   ` Tim.Bird
2019-11-25  3:21     ` Wang, Mingyu
2019-11-05  9:01 ` [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn Wang Mingyu
2019-11-08 13:13   ` Tim.Bird
2019-11-06 20:37 ` [Fuego] [PATCH v3] logrotate: Add test cases for command logrotate Tim.Bird
2019-11-07 14:08 ` Tim.Bird
2019-11-18 10:49 [Fuego] [PATCH v2] " Wang Mingyu
2019-11-18 10:49 ` [Fuego] [PATCH v3] openvpn: Add test cases of service openvpn Wang Mingyu
2019-11-19 17:00   ` Tim.Bird

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.