From ae6275cfa1a3905f2c46ab825796eab6a08706bc Mon Sep 17 00:00:00 2001 From: Jan-Olof Carlson Date: Wed, 21 Sep 2022 08:37:08 +0000 Subject: [PATCH] New testcase to verify With-Defaults Corner Case where top container is trimmed --- test/test_yang_wdcc.sh | 255 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100755 test/test_yang_wdcc.sh diff --git a/test/test_yang_wdcc.sh b/test/test_yang_wdcc.sh new file mode 100755 index 00000000..1eaaceea --- /dev/null +++ b/test/test_yang_wdcc.sh @@ -0,0 +1,255 @@ +#!/usr/bin/env bash + +# Test of the IETF rfc6243: With-defaults Capability for NETCONF +# +# Test cases below represents a corner case where the topmost container will be trimmed. +# + +# 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_yang.xml +fyang=$dir/example-default.yang +fstate=$dir/state.xml +clispec=$dir/spec.cli +RESTCONFIG=$(restconf_config none false) + +cat < $cfg + + $cfg + ietf-netconf:startup + 42 + ${YANG_INSTALLDIR} + $fyang + $dir + /usr/local/lib/$APPNAME/backend + example_backend.so$ + /usr/local/lib/$APPNAME/netconf + /usr/local/lib/$APPNAME/cli + $APPNAME + $dir/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + false + $dir + false + $IETFRFC + true + clixon-restconf:allow-auth-none + $RESTCONFIG + +EOF + +# Corner case model + +cat < $fyang +module example { + + namespace "http://example.com/ns/wdcc"; + + prefix wdcc; + + container wd { + description "With-defaults container"; + + leaf wdc { + description "With-defaults config"; + type uint32; + default 1500; + } + leaf wdce { + description "With-defaults config explicit"; + type uint32; + default 1500; + } + leaf wds { + description "Width-defaults state"; + type string; + config false; + default "ok"; + } + } +} +EOF + +# CLIspec for cli tests +cat < $clispec +CLICON_MODE="example"; +CLICON_PROMPT="%U@%H %W> "; +CLICON_PLUGIN="example_cli"; + +set @datamodel, cli_auto_set(); +validate("Validate changes"), cli_validate(); +commit("Commit the changes"), cli_commit(); +quit("Quit"), cli_quit(); +discard("Discard edits (rollback 0)"), discard_changes(); +show("Show a particular state of the system"){ + configuration("Show configuration") + xml("Show configuration and state as XML") + default("With-default mode"){ + report-all @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all"); + trim @datamodelshow, cli_show_auto("candidate", "xml", false, false, "trim"); + explicit @datamodelshow, cli_show_auto("candidate", "xml", false, false, "explicit"); + report-all-tagged @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged"); + report-all-tagged-default @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-default"); + report-all-tagged-strip @datamodelshow, cli_show_auto("candidate", "xml", false, false, "report-all-tagged-strip"); + } + state("Show configuration and state") + xml("Show configuration and state as XML") + default("With-default mode"){ + report-all @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all"); + trim @datamodelshow, cli_show_auto("running", "xml", false, true, "trim"); + explicit @datamodelshow, cli_show_auto("running", "xml", false, true, "explicit"); + report-all-tagged @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged"); + report-all-tagged-default @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-default"); + report-all-tagged-strip @datamodelshow, cli_show_auto("running", "xml", false, true, "report-all-tagged-strip"); + } +} +EOF + +# A.2. Example Data Set + +EXAMPLENS="xmlns=\"http://example.com/ns/wdcc\"" + +XML="1500" + + +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 "wait backend" +wait_backend + +# permission kludges +new "chmod datastores" +sudo chmod 666 $dir/running_db +if [ $? -ne 0 ]; then + err1 "chmod $dir/running_db" +fi +sudo chmod 666 $dir/startup_db +if [ $? -ne 0 ]; then + err1 "chmod $dir/startup_db" +fi + +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 + +if [ $RC -ne 0 ]; then + new "kill old restconf daemon" + stop_restconf_pre + + new "start restconf daemon" + start_restconf -f $cfg +fi + +new "wait restconf" +wait_restconf + +new "rfc6243 3.1. 'report-all' Retrieval Mode" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \ +"\ +report-all" \ +"" \ +"\ +15001500ok\ +" + + +new "rfc6243 3.2. 'trim' Retrieval Mode" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \ +"\ +trim" \ +"" \ +"" + +new "rfc6243 3.3. 'explicit' Retrieval Mode" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \ +"\ +explicit" \ +"" \ +"\ +1500ok\ +" + +new "rfc6243 3.4. 'report-all-tagged' Retrieval Mode" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \ +"\ +report-all-tagged" \ +"\ +15001500ok\ +" + +new "rfc6243 2.3.1. 'explicit' Basic Mode Retrieval" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \ +"" "" \ +"\ +15001500ok\ +" + + +new "rfc8040 B.3.9. RESTONF with-defaults parameter = trim json" +expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:wd?with-defaults=trim)" \ +0 \ +"HTTP/$HVER 404" \ +"Content-Type: application/yang-data+json" \ +'{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}' + +new "rfc8040 B.3.9. RESTONF with-defaults parameter = trim xml" +expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example:wd?with-defaults=trim)" \ +0 \ +"HTTP/$HVER 404" \ +"Content-Type: application/yang-data+xml" \ +'applicationinvalid-valueerrorInstance does not exist' + +# CLI tests + +mode=trim +new "cli with-default config $mode" +expectpart "$($clixon_cli -1 -f $cfg show config xml default $mode wd)" 0 "" + +new "cli with-default state $mode" +expectpart "$($clixon_cli -1 -f $cfg show state xml default $mode wd)" 0 "" + +if [ $RC -ne 0 ]; then + new "Kill restconf daemon" + stop_restconf +fi + +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 + +rm -rf $dir + +unset ret + +new "endtest" +endtest