SNMP: Internal cache handling for rowstatus
Test: prefix SN=0 instead of CS=0 for override clixon_snmp start
This commit is contained in:
parent
5175cb8223
commit
49d19b263c
11 changed files with 554 additions and 336 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -473,8 +473,8 @@ type_yang2asn1(yang_stmt *ys,
|
|||
*
|
||||
* @param[in] snmpval Malloc:ed snmp type
|
||||
* @param[in] snmplen Length of snmp type
|
||||
* @param[in] reqinfo snmpd API struct for error
|
||||
* @param[in] requests snmpd API struct for error
|
||||
* @param[in] reqinfo Agent transaction request structure
|
||||
* @param[in] request The netsnmp request info structure.
|
||||
* @param[out] valstr Clixon/yang/xml string value, free after use)
|
||||
* @retval 1 OK, and valstr set
|
||||
* @retval 0 Invalid value or type
|
||||
|
|
@ -486,7 +486,7 @@ type_snmp2xml(yang_stmt *ys,
|
|||
int *asn1type,
|
||||
netsnmp_variable_list *requestvb,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests,
|
||||
netsnmp_request_info *request,
|
||||
char **valstr)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -494,7 +494,7 @@ type_snmp2xml(yang_stmt *ys,
|
|||
enum cv_type cvtype;
|
||||
cg_var *cv = NULL;
|
||||
char *restype = NULL; /* resolved type */
|
||||
char *origtype = NULL; /* original type */
|
||||
char *origtype = NULL; /* original type */
|
||||
yang_stmt *yrestype = NULL;
|
||||
int ret;
|
||||
|
||||
|
|
@ -583,7 +583,7 @@ type_snmp2xml(yang_stmt *ys,
|
|||
default:
|
||||
assert(0); // XXX
|
||||
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");
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,12 +107,16 @@ snmp_terminate(clicon_handle h)
|
|||
{
|
||||
yang_stmt *yspec;
|
||||
cvec *nsctx;
|
||||
cxobj *x;
|
||||
cxobj *x = NULL;
|
||||
char *pidfile = clicon_snmp_pidfile(h);
|
||||
|
||||
snmp_shutdown(__FUNCTION__);
|
||||
shutdown_agent();
|
||||
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);
|
||||
if ((yspec = clicon_dbspec_yang(h)) != NULL)
|
||||
ys_free(yspec);
|
||||
|
|
|
|||
|
|
@ -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 `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.
|
||||
|
||||
Other variables include:
|
||||
|
|
|
|||
28
test/lib.sh
28
test/lib.sh
|
|
@ -75,7 +75,7 @@ testname=
|
|||
: ${RCLOG:=}
|
||||
|
||||
# If set to 0, override starting of clixon_snmp in test (you bring your own)
|
||||
: ${CS:=1}
|
||||
: ${SN:=1}
|
||||
|
||||
# Namespace: netconf base
|
||||
BASENS='urn:ietf:params:xml:ns:netconf:base:1.0'
|
||||
|
|
@ -283,32 +283,6 @@ if $SNMPCHECK; then
|
|||
expectpart "$($getnext $oid)" 0 "$result"
|
||||
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
|
||||
|
||||
# Check sanity between --with-restconf setting and if nginx is started by systemd or not
|
||||
|
|
|
|||
|
|
@ -120,13 +120,13 @@ function testinit(){
|
|||
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
|
||||
if [ $SN -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 &
|
||||
new "Starting clixon_snmp"
|
||||
start_snmp $cfg &
|
||||
fi
|
||||
|
||||
new "wait snmp"
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ function testinit(){
|
|||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $CS -ne 0 ]; then
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
|
|
|||
|
|
@ -178,13 +178,13 @@ function testinit(){
|
|||
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
|
||||
if [ $SN -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 &
|
||||
new "Starting clixon_snmp"
|
||||
start_snmp $cfg &
|
||||
fi
|
||||
|
||||
new "wait snmp"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
# SNMP table rowstatus tests
|
||||
#
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
|
@ -84,7 +83,7 @@ function testinit(){
|
|||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $CS -ne 0 ]; then
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
|
@ -106,13 +105,19 @@ function testrun_createAndGo()
|
|||
|
||||
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)"
|
||||
|
||||
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)"
|
||||
|
||||
new "Get tag"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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
|
||||
|
||||
new "Set rowstatus to createandgo"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndGo)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index'"
|
||||
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)"
|
||||
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
expectpart "$($snmpset SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.\'$index\' = createAndWait)" 0 "SNMP-NOTIFICATION-MIB::snmpNotifyRowStatus.'$index'"
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ function testinit(){
|
|||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $CS -ne 0 ]; then
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/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)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
|
@ -105,7 +105,7 @@ function testinit(){
|
|||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
if [ $CS -ne 0 ]; then
|
||||
if [ $SN -ne 0 ]; then
|
||||
# Kill old clixon_snmp, if any
|
||||
new "Terminating any old clixon_snmp processes"
|
||||
sudo killall -q clixon_snmp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue