From 83cb696d0e4a6f15016a599b195fb3fe86c1b372 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sat, 6 Jan 2018 13:40:14 +0100 Subject: [PATCH] Corrected "No yang spec" printed on tty on leafref CLI usage --- CHANGELOG.md | 2 ++ lib/src/clixon_proto_client.c | 15 ++++++++++----- lib/src/clixon_xml_sort.c | 8 +++++--- lib/src/clixon_yang.c | 8 +++----- test/test_leafref.sh | 4 ++-- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcb394ee..2b58a9e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ * Clixon XML C-lib prior to 3.4.0. As enabled with `configure --with-xml-compat` ### Corrected Bugs +* Corrected "No yang spec" printed on tty on leafref CLI usage + ### Known issues ## 3.4.0 (1 January 2018) diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 83fc792a..4a5808cf 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -71,10 +71,11 @@ /*! Send internal netconf rpc from client to backend * @param[in] h CLICON handle * @param[in] msg Encoded message. Deallocate woth free - * @param[out] xret Return value from backend as netconf xml tree. Free w xml_free + * @param[out] xret Return value from backend as xml tree. Free w xml_free * @param[inout] sock0 If pointer exists, do not close socket to backend on success * and return it here. For keeping a notify socket open - * Note: sock0 is if connection should be persistent, like a notification/subscribe api + * @note sock0 is if connection should be persistent, like a notification/subscribe api + * @note xret is populated with yangspec according to standard handle yangspec */ int clicon_rpc_msg(clicon_handle h, @@ -87,6 +88,7 @@ clicon_rpc_msg(clicon_handle h, int port; char *retdata = NULL; cxobj *xret = NULL; + yang_spec *yspec; if ((sock = clicon_sock(h)) == NULL){ clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set"); @@ -119,9 +121,12 @@ clicon_rpc_msg(clicon_handle h, break; } clicon_debug(1, "%s retdata:%s", __FUNCTION__, retdata); - if (retdata && - xml_parse_string(retdata, NULL, &xret) < 0) - goto done; + + if (retdata){ + yspec = clicon_dbspec_yang(h); + if (xml_parse_string(retdata, yspec, &xret) < 0) + goto done; + } if (xret0){ *xret0 = xret; xret = NULL; diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c index 5d4c7eb9..ef7e27c8 100644 --- a/lib/src/clixon_xml_sort.c +++ b/lib/src/clixon_xml_sort.c @@ -592,11 +592,8 @@ match_base_child(cxobj *x0, } /* Get match */ { - yang_node *y0; int yorder; - if ((y0 = yc->ys_parent) == NULL) - goto done; /* XXX: No we cant do this. on uppermost layer it can look like this: * config * ximport-----ymod = ietf @@ -613,7 +610,12 @@ match_base_child(cxobj *x0, *x0cp = xml_search(x0, xml_name(x1c), yorder, yc->ys_keyword, keynr, keyvec, keyval); } else{ +#if 1 /* This is just a warning, but a catcher for when xml tree is not + populated with yang spec. If you see this, a previous inovation of, + for example xml_spec_populate() may be missing + */ clicon_log(LOG_WARNING, "%s No yspec", __FUNCTION__); +#endif *x0cp = xml_match(x0, xml_name(x1c), yc->ys_keyword, keynr, keyvec, keyval); } #else diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 7e435feb..2dcb578d 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -549,10 +549,8 @@ yang_find_myprefix(yang_stmt *ys) clicon_err(OE_YANG, 0, "My yang module not found"); goto done; } - if ((yprefix = yang_find((yang_node*)ymod, Y_PREFIX, NULL)) == NULL){ - clicon_err(OE_YANG, 0, "No prefix in my module"); + if ((yprefix = yang_find((yang_node*)ymod, Y_PREFIX, NULL)) == NULL) goto done; - } prefix = yprefix->ys_argument; done: return prefix; @@ -729,7 +727,6 @@ yang_find_module_by_prefix(yang_stmt *ys, clicon_err(OE_YANG, 0, "My yang spec not found"); goto done; } - myprefix = yang_find_myprefix(ys); if ((my_ymod = ys_module(ys)) == NULL){ clicon_err(OE_YANG, 0, "My yang module not found"); goto done; @@ -741,7 +738,8 @@ yang_find_module_by_prefix(yang_stmt *ys, goto done; } #endif - if (strcmp(myprefix, prefix) == 0){ + myprefix = yang_find_myprefix(ys); + if (myprefix && strcmp(myprefix, prefix) == 0){ ymod = my_ymod; goto done; } diff --git a/test/test_leafref.sh b/test/test_leafref.sh index e4986695..715bb89b 100755 --- a/test/test_leafref.sh +++ b/test/test_leafref.sh @@ -55,7 +55,7 @@ if [ $? -ne 0 ]; then err fi -new "start backend" +new "start backend -s init -f $cfg -y $fyang" # start new backend sudo clixon_backend -s init -f $cfg -y $fyang if [ $? -ne 0 ]; then @@ -102,7 +102,7 @@ expecteof "$clixon_netconf -qf $cfg -y $fyang" "]]>]]>" "^]]>]]>$" -exit + new "cli leafref lo" expectfn "$clixon_cli -1f $cfg -y $fyang -l o set default-address absname lo" "^$"