#!/usr/bin/env bash # snmpset. This requires deviation of MIB-YANG to make write operations # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=snmp # XXX skip for now if [ ${WITH_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 " snmpset="$(type -p snmpset) -On -c public -v2c localhost " cfg=$dir/conf_startup.xml fyang=$dir/clixon-example.yang fstate=$dir/state.xml # AgentX unix socket SOCK=/var/run/snmp.sock cat < $cfg $cfg ${YANG_INSTALLDIR} ${YANG_STANDARD_DIR} ${MIB_GENERATED_YANG_DIR} $fyang $dir/$APPNAME.sock /var/tmp/$APPNAME.pidfile $dir unix:$SOCK NET-SNMP-EXAMPLES-MIB 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"; } deviation "/net-snmp-examples:NET-SNMP-EXAMPLES-MIB" { deviate replace { config true; } } } EOF # This is state data written to file that backend reads from (on request) cat < $fstate x EOF function testinit(){ new "test params: -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 init -f $cfg 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 } function testexit(){ stop_snmp } new "SNMP tests" testinit # NET-SNMP-EXAMPLES-MIB::netSnmpExamples MIB=".1.3.6.1.4.1.8072.2" OID="${MIB}.1.1" # netSnmpExampleInteger new "Test SNMP get for default value" expectpart "$($snmpget $OID)" 0 "$OID = INTEGER: 42" new "Set new value to OID" expectpart "$($snmpset $OID i 1234)" 0 "$OID = INTEGER: 1234" new "Get new value" expectpart "$($snmpget $OID)" 0 "$OID = INTEGER: 1234" new "Cleaning up" testexit new "endtest" endtest