From a61da8715dec74860869f355a0ee63c9d76817ee Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 8 Sep 2020 10:46:35 +0200 Subject: [PATCH] Fixed: [min-elements attribute prevents from deleting list entries #133](https://github.com/clicon/clixon/issues/133) --- CHANGELOG.md | 1 + lib/src/clixon_yang.c | 17 ++++++++++++----- test/test_minmax.sh | 29 +++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66abd3db..a9ebecf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ Developers may need to change their code ### Corrected Bugs +* Fixed: [min-elements attribute prevents from deleting list entries #133](https://github.com/clicon/clixon/issues/133) * Fixed: [xmldb_get0 returns invalid candidate on startup transaction callbacks #126](https://github.com/clicon/clixon/issues/126). Always clear candidate-db before db initialization. * Fixed: YANG `uses` statements in sub-modules did not search for `grouping` statements in other submodules of the module it belongs to. * Fixed: [CLI crash if error-info is empty #134](https://github.com/clicon/clixon/issues/134) diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index be5585d3..b5f98ca1 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -2630,7 +2630,7 @@ yang_desc_schema_nodeid(yang_stmt *yn, return retval; } -/*! Return if this leaf is mandatory or not +/*! Check if this leaf is mandatory or not * Note: one can cache this value in ys_cvec instead of functionally evaluating it. * @retval 1 yang statement is leaf and it has a mandatory sub-stmt with value true * @retval 0 The negation of conditions for return value 1. @@ -2638,16 +2638,21 @@ yang_desc_schema_nodeid(yang_stmt *yn, * o mandatory node: A mandatory node is one of: * 1) A leaf, choice, anydata, or anyxml node with a "mandatory" * statement with the value "true". - * 2) A list or leaf-list node with a "min-elements" statement with a - * value greater than zero. + * 2) # see below * 3) A container node without a "presence" statement and that has at * least one mandatory node as a child. + * + * @note There is also this statement + * 2) A list or leaf-list node with a "min-elements" statement with a + * value greater than zero. + * which we ignore here since: + * (a) it does not consider the XML siblings and therefore returns false positives + * (b) where the actual check is catched by check_list_unique_minmax() */ int yang_mandatory(yang_stmt *ys) { yang_stmt *ym; - cg_var *cv; /* 1) A leaf, choice, anydata, or anyxml node with a "mandatory" * statement with the value "true". */ @@ -2658,14 +2663,16 @@ yang_mandatory(yang_stmt *ys) return cv_bool_get(ym->ys_cv); } } +#if 0 /* See note above */ /* 2) A list or leaf-list node with a "min-elements" statement with a * value greater than zero. */ else if (ys->ys_keyword == Y_LIST || ys->ys_keyword == Y_LEAF_LIST){ if ((ym = yang_find(ys, Y_MIN_ELEMENTS, NULL)) != NULL){ cv = yang_cv_get(ym); - return cv_uint32_get(cv) > 0; + return cv_uint32_get(cv) > 0; /* Not true if XML considered */ } } +#endif /* 3) A container node without a "presence" statement and that has at * least one mandatory node as a child. */ else if (ys->ys_keyword == Y_CONTAINER && diff --git a/test/test_minmax.sh b/test/test_minmax.sh index 2d888f21..3a6da5e5 100755 --- a/test/test_minmax.sh +++ b/test/test_minmax.sh @@ -117,7 +117,7 @@ if [ $BE -ne 0 ]; then wait_backend fi -new "minmax: minimal" +new "minmax: minimal: 1x a1,b1 (should be [1:2]" expecteof "$clixon_netconf -qf $cfg" 0 "replace 0 0 @@ -126,13 +126,13 @@ expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" -new "minmax: maximal" -expecteof "$clixon_netconf -qf $cfg" 0 "replace01unbounded0101unbounded01]]>]]>" "^]]>]]>$" +new "minmax: maximal: 2x a1,b1" +expecteof "$clixon_netconf -qf $cfg" 0 "replace01unbounded0101unbounded101]]>]]>" "^]]>]]>$" new "minmax: validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" -new "minmax: empty" +new "minmax: replace with 0x a1,b1" expecteof "$clixon_netconf -qf $cfg" 0 "replace]]>]]>" "^]]>]]>$" #XXX echo "]]>]]>" |$clixon_netconf -qf $cfg @@ -224,6 +224,27 @@ expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" +# Above only tests on candidate -> empty running +# Also need to do commit tests when running has elements and candidate has fewer + +new "Set maximal: 2x a1,b1" +expecteof "$clixon_netconf -qf $cfg" 0 "replace0110]]>]]>" "^]]>]]>$" + +new "netconf commit" +expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" + +new "minmax: delete to minimal: 1x a1,b1" +expecteof "$clixon_netconf -qf $cfg" 0 "none11]]>]]>" "^]]>]]>$" + +new "minmax: commit minimal list" +expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" + +new "minmax: delete to no list" +expecteof "$clixon_netconf -qf $cfg" 0 "none00]]>]]>" "^]]>]]>$" + +new "minmax: validate should fail empty list" +expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocoloperation-failedtoo-few-elementserror/c/a1]]>]]>$" + if [ $BE -eq 0 ]; then exit # BE fi