#!/usr/bin/env bash # Test of CLICON_XMLDB_UPGRADE_CHECKOLD where original config in an upgrade scenario is tested, # not just current after upgrade # Assume read a config from startup of module A@2016 to be upgraded to A@2021 using auto-upgrade # Using CLICON_XMLDB_UPGRADE_CHECKOLD=true try all variations of: # oldyang: A@2016 exists or not # modstate: startupdb has correct modstate or not # xmlok: startdb has the right "old" syntax or not "wrong" # These are 8 combinations. Only one is right, others give some variants of error messages # XXX remains to check all cases with CLICON_XMLDB_UPGRADE_CHECKOLD = false # 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/A@2016-01-01.yang fyang2=$dir/A@2021-01-01.yang changelog=$dir/changelog.xml # Module revision changelog # Create configuration cat < $cfg $cfg ietf-netconf:startup /usr/local/share/clixon $dir /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/example/backend /usr/local/var/$APPNAME/$APPNAME.pidfile true $changelog $dir true /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME EOF # New yang cat < $fyang2 module A{ prefix a; revision 2021-01-01; namespace "urn:example:a"; container upgraded{ } } EOF # Changelog of example-a: cat < $changelog urn:example:a 2016-01-01 2021-01-01 0 rename /a:old "upgraded" EOF # Arguments: # 1: expect return xml function testrun(){ checkold=$1 expectxml=$2 new "test params: -f $cfg" new "start backend -D $DBG -s startup -f $cfg -q -l o" expectpart "$(sudo $clixon_backend -D $DBG -o CLICON_XMLDB_UPGRADE_CHECKOLD=$checkold -s startup -f $cfg -q -l e 2>&1)" 0 "$expectxml" } # kill old backend (if any) new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi let j=1 for checkold in true; do # XXX remains to check all cases with CLICON_XMLDB_UPGRADE_CHECKOLD = false for oldyang in true false; do if $oldyang; then # create old yang cat < $fyang1 module A{ prefix a; revision 2016-01-01; namespace "urn:example:a"; container old{ } } EOF else rm -f $fyang1 fi for modstate in true false; do if $modstate; then modstatestr="42A2016-01-01urn:example:a" else modstatestr="" fi for xml in true false; do if $xml; then xmltag="old" expectxml="Failed to find YANG spec of XML node: $xmltag with parent: config in namespace: urn:example:a" if $oldyang; then if $modstate; then expectxml="" fi elif $modstate; then expectxml="Internal error: No yang files found matching \"A@2016-01-01\" in the list of CLICON_YANG_DIRs" fi else # xml false xmltag="wrong" expectxml="Failed to find YANG spec of XML node: $xmltag with parent: config in namespace: urn:example:a" if ! $oldyang; then if $modstate; then expectxml="Internal error: No yang files found matching \"A@2016-01-01\" in the list of CLICON_YANG_DIRs" fi fi fi cat < $dir/startup_db <${DATASTORE_TOP}> $modstatestr <$xmltag xmlns="urn:example:a"/> EOF # Here is actual call new "$j. checkold:$checkold oldyang:$oldyang modstate:$modstate xmlok:$xml" testrun "$checkold" "$expectxml" let j++ done done done done rm -rf $dir unset j unset xml unset xmltag unset oldyang unset modstate unset modstatestr unset fyang1 unset fyang2 new "endtest" endtest