SNMP frontend, main test for config false only, write test move to test_snmp_set.sh

This commit is contained in:
Olof hagsand 2022-05-07 14:36:14 +02:00
parent 182b72a4cc
commit 3bb681ffe2
2 changed files with 130 additions and 11 deletions

View file

@ -1,9 +1,10 @@
#!/usr/bin/env bash
# SNMP "smoketest" Basic snmpget test for a scalar
# 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
APPNAME=example
if [ ${WITH_NETSNMP} != "yes" ]; then
echo "Skipping test, Net-SNMP support not enabled."
@ -21,6 +22,8 @@ fstate=$dir/state.xml
# AgentX unix socket
SOCK=/var/run/snmp.sock
# Relies on example_backend.so for $fstate file handling
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
@ -29,10 +32,12 @@ cat <<EOF > $cfg
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
<CLICON_SNMP_MIB>NET-SNMP-EXAMPLES-MIB</CLICON_SNMP_MIB>
</clixon-config>
EOF
@ -49,9 +54,11 @@ EOF
# This is state data written to file that backend reads from (on request)
cat <<EOF > $fstate
<sender-state xmlns="urn:example:example">
<ref>x</ref>
</sender-state>
<NET-SNMP-EXAMPLES-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:NET-SNMP-EXAMPLES-MIB">
<netSnmpExampleScalars>
<netSnmpExampleInteger>42</netSnmpExampleInteger>
</netSnmpExampleScalars>
</NET-SNMP-EXAMPLES-MIB>
EOF
function testinit(){
@ -98,15 +105,9 @@ testinit
MIB=".1.3.6.1.4.1.8072.2"
OID="${MIB}.1.1" # netSnmpExampleInteger
new "Test SNMP get for default value"
new "Test SNMP get for value in state file"
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