SNMP frontend generic code for tables and clixon backend

Added snmp-msg translation table
Changed test-table to only GET
This commit is contained in:
Olof hagsand 2022-05-15 13:42:28 +02:00
parent 8a208693ba
commit 38d91a1305
5 changed files with 279 additions and 105 deletions

View file

@ -1,11 +1,11 @@
#!/usr/bin/env bash
# Use NET-SNMP-EXAMPLES-MIB
# with OID: .iso.org.dod.internet.private.enterprises.netSnmp.netSnmpExamples (.1.3.6.1.4.1.8072.2)
# 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
APPNAME=snmp
# Re-use main example backend state callbacks
APPNAME=example
if [ ${ENABLE_NETSNMP} != "yes" ]; then
echo "Skipping test, Net-SNMP support not enabled."
@ -19,6 +19,7 @@ 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
@ -38,6 +39,7 @@ 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>
@ -56,12 +58,25 @@ module clixon-example{
}
EOF
# This is state data written to file that backend reads from (on request)
cat <<EOF > $fstate
<NET-SNMP-EXAMPLES-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:NET-SNMP-EXAMPLES-MIB">
<netSnmpIETFWGTable>
<netSnmpIETFWGEntry>
<nsIETFWGName>snmpv3</nsIETFWGName>
<nsIETFWGChair1>Russ Mundy</nsIETFWGChair1>
<nsIETFWGChair2>David Harrington</nsIETFWGChair2>
</netSnmpIETFWGEntry>
</netSnmpIETFWGTable>
</NET-SNMP-EXAMPLES-MIB>
EOF
function testinit(){
new "test params: -f $cfg"
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
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
err "Failed to start backend"
fi
@ -69,7 +84,7 @@ function testinit(){
sudo pkill -f clixon_backend
new "Starting backend"
start_backend -s init -f $cfg
start_backend -s init -f $cfg -- -sS $fstate
fi
new "wait backend"
@ -87,8 +102,8 @@ function testinit(){
new "wait snmp"
wait_snmp
# XXX: This should be remoeved!
$($snmptable $OID)
# XXX: It is necessary to run twice? (should be removed!)
$snmptable $OID
}
function testexit()
@ -102,16 +117,18 @@ new "SNMP table tests"
testinit
new "Test SNMP table for netSnmpIETFWGTable"
expectpart "$($snmptable $OID)" 0 "SNMP table: NET-SNMP-EXAMPLES-MIB::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\""
if false; then # NOT YET
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 invalid type"
expectpart "$($snmpset $OID_SET u 1234)" 1
new "Test SNMP table for netSnmpIETFWGTable with new value"
expectpart "$($snmptable $OID)" 0 "newstring"
new "Test SNMP table for netSnmpIETFWGTable with new value"
expectpart "$($snmptable $OID)" 0 "newstring"
fi
new "Cleaning up"
testexit