From c366962054d6ba238f41f40005ec843c7cc13fdb Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 17 May 2022 20:23:15 +0200 Subject: [PATCH] SNMP frontend: changed default mibyang dir to /share/mib-yangs to be same as repo Test: new prel test_snmp_ifmib.sh --- configure | 4 +- configure.ac | 4 +- test/test_snmp.sh | 4 +- test/test_snmp_ifmib.sh | 120 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 6 deletions(-) create mode 100755 test/test_snmp_ifmib.sh diff --git a/configure b/configure index e2768846..4db41f9c 100755 --- a/configure +++ b/configure @@ -1391,7 +1391,7 @@ Optional Packages: --without-restconf Disable restconf altogether --with-mib-generated-yang-dir=DIR Directory of generated YANG specs (default: - $prefix/share/mibyang) + $prefix/share/mib-yangs) --with-configfile=FILE Set default path to config file --with-libxml2 Use gnome/libxml2 regex engine --without-sigaction Don't use sigaction @@ -5447,7 +5447,7 @@ done if test "${with_mib_generated_yang_dir+set}" = set; then : withval=$with_mib_generated_yang_dir; MIB_GENERATED_YANG_DIR="$withval" else - MIB_GENERATED_YANG_DIR="${prefix}/share/mibyang" + MIB_GENERATED_YANG_DIR="${prefix}/share/mib-yangs" fi diff --git a/configure.ac b/configure.ac index eebe76ae..ef623c50 100644 --- a/configure.ac +++ b/configure.ac @@ -302,9 +302,9 @@ if test "$enable_netsnmp" = "yes"; then # However, it is required by SNMP tests. # To generate: for i in /usr/share/snmp/mibs/*; do smidump -f yang $i > `basename -s .txt $i`.yang; done AC_ARG_WITH(mib-generated-yang-dir, - [AS_HELP_STRING([--with-mib-generated-yang-dir=DIR],[Directory of generated YANG specs (default: $prefix/share/mibyang)])], + [AS_HELP_STRING([--with-mib-generated-yang-dir=DIR],[Directory of generated YANG specs (default: $prefix/share/mib-yangs)])], [MIB_GENERATED_YANG_DIR="$withval"], - [MIB_GENERATED_YANG_DIR="${prefix}/share/mibyang"] + [MIB_GENERATED_YANG_DIR="${prefix}/share/mib-yangs"] ) AC_MSG_RESULT(Generated YANGs from MIB files are expected to be in ${MIB_GENERATED_YANG_DIR}) fi diff --git a/test/test_snmp.sh b/test/test_snmp.sh index 75f4b7da..e961d11f 100755 --- a/test/test_snmp.sh +++ b/test/test_snmp.sh @@ -126,8 +126,8 @@ expectpart "$($snmpgetnext $OID2)" 0 "$OID3 = STRING: This is not default" new "Test SNMP get string" expectpart "$($snmpget $OID3)" 0 "$OID3 = STRING: This is not default" --not-- "fish" -new "Test SNMP getnext string (expect heartbeat / no such object?)" -expectpart "$($snmpgetnext $OID3)" 0 "$OID3 = No more variables" # XXX this is a notification? +new "Test SNMP getnext string" +expectpart "$($snmpgetnext $OID3)" 0 "" # "$OID3 = No more variables" Can be any object new "Cleaning up" testexit diff --git a/test/test_snmp_ifmib.sh b/test/test_snmp_ifmib.sh new file mode 100755 index 00000000..37e58359 --- /dev/null +++ b/test/test_snmp_ifmib.sh @@ -0,0 +1,120 @@ +#!/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 + +# Re-use main example backend state callbacks +APPNAME=example + +if [ ${ENABLE_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 " +snmpgetnext="$(type -p snmpgetnext) -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 + +# Relies on example_backend.so for $fstate file handling + +cat < $cfg + + $cfg + ${YANG_INSTALLDIR} + ${YANG_STANDARD_DIR} + ${MIB_GENERATED_YANG_DIR} + $fyang + $dir/$APPNAME.sock + /usr/local/lib/$APPNAME/backend + /var/tmp/$APPNAME.pidfile + $dir + unix:$SOCK + IF-MIB + +EOF + +cat < $fyang +module clixon-example{ + yang-version 1.1; + namespace "urn:example:clixon"; + prefix ex; + import IF-MIB { + prefix "if-mib"; + } +} +EOF + +# This is state data written to file that backend reads from (on request) +# integer and string have values, sleeper does not and uses default (=1) +cat < $fstate + + + 42 + + This is not default + + +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 + +# IF-MIB::interfaces +MIB=".1.3.6.1.2.1" +OID1="${MIB}.2.1.0" # XXX interfaces +OID2="${MIB}.31" # ifMIB + +new "$snmpget" + +new "Test SNMP get int" +expectpart "$($snmpget $OID1)" 0 "$OID1 = INTEGER: 8" + +new "Cleaning up" +testexit + +new "endtest" +endtest