From b10c3c57272ade542090180ea238085cd54a7109 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Thu, 28 Mar 2019 10:56:53 +0100 Subject: [PATCH] more upgrade-interfaces test cases --- doc/startup.md | 21 +-- lib/src/clixon_options.c | 2 +- test/test_upgrade_interfaces.sh | 242 +++++++++++++++++++++----------- 3 files changed, 174 insertions(+), 91 deletions(-) diff --git a/doc/startup.md b/doc/startup.md index 3354086b..921c0072 100644 --- a/doc/startup.md +++ b/doc/startup.md @@ -113,7 +113,7 @@ a set of current yang models that loads a datastore with old or even obsolete data. Note that this feature is only available if -[module-state](module-state) in the datastore is enabled. +[module-state](#module-state) in the datastore is enabled. If the module-state of the startup configuration does not match the module-state of the backend daemon, a set of _upgrade_ callbacks are @@ -153,7 +153,7 @@ One example of registering a "catch-all" upgrade: upgrade_callback_register(h, xml_changelog_upgrade, NULL, 0, 0, NULL); ``` -Another example are fine-grained stepwise upgrades of a singlemodule [upgrade example](#example-upgrade): +Another example are fine-grained stepwise upgrades of a single module [upgrade example](#example-upgrade): ``` upgrade_callback_register(h, upgrade_2016, "urn:example:interfaces", 20140508, 20160101, NULL); @@ -175,20 +175,19 @@ When Clixon loads a startup datastore with outdated modules, the matching upgrade callbacks will be called. Note the following: -* Upgrade callbacks will _not_ be called for data that is up-to-date with the current system -* Upgrade callbacks will _not_ be called if there is no module-state in the datastore, or if module-state support is disabled. +* Upgrade callbacks _will_ _not_ be called for data that is up-to-date with the current system +* Upgrade callbacks _will_ _not_ be called if there is no module-state in the datastore, or if module-state support is disabled. * Upgrade callbacks _will_ be called if the datastore contains a version of a module that is older than the module loaded in Clixon. * Upgrade callbacks _will_ also be called if the datastore contains a version of a module that is not present in Clixon - an obsolete module. -Re-using the previous stepwise example, if a datastore is loaded based on revision 20140508 by a system supporting revision 20180220, the following two callbacks will be made: +Re-using the previous stepwise example, if a datastore is loaded based on revision 20140508 by a system supporting revision 2018-02-20, the following two callbacks are made: ``` upgrade_2016(h, , "urn:example:interfaces", 20140508, 20180220, NULL, cbret); upgrade_2018(h, , "urn:example:interfaces", 20140508, 20180220, NULL, cbret); ``` Note that the example shown is a template for an upgrade function. It gets the nodes of an yang module given by `namespace` and the -(outdated) `from` revision, and iterates through them. Actual -upgrading code is in [the example](../example/example_backend.c). +(outdated) `from` revision, and iterates through them. If no action is made by the upgrade calback, and thus the XML is not upgraded, the next step is XML/Yang validation. @@ -202,18 +201,22 @@ configuration. ### Example upgrade -[The example](../example/example_backend.c) and [test](../test/test_upgrade_interfaces.sh) shos the code for upgrading of an interface module. The example is inspired by the ietf-interfaces module that made a subset of the upgrades shown in the examples. +The example and shows the code for upgrading of an interface module. The example is inspired by the ietf-interfaces module that made a subset of the upgrades shown in the examples. The code is split in two steps. The `upgrade_2016` callback does the following transforms: * Move /if:interfaces-state/if:interface/if:admin-status to /if:interfaces/if:interface/ * Move /if:interfaces-state/if:interface/if:statistics to if:interfaces/if:interface/ * Rename /interfaces/interface/description to /interfaces/interface/descr -While the `upgrade_2018` callback does the following transforms: +The `upgrade_2018` callback does the following transforms: * Delete /if:interfaces-state * Wrap /interfaces/interface/descr to /interfaces/interface/docs/descr * Change type /interfaces/interface/statistics/in-octets to decimal64 and divide all values with 1000 +Please consult the `upgrade_2016` and `upgrade_2018` functions in [the +example](../example/example_backend.c) and +[test](../test/test_upgrade_interfaces.sh) for more details. + ## Extra XML If the Yang validation succeeds and the startup configuration has been committed to the running database, a user may add "extra" XML. diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index 6862605f..e16f97ff 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -419,7 +419,7 @@ clicon_option_str_set(clicon_handle h, * @endcode * Note that -1 can be both error and value. * This means that it should be used together with clicon_option_exists() and - * supply a defualt value as shown in the example. + * supply a default value as shown in the example. */ int clicon_option_int(clicon_handle h, diff --git a/test/test_upgrade_interfaces.sh b/test/test_upgrade_interfaces.sh index 3b641eb6..3bb2ed7f 100755 --- a/test/test_upgrade_interfaces.sh +++ b/test/test_upgrade_interfaces.sh @@ -8,16 +8,15 @@ # draft-wang-netmod-module-revision-management-01 # The example here is simplified and also extended. # It has also been broken up into two parts to test a series of upgrades. -# These are the operations (authentic): -# Move /if:interfaces-state/if:interface/if:admin-status to +# These are the operations (authentic move/delete are from ietf-interfaces): +# Move /if:interfaces-state/if:interface/if:admin-status to (2016) # /if:interfaces/if:interface/ -# Move /if:interfaces-state/if:interface/if:statistics to +# Move /if:interfaces-state/if:interface/if:statistics to (2016) # if:interfaces/if:interface/ -# Delete /if:interfaces-state -# These are extra added for test: -# Rename /interfaces/interface/description to /interfaces/interface/descr -# Wrap /interfaces/interface/descr to /interfaces/interface/docs/descr -# Change type /interfaces/interface/statistics/in-octets to decimal64 and divide all values with 1000 +# Delete /if:interfaces-state (2018) +# Rename /interfaces/interface/description to /interfaces/interface/descr (2016) +# Wrap /interfaces/interface/descr to /interfaces/interface/docs/descr (2018) +# Change type /interfaces/interface/statistics/in-octets to decimal64 and divide all values with 1000 (2018) # # Magic line must be first in script (see README.md) @@ -185,9 +184,8 @@ module interfaces{ } EOF - -# Create startup db revision example-a and example-b 2017-12-01 -# this should be automatically upgraded to 2017-12-20 +# Create startup db revision from 2014-05-08 to be upgraded to 2018-02-20 +# This is 2014 syntax cat < $dir/startup_db @@ -230,41 +228,6 @@ cat < $dir/startup_db EOF -# Wanted new XML -# Note interface e2 is not moved -cat < $dir/wanted - - - 42 - - interfaces - 2018-02-20 - urn:example:interfaces - - - - - e0 - eth - up - First interface - - 54326.432 - 8458765 - - - - e1 - eth - down - - - -EOF - -XML='e0First interfaceethup54326.4328458765e1ethdown' - - # Create configuration cat < $cfg @@ -285,49 +248,166 @@ cat < $cfg EOF -# Start new system from old datastore -mode=startup +# Start from startup and upgrade, check running +testrun(){ + runxml=$1 -# -u means trigger example upgrade -new "test params: -s $mode -f $cfg -- -u" -# 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 + # -u means trigger example upgrade + new "test params: -s startup -f $cfg -- -u" + # 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 "start backend -s $mode -f $cfg -- -u" - start_backend -s $mode -f $cfg -- -u -fi -new "waiting" -sleep $RCWAIT + new "waiting" + sleep $RCWAIT -new "kill old restconf daemon" -sudo pkill -u www-data clixon_restconf + new "kill old restconf daemon" + sudo pkill -u www-data clixon_restconf -new "start restconf daemon" -start_restconf -f $cfg + new "start restconf daemon" + start_restconf -f $cfg -new "waiting" -sleep $RCWAIT + new "waiting" + sleep $RCWAIT -new "Check running db content" -expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$XML]]>]]>$" + new "Check running db content" + expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$runxml]]>]]>$" -new "Kill restconf daemon" -stop_restconf + 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 + fi +} + +XML='e0First interfaceethup54326.4328458765e1ethdown' + +new "1. Upgrade from 2014 to 2018-02-20" +testrun "$XML" + +# This is "2016" syntax +cat < $dir/startup_db + + + 42 + + interfaces + 2016-01-01 + urn:example:interfaces + + + + + e0 + up + eth + First interface + + 54326432 + 8458765 + + + + e1 + eth + down + + + + + e0 + down + + 946743234 + 218347 + + + + e1 + up + + + e2 + testing + + + +EOF + +# 2. Upgrade from intermediate 2016-01-01 to 2018-02-20 +new "2. Upgrade from intermediate 2016-01-01 to 2018-02-20" +testrun "$XML" + +# Again 2014 syntax +cat < $dir/startup_db + + + 42 + + interfaces + 2014-05-08 + urn:example:interfaces + + + + + e0 + eth + First interface + + + e1 + eth + + + + + e0 + up + + 54326432 + 8458765 + + + + e1 + down + + + e2 + testing + + + + +EOF +rm $if2018 +# Original XML +XML='e0First interfaceethe1ethe0up543264328458765e1downe2testing' + +new "3. No 2018 (upgrade) model -> dont trigger upgrade" +testrun "$XML" + +#rm $if2014 +#new "4. No model at all" +#testrun "$XML" 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 +