#!/bin/bash # Upgrade a module by registering a manually programmed callback # The usecase is insipred by the ietf-interfaces upgrade from # 2014-05-08 to 2018-02-20. # That includes moving parts from interfaces-state to interfaces and then # deprecating the whole /interfaces-state tree. # A preliminary change list is in Appendix A of # 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/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 (2016) # if:interfaces/if:interface/ # 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) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example cfg=$dir/conf.xml if2014=$dir/interfaces@2014-05-08.yang if2018=$dir/interfaces@2018-02-20.yang # Original simplified version - note all is config to allow for storing in # datastore cat < $if2014 module interfaces{ yang-version 1.1; namespace "urn:example:interfaces"; prefix "if"; import ietf-yang-types { prefix yang; } revision 2014-05-08 { description "Initial revision."; reference "RFC 7223: A YANG Data Model for Interface Management"; } feature if-mib { description "This feature indicates that the device implements the IF-MIB."; reference "RFC 2863: The Interfaces Group MIB"; } container interfaces { description "Interface configuration parameters."; list interface { key "name"; leaf name { type string; } leaf description { type string; } leaf type { type string; mandatory true; } leaf link-up-down-trap-enable { if-feature if-mib; type enumeration { enum enabled; enum disabled; } } } } container interfaces-state { list interface { key "name"; leaf name { type string; } leaf admin-status { if-feature if-mib; type enumeration { enum up; enum down; enum testing; } mandatory true; } container statistics { leaf in-octets { type yang:counter64; } leaf in-unicast-pkts { type yang:counter64; } } } } } EOF cat < $if2018 module interfaces{ yang-version 1.1; namespace "urn:example:interfaces"; prefix "if"; import ietf-yang-types { prefix yang; } revision 2018-02-20 { description "Updated to support NMDA."; reference "RFC 8343: A YANG Data Model for Interface Management"; } revision 2014-05-08 { description "Initial revision."; reference "RFC 7223: A YANG Data Model for Interface Management"; } feature if-mib { description "This feature indicates that the device implements the IF-MIB."; reference "RFC 2863: The Interfaces Group MIB"; } container interfaces { description "Interface configuration parameters."; list interface { key "name"; leaf name { type string; } container docs{ description "Original description is wrapped and renamed"; leaf descr { type string; } } leaf type { type string; mandatory true; } leaf link-up-down-trap-enable { if-feature if-mib; type enumeration { enum enabled; enum disabled; } } leaf admin-status { if-feature if-mib; type enumeration { enum up; enum down; enum testing; } mandatory true; } container statistics { leaf in-octets { type decimal64{ fraction-digits 3; } } leaf in-unicast-pkts { type yang:counter64; } } } } } EOF # Create startup db revision from 2014-05-08 to be upgraded to 2018-02-20 # This is 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 # Create configuration cat < $cfg $cfg /usr/local/share/clixon interfaces:if-mib $dir /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/example/backend /usr/local/var/$APPNAME/$APPNAME.pidfile $dir true false /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME EOF # Start from startup and upgrade, check running testrun(){ runxml=$1 # -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 "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 running db content" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$runxml]]>]]>$" 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 rm -rf $dir fi