#!/usr/bin/env 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 OLDDATE=0814-01-28 # This is alphabeticaly after 2018-12-02 NEWDATE=2018-12-02 cfg=$dir/conf_yang.xml fyang1=$dir/$APPNAME@2018-12-02.yang fyang2=$dir/$APPNAME@$OLDDATE.yang fyang3=$dir/other.yang # 1st variant of the example module cat < $fyang1 module example{ prefix ex; namespace "urn:example:clixon"; revision $NEWDATE; revision $OLDDATE; leaf newex{ type string; } } EOF # 2nd variant of the same example module cat < $fyang2 module example{ prefix ex; namespace "urn:example:clixon"; revision $OLDDATE; leaf oldex{ type string; } } EOF # Other module cat < $fyang3 module other{ prefix oth; namespace "urn:example:clixon2"; revision $NEWDATE; leaf other{ type string; } } EOF #--------------------------------- new "1. Load module as file" cat < $cfg $cfg $dir ${YANG_INSTALLDIR} $fyang1 /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME 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 "1. Set newex" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" new "Set oldex should fail (since oldex is in old revision and only the new is loaded)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementoldexerrorFailed to find YANG spec of XML node: oldex with parent: config in namespace: urn:example:clixon" new "Set other should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementothererrorFailed to find YANG spec of XML node: other with parent: config in namespace: urn:example:clixon2" 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 sudo pkill -u root -f clixon_backend fi #-------------------------------------- new "2. Load old module as file" cat < $cfg $cfg $dir ${YANG_INSTALLDIR} $fyang2 /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME EOF if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg" # start new backend start_backend -s init -f $cfg fi new "wait backend" wait_backend new "Set oldex" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" new "Set newex should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementnewexerrorFailed to find YANG spec of XML node: newex with parent: config in namespace: urn:example:clixon" new "Set other should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementothererrorFailed to find YANG spec of XML node: other with parent: config in namespace: urn:example:clixon2" 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 sudo pkill -u root -f clixon_backend fi #-------------------------------------- new "3. Load module with no revision" cat < $cfg $cfg $dir ${YANG_INSTALLDIR} example /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi new "wait backend" wait_backend new "Set newex" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" new "Set oldex should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementoldexerrorFailed to find YANG spec of XML node: oldex with parent: config in namespace: urn:example:clixon" new "Set other should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementothererrorFailed to find YANG spec of XML node: other with parent: config in namespace: urn:example:clixon2" 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 stop_backend -f $cfg sudo pkill -u root -f clixon_backend fi #-------------------------------------- new "4. Load module with old revision" cat < $cfg $cfg $dir ${YANG_INSTALLDIR} example $OLDDATE /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi new "wait backend" wait_backend new "Set oldex" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" new "Set newex should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementnewexerrorFailed to find YANG spec of XML node: newex with parent: config in namespace: urn:example:clixon" new "Set other should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementothererrorFailed to find YANG spec of XML node: other with parent: config in namespace: urn:example:clixon2" 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 sudo pkill -u root -f clixon_backend fi #-------------------------------------- new "5. Load dir" cat < $cfg $cfg $dir ${YANG_INSTALLDIR} $dir /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi new "wait backend" wait_backend new "Set newex" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" new "Set oldex should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementoldexerrorFailed to find YANG spec of XML node: oldex with parent: config in namespace: urn:example:clixon" new "Set other" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" 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 sudo pkill -u root -f clixon_backend fi #-------------------------------------- new "6. Load dir override with file" cat < $cfg $cfg $dir ${YANG_INSTALLDIR} $dir $fyang2 /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi new "wait backend" wait_backend new "Set oldex" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" new "Set newex should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementnewexerrorFailed to find YANG spec of XML node: newex with parent: config in namespace: urn:example:clixon" new "Set other" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" 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 sudo pkill -u root -f clixon_backend fi #-------------------------------------- new "7. Load dir override with module + revision" cat < $cfg $cfg $dir ${YANG_INSTALLDIR} $dir example $OLDDATE /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi new "wait backend" wait_backend new "Set oldex" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" new "Set newex should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementnewexerrorFailed to find YANG spec of XML node: newex with parent: config in namespace: urn:example:clixon" new "Set other" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" 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 sudo pkill -u root -f clixon_backend fi #-------------------------------------- new "8. Load module w new revision overrided by old file" cat < $cfg $cfg $dir ${YANG_INSTALLDIR} $fyang2 example $NEWDATE /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi new "wait backend" wait_backend new "Set oldex" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "" new "Set newex should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementnewexerrorFailed to find YANG spec of XML node: newex with parent: config in namespace: urn:example:clixon" new "Set other should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "str" "" "applicationunknown-elementothererrorFailed to find YANG spec of XML node: other with parent: config in namespace: urn:example:clixon2" 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 sudo pkill -u root -f clixon_backend rm -rf $dir fi new "endtest" endtest