#!/usr/bin/env bash # SNMP table rowstatus tests # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example # XXX skip for now if [ ${ENABLE_NETSNMP} != "yes" ]; then echo "Skipping test, Net-SNMP support not enabled." rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi snmpd=$(type -p snmpd) snmpget="$(type -p snmpget) -c public -v2c localhost " snmpset="$(type -p snmpset) -c public -v2c localhost " cfg=$dir/conf.xml fyang=$dir/clixon-example.yang # AgentX unix socket SOCK=/var/run/snmp.sock cat < $cfg $cfg ${YANG_INSTALLDIR} ${YANG_STANDARD_DIR} ${MIB_GENERATED_YANG_DIR} $fyang $dir/$APPNAME.sock /usr/local/var/run/$APPNAME.pidfile $dir unix:$SOCK SNMP-NOTIFICATION-MIB true ietf-netconf:startup $APPNAME /usr/local/lib/$APPNAME/cli /usr/local/lib/$APPNAME/clispec EOF cat < $fyang module clixon-example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; import SNMP-NOTIFICATION-MIB { prefix "snmp-notification"; } deviation "/snmp-notification:SNMP-NOTIFICATION-MIB" { deviate replace { config true; } } } EOF cat < $dir/startup_db <${DATASTORE_TOP}> EOF function testinit(){ new "test params: -s startup -f $cfg" 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 startup -f $cfg fi new "wait backend" wait_backend if [ $SN -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 } function testrun_createAndGo() { index=go new "Configuring a value without a row is a failure" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2 2>&1)" 2 "Reason: inconsistentValue" new "Set RowStatus to CreateAndGo and set tag" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndGo SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndGo(4)" new "Check rowstatus is active" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: active(1)" new "Get tag" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2" new "Get tag via netconf: candidate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$index2" new "Get tag via netconf: running" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$index2" new "set storage type" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.\'$index\' = 1)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.'$index' = INTEGER: other(1)" } function testrun_createAndWait() { index=wait new "Configuring a value without a row is a failure" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2 2>&1)" 2 "Reason: inconsistentValue" new "Set RowStatus to CreateAndWait and set tag" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndWait SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndWait(5)" new "Get tag" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2" new "Get tag via netconf: candidate expect fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Get rowstatus" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: notInService(2)" new "Set storagetype" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.\'$index\' = 1)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.'$index' = INTEGER: other(1)" new "Set rowstatus to active/ commit" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = active)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: active(1)" new "Set storagetype again" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.\'$index\' = 5)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.'$index' = INTEGER: readOnly(5)" new "Set rowstatus to createAndWait" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndWait)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndWait(5)" new "Set second rowstatus to createAndGo" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'${index}2\' = createAndGo)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'${index}2' = INTEGER: createAndGo(4)" new "Set third rowstatus to createAndWait" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'${index}3\' = createAndWait)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'${index}3' = INTEGER: createAndWait(5)" new "Set third rowstatus to active" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'${index}3\' = active)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'${index}3' = INTEGER: active(1)" new "Get rowstatus" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: notInService(2)" } function testrun_removeRows() { index=remove new "Set RowStatus to CreateAndGo and set tag" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndGo SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndGo(4)" new "Get tag" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2" new "Get tag via netconf" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$index2" new "Set rowstatus to destroy" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = destroy)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: destroy(6)" new "Get rowstatus" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = No Such Instance currently exists at this OID" # Default value is "" new "Get tag" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: " --not-- "= STRING: 2" new "Get tag via netconf: candidate expect fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Set rowstatus to createandwait" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndWait)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index'" new "Set rowstatus to destroy" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = destroy)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: destroy(6)" new "Get rowstatus" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = No Such Instance currently exists at this OID" } function testexit() { stop_snmp if [ $BE -ne 0 ]; then new "Kill backend" # Check if premature kill pid=$(pgrep -u root -f clixon_backend) if [ -z "$pid" ]; then err "backend already dead" fi # kill backend stop_backend -f $cfg fi } new "SNMP tests" testinit new "createAndGo" testrun_createAndGo new "createAndWait" testrun_createAndWait new "removeRows" testrun_removeRows new "Cleaning up" testexit rm -rf $dir new "endtest" endtest