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

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

> -----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 <[email protected]>
> ---
>  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="[email protected]"
> +        config_file="/etc/openvpn/loopback-server.conf"
> +        pid_file="/var/run/openvpn/loopback-server.pid"
> +else
> +        service_name="openvpn"
> +        if [ "$test_type" == "client" ]
> +        then
> +                config_file="/etc/openvpn/testcli.conf"
> +                pid_file="/var/run/openvpn.testcli.pid"
> +        elif [ "$test_type" == "server" ]
> +        then
> +                config_file="/etc/openvpn/testsrv.conf"
> +                pid_file="/var/run/openvpn.testsrv.pid"
> +        fi
> +fi
> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.