Add union test
This commit is contained in:
parent
ea40977382
commit
cc951fc3be
2 changed files with 60 additions and 66 deletions
|
|
@ -349,7 +349,7 @@ snmp_yang_type_get(yang_stmt *ys,
|
||||||
if (yang_type_get(ys, &origtype, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0)
|
if (yang_type_get(ys, &origtype, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
restype = yrestype?yang_argument_get(yrestype):NULL;
|
restype = yrestype?yang_argument_get(yrestype):NULL;
|
||||||
restype = yang_type_to_snmp(restype, restype);
|
restype = yang_type_to_snmp(yrestype, restype);
|
||||||
if (strcmp(restype, "leafref")==0){
|
if (strcmp(restype, "leafref")==0){
|
||||||
if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){
|
if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){
|
||||||
clicon_err(OE_YANG, 0, "No path in leafref");
|
clicon_err(OE_YANG, 0, "No path in leafref");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# SNMP test for yang union type with are same types of subtypes
|
# SNMP test for yang union type with are same types of subtypes.
|
||||||
|
|
||||||
# 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
|
||||||
|
|
@ -20,6 +20,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>
|
||||||
|
|
@ -32,6 +34,7 @@ cat <<EOF > $cfg
|
||||||
<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>clixon-example</CLICON_SNMP_MIB>
|
||||||
<CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
|
<CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -41,49 +44,28 @@ module clixon-example{
|
||||||
yang-version 1.1;
|
yang-version 1.1;
|
||||||
namespace "urn:example:clixon";
|
namespace "urn:example:clixon";
|
||||||
prefix ex;
|
prefix ex;
|
||||||
|
|
||||||
import ietf-yang-smiv2 {
|
import ietf-yang-smiv2 {
|
||||||
prefix smiv2;
|
prefix smiv2;
|
||||||
}
|
}
|
||||||
typedef first {
|
|
||||||
type string{
|
|
||||||
pattern
|
|
||||||
"first";
|
|
||||||
}
|
|
||||||
description "first string";
|
|
||||||
}
|
|
||||||
typedef second {
|
|
||||||
type string{
|
|
||||||
pattern
|
|
||||||
"second";
|
|
||||||
}
|
|
||||||
description "second string";
|
|
||||||
}
|
|
||||||
typedef third {
|
|
||||||
type string{
|
|
||||||
pattern
|
|
||||||
"third";
|
|
||||||
}
|
|
||||||
description "third string";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Generic config data */
|
/* Generic config data */
|
||||||
container table{
|
container table{
|
||||||
smiv2:oid "1.3.6.1.2.1.47.1.1.1";
|
smiv2:oid "1.3.6.1.2.1.47.1.1.1";
|
||||||
list parameter{
|
list parameter{
|
||||||
smiv2:oid "1.3.6.1.2.1.47.1.1.1.1";
|
smiv2:oid "1.3.6.1.2.1.47.1.1.1.1";
|
||||||
key index;
|
key Index;
|
||||||
leaf index{
|
|
||||||
|
leaf Index{
|
||||||
type int32;
|
type int32;
|
||||||
smiv2:oid "1.3.6.1.2.1.47.1.1.1.1.1";
|
smiv2:oid "1.3.6.1.2.1.47.1.1.1.1.1";
|
||||||
}
|
}
|
||||||
leaf name{
|
leaf Union_exm{
|
||||||
type union{
|
description "Union with same subtypes";
|
||||||
type ex:first;
|
config false;
|
||||||
type ex:second;
|
type union
|
||||||
type ex:third;
|
{
|
||||||
|
type int32;
|
||||||
|
type int32;
|
||||||
}
|
}
|
||||||
description "name";
|
|
||||||
smiv2:oid "1.3.6.1.2.1.47.1.1.1.1.2";
|
smiv2:oid "1.3.6.1.2.1.47.1.1.1.1.2";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,23 +74,21 @@ module clixon-example{
|
||||||
EOF
|
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)
|
||||||
|
# integer and string have values, sleeper does not and uses default (=1)
|
||||||
|
|
||||||
cat <<EOF > $fstate
|
cat <<EOF > $fstate
|
||||||
<table xmlns="urn:example:clixon">
|
<table xmlns="urn:example:clixon">
|
||||||
<parameter>
|
<parameter>
|
||||||
<index>1</index>
|
<Index>2</Index>
|
||||||
<name>first</name>
|
<Union_exm>4</Union_exm>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter>
|
<parameter>
|
||||||
<index>2</index>
|
<Index>12</Index>
|
||||||
<name>second</name>
|
<Union_exm>14</Union_exm>
|
||||||
</parameter>
|
|
||||||
<parameter>
|
|
||||||
<index>3</index>
|
|
||||||
<name>third</name>
|
|
||||||
</parameter>
|
</parameter>
|
||||||
</table>
|
</table>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
function testinit(){
|
function testinit(){
|
||||||
new "test params: -s init -f $cfg -- -sS $fstate"
|
new "test params: -s init -f $cfg -- -sS $fstate"
|
||||||
if [ $BE -ne 0 ]; then
|
if [ $BE -ne 0 ]; then
|
||||||
|
|
@ -158,28 +138,42 @@ function testexit(){
|
||||||
|
|
||||||
ENTITY_OID=".1.3.6.1.2.1.47.1.1.1"
|
ENTITY_OID=".1.3.6.1.2.1.47.1.1.1"
|
||||||
|
|
||||||
echo $($snmpwalk)
|
# name, value=2
|
||||||
|
OID1="${ENTITY_OID}.1.1.2"
|
||||||
|
# name, value=12
|
||||||
|
OID2="${ENTITY_OID}.1.1.12"
|
||||||
|
# value, value=2
|
||||||
|
OID3="${ENTITY_OID}.1.2.2"
|
||||||
|
# value, value=12
|
||||||
|
OID4="${ENTITY_OID}.1.2.12"
|
||||||
|
# stat, value=2
|
||||||
|
OIDX="${ENTITY_OID}.1.3.2"
|
||||||
|
# stat, value=12
|
||||||
|
OIDY="${ENTITY_OID}.1.3.12"
|
||||||
|
|
||||||
# first string, value=first
|
|
||||||
OID_FIRST="${ENTITY_OID}.1.1.1"
|
|
||||||
# second string, value=second
|
|
||||||
OID_SECOND="${ENTITY_OID}.1.1.2"
|
|
||||||
# third string, value=third
|
|
||||||
OID_THIRD="${ENTITY_OID}.1.1.3"
|
|
||||||
|
|
||||||
new "SNMP system tests"
|
new "SNMP system tests"
|
||||||
testinit
|
testinit
|
||||||
|
|
||||||
new "Get index, $OID_FIRST"
|
new "Get index, $OID1"
|
||||||
validate_oid $OID_FIRST $OID_FIRST "STRING" "1first"
|
validate_oid $OID1 $OID1 "INTEGER" "2"
|
||||||
# new "Get next $OID_FIRST"
|
|
||||||
# validate_oid $OID_FIRST $OID_SECOND "STRING" "second"
|
new "Get next $OID1"
|
||||||
# new "Get index, $OID_SECOND"
|
validate_oid $OID1 $OID2 "INTEGER" "12"
|
||||||
# validate_oid $OID_SECOND $OID_SECOND "STRING" "second"
|
|
||||||
# new "Get next $OID_SECOND"
|
new "Get index, $OID2"
|
||||||
# validate_oid $OID_SECOND $OID_THIRD "STRING" "third"
|
validate_oid $OID2 $OID2 "INTEGER" "12"
|
||||||
# new "Get index, $OID_THIRD"
|
new "Get next $OID2"
|
||||||
# validate_oid $OID_THIRD $OID_THIRD "STRING" "third"
|
validate_oid $OID2 $OID3 "INTEGER" "4"
|
||||||
|
|
||||||
|
new "Get index, $OID3"
|
||||||
|
validate_oid $OID3 $OID3 "INTEGER" "4"
|
||||||
|
|
||||||
|
new "Get next $OID4"
|
||||||
|
validate_oid $OID3 $OID4 "INTEGER" "14"
|
||||||
|
|
||||||
|
new "Get index, $OID4"
|
||||||
|
validate_oid $OID4 $OID4 "INTEGER" "14"
|
||||||
|
|
||||||
new "Cleaning up"
|
new "Cleaning up"
|
||||||
testexit
|
testexit
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue