#!/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 ${YANG_INSTALLDIR} $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 fi new "wait backend" wait_backend new "minmax: minimal: 1x a1,b1 (should be [1:2]" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace 0 0 " "" "" new "minmax: minimal validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "minmax: maximal: 2x a1,b1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace01unbounded0101unbounded101" "" "" new "minmax: validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "minmax: replace with 0x a1,b1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace" "" "" #XXX echo "$DEFAULTHELLO]]>]]>" |$clixon_netconf -qf $cfg new "minmax: validate should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocoloperation-failedtoo-few-elementserror/c/a1" new "minmax: no list" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace0" "" "" new "minmax: validate should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocoloperation-failedtoo-few-elementserror/c/a1" new "minmax: no leaf-list" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace0" "" "" new "minmax: validate should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocoloperation-failedtoo-few-elementserror/c/b1" new "minmax: Too large list" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace0120" "" "" new "minmax: validate should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocoloperation-failedtoo-many-elementserror/c/a1" new "minmax: Too large leaf-list" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace0012" "" "" new "minmax: validate should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocoloperation-failedtoo-many-elementserror/c/b1" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" # With choice c1 new "minmax choice: minimal" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace 0 0 " "" "" new "minmax choice: minimal validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "minmax choice: many a2" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace 0 1 2 0 " "" "" new "minmax choice: many a2 validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "minmax choice: too many a1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace 0 1 2 0 " "" "" new "minmax choice: too many validate should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocoloperation-failedtoo-many-elementserror/c2/a1" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" # top config level new "minmax top level" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace 0 1 " "" "" new "minmax top level ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "minmax top level too many" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace 0 1 2 " "" "protocoloperation-failedtoo-many-elementserror/rpc/edit-config/config/b3" new "minmax top level too many should fail" #expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocoloperation-failedtoo-many-elementserror/b3" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" # 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_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace0110" "" "" new "netconf commit" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "minmax: delete to minimal: 1x a1,b1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "none11" "" "" new "minmax: commit minimal list" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "minmax: delete to no list" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "none00" "" "" new "minmax: validate should fail empty list" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocoloperation-failedtoo-few-elementserror/c/a1" if [ $BE -ne 0 ]; then 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 fi rm -rf $dir new "endtest" endtest