#!/bin/bash # Yang list / leaf-list operations. min/max-elements APPNAME=example # include err() and new() functions and creates $dir . ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/test.yang cat < $cfg $cfg /usr/local/share/$APPNAME/yang /usr/local/share/clixon $APPNAME /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile 1 /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so EOF cat < $fyang module $APPNAME{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; container c{ presence true; list a0{ key k; leaf k { type string; } min-elements 0; max-elements "unbounded"; } list a1{ key k; leaf k { type string; } description "There must be at least one of these"; min-elements 1; max-elements 2; } leaf-list b0{ type string; min-elements 0; max-elements "unbounded"; } leaf-list b1{ description "There must be at least one of these"; type string; min-elements 1; max-elements 2; } } } EOF new "test params: -f $cfg -y $fyang" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg -y $fyang if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg -y $fyang" # start new backend sudo $clixon_backend -s init -f $cfg -y $fyang -D $DBG if [ $? -ne 0 ]; then err fi fi new "minmax: minimal" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "replace00]]>]]>" "^]]>]]>$" new "minmax: minimal validate ok" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "minmax: maximal" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "replace01unbounded0101unbounded01]]>]]>" "^]]>]]>$" new "minmax: validate ok" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "minmax: empty" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "replace]]>]]>" "^]]>]]>$" # NYI if false; then new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "minmax: no list" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "replace0]]>]]>" "^]]>]]>$" new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "minmax: no leaf-list" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "replace0]]>]]>" "^]]>]]>$" new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "minmax: Too large list" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "replace0120]]>]]>" "^]]>]]>$" new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "minmax: Too large leaf-list" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "replace0012]]>]]>" "^]]>]]>$" new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" fi # NYI if [ $BE -ne 0 ]; then exit # BE fi new "Kill backend" # Check if premature kill pid=`pgrep -u root -f clixon_backend` if [ -z "$pid" ]; then err "backend already dead" fi # kill backend sudo clixon_backend -z -f $cfg if [ $? -ne 0 ]; then err "kill backend" fi rm -rf $dir