#!/bin/bash # Load yang files. Test the different options # CLICON_YANG_MODULE_DIR vs CLICON_YANG_MAIN_FILE vs CLICON_YANG_MAIN_DIR # as well as revisions # Test is made by having different config files and then try to set configure # options available in specific modules # 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 fyang1=$dir/$APPNAME@2018-12-02.yang fyang2=$dir/$APPNAME@2018-01-01.yang fyang3=$dir/other.yang # 1st variant of the example module cat < $fyang1 module example{ prefix ex; revision 2018-12-02; namespace "urn:example:clixon"; leaf newex{ type string; } } EOF # 2nd variant of the same example module cat < $fyang2 module example{ prefix ex; revision 2018-01-01; namespace "urn:example:clixon"; leaf oldex{ type string; } } EOF # Other module cat < $fyang3 module other{ prefix oth; revision 2018-01-01; namespace "urn:example:clixon2"; leaf other{ type string; } } EOF #--------------------------------- new "1. Load module as file" cat < $cfg $cfg $dir /usr/local/share/clixon $IETFRFC $fyang1 /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME 1 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 new "waiting" sleep $RCWAIT fi new "1. Set newex" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' new "Set oldex should fail (since oldex is in old revision and only the new is loaded)" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementoldexerrorUnassigned yang spec]]>]]>$' new "Set other should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementothererrorUnassigned yang spec]]>]]>$' 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 sudo pkill -u root -f clixon_backend #-------------------------------------- new "2. Load old module as file" cat < $cfg $cfg $dir /usr/local/share/clixon $IETFRFC $fyang2 /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME 1 EOF new "start backend -s init -f $cfg" # start new backend start_backend -s init -f $cfg new "waiting" sleep $RCWAIT new "Set oldex" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' new "Set newex should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementnewexerrorUnassigned yang spec]]>]]>$' new "Set other should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementothererrorUnassigned yang spec]]>]]>$' 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 sudo pkill -u root -f clixon_backend #-------------------------------------- new "3. Load module with no revision" cat < $cfg $cfg $dir /usr/local/share/clixon $IETFRFC example /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so EOF new "start backend -s init -f $cfg" start_backend -s init -f $cfg new "waiting" sleep $RCWAIT new "Set newex" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' new "Set oldex should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementoldexerrorUnassigned yang spec]]>]]>$' new "Set other should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementothererrorUnassigned yang spec]]>]]>$' new "Kill backend" # Check if premature kill pid=`pgrep -u root -f clixon_backend` if [ -z "$pid" ]; then err "backend already dead" fi stop_backend -f $cfg sudo pkill -u root -f clixon_backend #-------------------------------------- new "4. Load module with old revision" cat < $cfg $cfg $dir /usr/local/share/clixon $IETFRFC example 2018-01-01 /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so EOF new "start backend -s init -f $cfg" start_backend -s init -f $cfg new "waiting" sleep $RCWAIT new "Set oldex" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' new "Set newex should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementnewexerrorUnassigned yang spec]]>]]>$' new "Set other should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementothererrorUnassigned yang spec]]>]]>$' 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 sudo pkill -u root -f clixon_backend #-------------------------------------- new "5. Load dir" cat < $cfg $cfg $dir /usr/local/share/clixon $IETFRFC $dir /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so EOF new "start backend -s init -f $cfg" start_backend -s init -f $cfg new "waiting" sleep $RCWAIT new "Set newex" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' new "Set oldex should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementoldexerrorUnassigned yang spec]]>]]>$' new "Set other" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' 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 sudo pkill -u root -f clixon_backend #-------------------------------------- new "6. Load dir override with file" cat < $cfg $cfg $dir /usr/local/share/clixon $IETFRFC $dir $fyang2 /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so EOF new "start backend -s init -f $cfg" start_backend -s init -f $cfg new "waiting" sleep $RCWAIT new "Set oldex" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' new "Set newex should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementnewexerrorUnassigned yang spec]]>]]>' new "Set other" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' 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 sudo pkill -u root -f clixon_backend #-------------------------------------- new "7. Load dir override with module + revision" cat < $cfg $cfg $dir /usr/local/share/clixon $IETFRFC $dir example 2018-01-01 /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so EOF new "start backend -s init -f $cfg" start_backend -s init -f $cfg new "waiting" sleep $RCWAIT new "Set oldex" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' new "Set newex should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementnewexerrorUnassigned yang spec]]>]]>$' new "Set other" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' 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 sudo pkill -u root -f clixon_backend #-------------------------------------- new "8. Load module w new revision overrided by old file" cat < $cfg $cfg $dir /usr/local/share/clixon $IETFRFC $fyang2 example 2018-12-02 /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so EOF new "start backend -s init -f $cfg" start_backend -s init -f $cfg new "waiting" sleep $RCWAIT new "Set oldex" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' new "Set newex should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementnewexerrorUnassigned yang spec]]>]]>$' new "Set other should fail" expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationunknown-elementothererrorUnassigned yang spec]]>]]>$' 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 sudo pkill -u root -f clixon_backend rm -rf $dir