#!/usr/bin/env bash # XML Insert elements and test if they are sorted according to yang # First a list with 0-5 base elements, insert in different places # Second varying yangs: container, leaf, list, leaf-list, choice, user-order list # 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_xml_mod:=clixon_util_xml_mod -o insert} OPTS="-D $DBG" APPNAME=example cfg=$dir/conf_yang.xml fyang=$dir/example.yang cat < $cfg $cfg $dir /usr/local/share/clixon /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile $dir EOF cat < $fyang module example { yang-version 1.1; namespace "urn:example:example"; prefix ex; revision 2019-01-13; container c{ list a{ key x; leaf x{ type int32; } } } } EOF # Insert a sub tree into base tree. Verify its inserted in the right place # Args: # 1: base tree # 2: sub tree testrun(){ x0=$1 xi="$2" xp=c new "insert list into $x0, verify order" # First run sorted (assume this is the reference == correct) rs=$($clixon_util_xml_mod -y $fyang -x "$xi" -b "$x0" -p $xp $OPTS -s) # Then run actual insert r0=$($clixon_util_xml_mod -y $fyang -x "$xi" -b "$x0" -p $xp $OPTS) # If both are null something is amiss if [ -z "$r0" -a -z "$rs" ]; then err "length of retval is zero" fi # echo "rs:$rs" # echo "r0:$r0" # Check they are equal if [[ "$r0" != "$rs" ]]; then err "$rs" "$r0" fi } new "test params: -y $fyang $OPTS" # Empty element base list x0='' new "empty list" testrun "$x0" "1" # One element base list x0='99' new "one element list first" testrun "$x0" "1" new "one element list last" testrun "$x0" "100" # Two element base list x0='299' new "two element list first" testrun "$x0" "1" new "two element list mid" testrun "$x0" "12" new "two element list last" testrun "$x0" "3000" # Three element base list x0='299101' new "three element list first" testrun "$x0" "1" new "three element list second" testrun "$x0" "10" new "three element list third" testrun "$x0" "100" new "three element list last" testrun "$x0" "1000" # Four element base list x0='299101200' new "four element list first" testrun "$x0" "1" new "four element list second" testrun "$x0" "10" new "four element list third" testrun "$x0" "100" new "four element list fourth" testrun "$x0" "102" new "four element list last" testrun "$x0" "1000" # Five element base list x0='299101200300' new "five element list first" testrun "$x0" "1" new "five element list mid" testrun "$x0" "100" new "five element list last" testrun "$x0" "1000" cat < $fyang module example { yang-version 1.1; namespace "urn:example:example"; prefix ex; revision 2019-01-13; container c{ leaf a{ type string; } container b{ leaf a { type string; } } choice c1{ case a{ leaf x{ type string; } } case b{ leaf y{ type int32; } } } choice c2{ leaf z{ type string; } leaf t{ type int32; } } list d{ key x; leaf x{ type int32; } ordered-by user; } leaf-list e{ type int32; } } } EOF # Advanced list # Empty base list x0='' xp=c new "adv empty list add leaf" testrun "$x0" "leaf" new "adv empty list add choice c1" testrun "$x0" "choice1" xi='33' new "adv empty list add leaf-list" testrun "$x0" "33" # base list x0='leafchoice133' new "adv list add leaf-list" testrun "$x0" "32" new "adv list add leaf-list" testrun "$x0" "32" rm -rf $dir # unset conditional parameters unset clixon_util_xml_mod