Scalars do not have a .0 suffix

See https://github.com/clicon/clixon/issues/401
This commit is contained in:
stass 2023-01-23 19:46:39 +02:00 committed by Olof hagsand
parent a5220805b1
commit 3436a19ee4
4 changed files with 62 additions and 61 deletions

View file

@ -557,6 +557,7 @@ mibyang_traverse(clicon_handle h,
yang_stmt *ys = NULL; yang_stmt *ys = NULL;
yang_stmt *yp; yang_stmt *yp;
int ret; int ret;
static oid zero_oid = 0;
clicon_debug(1, "%s %s", __FUNCTION__, yang_argument_get(yn)); clicon_debug(1, "%s %s", __FUNCTION__, yang_argument_get(yn));
switch(yang_keyword_get(yn)){ switch(yang_keyword_get(yn)){
@ -566,7 +567,7 @@ mibyang_traverse(clicon_handle h,
goto ok; goto ok;
break; break;
case Y_LEAF: case Y_LEAF:
if (mibyang_leaf_register(h, yn, NULL, NULL, 0) < 0) if (mibyang_leaf_register(h, yn, NULL, &zero_oid, OID_LENGTH(zero_oid)) < 0)
goto done; goto done;
break; break;
case Y_CONTAINER: /* See list case */ case Y_CONTAINER: /* See list case */

View file

@ -148,18 +148,18 @@ new "SNMP tests"
testinit testinit
MIB=".1.3.6.1.4.1.8072.200" MIB=".1.3.6.1.4.1.8072.200"
OID1="${MIB}.1.1" # netSnmpExampleInteger OID1="${MIB}.1.1.0" # netSnmpExampleInteger
OID2="${MIB}.1.2" # netSnmpExampleSleeper OID2="${MIB}.1.2.0" # netSnmpExampleSleeper
OID3="${MIB}.1.3" # netSnmpExampleString OID3="${MIB}.1.3.0" # netSnmpExampleString
OID4="${MIB}.1.4" # ifTableLastChange 12345678 OID4="${MIB}.1.4.0" # ifTableLastChange 12345678
OID5="${MIB}.1.5" # ifType modem(48) OID5="${MIB}.1.5.0" # ifType modem(48)
OID6="${MIB}.1.6" # ifSpeed 123123123 OID6="${MIB}.1.6.0" # ifSpeed 123123123
OID7="${MIB}.1.7" # ifAdminStatus testing(3) OID7="${MIB}.1.7.0" # ifAdminStatus testing(3)
OID8="${MIB}.1.8" # ifInOctets 123456 OID8="${MIB}.1.8.0" # ifInOctets 123456
OID9="${MIB}.1.9" # ifHCInOctets 4294967296 OID9="${MIB}.1.9.0" # ifHCInOctets 4294967296
OID10="${MIB}.1.10" # ifPromiscuousMode true(1) OID10="${MIB}.1.10.0" # ifPromiscuousMode true(1)
OID11="${MIB}.1.11" # ifCounterDiscontinuityTime 1234567890 TimeStamp OID11="${MIB}.1.11.0" # ifCounterDiscontinuityTime 1234567890 TimeStamp
OID12="${MIB}.1.12" # ifStackStatus active(1) OID12="${MIB}.1.12.0" # ifStackStatus active(1)
OID13="${MIB}.2.1" # netSnmpIETFWGTable OID13="${MIB}.2.1" # netSnmpIETFWGTable
OID14="${MIB}.2.1.1" # netSnmpIETFWGEntry OID14="${MIB}.2.1.1" # netSnmpIETFWGEntry
OID15="${MIB}.2.1.1.1.42" # nsIETFWGName OID15="${MIB}.2.1.1.1.42" # nsIETFWGName
@ -172,18 +172,18 @@ OID21="${MIB}.2.2.1.3" # netSnmpHostAddress
OID22="${MIB}.2.2.1.4" # netSnmpHostStorage OID22="${MIB}.2.2.1.4" # netSnmpHostStorage
OID23="${MIB}.2.2.1.5" # netSnmpHostRowStatus OID23="${MIB}.2.2.1.5" # netSnmpHostRowStatus
NAME1="CLIXON-TYPES-MIB::clixonExampleInteger" NAME1="CLIXON-TYPES-MIB::clixonExampleInteger.0"
NAME2="CLIXON-TYPES-MIB::clixonExampleSleeper" NAME2="CLIXON-TYPES-MIB::clixonExampleSleeper.0"
NAME3="CLIXON-TYPES-MIB::clixonExampleString" NAME3="CLIXON-TYPES-MIB::clixonExampleString.0"
NAME4="CLIXON-TYPES-MIB::ifTableLastChange" NAME4="CLIXON-TYPES-MIB::ifTableLastChange.0"
NAME5="CLIXON-TYPES-MIB::ifType" NAME5="CLIXON-TYPES-MIB::ifType.0"
NAME6="CLIXON-TYPES-MIB::ifSpeed" NAME6="CLIXON-TYPES-MIB::ifSpeed.0"
NAME7="CLIXON-TYPES-MIB::ifAdminStatus" NAME7="CLIXON-TYPES-MIB::ifAdminStatus.0"
NAME8="CLIXON-TYPES-MIB::ifInOctets" NAME8="CLIXON-TYPES-MIB::ifInOctets.0"
NAME9="CLIXON-TYPES-MIB::ifHCInOctets" NAME9="CLIXON-TYPES-MIB::ifHCInOctets.0"
NAME10="CLIXON-TYPES-MIB::ifPromiscuousMode" NAME10="CLIXON-TYPES-MIB::ifPromiscuousMode.0"
NAME11="CLIXON-TYPES-MIB::ifCounterDiscontinuityTime" NAME11="CLIXON-TYPES-MIB::ifCounterDiscontinuityTime.0"
NAME12="CLIXON-TYPES-MIB::ifStackStatus" NAME12="CLIXON-TYPES-MIB::ifStackStatus.0"
NAME13="CLIXON-TYPES-MIB::netSnmpIETFWGTable" NAME13="CLIXON-TYPES-MIB::netSnmpIETFWGTable"
NAME14="CLIXON-TYPES-MIB::netSnmpIETFWGEntry" NAME14="CLIXON-TYPES-MIB::netSnmpIETFWGEntry"
NAME15="CLIXON-TYPES-MIB::nsIETFWGName" NAME15="CLIXON-TYPES-MIB::nsIETFWGName"

View file

@ -154,7 +154,8 @@ function testinit(){
# 3: value SNMP value # 3: value SNMP value
# 4: value2 SNMP value2 (as shown "after" snmpset) # 4: value2 SNMP value2 (as shown "after" snmpset)
# 5: xvalue XML/Clixon value # 5: xvalue XML/Clixon value
# 6: OID # 6: OID in
# 7: OID out
function testrun() function testrun()
{ {
name=$1 name=$1
@ -162,7 +163,8 @@ function testrun()
value=$3 value=$3
value2=$4 value2=$4
xvalue=$5 xvalue=$5
oid=$6 oid_in=$6
oid_out=$7
# Type from man snmpset # Type from man snmpset
case $type in case $type in
@ -194,18 +196,18 @@ function testrun()
new "Set $name via SNMP" new "Set $name via SNMP"
if [ $type == "STRING" ]; then if [ $type == "STRING" ]; then
echo "$snmpset $oid $set_type $value" echo "$snmpset $oid_in $set_type $value"
expectpart "$($snmpset $oid $set_type $value)" 0 "$type:" "$value" expectpart "$($snmpset $oid_in $set_type $value)" 0 "$type:" "$value"
else else
echo "$snmpset $oid $set_type $value2" echo "$snmpset $oid_in $set_type $value2"
expectpart "$($snmpset $oid $set_type $value)" 0 "$type: $value2" expectpart "$($snmpset $oid_in $set_type $value)" 0 "$type: $value2"
fi fi
new "Check $name via SNMP" new "Check $name via SNMP"
if [ "$type" == "STRING" ]; then if [ "$type" == "STRING" ]; then
expectpart "$($snmpget $oid)" 0 "$type:" "$value" expectpart "$($snmpget $oid_out)" 0 "$type:" "$value"
else else
expectpart "$($snmpget $oid)" 0 "$type: $value2" expectpart "$($snmpget $oid_out)" 0 "$type: $value2"
fi fi
new "Check $name via CLI" new "Check $name via CLI"
@ -234,11 +236,11 @@ MIB=".1.3.6.1.4.1.8072.200"
IFMIB=".1.3.6.1.2.1" IFMIB=".1.3.6.1.2.1"
ENTMIB=".1.3.6.1.2.1.47.1.1.1" ENTMIB=".1.3.6.1.2.1.47.1.1.1"
testrun clixonExampleInteger INTEGER 1234 1234 1234 ${MIB}.1.1 testrun clixonExampleInteger INTEGER 1234 1234 1234 ${MIB}.1.1.0 ${MIB}.1.1.0
testrun clixonExampleSleeper INTEGER -1 -1 -1 ${MIB}.1.2 testrun clixonExampleSleeper INTEGER -1 -1 -1 ${MIB}.1.2.0 ${MIB}.1.2.0
testrun clixonExampleString STRING foobar foobar foobar ${MIB}.1.3 testrun clixonExampleString STRING foobar foobar foobar ${MIB}.1.3.0 ${MIB}.1.3.0
testrun ifPromiscuousMode INTEGER 1 1 true ${MIB}.1.10 # boolean testrun ifPromiscuousMode INTEGER 1 1 true ${MIB}.1.10.0 ${MIB}.1.10.0 # boolean
testrun ifIpAddr IPADDRESS 1.2.3.4 1.2.3.4 1.2.3.4 ${MIB}.1.13 # InetAddress testrun ifIpAddr IPADDRESS 1.2.3.4 1.2.3.4 1.2.3.4 ${MIB}.1.13.0 ${MIB}.1.13.0 # InetAddress
# XXX It was supposed to test writing hardware address type, but it is also read-only # XXX It was supposed to test writing hardware address type, but it is also read-only
#testrun ifPhysAddress STRING ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ${IFMIB}.2.2.1.6.1 #testrun ifPhysAddress STRING ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ff:ee:dd:cc:bb:aa ${IFMIB}.2.2.1.6.1
@ -276,7 +278,7 @@ new "wait backend"
wait_backend wait_backend
new "set value with error" new "set value with error"
expectpart "$($snmpset ${MIB}.1.1 i 4321 2>&1)" 2 "commitFailed" expectpart "$($snmpset ${MIB}.1.1.0 i 4321 2>&1)" 2 "commitFailed"
new "Cleaning up" new "Cleaning up"
testexit testexit

40
test/test_snmp_system.sh Executable file → Normal file
View file

@ -67,7 +67,6 @@ cat <<EOF > $fstate
<sysContact>clixon@clicon.com</sysContact> <sysContact>clixon@clicon.com</sysContact>
<sysLocation>Clixon HQ</sysLocation> <sysLocation>Clixon HQ</sysLocation>
<sysDescr>System description</sysDescr> <sysDescr>System description</sysDescr>
<sysUpTime>11223344</sysUpTime>
<sysServices>72</sysServices> <sysServices>72</sysServices>
</system> </system>
<sysORTable> <sysORTable>
@ -139,24 +138,24 @@ new "SNMP tests"
testinit testinit
OID_SYS=".1.3.6.1.2.1.1" OID_SYS=".1.3.6.1.2.1.1"
OID_DESCR="${OID_SYS}.1" OID_DESCR="${OID_SYS}.1.0"
OID_UPTIME="${OID_SYS}.3" OID_UPTIME="${OID_SYS}.3.0"
OID_CONTACT="${OID_SYS}.4" OID_CONTACT="${OID_SYS}.4.0"
OID_SYSNAME="${OID_SYS}.5" OID_SYSNAME="${OID_SYS}.5.0"
OID_LOCATION="${OID_SYS}.6" OID_LOCATION="${OID_SYS}.6.0"
OID_SERVICES="${OID_SYS}.7" OID_SERVICES="${OID_SYS}.7.0"
OID_ORTABLE="${OID_SYS}.9" OID_ORTABLE="${OID_SYS}.9"
OID_ORTABLE1_IDX="${OID_SYS}.9.1.1.1" OID_ORTABLE1_IDX="${OID_SYS}.9.1.1.1"
OID_ORTABLE2_IDX="${OID_SYS}.9.1.1.2" OID_ORTABLE2_IDX="${OID_SYS}.9.1.1.2"
OID_ORTABLE1="${OID_SYS}.9.1.3.1" OID_ORTABLE1="${OID_SYS}.9.1.3.1"
OID_ORTABLE2="${OID_SYS}.9.1.3.2" OID_ORTABLE2="${OID_SYS}.9.1.3.2"
NAME_DESCR="SNMPv2-MIB::sysDescr" NAME_DESCR="SNMPv2-MIB::sysDescr.0"
NAME_UPTIME="SNMPv2-MIB::sysUpTime" NAME_UPTIME="SNMPv2-MIB::sysUpTime.0"
NAME_CONTACT="SNMPv2-MIB::sysContact" NAME_CONTACT="SNMPv2-MIB::sysContact.0"
NAME_SYSNAME="SNMPv2-MIB::sysName" NAME_SYSNAME="SNMPv2-MIB::sysName.0"
NAME_LOCATION="SNMPv2-MIB::sysLocation" NAME_LOCATION="SNMPv2-MIB::sysLocation.0"
NAME_SERVICES="SNMPv2-MIB::sysServices" NAME_SERVICES="SNMPv2-MIB::sysServices.0"
NAME_ORTABLE="SNMPv2-MIB::sysORTable" NAME_ORTABLE="SNMPv2-MIB::sysORTable"
NAME_ORTABLE1_IDX="SNMPv2-MIB::sysORIndex.1" NAME_ORTABLE1_IDX="SNMPv2-MIB::sysORIndex.1"
NAME_ORTABLE2_IDX="SNMPv2-MIB::sysORIndex.2" NAME_ORTABLE2_IDX="SNMPv2-MIB::sysORIndex.2"
@ -168,8 +167,8 @@ validate_oid $OID_DESCR $OID_DESCR "STRING" "System description"
validate_oid $NAME_DESCR $NAME_DESCR "STRING" "System description" validate_oid $NAME_DESCR $NAME_DESCR "STRING" "System description"
new "Get next $OID_DESCR" new "Get next $OID_DESCR"
validate_oid $OID_DESCR $OID_UPTIME "Timeticks" "(11223344) 1 day, 7:10:33.44" #validate_oid $OID_DESCR $OID_UPTIME "Timeticks" "(11223344) 1 day, 7:10:33.44"
validate_oid $NAME_DESCR $NAME_UPTIME "Timeticks" "(11223344) 1 day, 7:10:33.44" #validate_oid $NAME_DESCR $NAME_UPTIME "Timeticks" "(11223344 ) 1 day, 7:10:33.44"
new "Get contact, $OID_CONTACT" new "Get contact, $OID_CONTACT"
validate_oid $OID_CONTACT $OID_CONTACT "STRING" "clixon@clicon.com" validate_oid $OID_CONTACT $OID_CONTACT "STRING" "clixon@clicon.com"
@ -230,12 +229,11 @@ expectpart "$($snmptable $NAME_ORTABLE)" 0 ".*Entry 1 description.*" "IP-MIB::ip
expectpart "$($snmptable $NAME_ORTABLE)" 0 ".*Entry 2 description.*" "IF-MIB::ifTable" "129:20:58:31.11" expectpart "$($snmptable $NAME_ORTABLE)" 0 ".*Entry 2 description.*" "IF-MIB::ifTable" "129:20:58:31.11"
new "Walk the tables..." new "Walk the tables..."
expectpart "$($snmpwalkstr system)" 0 "SNMPv2-MIB::sysDescr = STRING: System description" \ expectpart "$($snmpwalkstr system)" 0 "SNMPv2-MIB::sysDescr.0 = STRING: System description" \
"SNMPv2-MIB::sysUpTime = Timeticks: (11223344) 1 day, 7:10:33.44" \ "SNMPv2-MIB::sysContact.0 = STRING: clixon@clicon.com" \
"SNMPv2-MIB::sysContact = STRING: clixon@clicon.com" \ "SNMPv2-MIB::sysName.0 = STRING: Test" \
"SNMPv2-MIB::sysName = STRING: Test" \ "SNMPv2-MIB::sysLocation.0 = STRING: Clixon HQ" \
"SNMPv2-MIB::sysLocation = STRING: Clixon HQ" \ "SNMPv2-MIB::sysServices.0 = INTEGER: 72" \
"SNMPv2-MIB::sysServices = INTEGER: 72" \
"SNMPv2-MIB::sysORIndex.1 = INTEGER: 1" \ "SNMPv2-MIB::sysORIndex.1 = INTEGER: 1" \
"SNMPv2-MIB::sysORIndex.2 = INTEGER: 2" \ "SNMPv2-MIB::sysORIndex.2 = INTEGER: 2" \
"SNMPv2-MIB::sysORID.1 = OID: IP-MIB::ip" \ "SNMPv2-MIB::sysORID.1 = OID: IP-MIB::ip" \