Skip to contentSkip to conversation

net-snmp: Add test cases for Net-SNMP.

PATCH In review Wang Mingyu 2 participants 3 messages Oct 16, 2019 – Oct 18, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net-snmp: Add test cases for Net-SNMP.

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.

---
 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
scripts/fuego_board_function_lib.sh +13 -0
index 1b8699a..a6cd842 100644
@@ -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
+}
tests/Functional.net-snmp/data/bind9/hosts new file +3 -0
new file mode 100644
index 0000000..c7b9f21
@@ -0,0 +1,3 @@
+# /etc/hosts test
+#
+127.0.0.1	localhost.localdomain	localhost
tests/Functional.net-snmp/data/net-snmp/snmpd.conf new file +22 -0
new file mode 100644
index 0000000..01c40a2
@@ -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 
+access  RWACCESS       ""      any       noauth    exact  iin_all iin_all none
+access  ROACCESS       ""      any       noauth    exact  iin_all none    none
tests/Functional.net-snmp/data/net-snmp/snmptrapd.conf new file +1 -0
new file mode 100644
index 0000000..2570e96
@@ -0,0 +1 @@
+disableAuthorization yes
tests/Functional.net-snmp/fuego_test.sh new file +27 -0
new file mode 100644
index 0000000..b5f460c
@@ -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
+}
+
+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"
+}
tests/Functional.net-snmp/net-snmp_test.sh new file +7 -0
new file mode 100755
index 0000000..95c34db
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ./fuego_board_function_lib.sh
+set_init_manager
+
+for i in tests/*.sh; do
+    source $i
+done
tests/Functional.net-snmp/spec.json new file +6 -0
new file mode 100644
index 0000000..ad97ce9
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.net-snmp",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.net-snmp/test.yaml new file +23 -0
new file mode 100644
index 0000000..35f19dd
@@ -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),
+      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
tests/Functional.net-snmp/tests/snmpd_ps.sh new file +52 -0

52 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmpd_snmpdf.sh new file +43 -0

43 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmpd_snmpget.sh new file +43 -0

43 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmpd_snmpgetnext.sh new file +43 -0

43 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmpd_snmpset.sh new file +43 -0

43 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmpd_snmptranslate.sh new file +43 -0

43 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmpd_snmpwalk.sh new file +43 -0

43 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmpd_syslog.sh new file +55 -0

55 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmpd_syslog_ip.sh new file +63 -0

63 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmptrapd_coldstart.sh new file +60 -0

60 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmptrapd_ps.sh new file +53 -0

53 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmptrapd_syslog.sh new file +54 -0

54 lines not on this page · raw message

tests/Functional.net-snmp/tests/snmptrapd_warmstart.sh new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 Add function get_service_logfile.

Set the logfile of service according to the init system.

---
 scripts/fuego_board_function_lib.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)
scripts/fuego_board_function_lib.sh +13 -0
index 1b8699a..a6cd842 100644
@@ -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
+}
Signature · 1 line
2.17.1
#2 lore raw
In reply to Wang Mingyu
Quoted 71 lines

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

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

scripts/fuego_board_function_lib.sh +3 -0
index 1b8699a..a6cd842 100644
@@ -87,3 +87,16 @@ get_service_status() {
     fi
     echo $service_status
 }
+
+# get_service_logfile:
+#  get logfile of service

scripts/fuego_board_function_lib.sh get_service_status() { · line 102

Quoted 10 lines
scripts/fuego_board_function_lib.sh +10 -0
+# 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.

Quoted 27 lines
tests/Functional.net-snmp/data/bind9/hosts new file +3 -0
new file mode 100644
index 0000000..c7b9f21
@@ -0,0 +1,3 @@
+# /etc/hosts test
+#
+127.0.0.1	localhost.localdomain	localhost
tests/Functional.net-snmp/data/net-snmp/snmpd.conf new file +10 -0
new file mode 100644
index 0000000..01c40a2
@@ -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

tests/Functional.net-snmp/data/net-snmp/snmpd.conf line 20

Quoted 10 lines
tests/Functional.net-snmp/data/net-snmp/snmpd.conf new file +10 -0
+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.

tests/Functional.net-snmp/data/net-snmp/snmptrapd.conf line 1

Quoted 10 lines
tests/Functional.net-snmp/data/net-snmp/snmpd.conf new file +2 -0
+access  RWACCESS       ""      any       noauth    exact  iin_all iin_all none
+access  ROACCESS       ""      any       noauth    exact  iin_all none    none
tests/Functional.net-snmp/data/net-snmp/snmptrapd.conf new file +1 -0
new file mode 100644
index 0000000..2570e96
@@ -0,0 +1 @@
+disableAuthorization yes

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

Quoted 7 lines
tests/Functional.net- renamed from tests/Functional.net-snmp/fuego_test.sh +0 -0

snmp/fuego_test.sh
new file mode 100644
index 0000000..b5f460c

tests/Functional.net-snmp/fuego_test.sh line 9

Quoted 9 lines
tests/Functional.net-snmp/fuego_test.sh new file +9 -0
@@ -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.

Quoted 57 lines
tests/Functional.net-snmp/fuego_test.sh new file +5 -0
+}
+
+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

tests/Functional.net-snmp/fuego_test.sh new file +13 -0
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    export remotehost=$IPADDR;\
+    ./net-snmp_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.net-snmp/net-snmp_test.sh new file +7 -0
new file mode 100755
index 0000000..95c34db
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ./fuego_board_function_lib.sh
+set_init_manager
+
+for i in tests/*.sh; do
+    source $i
+done
tests/Functional.net- renamed from tests/Functional.net-snmp/spec.json +0 -0

snmp/spec.json
new file mode 100644
index 0000000..ad97ce9

tests/Functional.net-snmp/spec.json new file +6 -0
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.net-snmp",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.net- renamed from tests/Functional.net-snmp/test.yaml +0 -0

snmp/test.yaml
new file mode 100644
index 0000000..35f19dd

tests/Functional.net-snmp/test.yaml new file +4 -0
@@ -0,0 +1,23 @@
+fuego_package_version: 1
+name: Functional.net-snmp
+description: |
+      Simple Network Management Protocol (SNMP) is a widely used protocol
Quoted 1 line

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.

Quoted 776 lines
tests/Functional.net-snmp/test.yaml new file +19 -0
+      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
tests/Functional.net-snmp/tests/snmpd_ps.sh new file +3 -0
new file mode 100644
index 0000000..3ffbfb2
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+#  In the target start snmpd, and confirm the process condition by command

ps.

tests/Functional.net-snmp/tests/snmpd_ps.sh new file +49 -0
+#  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
tests/Functional.net-snmp/tests/snmpd_snmpdf.sh new file +43 -0
new file mode 100644
index 0000000..49604f2
@@ -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
tests/Functional.net-snmp/tests/snmpd_snmpget.sh new file +32 -0
new file mode 100644
index 0000000..6ead310
@@ -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"

tests/Functional.net-snmp/tests/snmpd_snmpget.sh new file +11 -0
+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
tests/Functional.net-snmp/tests/snmpd_snmpgetnext.sh new file +32 -0
new file mode 100644
index 0000000..81c8aae
@@ -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"

tests/Functional.net-snmp/tests/snmpd_snmpgetnext.sh new file +11 -0
+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
tests/Functional.net-snmp/tests/snmpd_snmpset.sh new file +32 -0
new file mode 100644
index 0000000..fef07b9
@@ -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"

tests/Functional.net-snmp/tests/snmpd_snmpset.sh new file +11 -0
+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
tests/Functional.net-snmp/tests/snmpd_snmptranslate.sh new file +43 -0
new file mode 100644
index 0000000..f2f56cb
@@ -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
tests/Functional.net-snmp/tests/snmpd_snmpwalk.sh new file +32 -0
new file mode 100644
index 0000000..be1c8b5
@@ -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"

tests/Functional.net-snmp/tests/snmpd_snmpwalk.sh new file +11 -0
+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
tests/Functional.net-snmp/tests/snmpd_syslog.sh new file +55 -0
new file mode 100644
index 0000000..6d2c38a
@@ -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
tests/Functional.net-snmp/tests/snmpd_syslog_ip.sh new file +48 -0
new file mode 100644
index 0000000..0b9b7e6
@@ -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

tests/Functional.net-snmp/tests/snmpd_syslog_ip.sh new file +15 -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
tests/Functional.net-snmp/tests/snmptrapd_coldstart.sh new file +45 -0
new file mode 100644
index 0000000..914bc06
@@ -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

tests/Functional.net-snmp/tests/snmptrapd_coldstart.sh new file +15 -0
+
+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
tests/Functional.net-snmp/tests/snmptrapd_ps.sh new file +3 -0
new file mode 100644
index 0000000..f230f68
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+#  In the target start snmptrapd, and confirm the process condition by

command ps.

tests/Functional.net-snmp/tests/snmptrapd_ps.sh new file +50 -0
+#  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
tests/Functional.net-snmp/tests/snmptrapd_syslog.sh new file +54 -0
new file mode 100644
index 0000000..8882416
@@ -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
tests/Functional.net-snmp/tests/snmptrapd_warmstart.sh new file +46 -0
new file mode 100644
index 0000000..1cc9ffe
@@ -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

tests/Functional.net-snmp/tests/snmptrapd_warmstart.sh new file +15 -1
+
+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
--
Quoted 1 line

2.17.1

This all looks good. Thanks for the test.
I applied it with a few small changes as noted above.
-- Tim