From 77bacc93bb00e104bc1969c2c5facc91e1b9c0e9 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Wed, 21 Jul 2021 14:40:58 +0200 Subject: [PATCH] - Updated code to clixon 5.2 status - Added LIST_PAGINATION clixon_custom constant - Fix: leafs added as augments on rpc input/output lacked cv:s --- CHANGELOG.md | 1 + apps/backend/backend_client.c | 4 +++ apps/cli/cli_common.c | 9 ++++++ apps/restconf/restconf_err.c | 2 ++ apps/restconf/restconf_methods_get.c | 7 +++++ include/clixon_custom.h | 7 +++++ lib/src/clixon_netconf_lib.c | 4 ++- lib/src/clixon_proto_client.c | 3 ++ lib/src/clixon_yang_parse_lib.c | 30 +++++++++++++++----- test/test_pagination.sh | 41 +++++++++++++++++----------- test/test_restconf.sh | 4 --- test/test_restconf_op.sh | 4 ++- yang/mandatory/Makefile.in | 4 --- 13 files changed, 87 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28838c9d..b53a59d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,7 @@ Users may have to change how they access the system * YANG when was not properly implemented for default values * Fixed: SEGV in clixon_netconf_lib functions from internal errors including validation. * Check xerr argument both before and after call on netconf lib functions +* Fixed: Leafs added as augments on NETCONF RPC input/output lacked cv:s causing error in default handling * Fixed: RFC 8040 yang-data extension allows non-key lists * Added YANG_FLAG_NOKEY as exception to mandatory key lists * Fixed: mandatory leaf in a uses statement caused abort diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 5361c66f..300431eb 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -1335,6 +1335,7 @@ from_client_kill_session(clicon_handle h, return retval; } +#ifdef LIST_PAGINATION /*! Help function for parsing restconf query parameter and setting netconf attribute * * If not "unbounded", parse and set a numeric value @@ -1660,6 +1661,7 @@ from_client_get_pageable_list(clicon_handle h, xml_free(xret); return retval; } +#endif /* LIST_PAGINATION */ /*! Create a notification subscription * @param[in] h Clicon handle @@ -2286,10 +2288,12 @@ backend_rpc_init(clicon_handle h) if (rpc_callback_register(h, from_client_validate, NULL, NETCONF_BASE_NAMESPACE, "validate") < 0) goto done; +#ifdef LIST_PAGINATION /* draft-ietf-netconf-restconf-collection-00 */ if (rpc_callback_register(h, from_client_get_pageable_list, NULL, NETCONF_COLLECTION_NAMESPACE, "get-pageable-list") < 0) goto done; +#endif /* In backend_client.? RPC from RFC 5277 */ if (rpc_callback_register(h, from_client_create_subscription, NULL, EVENT_RFC5277_NAMESPACE, "create-subscription") < 0) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index f3724990..3eaa1954 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -1312,6 +1312,7 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv) return cligen_help(ch, stdout, pt); } +#ifdef LIST_PAGINATION /*! Show pagination/collection * XXX: This is hardcoded only for test_pagination.sh * @param[in] h Clicon handle @@ -1383,4 +1384,12 @@ cli_pagination(clicon_handle h, cvec *vars, cvec *argv) cbuf_free(cb); return retval; } +#else +int +cli_pagination(clicon_handle h, cvec *vars, cvec *argv) +{ + fprintf(stderr, "Not yet implemented\n"); + return 0; +} +#endif /* LIST_PAGINATION */ diff --git a/apps/restconf/restconf_err.c b/apps/restconf/restconf_err.c index 553fc16e..60af7059 100644 --- a/apps/restconf/restconf_err.c +++ b/apps/restconf/restconf_err.c @@ -309,6 +309,8 @@ api_return_err(clicon_handle h, } break; default: /* Just ignore the body so that there is a reply */ + clicon_err(OE_YANG, EINVAL, "Invalid media type %d", media); + goto done; break; } /* switch media */ assert(cbuf_len(cb)); diff --git a/apps/restconf/restconf_methods_get.c b/apps/restconf/restconf_methods_get.c index 6b9d1ae1..85239f18 100644 --- a/apps/restconf/restconf_methods_get.c +++ b/apps/restconf/restconf_methods_get.c @@ -311,6 +311,7 @@ api_data_get2(clicon_handle h, return retval; } +#ifdef LIST_PAGINATION /*! GET Collection * According to restconf collection draft. Lists, work in progress * @param[in] h Clixon handle @@ -528,6 +529,7 @@ api_data_collection(clicon_handle h, free(xvec); return retval; } +#endif /* LIST_PAGINATION */ /*! REST HEAD method * @param[in] h Clixon handle @@ -605,8 +607,13 @@ api_data_get(clicon_handle h, break; case YANG_COLLECTION_XML: case YANG_COLLECTION_JSON: +#ifdef LIST_PAGINATION if (api_data_collection(h, req, api_path, pcvec, pi, qvec, pretty, media_out) < 0) goto done; +#else + if (restconf_notimplemented(h, req, pretty, media_out) < 0) + goto done; +#endif break; default: break; diff --git a/include/clixon_custom.h b/include/clixon_custom.h index 920b45f4..32b75f88 100644 --- a/include/clixon_custom.h +++ b/include/clixon_custom.h @@ -117,3 +117,10 @@ * Remove this when regression test */ #undef YANG_PATCH + +/*! Enable list pagination drafts + * draft-wwlh-netconf-list-pagination-00, + * draft-wwlh-netconf-list-pagination-nc-00 + * draft-wwlh-netconf-list-pagination-rc-00 + */ +#define LIST_PAGINATION diff --git a/lib/src/clixon_netconf_lib.c b/lib/src/clixon_netconf_lib.c index 135cbbf2..d8df2fc4 100644 --- a/lib/src/clixon_netconf_lib.c +++ b/lib/src/clixon_netconf_lib.c @@ -1526,9 +1526,11 @@ netconf_module_load(clicon_handle h) if (clicon_option_bool(h, "CLICON_NETCONF_MESSAGE_ID_OPTIONAL") == 1) xml_bind_netconf_message_id_optional(1); #endif +#ifdef LIST_PAGINATION /* Load netconf list pagination */ if (yang_spec_parse_module(h, "ietf-netconf-list-pagination", NULL, yspec)< 0) - goto done; + goto done; +#endif retval = 0; done: return retval; diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index cb1487f7..4e80ffe1 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -878,6 +878,7 @@ clicon_rpc_get(clicon_handle h, return retval; } +#ifdef LIST_PAGINATION /*! Get database configuration and state data collection * @param[in] h Clicon handle * @param[in] xpath To identify a list/leaf-list @@ -939,6 +940,7 @@ clicon_rpc_get_pageable_list(clicon_handle h, cprintf(cb, " username=\"%s\"", username); cprintf(cb, " xmlns:%s=\"%s\"", NETCONF_BASE_PREFIX, NETCONF_BASE_NAMESPACE); + cprintf(cb, " %s", NETCONF_MESSAGE_ID_ATTR); cprintf(cb, "> $cfg $cfg ietf-netconf:startup + clixon-restconf:allow-auth-none /usr/local/share/clixon $IETFRFC $dir @@ -26,6 +30,7 @@ cat < $cfg $APPNAME /usr/local/lib/$APPNAME/cli /usr/local/lib/$APPNAME/clispec + $RESTCONFIG EOF @@ -303,22 +308,23 @@ if [ $RC -ne 0 ]; then new "start restconf daemon" start_restconf -f $cfg - - new "wait restconf" - wait_restconf fi +new "wait restconf" +wait_restconf + # draft-wwlh-netconf-list-pagination-nc-00.txt new "C.1. 'count' Parameter NETCONF" -expecteof "$clixon_netconf -qf $cfg" 0 "ds:running/exm:admins/exm:admin[exm:name='Bob']/exm:skill2]]>]]>" 'Conflict Resolution93Management23]]>]]>$' +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOds:running/exm:admins/exm:admin[exm:name='Bob']/exm:skill2]]>]]>" "Conflict Resolution93Management23]]>]]>$" new "C.2. 'skip' Parameter NETCONF" -expecteof "$clixon_netconf -qf $cfg" 0 "ds:running/exm:admins/exm:admin[exm:name='Bob']/exm:skill22]]>]]>" 'Organization44Problem Solving98]]>]]>$' +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOds:running/exm:admins/exm:admin[exm:name='Bob']/exm:skill22]]>]]>" "Organization44Problem Solving98]]>]]>$" # CLI # XXX This relies on a very specific clispec command: need a more generic test new "cli show" -expectpart "$($clixon_cli -1 -f $cfg -l o show pagination)" 0 "Conflict Resolution93" "Management23" --not-- "Organization44" +echo "$clixon_cli -1 -f $cfg -l o show pagination" +expectpart "$($clixon_cli -1 -f $cfg -l o show pagination)" 0 "" "Conflict Resolution" "93" "Management" "23" --not-- "Organization" "44" # draft-wwlh-netconf-list-pagination-rc-00.txt #new "A.1. 'count' Parameter RESTCONF" @@ -329,17 +335,20 @@ if [ $RC -ne 0 ]; then stop_restconf fi -if [ $BE -eq 0 ]; then - exit # BE +if [ $BE -ne 0 ]; then + new "Kill backend" + # Check if premature kill + pid=$(pgrep -u root -f clixon_backend) + if [ -z "$pid" ]; then + err "backend already dead" + fi + # kill backend + stop_backend -f $cfg fi -new "Kill backend" -# Check if premature kill -pid=$(pgrep -u root -f clixon_backend) -if [ -z "$pid" ]; then - err "backend already dead" -fi -# kill backend -stop_backend -f $cfg +unset RESTCONFIG rm -rf $dir + +new "endtest" +endtest diff --git a/test/test_restconf.sh b/test/test_restconf.sh index 135d2ba6..6d32d836 100755 --- a/test/test_restconf.sh +++ b/test/test_restconf.sh @@ -300,10 +300,6 @@ function testrun() new "restconf empty rpc JSON" expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d {\"clixon-example:input\":null} $proto://$addr/restconf/operations/clixon-example:empty)" 0 "HTTP/$HVER 204" - # -I / --head get headers only HEAD - new "restconf HEAD. RFC 8040 4.2" - expectpart "$(curl $CURLOPTS -I --head "Accept: application/yang-data+json" $RCPROTO://localhost/restconf/data)" 0 "HTTP/1.1 200 OK" "Content-Type: application/yang-data+json" - new "restconf empty rpc XML" expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" -d '' $proto://$addr/restconf/operations/clixon-example:empty)" 0 "HTTP/$HVER 204" diff --git a/test/test_restconf_op.sh b/test/test_restconf_op.sh index 40e58e06..8567b166 100755 --- a/test/test_restconf_op.sh +++ b/test/test_restconf_op.sh @@ -81,13 +81,15 @@ if [ $BE -ne 0 ]; then err fi sudo pkill -f clixon_backend # to be sure + new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi -new "waiting" +new "wait backend" wait_backend + if [ $RC -ne 0 ]; then new "kill old restconf daemon" stop_restconf_pre diff --git a/yang/mandatory/Makefile.in b/yang/mandatory/Makefile.in index d0d9d0ce..fc31d905 100644 --- a/yang/mandatory/Makefile.in +++ b/yang/mandatory/Makefile.in @@ -54,13 +54,9 @@ YANGSPECS += ietf-yang-patch@2017-02-22.yang YANGSPECS += ietf-origin@2018-02-14.yang YANGSPECS += ietf-yang-metadata@2016-08-05.yang YANGSPECS += ietf-netconf-with-defaults@2011-06-01.yang -<<<<<<< HEAD # in draft-wwlh-netconf-list-pagination: YANGSPECS += ietf-netconf-list-pagination@2020-10-30.yang -======= ->>>>>>> fixes for compilation - all: clean: