From 3a336838f7f1081245a7bb9571adaa69807d3cca Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 16 May 2022 13:12:59 +0200 Subject: [PATCH] Fixed a cornercase of RFC 7950 Sec 7.9, a choice witout case with sub-containers --- README.md | 2 +- lib/src/clixon_datastore_write.c | 15 +++++++----- test/test_choice.sh | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ae57c0d2..22b36f7a 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,6 @@ Clixon has a master branch continuously tested with CI, but releases are made ca 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-14apfsdlt-U8y5TX_VX7oP99wKKvTScQ)(updated 23/2 2022) +[Slack invite](https://join.slack.com/t/clixondev/shared_invite/zt-191czm376-kWvI3tyDdqDU86DlfbLRxg)(updated 16/5 2022) 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 20b8d432..56f0de7f 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -297,6 +297,7 @@ check_delete_existing_case(cxobj *x0, { int retval = -1; yang_stmt *yp; + yang_stmt *y0p; yang_stmt *y0case; yang_stmt *y1case; yang_stmt *y0choice; @@ -317,28 +318,30 @@ check_delete_existing_case(cxobj *x0, } else goto ok; + /* Now traverse existing tree and compare with choice yang structure of added tree */ x0prev = NULL; x0c = NULL; while ((x0c = xml_child_each(x0, x0c, CX_ELMNT)) != NULL) { if ((y0c = xml_spec(x0c)) == NULL || - (yp = yang_parent_get(y0c)) == NULL){ + yang_parent_get(y0c) == NULL){ x0prev = x0c; continue; } - if (yang_keyword_get(yp) == Y_CASE){ - y0case = yp; + y0p = yang_parent_get(y0c); + if (yang_keyword_get(y0p) == Y_CASE){ + y0case = y0p; y0choice = yang_parent_get(y0case); } - else if (yang_keyword_get(yp) == Y_CHOICE){ + else if (yang_keyword_get(y0p) == Y_CHOICE){ y0case = NULL; - y0choice = yp; + y0choice = y0p; } else{ x0prev = x0c; continue; } if (y0choice == y1choice){ - if (y0case == NULL || + if ((y0case == NULL && y0c != y1c) || y0case != y1case){ if (xml_purge(x0c) < 0) goto done; diff --git a/test/test_choice.sh b/test/test_choice.sh index 6ec8b26a..20ac6be7 100755 --- a/test/test_choice.sh +++ b/test/test_choice.sh @@ -106,6 +106,25 @@ module system{ } } } + /* Choice shorthand with sub-container */ + container choice-subcontainer { + presence true; + choice name { + container udp { + leaf udp1{ + type string; + } + leaf udp2{ + type string; + } + } + container tcp { + leaf tcp1{ + type string; + } + } + } + } } } EOF @@ -335,6 +354,29 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " new "netconf validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" +new "netconf discard-changes" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" + +# Merge in choice-subcontainer +new "netconf choice sub-container 1st leaf" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " +42 +" "" "" + +new "netconf choice sub-container 2nd leaf (dont remove 1st)" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " +99 +" "" "" + +new "netconf get both items" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "4299" "" + +new "netconf validate ok" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" + +new "netconf discard-changes" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" + if [ $RC -ne 0 ]; then new "Kill restconf daemon" stop_restconf