From 906d8bc63c1b9084ea19f085d2389a04c121be77 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 28 Dec 2020 14:52:56 +0100 Subject: [PATCH] [Presence container configs not displayed in 'show config set' #164 ](https://github.com/clicon/clixon/issues/164) --- CHANGELOG.md | 5 ++++- lib/src/clixon_xml_map.c | 22 ++++++++++++++++++++-- test/test_choice.sh | 12 ++++++------ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 515c12e8..66f6aaa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,8 +31,11 @@ Expected: February 2021 ### Corrected Bugs +* [Presence container configs not displayed in 'show config set' #164 ](https://github.com/clicon/clixon/issues/164) + * Treat presence container as a leaf: always print a placeholder regardless if it has children or not. An extra check for children could have been made to not print if it has, but this adds an extra minor complexity. + ## 4.9.0 -18 Dec 2020 +18 December 2020 ### New features diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 646ec408..7002b13e 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -238,7 +238,9 @@ xml2cli_recurse(FILE *f, goto ok; if ((ys = xml_spec(x)) == NULL) goto ok; - if (yang_keyword_get(ys) == Y_LEAF || yang_keyword_get(ys) == Y_LEAF_LIST){ + /* If leaf/leaf-list or presence container, then print line */ + if (yang_keyword_get(ys) == Y_LEAF || + yang_keyword_get(ys) == Y_LEAF_LIST){ if (prepend) (*fn)(f, "%s", prepend); if (gt == GT_ALL || gt == GT_VARS || gt == GT_HIDE) @@ -266,8 +268,8 @@ xml2cli_recurse(FILE *f, if (yang_container_cli_hide(ys, gt) == 0) cprintf(cbpre, "%s ", xml_name(x)); + /* If list then first loop through keys */ if (yang_keyword_get(ys) == Y_LIST){ - /* If list then first loop through keys */ xe = NULL; while ((xe = xml_child_each(x, xe, -1)) != NULL){ if ((match = yang_key_match(ys, xml_name(xe))) < 0) @@ -279,6 +281,22 @@ xml2cli_recurse(FILE *f, cprintf(cbpre, "%s ", xml_body(xe)); } } + else if ((yang_keyword_get(ys) == Y_CONTAINER) && + yang_find(ys, Y_PRESENCE, NULL) != NULL){ + /* If presence container, then print as leaf (but continue to children) */ + if (prepend) + (*fn)(f, "%s", prepend); + if (gt == GT_ALL || gt == GT_VARS || gt == GT_HIDE) + (*fn)(f, "%s ", xml_name(x)); + if ((body = xml_body(x)) != NULL){ + if (index(body, ' ')) + (*fn)(f, "\"%s\"", body); + else + (*fn)(f, "%s", body); + } + (*fn)(f, "\n"); + } + /* Then loop through all other (non-keys) */ xe = NULL; while ((xe = xml_child_each(x, xe, -1)) != NULL){ diff --git a/test/test_choice.sh b/test/test_choice.sh index ca438f3f..46d7caa6 100755 --- a/test/test_choice.sh +++ b/test/test_choice.sh @@ -185,22 +185,22 @@ new "restconf set protocol tcp+udp fail again" expectpart "$(curl $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/system:system/protocol -d '{"system:protocol":{"tcp": [null], "udp": [null]}}')" 0 "HTTP/1.1 400 Bad Request" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"bad-element","error-info":{"bad-element":"tcp"},"error-severity":"error","error-message":"Element in choice statement already exists"}}}' new "cli set protocol udp" -expectfn "$clixon_cli -1 -f $cfg -l o set system protocol udp" 0 "^$" +expectpart "$($clixon_cli -1 -f $cfg -l o set system protocol udp)" 0 "^$" new "cli get protocol udp" -expectfn "$clixon_cli -1 -f $cfg -l o show configuration cli " 0 "^set system protocol udp$" +expectpart "$($clixon_cli -1 -f $cfg -l o show configuration cli)" 0 "set system protocol" "set system protocol udp" new "cli change protocol to tcp" -expectfn "$clixon_cli -1 -f $cfg -l o set system protocol tcp" 0 "^$" +expectpart "$($clixon_cli -1 -f $cfg -l o set system protocol tcp)" 0 "^$" new "cli get protocol tcp" -expectfn "$clixon_cli -1 -f $cfg -l o show configuration cli " 0 "^set system protocol tcp$" +expectpart "$($clixon_cli -1 -f $cfg -l o show configuration cli)" 0 "set system protocol" "set system protocol tcp" new "cli delete all" -expectfn "$clixon_cli -1 -f $cfg -l o delete all" 0 "^$" +expectpart "$($clixon_cli -1 -f $cfg -l o delete all)" 0 "^$" new "commit" -expectfn "$clixon_cli -1 -f $cfg -l o commit" 0 "^$" +expectpart "$($clixon_cli -1 -f $cfg -l o commit)" 0 "^$" # Second shorthand (no case) new "netconf set protocol both udp and tcp"