#!/usr/bin/env bash # Instance-id tests with multiple results # RFC 7950 Sections 9.13 and 14 says that: # Predicates are used only for specifying the values for the key nodes for list entries # but does not explicitly say that list nodes can skip them # And in RFC8341 node-instance-identifiers are defined as: # All the same rules as an instance-identifier apply, except that predicates for keys are optional. # If a key predicate is missing, then the node-instance-identifier represents all possible server # instances for that key. # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi : ${clixon_util_path:=clixon_util_path -D $DBG} xml1=$dir/xml1.xml ydir=$dir/yang if [ ! -d $ydir ]; then mkdir $ydir fi # Nested lists cat < $ydir/example.yang module example{ yang-version 1.1; namespace "urn:example:id"; prefix ex; container table{ list parameter{ key name; leaf name{ type string; } container next{ list parameter{ key name; leaf name{ type string; } leaf value{ type string; } } } } } } EOF cat < $xml1 a a 11 b 22 b a 33
EOF new "instance-id top-level param" expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter)" 0 "0: aa11b22" "1: ba33" new "instance-id a/next" expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter[ex:name=\"a\"]/ex:next)" 0 "0: a11b22" new "instance-id a/next/param" expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter[ex:name=\"a\"]/ex:next/ex:parameter)" 0 "0: a11" "1: b22" new "instance-id a/next/param/a" expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter[ex:name=\"a\"]/ex:next/ex:parameter[ex:name=\"a\"])" 0 "0: a11" "0: a11" new "instance-id a/next/param/a/value" expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter[ex:name=\"a\"]/ex:next/ex:parameter[ex:name=\"a\"]/ex:value)" 0 "0: 11" new "instance-id top-level parameter/next" expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter/ex:next)" 0 "0: a11b22" "1: a33" new "instance-id top-level parameter/next/parameter" expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter/ex:next/ex:parameter)" 0 "0: a11" "1: b22" "2: a33" rm -rf $dir unset clixon_util_path # for other script reusing it