SNMP frontend, main test for config false only, write test move to test_snmp_set.sh
This commit is contained in:
parent
f1db15c2ad
commit
0473303a4c
2 changed files with 130 additions and 11 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# SNMP "smoketest" Basic snmpget test for a scalar
|
||||||
|
|
||||||
# Magic line must be first in script (see README.md)
|
# Magic line must be first in script (see README.md)
|
||||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||||
|
|
||||||
APPNAME=snmp
|
APPNAME=example
|
||||||
|
|
||||||
if [ ${WITH_NETSNMP} != "yes" ]; then
|
if [ ${WITH_NETSNMP} != "yes" ]; then
|
||||||
echo "Skipping test, Net-SNMP support not enabled."
|
echo "Skipping test, Net-SNMP support not enabled."
|
||||||
|
|
@ -21,6 +22,8 @@ fstate=$dir/state.xml
|
||||||
# AgentX unix socket
|
# AgentX unix socket
|
||||||
SOCK=/var/run/snmp.sock
|
SOCK=/var/run/snmp.sock
|
||||||
|
|
||||||
|
# Relies on example_backend.so for $fstate file handling
|
||||||
|
|
||||||
cat <<EOF > $cfg
|
cat <<EOF > $cfg
|
||||||
<clixon-config xmlns="http://clicon.org/config">
|
<clixon-config xmlns="http://clicon.org/config">
|
||||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||||
|
|
@ -29,10 +32,12 @@ cat <<EOF > $cfg
|
||||||
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
||||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
<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_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||||
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
||||||
<CLICON_SNMP_MIB>NET-SNMP-EXAMPLES-MIB</CLICON_SNMP_MIB>
|
<CLICON_SNMP_MIB>NET-SNMP-EXAMPLES-MIB</CLICON_SNMP_MIB>
|
||||||
|
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -49,9 +54,11 @@ EOF
|
||||||
|
|
||||||
# This is state data written to file that backend reads from (on request)
|
# This is state data written to file that backend reads from (on request)
|
||||||
cat <<EOF > $fstate
|
cat <<EOF > $fstate
|
||||||
<sender-state xmlns="urn:example:example">
|
<NET-SNMP-EXAMPLES-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:NET-SNMP-EXAMPLES-MIB">
|
||||||
<ref>x</ref>
|
<netSnmpExampleScalars>
|
||||||
</sender-state>
|
<netSnmpExampleInteger>42</netSnmpExampleInteger>
|
||||||
|
</netSnmpExampleScalars>
|
||||||
|
</NET-SNMP-EXAMPLES-MIB>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
function testinit(){
|
function testinit(){
|
||||||
|
|
@ -98,15 +105,9 @@ testinit
|
||||||
MIB=".1.3.6.1.4.1.8072.2"
|
MIB=".1.3.6.1.4.1.8072.2"
|
||||||
OID="${MIB}.1.1" # netSnmpExampleInteger
|
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"
|
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"
|
new "Cleaning up"
|
||||||
testexit
|
testexit
|
||||||
|
|
||||||
|
|
|
||||||
118
test/test_snmp_set.sh
Executable file
118
test/test_snmp_set.sh
Executable file
|
|
@ -0,0 +1,118 @@
|
||||||
|
#!/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
|
||||||
|
echo "NYI"
|
||||||
|
if [ "$s" = $0 ]; then exit 0; else return 0; 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 <<EOF > $cfg
|
||||||
|
<clixon-config xmlns="http://clicon.org/config">
|
||||||
|
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||||
|
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
|
||||||
|
<CLICON_YANG_DIR>${YANG_STANDARD_DIR}</CLICON_YANG_DIR>
|
||||||
|
<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_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
|
||||||
|
|
||||||
|
cat <<EOF > $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 <<EOF > $fstate
|
||||||
|
<sender-state xmlns="urn:example:example">
|
||||||
|
<ref>x</ref>
|
||||||
|
</sender-state>
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue