diff --git a/CHANGELOG.md b/CHANGELOG.md index a1d2a6d0..a75d1719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,8 @@ Developers may need to change their code ### Corrected Bugs +* [Delete and show config are oblivious to the leaf value #157](https://github.com/clicon/clixon/issues/157) + * Added equality of values necessary condition in edit-config delete/remove of leafs * Fixed error memory in RESTCONF PATCH/PUT when accessing top-level data node. * Fixed: [ Calling copy-config RPC from restconf #158](https://github.com/clicon/clixon/issues/158) * Fixed: [namespace prefix nc is not supported in full #154](https://github.com/clicon/clixon/issues/154) diff --git a/README.md b/README.md index c97e2abc..3a51f0fe 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,6 @@ See [CHANGELOG.md](CHANGELOG.md) release history. Clixon interaction is best done posting issues, pull requests, or joining the [slack channel](https://clixondev.slack.com). -[Slack invite](https://join.slack.com/t/clixondev/shared_invite/zt-hw9lofnk-C1iDFJ~E_CTiwtyGZi8fdQ) +[Slack invite](https://join.slack.com/t/clixondev/shared_invite/zt-jysz1bbp-Pua0_67fMWdPgG3GPbTIZA) Clixon is sponsored by [Rubicon Communications LLC(Netgate)](https://www.netgate.com/) diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index 0badffe9..593e6522 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -465,8 +465,20 @@ text_modify(clicon_handle h, if (ret == 0) goto fail; } - if (xml_purge(x0) < 0) - goto done; + x0bstr = xml_body(x0); + /* Purge if x1 value is NULL(match-all) or both values are equal */ + if ((x1bstr == NULL) || + ((x0bstr=xml_body(x0)) != NULL && strcmp(x0bstr, x1bstr)==0)){ + if (xml_purge(x0) < 0) + goto done; + } + else { + if (op == OP_DELETE){ + if (netconf_data_missing(cbret, NULL, "Data does not exist; cannot delete resource") < 0) + goto done; + goto fail; + } + } } break; default: @@ -540,7 +552,7 @@ text_modify(clicon_handle h, } /* OP_MERGE & insert */ case OP_NONE: /* fall thru */ /* Special case: anyxml, just replace tree, - See rfc6020 7.10.3:n + See rfc6020 7.10.3 An anyxml node is treated as an opaque chunk of data. This data can be modified in its entirety only. Any "operation" attributes present on subelements of an anyxml diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c index 5b78c021..d4e96cc1 100644 --- a/lib/src/clixon_xml_sort.c +++ b/lib/src/clixon_xml_sort.c @@ -1135,6 +1135,7 @@ xml_sort_verify(cxobj *x0, * @retval 0 OK * @retval -1 Error * @note only handles first match + * @see xml_cmp regarding what "match" means in this context (model-match not value-match) */ int match_base_child(cxobj *x0, diff --git a/test/test_cli_auto.sh b/test/test_cli_auto.sh index c3d29fa6..c872e3a6 100755 --- a/test/test_cli_auto.sh +++ b/test/test_cli_auto.sh @@ -1,11 +1,5 @@ #!/usr/bin/env bash -# Backend and cli basic functionality -# Start backend server -# Add an ethernet interface and an address -# Show configuration -# Validate without a mandatory type -# Set the mandatory type -# Commit +# Auto-cli test using modes up and down and table/parameter configs # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi @@ -224,7 +218,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/par cat < $fin edit table parameter b -delete value 17 +delete value 71 show config xml EOF new "delete value 71" diff --git a/test/test_cli_gen.sh b/test/test_cli_auto_genmodel.sh similarity index 85% rename from test/test_cli_gen.sh rename to test/test_cli_auto_genmodel.sh index c95245f3..92ba377a 100755 --- a/test/test_cli_gen.sh +++ b/test/test_cli_auto_genmodel.sh @@ -1,8 +1,10 @@ #!/usr/bin/env bash -# Tests for using the generated cli. +# Tests for using the auto cli. # In particular setting a config, displaying as cli commands and reconfigure it # Tests: # Make a config in CLI. Show output as CLI, save it and ensure it is the same +# Try the different GENMODEL settings +# NOTE this uses the "Old" autocli (eg cli_set()), see test_cli_auto.sh for "new" autocli using the cli_auto_*() API # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi @@ -130,7 +132,6 @@ testrun() fi new "set a" - echo "$clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg" expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg set$table parameter$name a value x)" 0 "" new "set b" @@ -147,11 +148,23 @@ SAVED=$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show config) new "show match a & b xml" expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show xml)" 0 "" "" "a" "x" "" "" "b" "z" "" "
" + # https://github.com/clicon/clixon/issues/157 + new "delete a y expect fail" + expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg delete$table parameter$name a value y 2>&1)" 0 "" + + new "show match a & b xml" # Expect same + expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show xml)" 0 "" "" "a" "x" "" "" "b" "z" "" "
" + + new "delete a x" + expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg delete$table parameter$name a value x)" 0 "" + + new "show match a & b xml" + expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show xml)" 0 "" "" "a" "" "" "b" "z" "" "
" --not-- "x" + new "delete a" expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg delete$table parameter$name a)" 0 "" new "show match b" -echo "$clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show config" expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show config)" 0 "$table parameter$name b" "$table parameter$name b value z" --not-- "$table parameter$name a" "$table parameter$name a value x" "$table parameter$name b value y" new "discard" diff --git a/test/test_cli_auto_sub.sh b/test/test_cli_auto_sub.sh index 9e90b369..ef9599a7 100755 --- a/test/test_cli_auto_sub.sh +++ b/test/test_cli_auto_sub.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Tests for generating clispec from a yang subtree +# Tests for generating clispec from a yang subtree, ie not the whole yang # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi