#!/bin/bash # Auto-upgrade using draft-wang-netmod-module-revision-management # Ways of changes (operation-type) are: # create, delete, move, modify # In this example, example-a has the following changes: # - Create y, delete x, replace host-name, move z # example-b is completely obsoleted # 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.xml changelog=$dir/changelog.xml # Module revision changelog changelog2=$dir/changelog2.xml # From draft appendix exa01y=$dir/example-a@2017-12-01.yang exa20y=$dir/example-a@2017-12-20.yang exb20y=$dir/example-b@2017-12-20.yang # draft-wang-netmod-module-revision-management-01 # 3.2.1 and 4.1 example-a revision 2017-12-01 cat < $exa01y module example-a{ yang-version 1.1; namespace "urn:example:a"; prefix "a"; organization "foo."; contact "fo@example.com"; description "foo."; revision 2017-12-01 { description "Initial revision."; } container system { leaf a { type string; description "no change"; } leaf x { type string; description "delete"; } leaf host-name { type uint32; description "modify type"; } leaf z { description "move to alt"; type string; } } container alt { } } EOF # 3.2.1 and 4.1 example-a revision 2017-12-20 cat < $exa20y module example-a { yang-version 1.1; namespace "urn:example:a"; prefix "a"; organization "foo."; contact "fo@example.com"; description "foo."; revision 2017-12-20 { description "Create y, delete x, replace host-name, move z"; } revision 2017-12-01 { description "Initial revision."; } container system { leaf a { type string; description "no change"; } leaf host-name { type string; description "replace"; } leaf y { type string; description "create"; } } container alt { leaf z { description "move to alt"; type string; } } } EOF # 3.2.1 and 4.1 example-a revision 2017-12-20 cat < $exb20y module example-b { yang-version 1.1; namespace "urn:example:b"; prefix "b"; organization "foo."; contact "fo@example.com"; description "foo."; revision 2017-12-20 { description "Remove all"; } } EOF # Create failsafe db cat < $dir/failsafe_db Failsafe EOF # Create startup db revision example-a and example-b 2017-12-01 # this should be automatically upgraded to 2017-12-20 cat < $dir/startup_db 42 example-a 2017-12-01 urn:example:a example-b 2017-12-01 urn:example:b dont change me modify me remove me move me Obsolete EOF # Wanted new XML XML='dont change mei am modifiedcreatedmove me' # Create configuration cat < $cfg $cfg /usr/local/share/clixon $dir /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/example/backend /usr/local/var/$APPNAME/$APPNAME.pidfile $dir /usr/local/lib/xmldb/text.so true true $changelog /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME EOF # Changelog of example-a: cat < $changelog urn:example:b 2017-12-01 2017-12-20 0001 delete /b:system-b urn:example:a 2017-12-01 2017-12-20 0001 insert /a:system <y>created</y> 0002 delete /a:system/a:x 0003 replace /a:system/a:host-name <host-name>i am modified</host-name> 0004 move /a:system/a:z /a:alt EOF # Start new system from old datastore 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" sleep $RCWAIT new "kill old restconf daemon" sudo pkill -u www-data clixon_restconf new "start restconf daemon" start_restconf -f $cfg new "waiting" sleep $RCWAIT new "Check failsafe (work in progress)" new "Check running db content" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$XML]]>]]>$" new "Kill restconf daemon" stop_restconf 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 rm -rf $dir fi