From e3857396c723a8f46c8aac5019657068b0afdf1d Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Wed, 8 Jun 2022 22:10:58 +0200 Subject: [PATCH] SNMP Test: some clixon mib table tests --- test/test_snmp_get.sh | 36 ++++++----- test/test_snmp_table.sh | 139 ---------------------------------------- 2 files changed, 20 insertions(+), 155 deletions(-) delete mode 100755 test/test_snmp_table.sh diff --git a/test/test_snmp_get.sh b/test/test_snmp_get.sh index 9066d6fd..165316b4 100755 --- a/test/test_snmp_get.sh +++ b/test/test_snmp_get.sh @@ -70,7 +70,7 @@ cat < $fstate - 1 + 42 Name1 Name2 @@ -142,12 +142,12 @@ OID11="${MIB}.1.11" # ifCounterDiscontinuityTime 1234567890 TimeStamp OID12="${MIB}.1.12" # ifStackStatus active(1) OID13="${MIB}.2.1" # netSnmpIETFWGTable OID14="${MIB}.2.1.1" # netSnmpIETFWGEntry -OID15="${MIB}.2.1.1.1" # nsIETFWGName -OID16="${MIB}.2.1.1.2" # nsIETFWGChair1 -OID17="${MIB}.2.1.1.3" # nsIETFWGChair2 +OID15="${MIB}.2.1.1.1.42" # nsIETFWGName +OID16="${MIB}.2.1.1.2.42" # nsIETFWGChair1 +OID17="${MIB}.2.1.1.3.42" # nsIETFWGChair2 OID18="${MIB}.2.2" # netSnmpHostsTable -OID19="${MIB}.2.2.1.1" # netSnmpHostName -OID20="${MIB}.2.2.1.2" # netSnmpHostAddressType +OID19="${MIB}.2.2.1.1.4.116.101.115.116" # netSnmpHostName +OID20="${MIB}.2.2.1.2.4.116.101.115.116" # netSnmpHostAddressType OID21="${MIB}.2.2.1.3" # netSnmpHostAddress OID22="${MIB}.2.2.1.4" # netSnmpHostStorage OID23="${MIB}.2.2.1.5" # netSnmpHostRowStatus @@ -251,19 +251,23 @@ validate_oid $NAME12 $NAME12 "INTEGER" 1 new "Get bulk OIDs" expectpart "$($snmpbulkget $OID1)" 0 "$OID2 = INTEGER: -1" "$OID3 = STRING: \"This is not default\"" "$OID4 = Timeticks: (12345) 0:02:03.45" "$OID5 = INTEGER: 48" "$OID6 = Gauge32: 123123123" "$OID7 = INTEGER: 3" "$OID8 = Counter32: 123456" "$OID9 = Counter64: 4294967296" "$OID10 = INTEGER: 1" "$OID11 = Timeticks: (1234567890) 142 days, 21:21:18.90" -if $snmp_debug; then - new "Test SNMP table netSnmpIETFWGTable" - expectpart "$($snmptable $OID13)" 0 "Name1" "Name2" +new "Test SNMP getnext netSnmpIETFWGTable" +expectpart "$($snmpgetnext $OID13)" 0 "$OID15 = INTEGER: 42" - new "Test SNMP getnext netSnmpIETFWGTable" - expectpart "$($snmpgetnext $OID13)" 0 "" +new "Test SNMP get nsIETFWGName" +expectpart "$($snmpget $OID15)" 0 "INTEGER: 42" - new "Test SNMP table netSnmpHostsTable" - expectpart "$($snmptable $OID18)" 0 "10.20.30.40" # Should verify all columns +new "Test SNMP getnext nsIETFWGName" +expectpart "$($snmpgetnext $OID15)" 0 "Hex-STRING: 4E 61 6D 65 31 00" - new "Test SNMP getnext netSnmpHostsTable $OID18" - expectpart "$($snmpgetnext $OID18)" 0 "" -fi +new "Test SNMP getnext netSnmpHostsTable" +expectpart "$($snmpgetnext $OID18)" 0 "$OID19 = Hex-STRING: 74 65 73 74 00" + +new "Test SNMP get netSnmpHostName" +expectpart "$($snmpget $OID19)" 0 "$OID19 = Hex-STRING: 74 65 73 74 00" + +new "Test SNMP getnext netSnmpHostName" +expectpart "$($snmpgetnext $OID19)" 0 "$OID20 = INTEGER: 1" new "Cleaning up" testexit diff --git a/test/test_snmp_table.sh b/test/test_snmp_table.sh deleted file mode 100755 index 14b912dc..00000000 --- a/test/test_snmp_table.sh +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env bash -# SNMP table snmpget / snmptable - -# Magic line must be first in script (see README.md) -s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi - -# Re-use main example backend state callbacks -APPNAME=example - -if [ ${ENABLE_NETSNMP} != "yes" ]; then - echo "Skipping test, Net-SNMP support not enabled." - if [ "$s" = $0 ]; then exit 0; else return 0; fi -fi - -snmpd=$(type -p snmpd) -snmpget="$(type -p snmpget) -On -c public -v2c localhost:161 " -snmpset="$(type -p snmpset) -On -c public -v2c localhost:161 " -snmptable="$(type -p snmptable) -c public -v2c localhost:161 " - -cfg=$dir/conf_startup.xml -fyang=$dir/clixon-example.yang -fstate=$dir/state.xml - -# AgentX unix socket -SOCK=/var/run/snmp.sock - -# OID -# .netSnmpExampleTables.netSnmpIETFWGTable -# NET-SNMP-EXAMPLES-MIB::netSnmpExamples -MIB=".1.3.6.1.4.1.8072.2" -OID="${MIB}.2.1" -OID_SET="${OID}.1.2.6.115.110.109.112.118.51" - -cat < $cfg - - $cfg - ${YANG_INSTALLDIR} - ${YANG_STANDARD_DIR} - ${MIB_GENERATED_YANG_DIR} - $fyang - $dir/$APPNAME.sock - /usr/local/lib/$APPNAME/backend - /var/tmp/$APPNAME.pidfile - $dir - unix:$SOCK - NET-SNMP-EXAMPLES-MIB - true - -EOF - -cat < $fyang -module clixon-example{ - yang-version 1.1; - namespace "urn:example:clixon"; - prefix ex; - import NET-SNMP-EXAMPLES-MIB { - prefix "net-snmp-examples"; - } -} -EOF - -# This is state data written to file that backend reads from (on request) -cat < $fstate - - - - snmpv3 - Russ Mundy - David Harrington - - - -EOF - -function testinit(){ - new "test params: -f $cfg -- -sS $fstate" - if [ $BE -ne 0 ]; then - # Kill old backend and start a new one - new "kill old backend" - sudo clixon_backend -zf $cfg - if [ $? -ne 0 ]; then - err "Failed to start backend" - fi - - sudo pkill -f clixon_backend - - new "Starting backend" - start_backend -s init -f $cfg -- -sS $fstate - fi - - new "wait backend" - wait_backend - - if [ $CS -ne 0 ]; then - # Kill old clixon_snmp, if any - new "Terminating any old clixon_snmp processes" - sudo killall -q clixon_snmp - - new "Starting clixon_snmp" - start_snmp $cfg & - fi - - new "wait snmp" - wait_snmp - - # XXX: It is necessary to run twice? (should be removed!) - $snmptable $OID -} - -function testexit() -{ - if [ $CS -ne 0 ]; then - stop_snmp - fi -} - -new "SNMP table tests" -testinit - -if false; then # NOT YET - new "Test SNMP table for netSnmpIETFWGTable" - expectpart "$($snmptable $OID)" 0 "SNMP table: NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable" "Russ Mundy" "David Harrington" - - - new "Set new value for one cell" - expectpart "$($snmpset $OID_SET s newstring)" 0 "$OID_SET = STRING: \"newstring\"" - - new "Test invalid type" - expectpart "$($snmpset $OID_SET u 1234)" 1 - - new "Test SNMP table for netSnmpIETFWGTable with new value" - expectpart "$($snmptable $OID)" 0 "newstring" -fi - -new "Cleaning up" -testexit - -new "endtest" -endtest