From 932ca2e8ceed58a2e189677f43d279bdb64296a0 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 12 Mar 2019 09:56:09 +0100 Subject: [PATCH] Changed (startup) running mode so that startup_db is not overwritten. This changes the upgrade semantics for running mode which will have to be accounted for later. --- apps/backend/backend_main.c | 10 ++-- apps/backend/backend_startup.c | 2 +- apps/backend/backend_startup.h | 2 +- test/test_startup.sh | 83 ++++++++++++++-------------------- test/test_upgrade.sh | 17 +++---- 5 files changed, 51 insertions(+), 63 deletions(-) diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index c2cf2e60..3c441039 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -671,11 +671,15 @@ main(int argc, break; case SM_RUNNING: /* Use running as startup */ /* Copy original running to startup and treat as startup */ - if (xmldb_copy(h, "running", "startup") < 0) + if (xmldb_copy(h, "running", "tmp") < 0) goto done; - case SM_STARTUP: /* Fall through */ + ret = startup_mode_startup(h, "tmp", cbret); + if (ret2status(ret, &status) < 0) + goto done; + break; + case SM_STARTUP: /* Load and commit from startup */ - ret = startup_mode_startup(h, cbret); + ret = startup_mode_startup(h, "startup", cbret); if (ret2status(ret, &status) < 0) goto done; /* if status = STARTUP_INVALID, cbret contains info */ diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index c378d047..11780244 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -144,11 +144,11 @@ startup --+-------------------------------------> BROKEN XML */ int startup_mode_startup(clicon_handle h, + char *db, cbuf *cbret) { int retval = -1; int ret; - char *db = "startup"; /* [Delete and] create running db */ if (startup_db_reset(h, "running") < 0) diff --git a/apps/backend/backend_startup.h b/apps/backend/backend_startup.h index cd269d5b..01fc8fea 100644 --- a/apps/backend/backend_startup.h +++ b/apps/backend/backend_startup.h @@ -41,7 +41,7 @@ * Prototypes */ int startup_db_reset(clicon_handle h, char *db); -int startup_mode_startup(clicon_handle h, cbuf *cbret); +int startup_mode_startup(clicon_handle h, char *db, cbuf *cbret); int startup_extraxml(clicon_handle h, char *file, cbuf *cbret); int startup_failsafe(clicon_handle h); int startup_module_state(clicon_handle h, yang_spec *yspec); diff --git a/test/test_startup.sh b/test/test_startup.sh index 03f9d5a8..4a7835d3 100755 --- a/test/test_startup.sh +++ b/test/test_startup.sh @@ -32,56 +32,32 @@ cat < $cfg /usr/local/lib/xmldb/text.so 0 init + false EOF +# Create running-db containin the interface "run" +runvar='runex:ethtrue' + +# Create startup-db containing the interface "startup" +startvar='startupex:ethtrue' + +# extra +extravar='extraex:ethtrue' + # Create a pre-set running, startup and (extra) config. # The configs are identified by an interface called run, startup, extra. # Depending on startup mode (init, none, running, or startup) -# expect different output of an initial get-config +# expect different output of an initial get-config of running testrun(){ mode=$1 - expect=$2 + exprun=$2 # expected running_db after startup - # Create running-db containin the interface "run" - sudo rm -f $dir/running_db - cat < $dir/running_db - - - - run - ex:eth - - - -EOF - - # Create startup-db containin the interface "startup" - sudo rm -f $dir/startup_db - cat < $dir/startup_db - - - - startup - ex:eth - - - -EOF - - # Create extra xml containin the interface "extra" - sudo rm -f $dir/config - cat < $dir/config - - - - extra - ex:eth - - - -EOF + sudo rm -f $dir/*_db + echo "$runvar" > $dir/running_db + echo "$startvar" > $dir/startup_db + echo "$extravar" > $dir/extra_db if [ $BE -ne 0 ]; then # Bring your own backend # kill old backend (if any) @@ -90,18 +66,24 @@ EOF if [ $? -ne 0 ]; then err fi - new "start backend -f $cfg -s $mode -c $dir/config" - start_backend -s $mode -f $cfg -c $dir/config + new "start backend -f $cfg -s $mode -c $dir/extra_db" + start_backend -s $mode -f $cfg -c $dir/extra_db new "waiting" sleep $RCWAIT else - new "Restart backend as eg follows: -Ff $cfg -s $mode -c $dir/config # $BETIMEOUT s" + new "Restart backend as eg follows: -Ff $cfg -s $mode -c $dir/extra_db # $BETIMEOUT s" sleep $BETIMEOUT fi - new "Startup test for init mode: $mode" - expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$expect]]>]]>$" + new "Startup test for $mode mode, check running" + expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$exprun]]>]]>$" + new "Startup test for $mode mode, check candidate" + expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$exprun]]>]]>$" + + new "Startup test for $mode mode, check startup is untouched" + expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$startvar]]>]]>$" + new "Kill backend" # Check if premature kill pid=`pgrep -u root -f clixon_backend` @@ -112,12 +94,17 @@ EOF stop_backend -f $cfg } # testrun -testrun init 'extraex:ethtrue' +# Init mode: delete running and reload from scratch (just extra) +testrun init "$extravar" -testrun none 'runex:ethtrue' +# None mode: do nothing, running remains +testrun none "$runvar" +# Running mode: keep running but load also extra testrun running 'extraex:ethtruerunex:ethtrue' +# Startup mode: scratch running, load startup with extra on top testrun startup 'extraex:ethtruestartupex:ethtrue' -rm -rf $dir +echo $dir +#rm -rf $dir diff --git a/test/test_upgrade.sh b/test/test_upgrade.sh index a6f0b84e..1198a807 100755 --- a/test/test_upgrade.sh +++ b/test/test_upgrade.sh @@ -2,10 +2,6 @@ # 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" @@ -250,8 +246,8 @@ EOF runtest(){ modstate=$1 mode=$2 - expect=$3 - startup=$4 + exprun=$3 # Expected running + expstartup=$4 # Expected startup new "test params: -f $cfg" # Bring your own backend @@ -273,10 +269,10 @@ runtest(){ fi new "Get running" - expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$expect]]>]]>$" + expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$exprun]]>]]>$" new "Get startup" - expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$startup]]>]]>$" + expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$expstartup]]>]]>$" if [ $BE -ne 0 ]; then new "Kill backend" @@ -292,7 +288,6 @@ runtest(){ # Compatible == all yang modules match # runtest - new "1. Run without CLICON_XMLDB_MODSTATE ensure no modstate in datastore" (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; cp compat-valid.xml startup_db) @@ -320,6 +315,7 @@ fi new "3. 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) +(cd $dir; cp compat-valid.xml startup_db) # XXX runtest true running 'always workother text' 'always workother text' new "4. Load non-compat valid startup" @@ -335,7 +331,8 @@ runtest true startup 'always work' ' new "6. 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 true running 'always work' 'old versionalways workother textbla bla' +(cd $dir; cp non-compat-valid.xml startup_db) # XXX tmp +#runtest true running 'always work' 'old versionalways workother textbla bla' new "7. Load compatible invalid startup." (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases