#!/bin/bash # Starting clixon with outdated (or not) modules # This relieas on storing RFC7895 YANG Module Library modules-state info # in the datastore (or XML files?) # There is also a: Factory default Setting: # draft-wu-netconf-restconf-factory-restore-03 # And: A YANG Data Model for module revision management: # draft-wang-netmod-module-revision-management-01 # The test is made with three Yang models A, B and C as follows: # Yang module A has revisions "814-01-28" and "2019-01-01" # Yang module B has only revision "2019-01-01" # Yang module C has only revision "2019-01-01" # The system is started YANG modules: # A revision "2019-01-01" # B revision "2019-01-01" # The (startup) configuration XML file has: # A revision "814-01-28"; # B revision "2019-01-01" # C revision "2019-01-01" # Which means the following: # A has an obsolete version # containing a0 which has been removed, and a1 which is OK # B has a compatible version # C is not present in the system APPNAME=example # include err() and new() functions and creates $dir . ./lib.sh cfg=$dir/conf_yang.xml fyangA0=$dir/A@814-01-28.yang fyangA1=$dir/A@2019-01-01.yang fyangB=$dir/B@2019-01-01.yang # Yang module A revision "814-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; revision 814-01-28; namespace "urn:example:a"; leaf a0{ type string; } leaf a1{ type string; } } EOF # Yang module A revision "2019-01-01" cat < $fyangA1 module A{ prefix a; revision 2019-01-01; revision 814-01-28; namespace "urn:example:a"; /* leaf a0 has been removed */ leaf a1{ description "exists in both versions"; type string; } leaf a2{ description "has been added"; type string; } } EOF # Yang module B revision "2019-01-01" cat < $fyangB module B{ prefix b; revision 2019-01-01; namespace "urn:example:b"; leaf b{ type string; } } EOF # Yang module C revision "2019-01-01" (note not written to yang dir) cat < /dev/null module C{ prefix c; revision 2019-01-01; namespace "urn:example:c"; leaf c{ type string; } } EOF # 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 /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME EOF # Create failsafe db cat < $dir/failsafe_db always work EOF # Create compatible startup db # startup config XML with following cat < $dir/compat-valid.xml 42 A 2019-01-01 urn:example:a B 2019-01-01 urn:example:b always work other text EOF # Create compatiblae startup db # startup config XML with following cat < $dir/compat-invalid.xml 42 A 2019-01-01 urn:example:a B 2019-01-01 urn:example:b old version always work other text bla bla EOF # Create non-compat valid startup db # startup config XML with following (A obsolete, B OK, C lacking) # But XML is OK cat < $dir/non-compat-valid.xml 42 A 814-01-28 urn:example:a B 2019-01-01 urn:example:b C 2019-01-01 urn:example:c always work other text EOF # Create non-compat startup db # startup config XML with following (A obsolete, B OK, C lacking) cat < $dir/non-compat-invalid.xml 42 A 814-01-28 urn:example:a B 2019-01-01 urn:example:b C 2019-01-01 urn:example:c old version always work other text bla bla EOF # Compatible startup with syntax errors cat < $dir/compat-err.xml 42 A 2019-01-01 urn:example:a B 2019-01-01 urn:example:b <always work other text EOF # Start system in $mode with existing (old) configuration in $db # mode is one of: init, none, running, or startup # db is one of: running_db or startup_db runtest(){ mode=$1 expect=$2 startup=$3 new "test params: -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 new backend sudo $clixon_backend -s $mode -f $cfg -D $DBG if [ $? -ne 0 ]; then err fi else new "Restart backend as eg follows: -Ff $cfg -s $mode ($BETIMEOUT s)" sleep $BETIMEOUT fi new "Get running" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$expect]]>]]>$" new "Get startup" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$startup]]>]]>$" 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 } # Compatible == all yang modules match # runtest new "1. Load compatible valid startup (all OK)" (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; cp compat-valid.xml startup_db) runtest startup 'always workother text' 'always workother text' new "2. Load compatible running valid running (rest of tests are startup)" (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; cp compat-valid.xml running_db) runtest running 'always workother text' 'always workother text' new "3. Load non-compat valid startup" (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; cp non-compat-valid.xml startup_db) runtest startup 'always workother text' 'always workother text' new "4. Load non-compat invalid startup. Enter failsafe, startup invalid." (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; cp non-compat-invalid.xml startup_db) runtest startup 'always work' 'old versionalways workother textbla bla' new "5. Load non-compat invalid running. Enter failsafe, startup invalid." (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; cp non-compat-invalid.xml running_db) runtest running 'always work' 'old versionalways workother textbla bla' new "6. Load compatible invalid startup." (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; cp compat-invalid.xml startup_db) runtest startup 'always work' 'old versionalways workother textbla bla' new "7. Load non-compat startup. Syntax fail, enter failsafe, startup invalid" (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; cp compat-err.xml startup_db) runtest startup 'always work' 'applicationoperation-failederrorread registry' if [ $BE -ne 0 ]; then rm -rf $dir fi