Re: [Fuego] [PATCH v2] net-snmp: Add test cases for Net-SNMP.

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

> -----Original Message-----
> From: Wang Mingyu on October 15, 2019 10:06 PM
> 
> Net-SNMP is a suite of applications used to implement SNMP.
> This test set is used to check applications of SNMP to monitor the health and
> welfare of network/computer/device equipment.
> 
> Signed-off-by: Wang Mingyu <[email protected]>
> ---
>  scripts/fuego_board_function_lib.sh           | 13 ++++
>  tests/Functional.net-snmp/data/bind9/hosts    |  3 +
>  .../data/net-snmp/snmpd.conf                  | 22 +++++++
>  .../data/net-snmp/snmptrapd.conf              |  1 +
>  tests/Functional.net-snmp/fuego_test.sh       | 27 ++++++++
>  tests/Functional.net-snmp/net-snmp_test.sh    |  7 +++
>  tests/Functional.net-snmp/spec.json           |  6 ++
>  tests/Functional.net-snmp/test.yaml           | 23 +++++++
>  tests/Functional.net-snmp/tests/snmpd_ps.sh   | 52 +++++++++++++++
>  .../Functional.net-snmp/tests/snmpd_snmpdf.sh | 43 +++++++++++++
>  .../tests/snmpd_snmpget.sh                    | 43 +++++++++++++
>  .../tests/snmpd_snmpgetnext.sh                | 43 +++++++++++++
>  .../tests/snmpd_snmpset.sh                    | 43 +++++++++++++
>  .../tests/snmpd_snmptranslate.sh              | 43 +++++++++++++
>  .../tests/snmpd_snmpwalk.sh                   | 43 +++++++++++++
>  .../Functional.net-snmp/tests/snmpd_syslog.sh | 55 ++++++++++++++++
>  .../tests/snmpd_syslog_ip.sh                  | 63 +++++++++++++++++++
>  .../tests/snmptrapd_coldstart.sh              | 60 ++++++++++++++++++
>  .../Functional.net-snmp/tests/snmptrapd_ps.sh | 53 ++++++++++++++++
>  .../tests/snmptrapd_syslog.sh                 | 54 ++++++++++++++++
>  .../tests/snmptrapd_warmstart.sh              | 61 ++++++++++++++++++
>  21 files changed, 758 insertions(+)
>  create mode 100644 tests/Functional.net-snmp/data/bind9/hosts
>  create mode 100644 tests/Functional.net-snmp/data/net-snmp/snmpd.conf
>  create mode 100644 tests/Functional.net-snmp/data/net-
> snmp/snmptrapd.conf
>  create mode 100644 tests/Functional.net-snmp/fuego_test.sh
>  create mode 100755 tests/Functional.net-snmp/net-snmp_test.sh
>  create mode 100644 tests/Functional.net-snmp/spec.json
>  create mode 100644 tests/Functional.net-snmp/test.yaml
>  create mode 100644 tests/Functional.net-snmp/tests/snmpd_ps.sh
>  create mode 100644 tests/Functional.net-snmp/tests/snmpd_snmpdf.sh
>  create mode 100644 tests/Functional.net-snmp/tests/snmpd_snmpget.sh
>  create mode 100644 tests/Functional.net-
> snmp/tests/snmpd_snmpgetnext.sh
>  create mode 100644 tests/Functional.net-snmp/tests/snmpd_snmpset.sh
>  create mode 100644 tests/Functional.net-
> snmp/tests/snmpd_snmptranslate.sh
>  create mode 100644 tests/Functional.net-snmp/tests/snmpd_snmpwalk.sh
>  create mode 100644 tests/Functional.net-snmp/tests/snmpd_syslog.sh
>  create mode 100644 tests/Functional.net-snmp/tests/snmpd_syslog_ip.sh
>  create mode 100644 tests/Functional.net-
> snmp/tests/snmptrapd_coldstart.sh
>  create mode 100644 tests/Functional.net-snmp/tests/snmptrapd_ps.sh
>  create mode 100644 tests/Functional.net-snmp/tests/snmptrapd_syslog.sh
>  create mode 100644 tests/Functional.net-
> snmp/tests/snmptrapd_warmstart.sh
> 
> diff --git a/scripts/fuego_board_function_lib.sh
> b/scripts/fuego_board_function_lib.sh
> index 1b8699a..a6cd842 100644
> --- a/scripts/fuego_board_function_lib.sh
> +++ b/scripts/fuego_board_function_lib.sh
> @@ -87,3 +87,16 @@ get_service_status() {
>      fi
>      echo $service_status
>  }
> +
> +# get_service_logfile:
> +#  get logfile of service
> +# returns: logfile of service
> +get_service_logfile() {
> +    if [ "$init_manager" = "systemd" ]
> +    then
> +        service_logfile="/var/log/syslog"
> +    else
> +        service_logfile="/var/log/messages"
> +    fi
> +    echo $service_logfile
> +}

I accepted this as a separate patch.  So I had to remove this hunk.

> diff --git a/tests/Functional.net-snmp/data/bind9/hosts
> b/tests/Functional.net-snmp/data/bind9/hosts
> new file mode 100644
> index 0000000..c7b9f21
> --- /dev/null
> +++ b/tests/Functional.net-snmp/data/bind9/hosts
> @@ -0,0 +1,3 @@
> +# /etc/hosts test
> +#
> +127.0.0.1	localhost.localdomain	localhost
> diff --git a/tests/Functional.net-snmp/data/net-snmp/snmpd.conf
> b/tests/Functional.net-snmp/data/net-snmp/snmpd.conf
> new file mode 100644
> index 0000000..01c40a2
> --- /dev/null
> +++ b/tests/Functional.net-snmp/data/net-snmp/snmpd.conf
> @@ -0,0 +1,22 @@
> +# added community
> +#       sec.name  source          community
> +com2sec xfile     localhost       RWIINCOM
> +
> +# map the security name into a group name
> +#       groupName      securityModel securityName
> +group   RWACCESS       v1            xfile
> +group   RWACCESS       v2c           xfile
> +group   RWACCESS       usm           xfile
> +group   ROACCESS       v1            yfile
> +group   ROACCESS       v2c           yfile
> +group   ROACCESS       usm           yfile
> +
> +# create view to let the group have rights to
> +view    iin_all       included   .1                  80
> +view    iin_ucdmib    included   .1.3.6.1.4.1.2021   fe
> +view    iin_mib2      included   .1.3.6.1.2.1        fc
> +
> +# grant the group permission to the systemview view
> +#       group          context sec.model sec.level prefix read   write  notif
This line had a trailing space, that I removed.

> +access  RWACCESS       ""      any       noauth    exact  iin_all iin_all none
> +access  ROACCESS       ""      any       noauth    exact  iin_all none    none
> diff --git a/tests/Functional.net-snmp/data/net-snmp/snmptrapd.conf
> b/tests/Functional.net-snmp/data/net-snmp/snmptrapd.conf
> new file mode 100644
> index 0000000..2570e96
> --- /dev/null
> +++ b/tests/Functional.net-snmp/data/net-snmp/snmptrapd.conf
> @@ -0,0 +1 @@
> +disableAuthorization yes

Wow, these reduced test configuration files are much better!
Thank you for trimming these down.

> diff --git a/tests/Functional.net-snmp/fuego_test.sh b/tests/Functional.net-
> snmp/fuego_test.sh
> new file mode 100644
> index 0000000..b5f460c
> --- /dev/null
> +++ b/tests/Functional.net-snmp/fuego_test.sh
> @@ -0,0 +1,27 @@
> +NEED_ROOT=1
> +
> +function test_pre_check {
> +    assert_has_program snmpget
> +    assert_has_program snmpgetnext
> +    assert_has_program snmpset
> +    assert_has_program snmpwalk
> +    assert_has_program snmptrap
> +    assert_has_program snmptranslate

OK - get ready.  Here's a long discussion about a very minor issue.
I'm just thinking out loud here, and interested in your opinion.

I'm sympathetic to the time cost to perform these assertions.
See my response in another message about that.

I would like to know your opinion:  Do you think we need
to check for all of these, or would it be sufficient to check for 
only a few, or even only one?

Let me give some context for my question...

Here are my thoughts:
 - it is expensive to check for these (though I am trying to fix that)
 - it seems like if one of these is present on the board, it is extremely
unlikely that others would not be present.  So checking for all of them
is only going to matter if the snmp package or the board filesystem
somehow gets messed up, which is a low probability event.
 - the purpose of assert_has_program is not to validate whether
the snmp package has the correct contents on the target.  A test for
that would be structured differently (checking for the package contents
in test_runtime and reporting problems there).  There's actually a rich
area for creating tests for validating package contents, that we could add
to Fuego pretty easily.  It's on my to-do list.  (anyway, that's an aside)
 - the purpose of test_pre_check is twofold: 1) to see if this test is relevant
to a given board.  If the board doesn't have the snmp package installed, then
it is useless to run the test.  This is intended to eventually help QA developers
automatically determine the tests that apply to their board.  This system is
not developed in Fuego yet, but is on the roadmap.  I envision something
like a script to install (create jobs for) all tests that are relevant to a board,
based on the board dependencies. 2) the other purpose is to prevent the
test from running if the binaries are not present, and provide to the user
a better error message (and early test exit).  If we don't check ahead of time,
then if we get to test_run, then we get messages like "missing command or file",
instead of a nice message saying exactly what was missing.  Also, by checking
ahead of time we save the time required to do a build.  This doesn't apply
to this test, but for some tests (e.g. LTP) the build can be quite long, and
avoiding it when possible is useful.

OK - having said all that, it seems like if there's a single command that
we can check for, that, when present, implies the rest of the commands are
present, then... we can just check for that single file and not have to check
for all the other ones.  This is only true, IMHO, for commands that are all in the
same "package".  It wouldn't be obvious to test reviewers and possibly future
test maintainers when this was the case.
So the easiest thing is just to list all as dependencies all programs that
are 1) called by the test, 2) not installed by the test, and 3) not already required by fuego.

But, do you think we should change that policy to shorten these dependency lists?
(anyone else want to chime in?)

This is more of a general policy question than one about this particular test.
I'll accept this test as is, with this list of assert_has_programs.


> +}
> +
> +function test_deploy {
> +    put $TEST_HOME/net-snmp_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;\
> +    export remotehost=$IPADDR;\
> +    ./net-snmp_test.sh"
> +}
> +
> +function test_processing {
> +    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
> +}
> diff --git a/tests/Functional.net-snmp/net-snmp_test.sh
> b/tests/Functional.net-snmp/net-snmp_test.sh
> new file mode 100755
> index 0000000..95c34db
> --- /dev/null
> +++ b/tests/Functional.net-snmp/net-snmp_test.sh
> @@ -0,0 +1,7 @@
> +#!/bin/sh
> +. ./fuego_board_function_lib.sh
> +set_init_manager
> +
> +for i in tests/*.sh; do
> +    source $i
> +done
> diff --git a/tests/Functional.net-snmp/spec.json b/tests/Functional.net-
> snmp/spec.json
> new file mode 100644
> index 0000000..ad97ce9
> --- /dev/null
> +++ b/tests/Functional.net-snmp/spec.json
> @@ -0,0 +1,6 @@
> +{
> +    "testName": "Functional.net-snmp",
> +    "specs": {
> +        "default": {}
> +    }
> +}
> diff --git a/tests/Functional.net-snmp/test.yaml b/tests/Functional.net-
> snmp/test.yaml
> new file mode 100644
> index 0000000..35f19dd
> --- /dev/null
> +++ b/tests/Functional.net-snmp/test.yaml
> @@ -0,0 +1,23 @@
> +fuego_package_version: 1
> +name: Functional.net-snmp
> +description: |
> +      Simple Network Management Protocol (SNMP) is a widely used protocol
> for monitoring the health and welfare of network equipment (eg. routers),

This line should be wrapped.  I'll change that when I commit this.
Please keep test.yaml lines to less than 80 chars.

> +      computer equipment and even devices like UPSs.
> +      This is a simple test to check the service and SNMP-capable device.
> +license: BSD-3-Clause
> +author: Wang Mingyu <[email protected]>
> +maintainer: Wang Mingyu <[email protected]>
> +version: 1.00
> +fuego_release: 1
> +type: Functional
> +tags: ['net-snmp']
> +params:
> +    IPADDR:
> +        description: the IP address of your target board - Defined in board file
> +data_files:
> + - net-snmp_test.sh
> + - fuego_test.sh
> + - spec.json
> + - test.yaml
> + - data
> + - tests
> diff --git a/tests/Functional.net-snmp/tests/snmpd_ps.sh
> b/tests/Functional.net-snmp/tests/snmpd_ps.sh
> new file mode 100644
> index 0000000..3ffbfb2
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmpd_ps.sh
> @@ -0,0 +1,52 @@
> +#!/bin/sh
> +
> +#  In the target start snmpd, and confirm the process condition by command
> ps.
> +#  check the keyword "snmpd".
> +
> +test="snmpd_ps"
> +
> +snmpd_status=$(get_service_status snmpd)
> +
> +exec_service_on_target snmpd stop
> +
> +if exec_service_on_target snmpd start
> +then
> +    echo " -> start of snmpd succeeded."
> +else
> +    echo " -> start of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if ps aux | grep "[/]usr/sbin/snmpd"
> +then
> +    echo " -> get the pid of snmpd."
> +else
> +    echo " -> can't get the pid of snmpd."
> +    echo " -> $test: TEST-FAIL"
> +    if [ "$snmpd_status" = "inactive" ]
> +    then
> +        exec_service_on_target snmpd stop
> +    fi
> +    exit
> +fi
> +
> +if exec_service_on_target snmpd stop
> +then
> +    echo " -> stop of snmpd succeeded."
> +else
> +    echo " -> stop of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if ps aux | grep "[/]usr/sbin/snmpd"
> +then
> +    echo " -> $test: TEST-FAIL"
> +else
> +    echo " -> $test: TEST-PASS"
> +fi
> +if [ "$snmpd_status" = "active" -o "$snmpd_status" = "unknown" ]
> +then
> +    exec_service_on_target snmpd start
> +fi
> diff --git a/tests/Functional.net-snmp/tests/snmpd_snmpdf.sh
> b/tests/Functional.net-snmp/tests/snmpd_snmpdf.sh
> new file mode 100644
> index 0000000..49604f2
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmpd_snmpdf.sh
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +
> +#  In the target start service snmpd.
> +#  Run command snmpdf and check the keyword "Memory Buffers".
> +
> +test="snmpdf"
> +
> +snmpd_status=$(get_service_status snmpd)
> +
> +exec_service_on_target snmpd stop
> +
> +mv /etc/hosts /etc/hosts_bak
> +cp data/bind9/hosts /etc/hosts
> +mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf_bak
> +cp data/net-snmp/snmpd.conf /etc/snmp/snmpd.conf
> +
> +restore_target() {
> +    mv /etc/hosts_bak /etc/hosts
> +    mv /etc/snmp/snmpd.conf_bak /etc/snmp/snmpd.conf
> +}
> +
> +if exec_service_on_target snmpd start
> +then
> +    echo " -> start of snmpd succeeded."
> +else
> +    echo " -> start of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +if snmpdf -v1 -c RWIINCOM localhost | grep "Physical memory"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmpd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmpd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmpd_snmpget.sh
> b/tests/Functional.net-snmp/tests/snmpd_snmpget.sh
> new file mode 100644
> index 0000000..6ead310
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmpd_snmpget.sh
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +
> +#  In the target start snmpd.
> +# Check the keyword "Linux".
> +
> +test="snmpget"
> +
> +snmpd_status=$(get_service_status snmpd)
> +
> +exec_service_on_target snmpd stop
> +
> +mv /etc/hosts /etc/hosts_bak
> +cp data/bind9/hosts /etc/hosts
> +mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf_bak
> +cp data/net-snmp/snmpd.conf /etc/snmp/snmpd.conf
> +
> +restore_target() {
> +    mv /etc/hosts_bak /etc/hosts
> +    mv /etc/snmp/snmpd.conf_bak /etc/snmp/snmpd.conf
> +}
> +
> +if exec_service_on_target snmpd start
> +then
> +    echo " -> start of snmpd succeeded."
> +else
> +    echo " -> start of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +if snmpget -v1 -c RWIINCOM -M /usr/share/snmp/mibs localhost
> system.sysDescr.0 | grep "Linux"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmpd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmpd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmpd_snmpgetnext.sh
> b/tests/Functional.net-snmp/tests/snmpd_snmpgetnext.sh
> new file mode 100644
> index 0000000..81c8aae
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmpd_snmpgetnext.sh
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +
> +#  In the target start snmpd.
> +# Check the keyword "sysDescr".
> +
> +test="snmpgetnext"
> +
> +snmpd_status=$(get_service_status snmpd)
> +
> +exec_service_on_target snmpd stop
> +
> +mv /etc/hosts /etc/hosts_bak
> +cp data/bind9/hosts /etc/hosts
> +mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf_bak
> +cp data/net-snmp/snmpd.conf /etc/snmp/snmpd.conf
> +
> +restore_target() {
> +    mv /etc/hosts_bak /etc/hosts
> +    mv /etc/snmp/snmpd.conf_bak /etc/snmp/snmpd.conf
> +}
> +
> +if exec_service_on_target snmpd start
> +then
> +    echo " -> start of snmpd succeeded."
> +else
> +    echo " -> start of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +if snmpgetnext -v1 -c RWIINCOM -M /usr/share/snmp/mibs localhost
> system | grep "sysDescr"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmpd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmpd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmpd_snmpset.sh
> b/tests/Functional.net-snmp/tests/snmpd_snmpset.sh
> new file mode 100644
> index 0000000..fef07b9
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmpd_snmpset.sh
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +
> +#  In the target start snmpd.
> +# Check the keyword "INTEGER: 1".
> +
> +test="snmpset"
> +
> +snmpd_status=$(get_service_status snmpd)
> +
> +exec_service_on_target snmpd stop
> +
> +mv /etc/hosts /etc/hosts_bak
> +cp data/bind9/hosts /etc/hosts
> +mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf_bak
> +cp data/net-snmp/snmpd.conf /etc/snmp/snmpd.conf
> +
> +restore_target() {
> +    mv /etc/hosts_bak /etc/hosts
> +    mv /etc/snmp/snmpd.conf_bak /etc/snmp/snmpd.conf
> +}
> +
> +if exec_service_on_target snmpd start
> +then
> +    echo " -> start of snmpd succeeded."
> +else
> +    echo " -> start of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +if snmpset -v1 -c RWIINCOM -M /usr/share/snmp/mibs localhost
> versionUpdateConfig.0 i 1 | grep "INTEGER: 1"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmpd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmpd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmpd_snmptranslate.sh
> b/tests/Functional.net-snmp/tests/snmpd_snmptranslate.sh
> new file mode 100644
> index 0000000..f2f56cb
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmpd_snmptranslate.sh
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +
> +#  In the target start snmpd.
> +#  Translate MIB OID names between numeric and textual forms.
> +
> +test="snmptranslate"
> +
> +snmpd_status=$(get_service_status snmpd)
> +
> +exec_service_on_target snmpd stop
> +
> +mv /etc/hosts /etc/hosts_bak
> +cp data/bind9/hosts /etc/hosts
> +mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf_bak
> +cp data/net-snmp/snmpd.conf /etc/snmp/snmpd.conf
> +
> +restore_target() {
> +    mv /etc/hosts_bak /etc/hosts
> +    mv /etc/snmp/snmpd.conf_bak /etc/snmp/snmpd.conf
> +}
> +
> +if exec_service_on_target snmpd start
> +then
> +    echo " -> start of snmpd succeeded."
> +else
> +    echo " -> start of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +if snmptranslate -On -IR sysDescr
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmpd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmpd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmpd_snmpwalk.sh
> b/tests/Functional.net-snmp/tests/snmpd_snmpwalk.sh
> new file mode 100644
> index 0000000..be1c8b5
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmpd_snmpwalk.sh
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +
> +#  In the target start snmpd.
> +# Check the IP address of host.
> +
> +test="snmpwalk"
> +
> +snmpd_status=$(get_service_status snmpd)
> +
> +exec_service_on_target snmpd stop
> +
> +mv /etc/hosts /etc/hosts_bak
> +cp data/bind9/hosts /etc/hosts
> +mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf_bak
> +cp data/net-snmp/snmpd.conf /etc/snmp/snmpd.conf
> +
> +restore_target() {
> +    mv /etc/hosts_bak /etc/hosts
> +    mv /etc/snmp/snmpd.conf_bak /etc/snmp/snmpd.conf
> +}
> +
> +if exec_service_on_target snmpd start
> +then
> +    echo " -> start of snmpd succeeded."
> +else
> +    echo " -> start of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +if snmpwalk -v1 -c RWIINCOM -M /usr/share/snmp/mibs localhost ip | grep
> "$remotehost"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmpd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmpd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmpd_syslog.sh
> b/tests/Functional.net-snmp/tests/snmpd_syslog.sh
> new file mode 100644
> index 0000000..6d2c38a
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmpd_syslog.sh
> @@ -0,0 +1,55 @@
> +#!/bin/sh
> +
> +#  In the target start snmpd.
> +# Check the log of snmpd.
> +
> +test="snmpd_syslog"
> +
> +logger_service=$(detect_logger_service)
> +
> +snmpd_status=$(get_service_status snmpd)
> +snmpd_logfile=$(get_service_logfile)
> +
> +exec_service_on_target snmpd stop
> +exec_service_on_target $logger_service stop
> +
> +if [ -f $snmpd_logfile ]
> +then
> +    mv $snmpd_logfile $snmpd_logfile"_bak"
> +fi
> +
> +restore_target() {
> +    if [ -f $snmpd_logfile"_bak" ]
> +    then
> +        mv $snmpd_logfile"_bak" $snmpd_logfile
> +    fi
> +}
> +
> +exec_service_on_target $logger_service restart
> +
> +sleep 2
> +
> +if exec_service_on_target snmpd start
> +then
> +    echo " -> start of snmpd succeeded."
> +else
> +    echo " -> start of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +sleep 3
> +
> +if cat $snmpd_logfile | grep "snmpd"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmpd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmpd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmpd_syslog_ip.sh
> b/tests/Functional.net-snmp/tests/snmpd_syslog_ip.sh
> new file mode 100644
> index 0000000..0b9b7e6
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmpd_syslog_ip.sh
> @@ -0,0 +1,63 @@
> +#!/bin/sh
> +
> +#  In the target start snmpd.
> +# Check the log of IP address.
> +
> +test="snmpd_syslog_ip"
> +
> +logger_service=$(detect_logger_service)
> +
> +snmpd_status=$(get_service_status snmpd)
> +snmpd_logfile=$(get_service_logfile)
> +exec_service_on_target snmpd stop
> +exec_service_on_target $logger_service stop
> +
> +if [ -f $snmpd_logfile ]
> +then
> +    mv $snmpd_logfile $snmpd_logfile"_bak"
> +fi
> +
> +mv /etc/hosts /etc/hosts_bak
> +cp data/bind9/hosts /etc/hosts
> +mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf_bak
> +cp data/net-snmp/snmpd.conf /etc/snmp/snmpd.conf
> +
> +restore_target() {
> +    mv /etc/hosts_bak /etc/hosts
> +    mv /etc/snmp/snmpd.conf_bak /etc/snmp/snmpd.conf
> +    if [ -f $snmpd_logfile"_bak" ]
> +    then
> +        mv $snmpd_logfile"_bak" $snmpd_logfile
> +    fi
> +}
> +
> +exec_service_on_target $logger_service restart
> +
> +sleep 2
> +
> +if exec_service_on_target snmpd start
> +then
> +    echo " -> start of snmpd succeeded."
> +else
> +    echo " -> start of snmpd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +snmpget -v1 -c RWIINCOM -M /usr/share/snmp/mibs localhost
> system.sysDescr.0
> +
> +sleep 3
> +
> +if cat $snmpd_logfile | grep "127.0.0.1"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmpd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmpd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmptrapd_coldstart.sh
> b/tests/Functional.net-snmp/tests/snmptrapd_coldstart.sh
> new file mode 100644
> index 0000000..914bc06
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmptrapd_coldstart.sh
> @@ -0,0 +1,60 @@
> +#!/bin/sh
> +
> +#  In the target start snmptrapd, and check the syslog.
> +#  check the keyword "SNMPv2-MIB::coldStart".
> +
> +test="snmptrapd_coldstart.sh"
> +
> +snmptrapd_status=$(get_service_status snmptrapd)
> +snmptrapd_logfile=$(get_service_logfile)
> +logger_service=$(detect_logger_service)
> +
> +exec_service_on_target snmptrapd stop
> +exec_service_on_target $logger_service stop
> +
> +mv /etc/snmp/snmptrapd.conf /etc/snmp/snmptrapd.conf_bak
> +cp data/net-snmp/snmptrapd.conf /etc/snmp/snmptrapd.conf
> +
> +restore_target() {
> +    mv /etc/snmp/snmptrapd.conf_bak /etc/snmp/snmptrapd.conf
> +    if [ -f $snmptrapd_logfile"_bak" ]
> +    then
> +        mv $snmptrapd_logfile"_bak" $snmptrapd_logfile
> +    fi
> +}
> +
> +if [ -f $snmptrapd_logfile ]
> +then
> +    mv $snmptrapd_logfile $snmptrapd_logfile"_bak"
> +fi
> +
> +exec_service_on_target $logger_service restart
> +
> +sleep 2
> +
> +if exec_service_on_target snmptrapd start
> +then
> +    echo " -> start of snmptrapd succeeded."
> +else
> +    echo " -> start of snmptrapd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +snmptrap -v2c -c "" -M /usr/share/snmp/mibs localhost "" SNMPv2-
> MIB::coldStart
> +
> +sleep 3
> +
> +if cat $snmptrapd_logfile | grep "SNMPv2-MIB::coldStart"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmptrapd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmptrapd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmptrapd_ps.sh
> b/tests/Functional.net-snmp/tests/snmptrapd_ps.sh
> new file mode 100644
> index 0000000..f230f68
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmptrapd_ps.sh
> @@ -0,0 +1,53 @@
> +#!/bin/sh
> +
> +#  In the target start snmptrapd, and confirm the process condition by
> command ps.
> +#  check the keyword "snmptrapd".
> +
> +test="snmptrapd_ps"
> +
> +snmptrapd_status=$(get_service_status snmptrapd)
> +exec_service_on_target snmptrapd stop
> +
> +if exec_service_on_target snmptrapd start
> +then
> +    echo " -> start of snmptrapd succeeded."
> +else
> +    echo " -> start of snmptrapd failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if ps aux | grep "[/]usr/sbin/snmptrapd"
> +then
> +    echo " -> get the pid of snmptrapd."
> +else
> +    echo " -> can't get the pid of snmptrapd."
> +    echo " -> $test: TEST-FAIL"
> +
> +    if [ "$snmptrapd_status" = "inactive" ]
> +    then
> +        exec_service_on_target snmptrapd stop
> +    fi
> +    exit
> +fi
> +
> +if exec_service_on_target snmptrapd stop
> +then
> +    echo " -> stop of snmptrapd succeeded."
> +else
> +    echo " -> stop of snmptrapd failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if ps aux | grep "[/]usr/sbin/snmptrapd"
> +then
> +    echo " -> $test: TEST-FAIL"
> +else
> +    echo " -> $test: TEST-PASS"
> +fi
> +
> +if [ "$snmptrapd_status" = "active" -o "$snmptrapd_status" = "unknown" ]
> +then
> +    exec_service_on_target snmptrapd start
> +fi
> diff --git a/tests/Functional.net-snmp/tests/snmptrapd_syslog.sh
> b/tests/Functional.net-snmp/tests/snmptrapd_syslog.sh
> new file mode 100644
> index 0000000..8882416
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmptrapd_syslog.sh
> @@ -0,0 +1,54 @@
> +#!/bin/sh
> +
> +#  In the target start snmptrapd, and check if the $snmptrapd_logfile
> +#  check the keyword "snmptrapd".
> +
> +test="snmptrapd_syslog"
> +
> +logger_service=$(detect_logger_service)
> +
> +snmptrapd_status=$(get_service_status snmptrapd)
> +snmptrapd_logfile=$(get_service_logfile)
> +exec_service_on_target snmptrapd stop
> +exec_service_on_target $logger_service stop
> +
> +if [ -f $snmptrapd_logfile ]
> +then
> +    mv $snmptrapd_logfile $snmptrapd_logfile"_bak"
> +fi
> +
> +restore_target() {
> +    if [ -f $snmptrapd_logfile"_bak" ]
> +    then
> +        mv $snmptrapd_logfile"_bak" $snmptrapd_logfile
> +    fi
> +}
> +
> +exec_service_on_target $logger_service restart
> +
> +sleep 3
> +
> +if exec_service_on_target snmptrapd start
> +then
> +    echo " -> start of snmptrapd succeeded."
> +else
> +    echo " -> start of snmptrapd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +sleep 3
> +
> +if cat $snmptrapd_logfile | grep "snmptrapd"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmptrapd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmptrapd stop
> +fi
> +restore_target
> diff --git a/tests/Functional.net-snmp/tests/snmptrapd_warmstart.sh
> b/tests/Functional.net-snmp/tests/snmptrapd_warmstart.sh
> new file mode 100644
> index 0000000..1cc9ffe
> --- /dev/null
> +++ b/tests/Functional.net-snmp/tests/snmptrapd_warmstart.sh
> @@ -0,0 +1,61 @@
> +#!/bin/sh
> +
> +#  In the target start snmptrapd, and check the syslog.
> +#  check the keyword "SNMPv2-MIB::warmStart".
> +
> +test="snmptrapd_warmstart"
> +
> +snmptrapd_status=$(get_service_status snmptrapd)
> +snmptrapd_logfile=$(get_service_logfile)
> +logger_service=$(detect_logger_service)
> +
> +exec_service_on_target snmptrapd stop
> +exec_service_on_target $logger_service stop
> +
> +mv /etc/snmp/snmptrapd.conf /etc/snmp/snmptrapd.conf_bak
> +cp data/net-snmp/snmptrapd.conf /etc/snmp/snmptrapd.conf
> +
> +restore_target() {
> +    mv /etc/snmp/snmptrapd.conf_bak /etc/snmp/snmptrapd.conf
> +    if [ -f $snmptrapd_logfile"_bak" ]
> +    then
> +        mv $snmptrapd_logfile"_bak" $snmptrapd_logfile
> +    fi
> +}
> +
> +
> +if [ -f $snmptrapd_logfile ]
> +then
> +    mv $snmptrapd_logfile $snmptrapd_logfile"_bak"
> +fi
> +
> +exec_service_on_target $logger_service restart
> +
> +sleep 2
> +
> +if exec_service_on_target snmptrapd start
> +then
> +    echo " -> start of snmptrapd succeeded."
> +else
> +    echo " -> start of snmptrapd failed."
> +    echo " -> $test: TEST-FAIL"
> +    restore_target
> +    exit
> +fi
> +
> +snmptrap -v2c -c "" -M /usr/share/snmp/mibs localhost "" SNMPv2-
> MIB::warmStart
> +
> +sleep 3
> +
> +if cat $snmptrapd_logfile | grep "SNMPv2-MIB::warmStart"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ "$snmptrapd_status" = "inactive" ]
> +then
> +    exec_service_on_target snmptrapd stop
> +fi
> +restore_target
> --
> 2.17.1

This all looks good.  Thanks for the test.
I applied it with a few small changes as noted above.
 -- 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.