Commit 528f92bc authored by Adam Wujek's avatar Adam Wujek 💬

test/snmp: add tests for SNMP

Tests use bats (https://github.com/sstephenson/bats) for testing.
Clone bat's repo, checkout commit 03608115

To test invoke "make TARGET_IP=x.x.x.x"
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 4e8f90f6
bats
snmp_test_config.bash
ifndef TARGET_IP
$(error TARGET_IP is not set)
endif
all: test
prepare: bats/libexec/bats
bats/libexec/bats:
@echo "bats not installed!"
@echo "Please perform the following commands:"
@echo "git clone https://github.com/sstephenson/bats"
# be sure which version we use
@echo "cd bats; git checkout 03608115"
@exit 1
test: prepare
bats/libexec/bats snmp_tests_*.bats
SNMP_OPTIONS_NO_M="-On -c public -v 2c "
# be sure you have run download-mibs to download MIBs
SNMP_OPTIONS="$SNMP_OPTIONS_NO_M -m WR-WRPC-MIB -M +/var/lib/mibs/ietf:../../lib"
TOTAL_NUM_OIDS_EXPECT_TEXT="4 temperature sensors, 4 entries in the SFPs database"
# number of OIDs expected
TOTAL_NUM_OIDS=68
helper_snmpget() {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP $1 | grep "$2" | wc -l)"
[ "$result" -eq 1 ]
}
helper_snmpget_oidnotfound() {
run snmpget $SNMP_OPTIONS $TARGET_IP $1
[ "$status" -eq 2 ]
}
helper_snmpget_oidfound() {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP $1 | grep "$1" | wc -l)"
[ "$result" -eq 1 ]
}
helper_snmpgetnext() {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP $1 | grep "$2" | wc -l)"
[ "$result" -eq 1 ]
}
helper_snmpset() {
result="$(snmpset $SNMP_OPTIONS $TARGET_IP $1 = "$2" | grep "$2" | wc -l)"
[ "$result" -eq 1 ]
}
helper_erase_sfp_database() {
result="$(snmpset $SNMP_OPTIONS $TARGET_IP wrpcPtpConfigApply.0 = eraseFlash | grep applySuccessful | wc -l)"
[ "$result" -eq 1 ]
}
load snmp_test_config
@test "Host up $TARGET_IP" {
if [ x"$TARGET_IP" = "x" ]; then
echo "no TARGET_IP set"
fi
# to know if out target system is up
run ping -c 1 $TARGET_IP -W 2
[ "$status" -eq 0 ]
}
@test "Check the presence of snmpget" {
# to know if we have snmpget available
run command -v snmpget
[ "$status" -eq 0 ]
}
@test "Check the presence of snmpgetnext" {
# to know if we have snmpgetnext available
run command -v snmpgetnext
[ "$status" -eq 0 ]
}
@test "Check the presence of snmpwalk" {
# to know if we have snmpwalk available
run command -v snmpwalk
[ "$status" -eq 0 ]
}
@test "Check the presence of snmpset" {
# to know if we have snmpset available
run command -v snmpset
[ "$status" -eq 0 ]
}
load snmp_test_config
load snmp_test_helpers
@test "snmpget existing oid 1.3.6.1.4.1.96.101.1.1.1.0" {
helper_snmpget 1.3.6.1.4.1.96.101.1.1.1.0 1.3.6.1.4.1.96.101.1.1.1.0
}
@test "snmpget existing oid 1.3.6.1.4.1.96.101.1.1.2.0" {
helper_snmpget 1.3.6.1.4.1.96.101.1.1.2.0 1.3.6.1.4.1.96.101.1.1.2.0
[ "$result" -eq 1 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96.101.1.1.2" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.2 | grep 1.3.6.1.4.1.96.101.1.1.2 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96.101.1.1" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1 | grep 1.3.6.1.4.1.96.101.1.1 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96.101.1" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1 | grep 1.3.6.1.4.1.96.101.1 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96.101" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1 | grep 1.3.6.1.4.1.96.101.1 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96 | grep 1.3.6.1.4.1.96 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1 | grep 1.3.6.1.4.1 | wc -l)"
[ "$result" -eq 0 ]
}
load snmp_test_config
@test "Get next object after 1.3.6.1.4.1.96.101.1.1.3.0, check if other returned" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.3.0 | grep 1.3.6.1.4.1.96.101.1.1.3.0 | wc -l)"
[ "$result" -eq 0 ]
}
@test "Get next object after 1.3.6.1.4.1.96.101.1.1.3.0, check if correct returned" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.3.0 | grep 1.3.6.1.4.1.96.101.1.1.4.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after 1.3.6.1.4.1.95 (first object)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.95 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after the last object (getnext 1.3.6.1.4.1.97)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.97 | wc -l)"
[ "$result" -eq 0 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96 (oid too short)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.0 (oid too short with 0 at the end)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.0 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101 (oid too short)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1 (oid too short)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1 (oid too short)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1 (missing 0 at the end)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.2 (missing 0 at the end)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.2 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1.0 (jump to the next oid in the branch)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1.0 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1.1 (too deep in the branch)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1.1 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1.1.1 (too deep in the branch)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1.1.1 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1.1.1.0 (too deep in the branch)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1.1.1.0 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
This diff is collapsed.
load snmp_test_config
load snmp_test_helpers
@test "Get wrpcTemperatureTable" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3
}
@test "Get wrpcTemperatureTable.0" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.0
}
@test "Get wrpcTemperatureTable.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1
}
@test "Get wrpcTemperatureTable.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.1
}
@test "Get wrpcTemperatureTable.1.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.1.1
}
@test "Get wrpcTemperatureTable.1.1.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.1.1.1
}
@test "Get wrpcTemperatureTable.1.2" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.2
}
@test "Get wrpcTemperatureTable.1.2.1" {
helper_snmpget_oidfound .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get wrpcTemperatureTable.1.2.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.2.1.1
}
@test "Get wrpcTemperatureTable.1.2.1.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.2.1.1.1
}
@test "Get wrpcTemperatureTable.1.3" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.3
}
@test "Get wrpcTemperatureTable.1.3.1" {
helper_snmpget_oidfound .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get wrpcTemperatureTable.1.3.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.3.1.1
}
@test "Get wrpcTemperatureTable.1.3.1.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.3.1.1.1
}
@test "Get next wrpcTemperatureTable" {
helper_snmpgetnext wrpcTemperatureTable .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.0" {
helper_snmpgetnext wrpcTemperatureTable.0 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1" {
helper_snmpgetnext wrpcTemperatureTable.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.1.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.1.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.1.1.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.1.1.2" {
helper_snmpgetnext wrpcTemperatureTable.1.1.1.1.2 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.2" {
helper_snmpgetnext wrpcTemperatureTable.1.1.2 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.2" {
helper_snmpgetnext wrpcTemperatureTable.1.2 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.2.0" {
helper_snmpgetnext wrpcTemperatureTable.1.2.0 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.2.1" {
helper_snmpgetnext wrpcTemperatureTable.1.2.1 .1.3.6.1.4.1.96.101.1.3.1.2.2
}
@test "Get next wrpcTemperatureTable.1.2.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.2.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.2
}
@test "Get next wrpcTemperatureTable.1.2.2" {
helper_snmpgetnext wrpcTemperatureTable.1.2.2 .1.3.6.1.4.1.96.101.1.3.1.2.3
}
@test "Get next wrpcTemperatureTable.1.2.3" {
helper_snmpgetnext wrpcTemperatureTable.1.2.3 .1.3.6.1.4.1.96.101.1.3.1.2.4
}
@test "Get next wrpcTemperatureTable.1.2.4" {
helper_snmpgetnext wrpcTemperatureTable.1.2.4 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.2.5" {
helper_snmpgetnext wrpcTemperatureTable.1.2.5 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.3" {
helper_snmpgetnext wrpcTemperatureTable.1.3 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.3.0" {
helper_snmpgetnext wrpcTemperatureTable.1.3.0 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.3.0.0" {
helper_snmpgetnext wrpcTemperatureTable.1.3.0.0 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.3.1" {
helper_snmpgetnext wrpcTemperatureTable.1.3.1 .1.3.6.1.4.1.96.101.1.3.1.3.2
}
@test "Get next wrpcTemperatureTable.1.3.2" {
helper_snmpgetnext wrpcTemperatureTable.1.3.2 .1.3.6.1.4.1.96.101.1.3.1.3.3
}
@test "Get next wrpcTemperatureTable.1.3.3" {
helper_snmpgetnext wrpcTemperatureTable.1.3.3 .1.3.6.1.4.1.96.101.1.3.1.3.4
}
@test "Get next wrpcTemperatureTable.1.3.4" {
helper_snmpgetnext wrpcTemperatureTable.1.3.4 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.3.4.0" {
helper_snmpgetnext wrpcTemperatureTable.1.3.4.0 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.3.4.1" {
helper_snmpgetnext wrpcTemperatureTable.1.3.4.1 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.3.4.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.3.4.1.1 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.3.5" {
helper_snmpgetnext wrpcTemperatureTable.1.3.5 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.4" {
helper_snmpgetnext wrpcTemperatureTable.1.4 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.4.0" {
helper_snmpgetnext wrpcTemperatureTable.1.4.0 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.4.1" {
helper_snmpgetnext wrpcTemperatureTable.1.4.1 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.2" {
helper_snmpgetnext wrpcTemperatureTable.2 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.2.0" {
helper_snmpgetnext wrpcTemperatureTable.2.0 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "set read only wrpcTemperatureTable.1.2.1" {
run snmpset $SNMP_OPTIONS $TARGET_IP wrpcTemperatureTable.1.2.1 = 141415
[ "$status" -eq 2 ]
}
load snmp_test_config
@test "snmpwalk 1.3.6.1.4.1.96.101.1.1" {
result="$(snmpwalk $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1 | wc -l)"
[ "$result" -eq 4 ]
}
@test "snmpwalk 1.3.6.1.4.1.95" {
result="$(snmpwalk $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.95 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpwalk 1.3.6 count all OIDs" {
result="$(snmpwalk $SNMP_OPTIONS $TARGET_IP 1.3.6 | wc -l)"
if [ "$result" -ne $TOTAL_NUM_OIDS ]; then
echo "Wrong number of OIDs! We expect $TOTAL_NUM_OIDS, while got $result"
echo "Please check WRPC's configuration. We expect to be in the WRPC:"
echo $TOTAL_NUM_OIDS_EXPECT_TEXT
false
fi
}
#
# Automatically generated make config: don't edit
#
# CONFIG_WR_SWITCH is not set
CONFIG_WR_NODE=y
CONFIG_PRINT_BUFSIZE=128
CONFIG_PRINTF_XINT=y
CONFIG_RAMSIZE=131072
CONFIG_TEMP_POLL_INTERVAL=15
# CONFIG_PLL_VERBOSE is not set
# CONFIG_PFILTER_VERBOSE is not set
# CONFIG_WRC_VERBOSE is not set
# CONFIG_VLAN is not set
CONFIG_VLAN_NR=0
CONFIG_VLAN_1_FOR_CLASS7=0
CONFIG_VLAN_2_FOR_CLASS7=0
CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_LM32=y
CONFIG_EMBEDDED_NODE=y
# CONFIG_WR_NODE_PCS16 is not set
CONFIG_STACKSIZE=2048
CONFIG_PPSI=y
CONFIG_UART=y
CONFIG_W1=y
CONFIG_IP=y
CONFIG_CMD_CONFIG=y
CONFIG_SYSLOG=y
CONFIG_SNMP=y
CONFIG_SNMP_SET=y
CONFIG_SNMP_HW_TYPE="spec"
CONFIG_BUILD_INIT=y
CONFIG_INIT_COMMAND="ptp stop"
CONFIG_HAS_BUILD_INIT=1
CONFIG_HAS_FLASH_INIT=1
CONFIG_FLASH_INIT=y
#
# wrpc-sw is tainted if you change the following options
#
CONFIG_DEVELOPER=y
CONFIG_TEMP_HIGH_THRESHOLD=70
CONFIG_TEMP_HIGH_RAPPEL=60
# CONFIG_CMD_LL is not set
# CONFIG_CHECK_RESET is not set
# CONFIG_SPLL_FIFO_LOG is not set
# CONFIG_PRINTF_FULL is not set
# CONFIG_PRINTF_MINI is not set
# CONFIG_PRINTF_NONE is not set
# CONFIG_DETERMINISTIC_BINARY is not set
# CONFIG_UART_SW is not set
# CONFIG_NET_VERBOSE is not set
# CONFIG_SNMP_VERBOSE is not set
CONFIG_FAKE_TEMPERATURES=y
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
CONFIG_VLAN_ARRAY_SIZE=1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment