#!/usr/bin/env bash # Test quit startup after upgrade (-q) functionality # The yang is from test_upgrade_interfaces and the upgrade code # is implemented in the main example # The test is just having 2014 xml syntax in file and the backend printing the upgraded # syntax to stdout # The output syntax is datastore syntax, as a running db would have looked like # Note that the admin and stats field are non-config in the original, not here # 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 # Create configuration cat < $cfg $cfg ietf-netconf:startup ${YANG_INSTALLDIR} interfaces:if-mib $dir /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/example/backend /usr/local/var/$APPNAME/$APPNAME.pidfile $dir true false false true /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME EOF # 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"; } leaf foo{ description "Should not appear"; type string; default "bar"; } container interfaces { description "Interface configuration parameters."; list interface { key "name"; leaf name { type string; } leaf description { type string; } leaf foo{ description "Should not appear"; type string; default "bar"; } 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"; } leaf foo{ description "Should not appear"; type string; default "fie"; } container interfaces { description "Interface configuration parameters."; list interface { key "name"; leaf name { type string; } leaf foo{ description "Should not appear"; type string; default "bar"; } 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 <${DATASTORE_TOP}> 42 interfaces 2014-05-08 urn:example:interfaces e0 eth First interface e1 eth e0 up 54326432 8458765 e1 down e2 testing EOF # This is 2014 syntax cat < $dir/startup_db <${DATASTORE_TOP}> 42 interfaces 2014-05-08 urn:example:interfaces e0 eth First interface e1 eth e0 up 54326432 8458765 e1 down e2 testing EOF MODSTATE1="0clixon-lib${CLIXON_LIB_REV}http://clicon.org/lib" MODSTATE2='interfaces2018-02-20urn:example:interfaces' XML='e0First interfaceethup54326.4328458765e1ethdown' ALL="<${DATASTORE_TOP}>$MODSTATE$XML" # -u means trigger example upgrade # 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 -q -- -u" output=$(sudo $clixon_backend -F -D $DBG -s startup -f $cfg -q -- -u) new "check modstate1" match=$(echo "$output" | grep --null -o "$MODSTATE1") if [ -z "$match" ]; then err "$MODSTATE1" "$output" fi new "check modstate" match=$(echo "$output" | grep --null -o "$MODSTATE2") if [ -z "$match" ]; then err "$MODSTATE2" "$output" fi new "check xml" match=$(echo "$output" | grep --null -o "$XML") if [ -z "$match" ]; then err "$XML" "$output" fi rm -rf $dir new "endtest" endtest