From cfe1f2936e2844595c0e3eaa9667d04baec3df83 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 16 Nov 2021 15:29:00 +0100 Subject: [PATCH] stronger defaults test --- apps/cli/cli_common.c | 1 - test/test_yang_default.sh | 133 ++++++++++++++++++++++---------------- 2 files changed, 77 insertions(+), 57 deletions(-) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 76aad286..90f118e9 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -908,7 +908,6 @@ save_config_file(clicon_handle h, char *dbstr; char *varstr; cxobj *xt = NULL; - cxobj *xc; cxobj *xerr; FILE *f = NULL; enum genmodel_type gt; diff --git a/test/test_yang_default.sh b/test/test_yang_default.sh index 0b2a53e5..cac5df60 100755 --- a/test/test_yang_default.sh +++ b/test/test_yang_default.sh @@ -1,14 +1,11 @@ #!/usr/bin/env bash + # Default handling and datastores. # There was a bug with loading startup and writing it back to candidate/running # where default mode in startup being "explicit" was transformed to "report-all" # according to RFC 6243. # Ie, all default values were populated. -# This test goes through (all) testcases where clixon writes data back to a datastore, and -# ensures default values are not present in the datastore. -# XXX two errors: -# 1. Running is changed -# XXX 2. type default not set +# Also: Check default values and xpaths # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi @@ -41,7 +38,7 @@ cat < $cfg EOF cat < $fyang - module example-default { +module example-default { namespace "urn:example:default"; prefix "ex"; typedef def { @@ -50,6 +47,11 @@ cat < $fyang default 42; } container a{ + leaf d0 { + description "container default"; + type int32; + default 88; + } list b { key c; leaf c{ @@ -66,63 +68,82 @@ cat < $fyang } } } - } +} EOF -# No args -function testrun(){ - # Initial data (default y not given) - XML='0' +# Initial data (default y not given) +XML='0' - db=startup - if [ $db = startup ]; then - sudo echo "<${DATASTORE_TOP}>$XML" > $dir/startup_db - fi - if [ $BE -ne 0 ]; then # Bring your own backend - new "kill old backend" - sudo clixon_backend -zf $cfg - if [ $? -ne 0 ]; then - err - fi - new "start backend -s $db -f $cfg" - start_backend -s $db -f $cfg - fi - - new "waiting" - wait_backend - - # permission kludges - sudo chmod 666 $dir/running_db - sudo chmod 666 $dir/startup_db - - new "Checking startup unchanged" - ret=$(diff $dir/startup_db <(echo "<${DATASTORE_TOP}>$XML")) +db=startup +if [ $db = startup ]; then + sudo echo "<${DATASTORE_TOP}>$XML" > $dir/startup_db +fi +if [ $BE -ne 0 ]; then # Bring your own backend + new "kill old backend" + sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then - err "<${DATASTORE_TOP}>$XML" "$ret" + err fi + new "start backend -s $db -f $cfg" + start_backend -s $db -f $cfg +fi - new "Checking running unchanged" - ret=$(diff $dir/running_db <(echo -n "<${DATASTORE_TOP}>$XML")) - if [ $? -ne 0 ]; then - err "<${DATASTORE_TOP}>$XML" "$ret" +# permission kludges +sudo chmod 666 $dir/running_db +sudo chmod 666 $dir/startup_db + +new "Checking startup unchanged" +ret=$(diff $dir/startup_db <(echo "<${DATASTORE_TOP}>$XML")) +if [ $? -ne 0 ]; then + err "<${DATASTORE_TOP}>$XML" "$ret" +fi + +new "Checking running unchanged" +ret=$(diff $dir/running_db <(echo -n "<${DATASTORE_TOP}>$XML")) +if [ $? -ne 0 ]; then + err "<${DATASTORE_TOP}>$XML" "$ret" +fi + +new "check running defaults" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^880foo42]]>]]>$" + +new "delete existing list element" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO0]]>]]>" "^]]>]]>$" + +new "netconf commit" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" + +new "set new list element" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO17]]>]]>" "^]]>]]>$" + +new "get the list top" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^8817foo42]]>]]>$" + +new "get the list xpath /a" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^8817foo42]]>]]>$" + +new "get the list xpath /a/b" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^17foo42]]>]]>$" + +new "get the list xpath /a/b/c" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^17]]>]]>$" + +new "get the list xpath /a/b/c=17" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO17]]>]]>" "^17foo42]]>]]>$" + +new "get the list xpath /a/b/c=17/d1" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO17]]>]]>" "^17foo]]>]]>$" + +if [ $BE -ne 0 ]; then # Bring your own backend + new "Kill backend" + # Check if premature kill + pid=$(pgrep -u root -f clixon_backend) + if [ -z "$pid" ]; then + err "backend already dead" fi - - new "check running defaults" - expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^0foo42]]>]]>$" - - if [ $BE -ne 0 ]; then # Bring your own backend - 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 -} # testrun - -testrun + # kill backend + stop_backend -f $cfg +fi rm -rf $dir