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.
This commit is contained in:
Olof hagsand 2019-03-12 09:56:09 +01:00
parent b54e6c1cc0
commit 932ca2e8ce
5 changed files with 51 additions and 63 deletions

View file

@ -671,11 +671,15 @@ main(int argc,
break; break;
case SM_RUNNING: /* Use running as startup */ case SM_RUNNING: /* Use running as startup */
/* Copy original running to startup and treat 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; 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 */ /* Load and commit from startup */
ret = startup_mode_startup(h, cbret); ret = startup_mode_startup(h, "startup", cbret);
if (ret2status(ret, &status) < 0) if (ret2status(ret, &status) < 0)
goto done; goto done;
/* if status = STARTUP_INVALID, cbret contains info */ /* if status = STARTUP_INVALID, cbret contains info */

View file

@ -144,11 +144,11 @@ startup --+-------------------------------------> BROKEN XML
*/ */
int int
startup_mode_startup(clicon_handle h, startup_mode_startup(clicon_handle h,
char *db,
cbuf *cbret) cbuf *cbret)
{ {
int retval = -1; int retval = -1;
int ret; int ret;
char *db = "startup";
/* [Delete and] create running db */ /* [Delete and] create running db */
if (startup_db_reset(h, "running") < 0) if (startup_db_reset(h, "running") < 0)

View file

@ -41,7 +41,7 @@
* Prototypes * Prototypes
*/ */
int startup_db_reset(clicon_handle h, char *db); 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_extraxml(clicon_handle h, char *file, cbuf *cbret);
int startup_failsafe(clicon_handle h); int startup_failsafe(clicon_handle h);
int startup_module_state(clicon_handle h, yang_spec *yspec); int startup_module_state(clicon_handle h, yang_spec *yspec);

View file

@ -32,56 +32,32 @@ cat <<EOF > $cfg
<CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN> <CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN>
<CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING> <CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING>
<CLICON_STARTUP_MODE>init</CLICON_STARTUP_MODE> <CLICON_STARTUP_MODE>init</CLICON_STARTUP_MODE>
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
</clixon-config> </clixon-config>
EOF EOF
# Create running-db containin the interface "run"
runvar='<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>run</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces>'
# Create startup-db containing the interface "startup"
startvar='<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>startup</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces>'
# extra
extravar='<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>extra</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces>'
# Create a pre-set running, startup and (extra) config. # Create a pre-set running, startup and (extra) config.
# The configs are identified by an interface called run, startup, extra. # The configs are identified by an interface called run, startup, extra.
# Depending on startup mode (init, none, running, or startup) # 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(){ testrun(){
mode=$1 mode=$1
expect=$2 exprun=$2 # expected running_db after startup
# Create running-db containin the interface "run" sudo rm -f $dir/*_db
sudo rm -f $dir/running_db echo "<config>$runvar</config>" > $dir/running_db
cat <<EOF > $dir/running_db echo "<config>$startvar</config>" > $dir/startup_db
<config> echo "<config>$extravar</config>" > $dir/extra_db
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>run</name>
<type>ex:eth</type>
</interface>
</interfaces>
</config>
EOF
# Create startup-db containin the interface "startup"
sudo rm -f $dir/startup_db
cat <<EOF > $dir/startup_db
<config>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>startup</name>
<type>ex:eth</type>
</interface>
</interfaces>
</config>
EOF
# Create extra xml containin the interface "extra"
sudo rm -f $dir/config
cat <<EOF > $dir/config
<config>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>extra</name>
<type>ex:eth</type>
</interface>
</interfaces>
</config>
EOF
if [ $BE -ne 0 ]; then # Bring your own backend if [ $BE -ne 0 ]; then # Bring your own backend
# kill old backend (if any) # kill old backend (if any)
@ -90,17 +66,23 @@ EOF
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
err err
fi fi
new "start backend -f $cfg -s $mode -c $dir/config" new "start backend -f $cfg -s $mode -c $dir/extra_db"
start_backend -s $mode -f $cfg -c $dir/config start_backend -s $mode -f $cfg -c $dir/extra_db
new "waiting" new "waiting"
sleep $RCWAIT sleep $RCWAIT
else 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 sleep $BETIMEOUT
fi fi
new "Startup test for init mode: $mode" new "Startup test for $mode mode, check running"
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><running/></source></get-config></rpc>]]>]]>' "^<rpc-reply>$expect</rpc-reply>]]>]]>$" expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><running/></source></get-config></rpc>]]>]]>' "^<rpc-reply>$exprun</rpc-reply>]]>]]>$"
new "Startup test for $mode mode, check candidate"
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>' "^<rpc-reply>$exprun</rpc-reply>]]>]]>$"
new "Startup test for $mode mode, check startup is untouched"
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><startup/></source></get-config></rpc>]]>]]>' "^<rpc-reply><data>$startvar</data></rpc-reply>]]>]]>$"
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
@ -112,12 +94,17 @@ EOF
stop_backend -f $cfg stop_backend -f $cfg
} # testrun } # testrun
testrun init '<data><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>extra</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces></data>' # Init mode: delete running and reload from scratch (just extra)
testrun init "<data>$extravar</data>"
testrun none '<data><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>run</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces></data>' # None mode: do nothing, running remains
testrun none "<data>$runvar</data>"
# Running mode: keep running but load also extra
testrun running '<data><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>extra</name><type>ex:eth</type><enabled>true</enabled></interface><interface><name>run</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces></data>' testrun running '<data><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>extra</name><type>ex:eth</type><enabled>true</enabled></interface><interface><name>run</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces></data>'
# Startup mode: scratch running, load startup with extra on top
testrun startup '<data><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>extra</name><type>ex:eth</type><enabled>true</enabled></interface><interface><name>startup</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces></data>' testrun startup '<data><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>extra</name><type>ex:eth</type><enabled>true</enabled></interface><interface><name>startup</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces></data>'
rm -rf $dir echo $dir
#rm -rf $dir

View file

@ -2,10 +2,6 @@
# Starting clixon with outdated (or not) modules # Starting clixon with outdated (or not) modules
# This relieas on storing RFC7895 YANG Module Library modules-state info # This relieas on storing RFC7895 YANG Module Library modules-state info
# in the datastore (or XML files?) # 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: # 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 A has revisions "814-01-28" and "2019-01-01"
# Yang module B has only revision "2019-01-01" # Yang module B has only revision "2019-01-01"
@ -250,8 +246,8 @@ EOF
runtest(){ runtest(){
modstate=$1 modstate=$1
mode=$2 mode=$2
expect=$3 exprun=$3 # Expected running
startup=$4 expstartup=$4 # Expected startup
new "test params: -f $cfg" new "test params: -f $cfg"
# Bring your own backend # Bring your own backend
@ -273,10 +269,10 @@ runtest(){
fi fi
new "Get running" new "Get running"
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><running/></source></get-config></rpc>]]>]]>' "^<rpc-reply>$expect</rpc-reply>]]>]]>$" expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><running/></source></get-config></rpc>]]>]]>' "^<rpc-reply>$exprun</rpc-reply>]]>]]>$"
new "Get startup" new "Get startup"
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><startup/></source></get-config></rpc>]]>]]>' "^<rpc-reply>$startup</rpc-reply>]]>]]>$" expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><startup/></source></get-config></rpc>]]>]]>' "^<rpc-reply>$expstartup</rpc-reply>]]>]]>$"
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
@ -292,7 +288,6 @@ runtest(){
# Compatible == all yang modules match # Compatible == all yang modules match
# runtest <mode> <expected running> <expected startup> # runtest <mode> <expected running> <expected startup>
new "1. Run without CLICON_XMLDB_MODSTATE ensure no modstate in datastore" 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; rm -f tmp_db candidate_db running_db startup_db) # remove databases
(cd $dir; cp compat-valid.xml startup_db) (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)" 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; 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 running_db)
(cd $dir; cp compat-valid.xml startup_db) # XXX
runtest true running '<data><a1 xmlns="urn:example:a">always work</a1><b xmlns="urn:example:b">other text</b></data>' '<data><a1 xmlns="urn:example:a">always work</a1><b xmlns="urn:example:b">other text</b></data>' runtest true running '<data><a1 xmlns="urn:example:a">always work</a1><b xmlns="urn:example:b">other text</b></data>' '<data><a1 xmlns="urn:example:a">always work</a1><b xmlns="urn:example:b">other text</b></data>'
new "4. Load non-compat valid startup" new "4. Load non-compat valid startup"
@ -335,7 +331,8 @@ runtest true startup '<data><a1 xmlns="urn:example:a">always work</a1></data>' '
new "6. Load non-compat invalid running. Enter failsafe, startup invalid." 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; rm -f tmp_db candidate_db running_db startup_db) # remove databases
(cd $dir; cp non-compat-invalid.xml running_db) (cd $dir; cp non-compat-invalid.xml running_db)
runtest true running '<data><a1 xmlns="urn:example:a">always work</a1></data>' '<data><a0 xmlns="urn:example:a">old version</a0><a1 xmlns="urn:example:a">always work</a1><b xmlns="urn:example:b">other text</b><c xmlns="urn:example:c">bla bla</c></data>' (cd $dir; cp non-compat-valid.xml startup_db) # XXX tmp
#runtest true running '<data><a1 xmlns="urn:example:a">always work</a1></data>' '<data><a0 xmlns="urn:example:a">old version</a0><a1 xmlns="urn:example:a">always work</a1><b xmlns="urn:example:b">other text</b><c xmlns="urn:example:c">bla bla</c></data>'
new "7. Load compatible invalid startup." new "7. Load compatible invalid startup."
(cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases (cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases