#!/usr/bin/env bash # Yang when conditional and mandatory # Testing of validation phase. # Variants: # - One level and two levels of non-presence containers # - when-condition true and false # - empty vs extra leaf in non-presence container # - mandatory leaf present or not # 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; identity routing-protocol { description "Base identity from which routing protocol identities are derived."; } identity direct { base routing-protocol; description "Routing pseudo-protocol which provides routes to directly connected networks."; } identity static { base routing-protocol; description "Static routing pseudo-protocol."; } list x { key "type"; leaf type { type identityref { base routing-protocol; } } container y { when "../type='static'" { description "This container is only valid for the 'static' routing protocol."; } leaf name{ type string; mandatory true; } leaf extra{ type string; } } } list x2 { key "type"; leaf type { type identityref { base routing-protocol; } } container y2 { when "../type='static'" { description "This container is only valid for the 'static' routing protocol."; } container y3 { leaf name{ type string; mandatory true; } leaf extra{ type string; } } } } list x3 { key "type"; leaf type { type identityref { base routing-protocol; } } container y2 { container y3 { when "../../type='static'" { description "This container is only valid for the 'static' routing protocol."; } leaf name{ type string; mandatory true; } leaf extra{ type string; } } } } } 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_backend -s init -f $cfg fi new "wait backend" wait_backend new "First: have mandatory leaf under an empty when-conditioned ccntainer" new "when false + no name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "direct" "" "" new "validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when true + no name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static" "" "" new "validate fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationmissing-elementyerrorMandatory variable of x in module example" new "when true + name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "statica" "" "" new "validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Second: have mandatory leaf under a non-empty when-conditioned ccntainer" new "when false + no name + extra" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "directb" "" "" new "validate fail extra" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationoperation-failederrorFailed WHEN condition of y in module example (WHEN xpath is ../type='static')" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when true + no name + extra" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "staticb" "" "" new "validate fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationmissing-elementnameerrorMandatory variable of y in module example" new "when true + name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "staticab" "" "" new "validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Third: have mandatory leaf under two empty when-conditioned ccntainer" new "when false + no name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "direct" "" "" new "validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when true + no name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static" "" "" new "validate fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationmissing-elementy2errorMandatory variable of x2 in module example" new "when true + name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "statica" "" "" new "validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Fourth: have mandatory leaf under two non-empty when-conditioned ccntainer" new "when false + no name + extra" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "directb" "" "" new "validate fail extra" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationoperation-failederrorFailed WHEN condition of y2 in module example (WHEN xpath is ../type='static')" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when true + no name + extra" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "staticb" "" "" new "validate fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationmissing-elementnameerrorMandatory variable of y3 in module example" new "when true + name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "staticab" "" "" new "validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Fifth: have mandatory leaf under one empty and one when-conditioned ccntainer" new "when false + no name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "direct" "" "" new "validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when true + no name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "static" "" "" new "validate fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationmissing-elementy2errorMandatory variable of x3 in module example" new "when true + name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "statica" "" "" new "validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Sixth: have mandatory leaf under one non-empty and one when-conditioned ccntainer" new "when false + no name + extra" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "directb" "" "" new "validate fail extra" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationoperation-failederrorFailed WHEN condition of y3 in module example (WHEN xpath is ../../type='static')" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when true + no name + extra" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "staticb" "" "" new "validate fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationmissing-elementnameerrorMandatory variable of y3 in module example" new "when true + name" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "staticab" "" "" new "validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "when: discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" 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