#!/usr/bin/env bash # Yang leafref + state tests # The difficulty here is a "leafref" in state data that references config-data. # Problem being that config-data from running needs to be mergedwith state data and filtered/cropped # correctly # # The YANG has two parts, one config part (sender-config) and one state part (sender-state) # The leafref in the sender-state part references a leaf in the sender-config part # Netconf tests are made to get state, state+config, using content attribute config/nonconfig/all # with different paths. # Using the -sS state capability of the main example, that is why CLICON_BACKEND_DIR is # /usr/local/lib/$APPNAME/backend so that the main backend plugins is included. # These tests require VALIDATE_STATE_XML to be set # 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 fstate=$dir/state.xml fyang=$dir/leafref.yang cat < $cfg $cfg $dir /usr/local/share/clixon $fyang /usr/local/lib/$APPNAME/backend /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock false /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME true EOF # NOTE prefix "example" used in module different from "ex" used in mport of that module cat < $fyang module leafref{ yang-version 1.1; namespace "urn:example:example"; prefix ex; list sender-config{ description "Main config of senders"; key name; leaf name{ type string; } } list sender-state{ description "State referencing configured senders"; config false; key ref; leaf ref{ type leafref { path "/ex:sender-config/ex:name"; } } } } EOF # This is state data written to file that backend reads from (on request) cat < $fstate x EOF new "test params: -f $cfg -- -sS $fstate" 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 -- -sS $fstate" start_backend -s init -f $cfg -- -sS $fstate new "waiting" wait_backend fi # Test top-level, default prefix, wrong leafref prefix and typedef path XML=$(cat < x EOF ) new "leafref config sender x" expecteof "$clixon_netconf -qf $cfg" 0 "$XML]]>]]>" '^]]>]]>$' new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" # Get path=/, state vs config new "netconf get / config+state" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^xx]]>]]>$' new "netconf get / state-only" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^x]]>]]>$' new "netconf get / config-only" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^x]]>]]>$' # Get path=/sender-state, state vs config new "netconf get /sender-state config+state" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^x]]>]]>$' new "netconf get /sender-state state-only" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^x]]>]]>$' new "netconf get /sender-state config-only" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^]]>]]>$' # Get path=/sender-config, state vs config new "netconf get /sender-config config+state" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^x]]>]]>$' new "netconf get /sender-config state-only" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^]]>]]>$' new "netconf get /sender-config config-only" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^x]]>]]>$' # Negative tests, # Double xmlns attribute cat < $fstate x EOF new "Merge same tree - check double xmlns attribute" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^x]]>]]>$' # Back to original cat < $fstate x EOF # delete x, add y XML=$(cat < x y EOF ) # Negative tests, start with remove x and and add y instead new "leafref config delete sender x add y" expecteof "$clixon_netconf -qf $cfg" 0 "$XML]]>]]>" '^]]>]]>$' new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" # Leafref wrong new "netconf get / config+state should fail" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^applicationoperation-failedxerrorLeafref validation failed: No leaf x matching path /ex:sender-config/ex:name. Internal error, state callback returned invalid XML]]>]]>$' new "netconf get / state-only should fail" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^applicationoperation-failedxerrorLeafref validation failed: No leaf x matching path /ex:sender-config/ex:name. Internal error, state callback returned invalid XML]]>]]>$' new "netconf get / config-only ok" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^y]]>]]>$' 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