SNMP: Internal cache handling for rowstatus

Test: prefix SN=0 instead of CS=0 for override clixon_snmp start
This commit is contained in:
Olof hagsand 2022-07-11 09:28:45 +02:00
parent 5175cb8223
commit 49d19b263c
11 changed files with 554 additions and 336 deletions

File diff suppressed because it is too large Load diff

View file

@ -473,8 +473,8 @@ type_yang2asn1(yang_stmt *ys,
* *
* @param[in] snmpval Malloc:ed snmp type * @param[in] snmpval Malloc:ed snmp type
* @param[in] snmplen Length of snmp type * @param[in] snmplen Length of snmp type
* @param[in] reqinfo snmpd API struct for error * @param[in] reqinfo Agent transaction request structure
* @param[in] requests snmpd API struct for error * @param[in] request The netsnmp request info structure.
* @param[out] valstr Clixon/yang/xml string value, free after use) * @param[out] valstr Clixon/yang/xml string value, free after use)
* @retval 1 OK, and valstr set * @retval 1 OK, and valstr set
* @retval 0 Invalid value or type * @retval 0 Invalid value or type
@ -486,7 +486,7 @@ type_snmp2xml(yang_stmt *ys,
int *asn1type, int *asn1type,
netsnmp_variable_list *requestvb, netsnmp_variable_list *requestvb,
netsnmp_agent_request_info *reqinfo, netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests, netsnmp_request_info *request,
char **valstr) char **valstr)
{ {
int retval = -1; int retval = -1;
@ -494,7 +494,7 @@ type_snmp2xml(yang_stmt *ys,
enum cv_type cvtype; enum cv_type cvtype;
cg_var *cv = NULL; cg_var *cv = NULL;
char *restype = NULL; /* resolved type */ char *restype = NULL; /* resolved type */
char *origtype = NULL; /* original type */ char *origtype = NULL; /* original type */
yang_stmt *yrestype = NULL; yang_stmt *yrestype = NULL;
int ret; int ret;
@ -583,7 +583,7 @@ type_snmp2xml(yang_stmt *ys,
default: default:
assert(0); // XXX assert(0); // XXX
clicon_debug(1, "%s %s not supported", __FUNCTION__, cv_type2str(cvtype)); clicon_debug(1, "%s %s not supported", __FUNCTION__, cv_type2str(cvtype));
if ((ret = netsnmp_request_set_error(requests, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }

View file

@ -107,12 +107,16 @@ snmp_terminate(clicon_handle h)
{ {
yang_stmt *yspec; yang_stmt *yspec;
cvec *nsctx; cvec *nsctx;
cxobj *x; cxobj *x = NULL;
char *pidfile = clicon_snmp_pidfile(h); char *pidfile = clicon_snmp_pidfile(h);
snmp_shutdown(__FUNCTION__); snmp_shutdown(__FUNCTION__);
shutdown_agent(); shutdown_agent();
clixon_snmp_api_agent_cleanup(); clixon_snmp_api_agent_cleanup();
if (clicon_ptr_get(h, "snmp-rowstatus-tree", (void**)&x) == 0 && x){
xml_free(x);
x = NULL;
}
clicon_rpc_close_session(h); clicon_rpc_close_session(h);
if ((yspec = clicon_dbspec_yang(h)) != NULL) if ((yspec = clicon_dbspec_yang(h)) != NULL)
ys_free(yspec); ys_free(yspec);

View file

@ -67,6 +67,8 @@ You can prefix a test with `BE=0` if you want to run your own backend.
You can prefix a test with `RC=0` if you want to run your own restconf process. You can prefix a test with `RC=0` if you want to run your own restconf process.
You can prefix a test with `SN=0` if you want to run your own SNMP process (in combination with `BE=0`)
To run with debug flags, use the `DBG=<number>` environment variable. To run with debug flags, use the `DBG=<number>` environment variable.
Other variables include: Other variables include:

View file

@ -75,7 +75,7 @@ testname=
: ${RCLOG:=} : ${RCLOG:=}
# If set to 0, override starting of clixon_snmp in test (you bring your own) # If set to 0, override starting of clixon_snmp in test (you bring your own)
: ${CS:=1} : ${SN:=1}
# Namespace: netconf base # Namespace: netconf base
BASENS='urn:ietf:params:xml:ns:netconf:base:1.0' BASENS='urn:ietf:params:xml:ns:netconf:base:1.0'
@ -283,32 +283,6 @@ if $SNMPCHECK; then
expectpart "$($getnext $oid)" 0 "$result" expectpart "$($getnext $oid)" 0 "$result"
fi fi
} }
function validate_set(){
oid=$1
type=$2
value=$3
case $type in
"INTEGER")
set_type="i"
;;
"STRING")
set_type="s"
;;
"TIMETICKS")
set_type="t"
;;
esac
new "Setting value $value to OID $oid with type $set_type"
if [ $type == "STRING" ]; then
expectpart "$($snmpset $oid $set_type "$value")" 0 "$type: \"$value\""
else
expectpart "$($snmpset $oid $set_type "$value")" 0 "$type: $value"
fi
}
fi fi
# Check sanity between --with-restconf setting and if nginx is started by systemd or not # Check sanity between --with-restconf setting and if nginx is started by systemd or not

View file

@ -120,13 +120,13 @@ function testinit(){
new "wait backend" new "wait backend"
wait_backend wait_backend
if [ $CS -ne 0 ]; then if [ $SN -ne 0 ]; then
# Kill old clixon_snmp, if any # Kill old clixon_snmp, if any
new "Terminating any old clixon_snmp processes" new "Terminating any old clixon_snmp processes"
sudo killall -q clixon_snmp sudo killall -q clixon_snmp
new "Starting clixon_snmp" new "Starting clixon_snmp"
start_snmp $cfg & start_snmp $cfg &
fi fi
new "wait snmp" new "wait snmp"

View file

@ -116,7 +116,7 @@ function testinit(){
new "wait backend" new "wait backend"
wait_backend wait_backend
if [ $CS -ne 0 ]; then if [ $SN -ne 0 ]; then
# Kill old clixon_snmp, if any # Kill old clixon_snmp, if any
new "Terminating any old clixon_snmp processes" new "Terminating any old clixon_snmp processes"
sudo killall -q clixon_snmp sudo killall -q clixon_snmp

View file

@ -178,13 +178,13 @@ function testinit(){
new "wait backend" new "wait backend"
wait_backend wait_backend
if [ $CS -ne 0 ]; then if [ $SN -ne 0 ]; then
# Kill old clixon_snmp, if any # Kill old clixon_snmp, if any
new "Terminating any old clixon_snmp processes" new "Terminating any old clixon_snmp processes"
sudo killall -q clixon_snmp sudo killall -q clixon_snmp
new "Starting clixon_snmp" new "Starting clixon_snmp"
start_snmp $cfg & start_snmp $cfg &
fi fi
new "wait snmp" new "wait snmp"

View file

@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# SNMP table rowstatus tests # SNMP table rowstatus tests
#
# 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
@ -84,7 +83,7 @@ function testinit(){
new "wait backend" new "wait backend"
wait_backend wait_backend
if [ $CS -ne 0 ]; then if [ $SN -ne 0 ]; then
# Kill old clixon_snmp, if any # Kill old clixon_snmp, if any
new "Terminating any old clixon_snmp processes" new "Terminating any old clixon_snmp processes"
sudo killall -q clixon_snmp sudo killall -q clixon_snmp
@ -106,13 +105,19 @@ function testrun_createAndGo()
new "Set RowStatus to CreateAndGo and set tag" new "Set RowStatus to CreateAndGo and set tag"
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndGo SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndGo(4)" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndGo SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndGo(4)"
new "Rowstatus is active" new "Check rowstatus is active"
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: active(1)" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: active(1)"
new "Get tag" new "Get tag"
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2"
new "Get tag via netconf: candidate"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><SNMP-NOTIFICATION-MIB xmlns=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"><snmpNotifyTable><snmpNotifyEntry><snmpNotifyName>$index</snmpNotifyName><snmpNotifyTag>2</snmpNotifyTag></snmpNotifyEntry></snmpNotifyTable></SNMP-NOTIFICATION-MIB></data></rpc-reply>"
new "Get tag via netconf: running"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><running/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><SNMP-NOTIFICATION-MIB xmlns=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"><snmpNotifyTable><snmpNotifyEntry><snmpNotifyName>$index</snmpNotifyName><snmpNotifyTag>2</snmpNotifyTag></snmpNotifyEntry></snmpNotifyTable></SNMP-NOTIFICATION-MIB></data></rpc-reply>"
new "set storage type" new "set storage type"
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.\'$index\' = 1)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.'$index' = INTEGER: other(1)" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.\'$index\' = 1)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyStorageType.'$index' = INTEGER: other(1)"
} }
@ -130,6 +135,9 @@ function testrun_createAndWait()
new "Get tag" new "Get tag"
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2"
new "Get tag via netconf: candidate expect fail"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data/></rpc-reply>"
new "Get rowstatus" new "Get rowstatus"
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: notInService(2)" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: notInService(2)"
@ -162,8 +170,14 @@ function testrun_removeRows()
{ {
index=remove index=remove
new "Set rowstatus to createandgo" new "Set RowStatus to CreateAndGo and set tag"
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndGo)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index'" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndGo SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\' = 2)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: createAndGo(4)"
new "Get tag"
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: 2"
new "Get tag via netconf"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><SNMP-NOTIFICATION-MIB xmlns=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"><snmpNotifyTable><snmpNotifyEntry><snmpNotifyName>$index</snmpNotifyName><snmpNotifyTag>2</snmpNotifyTag></snmpNotifyEntry></snmpNotifyTable></SNMP-NOTIFICATION-MIB></data></rpc-reply>"
new "Set rowstatus to destroy" new "Set rowstatus to destroy"
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = destroy)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: destroy(6)" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = destroy)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = INTEGER: destroy(6)"
@ -171,6 +185,13 @@ function testrun_removeRows()
new "Get rowstatus" new "Get rowstatus"
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = No Such Instance currently exists at this OID" expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index' = No Such Instance currently exists at this OID"
# Default value is ""
new "Get tag"
expectpart "$($snmpget SNMP-NOTIFICATION-MIB::snmpNotifyTag.\'$index\')" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyTag.'$index' = STRING: " --not-- "= STRING: 2"
new "Get tag via netconf: candidate expect fail"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/sn:SNMP-NOTIFICATION-MIB/sn:snmpNotifyTable/sn:snmpNotifyEntry[sn:snmpNotifyName='$index']/sn:snmpNotifyTag\" xmlns:sn=\"urn:ietf:params:xml:ns:yang:smiv2:SNMP-NOTIFICATION-MIB\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data/></rpc-reply>"
new "Set rowstatus to createandwait" new "Set rowstatus to createandwait"
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndWait)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index'" expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndWait)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index'"

View file

@ -132,7 +132,7 @@ function testinit(){
new "wait backend" new "wait backend"
wait_backend wait_backend
if [ $CS -ne 0 ]; then if [ $SN -ne 0 ]; then
# Kill old clixon_snmp, if any # Kill old clixon_snmp, if any
new "Terminating any old clixon_snmp processes" new "Terminating any old clixon_snmp processes"
sudo killall -q clixon_snmp sudo killall -q clixon_snmp

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# SNMP "smoketest" Basic snmpget test for a scalar # SNMP system MIB test
# 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
@ -105,7 +105,7 @@ function testinit(){
new "wait backend" new "wait backend"
wait_backend wait_backend
if [ $CS -ne 0 ]; then if [ $SN -ne 0 ]; then
# Kill old clixon_snmp, if any # Kill old clixon_snmp, if any
new "Terminating any old clixon_snmp processes" new "Terminating any old clixon_snmp processes"
sudo killall -q clixon_snmp sudo killall -q clixon_snmp