#!/usr/bin/env bash # Load startup with non-compatible and invalid module A with rev 0814-01-28 # Go into fail-safe with invalid startup # Repair by copying startup into candidate, editing and commit it # 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 fyangA0=$dir/A@0814-01-28.yang fyangA1=$dir/A@2019-01-01.yang OLDXML='old version' SAMEXML='always work' NEWXML='new version' # Yang module A revision "0814-01-28" # Note that this Yang model will exist in the DIR but will not be loaded # by the system. Just here for reference # XXX: Maybe it should be loaded and used in draft-wu? cat < $fyangA0 module A{ prefix a; namespace "urn:example:a"; revision 0814-01-28; leaf a0{ type string; } leaf a1{ type string; } } EOF # Yang module A revision "2019-01-01" cat < $fyangA1 module A{ prefix a; namespace "urn:example:a"; revision 2019-01-01; revision 0814-01-28; /* leaf a0 has been removed */ leaf a1{ description "exists in both versions"; type string; } leaf a2{ description "has been added"; type string; } } EOF # Create configuration cat < $cfg $cfg ietf-netconf:startup ${YANG_INSTALLDIR} $dir $dir /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/example/backend /usr/local/var/$APPNAME/$APPNAME.pidfile $dir true /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME EOF # Create failsafe db cat < $dir/failsafe_db <${DATASTORE_TOP}> $SAMEXML EOF # Create non-compat startup db # startup config XML with following (A obsolete, B OK, C lacking) cat < $dir/non-compat-invalid.xml <${DATASTORE_TOP}> 42 default A 0814-01-28 urn:example:a $OLDXML $SAMEXML EOF (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; cp non-compat-invalid.xml startup_db) mode=startup new "test params: -s $mode -f $cfg" # 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 $mode -f $cfg" start_backend -s $mode -f $cfg fi new "waiting" wait_backend new "Check running db content is failsafe" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$SAMEXML" new "copy startup->candidate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Check candidate db content is startup" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$OLDXML$SAMEXML" # Note you cannot edit invalid XML since a0 lacks namespace new "Put new version into candidate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$NEWXML$SAMEXML" "" "" new "Check candidate db content is updated" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$SAMEXML$NEWXML" new "commit to running" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Check running db content is updated" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$SAMEXML$NEWXML" 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 rm -rf $dir new "endtest" endtest