#!/usr/bin/env bash # Yang list / leaf-list min/max-element tests. # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example cfg=$dir/conf_yang.xml fyang=$dir/test.yang cat < $cfg $cfg /usr/local/share/clixon $IETFRFC $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME 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; } } container c2{ description "with choices"; choice ch1{ case x{ list a1{ key k; leaf k { type string; } min-elements 1; max-elements 2; } } case y{ list a2{ key k; leaf k { type string; } min-elements 0; max-elements 3; } } } choice ch2{ leaf-list b1{ type string; min-elements 1; max-elements 2; } } } leaf-list b3{ description "top-level"; type int32; min-elements 1; max-elements 2; } } EOF new "test params: -f $cfg" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg" # start new backend start_backend -s init -f $cfg new "waiting" wait_backend fi new "minmax: minimal: 1x a1,b1 (should be [1:2]" expecteof "$clixon_netconf -qf $cfg" 0 "replace 0 0 ]]>]]>" "^]]>]]>$" new "minmax: minimal validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "minmax: maximal: 2x a1,b1" expecteof "$clixon_netconf -qf $cfg" 0 "replace01unbounded0101unbounded101]]>]]>" "^]]>]]>$" new "minmax: validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "minmax: replace with 0x a1,b1" expecteof "$clixon_netconf -qf $cfg" 0 "replace]]>]]>" "^]]>]]>$" #XXX echo "]]>]]>" |$clixon_netconf -qf $cfg new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocoloperation-failedtoo-few-elementserror/c/a1]]>]]>$" new "minmax: no list" expecteof "$clixon_netconf -qf $cfg" 0 "replace0]]>]]>" "^]]>]]>$" new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocoloperation-failedtoo-few-elementserror/c/a1]]>]]>$" new "minmax: no leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "replace0]]>]]>" "^]]>]]>$" new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocoloperation-failedtoo-few-elementserror/c/b1]]>]]>$" new "minmax: Too large list" expecteof "$clixon_netconf -qf $cfg" 0 "replace0120]]>]]>" "^]]>]]>$" new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocoloperation-failedtoo-many-elementserror/c/a1]]>]]>$" new "minmax: Too large leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "replace0012]]>]]>" "^]]>]]>$" new "minmax: validate should fail" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocoloperation-failedtoo-many-elementserror/c/b1]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" # With choice c1 new "minmax choice: minimal" expecteof "$clixon_netconf -qf $cfg" 0 "replace 0 0 ]]>]]>" "^]]>]]>$" new "minmax choice: minimal validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "minmax choice: many a2" expecteof "$clixon_netconf -qf $cfg" 0 "replace 0 1 2 0 ]]>]]>" "^]]>]]>$" new "minmax choice: many a2 validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "minmax choice: too many a1" expecteof "$clixon_netconf -qf $cfg" 0 "replace 0 1 2 0 ]]>]]>" "^]]>]]>$" new "minmax choice: too many validate should fail" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocoloperation-failedtoo-many-elementserror/c2/a1]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" # top config level new "minmax top level" expecteof "$clixon_netconf -qf $cfg" 0 "replace 0 1 ]]>]]>" "^]]>]]>$" new "minmax top level ok" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "minmax top level too many" expecteof "$clixon_netconf -qf $cfg" 0 "replace 0 1 2 ]]>]]>" "^]]>]]>$" new "minmax top level too many should fail" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocoloperation-failedtoo-many-elementserror/b3]]>]]>" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" # Above only tests on candidate -> empty running # Also need to do commit tests when running has elements and candidate has fewer new "Set maximal: 2x a1,b1" expecteof "$clixon_netconf -qf $cfg" 0 "replace0110]]>]]>" "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "minmax: delete to minimal: 1x a1,b1" expecteof "$clixon_netconf -qf $cfg" 0 "none11]]>]]>" "^]]>]]>$" new "minmax: commit minimal list" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "minmax: delete to no list" expecteof "$clixon_netconf -qf $cfg" 0 "none00]]>]]>" "^]]>]]>$" new "minmax: validate should fail empty list" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocoloperation-failedtoo-few-elementserror/c/a1]]>]]>$" if [ $BE -eq 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 stop_backend -f $cfg rm -rf $dir