[Fuego] [PATCH] bind: Add test cases for commands of bind(named).

Tim.Bird at sony.com Tim.Bird at sony.com
Fri Oct 12 05:29:14 UTC 2018


Comments and questions inline below.

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


Missing description in commit message body.  Please add these in the future.


> 
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> ---
>  .../Functional.bind/tests/bind_named_chkconf.sh    | 30 ++++++++
>  .../Functional.bind/tests/bind_named_chkzone1.sh   | 28 +++++++
>  .../Functional.bind/tests/bind_named_chkzone2.sh   | 28 +++++++
>  .../tests/Functional.bind/tests/bind_named_dig1.sh | 68
> +++++++++++++++++
>  .../tests/Functional.bind/tests/bind_named_dig2.sh | 85
> ++++++++++++++++++++++
>  .../Functional.bind/tests/bind_named_lport.sh      | 46 ++++++++++++
>  .../Functional.bind/tests/bind_named_pidfile.sh    | 52 +++++++++++++
>  .../tests/Functional.bind/tests/bind_named_ps.sh   | 41 +++++++++++
>  .../Functional.bind/tests/bind_named_syslog.sh     | 57 +++++++++++++++
>  .../Functional.bind/tests/bind_rndc-confgen.sh     | 35 +++++++++
>  10 files changed, 470 insertions(+)
>  create mode 100644
> engine/tests/Functional.bind/tests/bind_named_chkconf.sh
>  create mode 100644
> engine/tests/Functional.bind/tests/bind_named_chkzone1.sh
>  create mode 100644
> engine/tests/Functional.bind/tests/bind_named_chkzone2.sh
>  create mode 100644
> engine/tests/Functional.bind/tests/bind_named_dig1.sh
>  create mode 100644
> engine/tests/Functional.bind/tests/bind_named_dig2.sh
>  create mode 100644
> engine/tests/Functional.bind/tests/bind_named_lport.sh
>  create mode 100644
> engine/tests/Functional.bind/tests/bind_named_pidfile.sh
>  create mode 100644 engine/tests/Functional.bind/tests/bind_named_ps.sh
>  create mode 100644
> engine/tests/Functional.bind/tests/bind_named_syslog.sh
>  create mode 100644 engine/tests/Functional.bind/tests/bind_rndc-
> confgen.sh
> 
> diff --git a/engine/tests/Functional.bind/tests/bind_named_chkconf.sh
> b/engine/tests/Functional.bind/tests/bind_named_chkconf.sh
> new file mode 100644
> index 0000000..7914e0d
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_named_chkconf.sh
> @@ -0,0 +1,30 @@
> +#!/bin/sh
> +
> +#  After running the /etc/named.conf to run to the target, run the named
> checkconf command and verify the normal end.
> +
> +test="named_chkconf"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target named stop

We stop named, but don't restart it.  We should leave the machine in the
same state we found it in.

> +
> +if [ -f /etc/bind/named.conf ]
> +then
> +    cp /etc/bind/named.conf /etc/bind/named.conf_bak
> +fi
> +
> +cp data/bind9/named.conf /etc/bind/named.conf
> +
> +if named-checkconf
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ -f /etc/bind/named.conf_bak ]
> +then
> +    mv /etc/bind/named.conf_bak /etc/bind/named.conf
> +fi
> diff --git a/engine/tests/Functional.bind/tests/bind_named_chkzone1.sh
> b/engine/tests/Functional.bind/tests/bind_named_chkzone1.sh
> new file mode 100644
> index 0000000..40a6387
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_named_chkzone1.sh
> @@ -0,0 +1,28 @@
> +#!/bin/sh
> +
> +# when the /var/named/ is transformed run the named checkzone
> command to verify that it is successfully terminated.
> +
> +test="named_chkzone1"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target named stop
> +
> +if [ ! -d /var/named ]
> +then
> +    mkdir -p /var/named
> +fi
> +
> +cp data/bind9/$tst_bind_file /var/named/$tst_bind_file
> +cp data/bind9/linux_test.com.db_$test_target_conf
> /var/named/linux_test.com.db
> +
> +if named-checkzone linux-test.com /var/named/linux_test.com.db
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +rm -f /var/named/$tst_bind_file /var/named/linux_test.com.db
> diff --git a/engine/tests/Functional.bind/tests/bind_named_chkzone2.sh
> b/engine/tests/Functional.bind/tests/bind_named_chkzone2.sh
> new file mode 100644
> index 0000000..6a3da22
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_named_chkzone2.sh
> @@ -0,0 +1,28 @@
> +#!/bin/sh
> +
> +# when the /var/named/ is transformed run the named checkzone
> command to verify that it is successfully terminated.
> +
> +test="named_chkzone2"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target named stop
> +
> +if [ ! -d /var/named ]
> +then
> +    mkdir -p /var/named
> +fi
> +
> +cp data/bind9/$tst_bind_file /var/named/$tst_bind_file
> +cp data/bind9/linux_test.com.db_$test_target_conf
> /var/named/linux_test.com.db
> +
> +if named-checkzone 192.168.0.0 /var/named/$tst_bind_file
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +rm -f /var/named/$tst_bind_file /var/named/linux_test.com.db
> diff --git a/engine/tests/Functional.bind/tests/bind_named_dig1.sh
> b/engine/tests/Functional.bind/tests/bind_named_dig1.sh
> new file mode 100644
> index 0000000..8cbbdb1
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_named_dig1.sh
> @@ -0,0 +1,68 @@
> +#!/bin/sh
> +
> +# Start the named on target.
> +# Check the IP address.
> +
> +test="named_dig1"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target named stop
> +
> +if [ ! -f /etc/bind/named.conf ]
> +then
> +    touch /etc/bind/named.conf
> +fi
> +
> +if [ ! -f /etc/bind/rndc.conf ]
> +then
> +    touch /etc/bind/rndc.conf
> +fi
> +
> +if [ ! -f /etc/resolv.conf ]
> +then
> +    touch /etc/resolv.conf
> +fi
> +
> +mv /etc/resolv.conf /etc/resolv.conf_bak
> +cp data/bind9/resolv.conf /etc/resolv.conf
> +cp data/bind9/sysconfig/named.nochroot /etc/sysconfig/named
> +
> +mv /etc/bind/named.conf /etc/bind/named.conf_bak
> +cp data/bind9/named.conf /etc/bind/named.conf
> +
> +mv /etc/bind/rndc.conf /etc/bind/rndc.conf_bak
> +cp data/bind9/rndc.conf /etc/bind/rndc.conf
> +
> +if [ ! -d /var/named ]
> +then
> +    mkdir -p /var/named
> +fi
> +
> +cp data/bind9/$tst_bind_file /var/named/$tst_bind_file
> +cp data/bind9/linux_test.com.db_$test_target_conf
> /var/named/linux_test.com.db
> +if [ ! -f /etc/hosts ]
> +then
> +    touch /etc/hosts
> +fi
> +mv /etc/hosts /etc/hosts_bak
> +cp data/bind9/hosts /etc/hosts
> +
> +exec_service_on_target named start
> +
> +if dig linux-test.com | grep $remotehost
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +exec_service_on_target named stop
> +
> +mv /etc/resolv.conf_bak /etc/resolv.conf
> +mv /etc/bind/named.conf_bak /etc/bind/named.conf
> +mv /etc/bind/rndc.conf_bak /etc/bind/rndc.conf
> +rm -fr /var/named

Are we deleting anything here that we didn't put on the board ourselves
for the test?  This is a little frightening.

> +mv /etc/hosts_bak /etc/hosts
> diff --git a/engine/tests/Functional.bind/tests/bind_named_dig2.sh
> b/engine/tests/Functional.bind/tests/bind_named_dig2.sh
> new file mode 100644
> index 0000000..1259f3e
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_named_dig2.sh
> @@ -0,0 +1,85 @@
> +#!/bin/sh
> +
> +# Start the named on target.
> +# Check the IP address.
> +
> +test="named_dig2"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target named stop
> +
> +if [ ! -f /etc/bind/named.conf ]
> +then
> +    touch /etc/bind/named.conf
> +fi
> +
> +if [ ! -f /etc/bind/rndc.conf ]
> +then
> +    touch /etc/bind/rndc.conf
> +fi
> +
> +if [ ! -f /etc/resolv.conf ]
> +then
> +    touch /etc/resolv.conf
> +fi
> +
> +mv /etc/resolv.conf /etc/resolv.conf_bak
> +cp data/bind9/resolv.conf /etc/resolv.conf
> +cp data/bind9/sysconfig/named.nochroot /etc/sysconfig/named
> +
> +mv /etc/bind/named.conf /etc/bind/named.conf_bak
> +cp data/bind9/named.conf /etc/bind/named.conf
> +
> +cp data/bind9/x86_64_named.conf /etc/bind/x86_64_named.conf
> +if [ -d /lib64/ ]
> +then
> +    cp -a /etc/bind/x86_64_named.conf /etc/bind/named.conf
> +fi
> +
> +mv /etc/bind/rndc.conf /etc/bind/rndc.conf_bak
> +cp data/bind9/rndc.conf /etc/bind/rndc.conf
> +
> +if [ ! -f /etc/bind/rndc.key ]
> +then
> +    touch /etc/bind/rndc.key
> +fi
> +mv /etc/bind/rndc.key /etc/bind/rndc.key_bak
> +cp data/bind9/rndc.key /etc/bind/rndc.key
> +
> +if [ ! -d /var/named ]
> +then
> +    mkdir -p /var/named
> +fi
> +
> +cp data/bind9/$tst_bind_file /var/named/$tst_bind_file
> +cp data/bind9/linux_test.com.db_$test_target_conf
> /var/named/linux_test.com.db
> +if [ ! -f /etc/hosts ]
> +then
> +    touch /etc/hosts
> +fi
> +mv /etc/hosts /etc/hosts_bak
> +cp data/bind9/hosts /etc/hosts
> +
> +exec_service_on_target named start
> +
> +sleep 5
> +
> +if dig -x $remotehost | grep "linux-test.com"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +exec_service_on_target named stop
> +
> +mv /etc/resolv.conf_bak /etc/resolv.conf
> +mv /etc/bind/named.conf_bak /etc/bind/named.conf
> +mv /etc/bind/rndc.conf_bak /etc/bind/rndc.conf
> +mv /etc/bind/rndc.key_bak /etc/bind/rndc.key
> +
> +rm -fr /var/named
> +mv /etc/hosts_bak /etc/hosts

Is named supposed to be running or not at the end of this test?

> diff --git a/engine/tests/Functional.bind/tests/bind_named_lport.sh
> b/engine/tests/Functional.bind/tests/bind_named_lport.sh
> new file mode 100644
> index 0000000..0a171a6
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_named_lport.sh
> @@ -0,0 +1,46 @@
> +#!/bin/sh
> +
> +# Start the named on target.
> +# Check the listening port.
> +
> +test="named_lport"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +if [ -f /etc/bind/rndc.key ]
> +then
> +    rm -f /etc/bind/rndc.key
> +fi
> +
> +exec_service_on_target named stop
> +
> +if exec_service_on_target named start
> +then
> +    echo " -> start of named succeeded."
> +else
> +    echo " -> start of named failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if netstat -ln | grep ":53"
> +then
> +    echo " -> port 53 is exist."
> +else
> +    echo " -> port 53 is not exist."
> +    echo " -> $test: TEST-FAIL"
> +    exec_service_on_target named stop
> +    exit
> +fi
> +
> +if netstat -ln | grep ":953"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> port 953 is not exist."
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +exec_service_on_target named stop
> diff --git a/engine/tests/Functional.bind/tests/bind_named_pidfile.sh
> b/engine/tests/Functional.bind/tests/bind_named_pidfile.sh
> new file mode 100644
> index 0000000..be2fc89
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_named_pidfile.sh
> @@ -0,0 +1,52 @@
> +#!/bin/sh
> +
> +# Start the named on target.
> +# Check the pid file.
> +
> +test="named_pidfile"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +if [ -f /etc/bind/rndc.key ]
> +then
> +    rm -f /etc/bind/rndc.key
> +fi
> +
> +exec_service_on_target named stop
> +
> +if exec_service_on_target named start
> +then
> +    echo " -> start of named succeeded."
> +else
> +    echo " -> start of named failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if ls /var/run/named/named.pid
> +then
> +    echo " -> pid file of named is exist."
> +else
> +    echo " -> pid file of named is not exist."
> +    echo " -> $test: TEST-FAIL"
> +    exec_service_on_target named stop
> +    exit
> +fi
> +
> +if exec_service_on_target named stop
> +then
> +    echo " -> stop of named succeeded."
> +else
> +    echo " -> stop of named failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if test ! -f /var/run/named/named.pid
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> diff --git a/engine/tests/Functional.bind/tests/bind_named_ps.sh
> b/engine/tests/Functional.bind/tests/bind_named_ps.sh
> new file mode 100644
> index 0000000..cd5fcc0
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_named_ps.sh
> @@ -0,0 +1,41 @@
> +#!/bin/sh
> +
> +#  In the target start bind, and confirm the process condition by command
> ps.
> +
> +test="named_ps"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target named stop
> +
> +if exec_service_on_target named start
> +then
> +    echo " -> start of named succeeded."
> +else
> +    echo " -> start of named failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +sleep 5
> +
> +if ps aux | grep "[/]usr/sbin/named"
> +then
> +    echo " -> get the process of named."
> +else
> +    echo " -> can't get the process of named."
> +    echo " -> $test: TEST-FAIL"
> +    exec_service_on_target named stop
> +    exit
> +fi
> +
> +exec_service_on_target named stop
> +
> +if ps aux | grep "[/]usr/sbin/named"
> +then
> +    echo " -> $test: TEST-FAIL"
> +else
> +    echo " -> $test: TEST-PASS"
> +fi
> diff --git a/engine/tests/Functional.bind/tests/bind_named_syslog.sh
> b/engine/tests/Functional.bind/tests/bind_named_syslog.sh
> new file mode 100644
> index 0000000..0b7c690
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_named_syslog.sh
> @@ -0,0 +1,57 @@
> +#!/bin/sh
> +
> +# Start the named on target.
> +# Check the log of named.
> +
> +test="named_syslog"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +logger_service=$(detect_logger_service)
> +
> +if [ -f /etc/bind/rndc.key ]
> +then
> +    rm -f /etc/bind/rndc.key
> +fi
> +
> +exec_service_on_target named stop
> +exec_service_on_target syslog.socket stop
> +exec_service_on_target $logger_service stop
> +
> +if [ -f /var/log/syslog ]
> +then
> +    mv /var/log/syslog /var/log/syslog_bak
> +fi
> +
> +exec_service_on_target $logger_service restart
> +sleep 5
> +
> +if exec_service_on_target named start
> +then
> +    echo " -> start of named succeeded."
> +else
> +    echo " -> start of named failed."
> +    echo " -> $test: TEST-FAIL"
> +    exec_service_on_target named stop
> +    if [ -f /var/log/syslog_bak ]
> +    then
> +        mv /var/log/syslog_bak /var/log/syslog
> +    fi
> +    exit
> +fi
> +
> +if cat /var/log/syslog | grep "starting up"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> log is not generated."
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +exec_service_on_target named stop
> +if [ -f /var/log/syslog_bak ]
> +then
> +    mv /var/log/syslog_bak /var/log/syslog
> +fi
> +
> diff --git a/engine/tests/Functional.bind/tests/bind_rndc-confgen.sh
> b/engine/tests/Functional.bind/tests/bind_rndc-confgen.sh
> new file mode 100644
> index 0000000..adc38ca
> --- /dev/null
> +++ b/engine/tests/Functional.bind/tests/bind_rndc-confgen.sh
> @@ -0,0 +1,35 @@
> +#!/bin/sh
> +
> +#  In the target execute command rndc-confgen, and confirm the file
> rndc.key.
> +
> +test="rndc-confgen"
> +
> +. ./fuego_board_function_lib.sh
> +
> +set_init_manager
> +
> +exec_service_on_target named stop
> +
> +if [ -f /etc/bind/rndc.key ]
> +then
> +    mv /etc/bind/rndc.key /etc/bind/rndc.key_bak
> +fi
> +
> +rndc-confgen -a -k rndckey -r /dev/urandom
> +
> +echo "sleep 60 seconds"
> +sleep 60
> +
> +if ls /etc/bind/rndc.key
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ -f /etc/bind/rndc.key_bak ]
> +then
> +    mv /etc/bind/rndc.key_bak /etc/bind/rndc.key
> +else
> +    rm -f /etc/bind/rndc.key
> +fi
> --
> 1.8.3.1

OK.  I applied this,  but I have a few concerns that the board being
tested is not left in the same condition as when we started the test.
In particular, I'm concerned about removing files that were present
before the test started, and about restoring named to the operational
status (running or not running) it was in before the test started.

Can you check this and suggest a patch on top of this to solve these
issues?

Thanks,
 -- Tim



More information about the Fuego mailing list