#!/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 ${YANG_INSTALLDIR} $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/run/$APPNAME.sock /usr/local/var/run/$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"; } typedef ref1 { type leafref { path "../x"; require-instance true; } } typedef ref2 { type leafref { path "../y"; require-instance true; } } 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 zdecl { description "leafref union using declared types"; type union { type ref1; type ref2; } } 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_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "4299merge " "" "" new "netconf commit x,y" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf set union 42" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "42none" "" "" new "netconf validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf check config" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "429942" new "netconf set union 66" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "66none" "" "" new "netconf validate not ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "applicationbad-element66errorLeafref validation failed: No leaf 66 matching path ../y" "" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "]]>]]>" "" "" new "netconf set union id saab" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "ex:saabnone" "" "" new "netconf validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf set union idref zzz" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "ex:zzznone" "" "" new "netconf validate idref not ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "applicationoperation-failederrorIdentityref validation failed" "" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "]]>]]>" "" "" new "netconf set union id des" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "ex:desnone" "" "" new "netconf validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf set union x=42" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "42none" "" "" new "netconf validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf set union 99" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "99none" "" "" new "netconf validate not ok" expecteof_netconf "$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