#!/usr/bin/env bash # Yang leafref + union test (+ identitytref) # See eg https://github.com/clicon/clixon/issues/277 # 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/leafref.yang cat < $cfg $cfg $dir /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 example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; identity crypto { description "Base identity from which all crypto algorithms are derived."; } identity des { base "crypto"; description "DES crypto algorithm."; } identity des3 { base "crypto"; description "Triple DES crypto algorithm."; } identity airplane; identity boeing { base "airplane"; } identity saab { base "airplane"; } container c { leaf x { type string; } leaf y { type string; } leaf z { description "leafref union"; type union { type leafref { path "../x"; require-instance true; } type leafref { path "../y"; require-instance true; } } } leaf w { description "idref union"; type union { type identityref { base crypto; } type identityref { base airplane; } } } leaf u { description "Union mix of idref and leafref"; type union { type identityref { base crypto; } type leafref { path "../x"; require-instance true; } } } } } 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 "netconf set x,y leafs" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO4299merge ]]>]]>" "^]]>]]>$" new "netconf commit x,y" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf set union 42" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO42none]]>]]>" "^]]>]]>$" new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf check config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^429942]]>]]>$" new "netconf set union 66" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO66none]]>]]>" "^]]>]]>$" new "netconf validate not ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationbad-element66errorLeafref validation failed: No leaf 66 matching path ../y" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf set union id saab" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOex:saabnone]]>]]>" "^]]>]]>$" new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf set union idref zzz" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOex:zzznone]]>]]>" "^]]>]]>$" new "netconf validate idref not ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationoperation-failederrorIdentityref validation failed" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf set union id des" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOex:desnone]]>]]>" "^]]>]]>$" new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf set union x=42" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO42none]]>]]>" "^]]>]]>$" new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf set union 99" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO99none]]>]]>" "^]]>]]>$" new "netconf validate not ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationbad-element99errorLeafref validation failed" 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