#!/usr/bin/env bash # Test of the general-purpose (raw) upgrade mechanism. # Input is a startup db without mod-state info. # It has wrong namespace bindings and needs to remove some nodes # Output is a valid config with correct namespaces and removed nods # The code for this is in the main example backend plugin. # 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 fyangA=$dir/A.yang fyangB=$dir/B.yang # Create configuration cat < $cfg $cfg ietf-netconf:startup ${YANG_INSTALLDIR} $dir /usr/local/var/run/$APPNAME.sock /usr/local/lib/$APPNAME/backend /usr/local/var/run/$APPNAME.pidfile $dir true false /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME EOF # Yang module A (base) cat < $fyangA module A{ prefix a; namespace "urn:example:a"; revision 2020-02-11; container x { container y { } } list remove_me { key k; leaf k { type string; } } } EOF # Yang module B (augments A) cat < $fyangB module B{ prefix b; namespace "urn:example:b"; import A { prefix "a"; } revision 2020-02-11; augment "/a:x/a:y" { container z { leaf w { type string; } } } } EOF # permission kludges sudo touch $dir/startup_db sudo chmod 666 $dir/startup_db # This is how it should look after repair, using prefixes AFTER=$(cat <foo EOF ) function testrun(){ new "test params: -f $cfg -- -U" # -U : upgrade # Bring your own backend if [ $BE -ne 0 ]; then # kill old backend (if any) new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s startup -f $cfg -- -U" start_backend -s startup -f $cfg -- -U fi new "wait backend" wait_backend new "netconf get config" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$AFTER" 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 } # end testrun # Create startup db of "old" db with incorrect augment namespace tagging # without modstate cat < $dir/startup_db <${DATASTORE_TOP}> foo This node is obsolete this too EOF new "general-purpose upgrade without modstate" testrun rm -rf $dir new "endtest" endtest