- 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
This commit is contained in:
Olof hagsand 2021-07-21 14:40:58 +02:00
parent 2485bec483
commit 77bacc93bb
13 changed files with 87 additions and 33 deletions

View file

@ -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

View file

@ -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)

View file

@ -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 */

View file

@ -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));

View file

@ -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;

View file

@ -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

View file

@ -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;
#endif
retval = 0;
done:
return retval;

View file

@ -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, "><get-pageable-list xmlns=\"%s\"", NETCONF_COLLECTION_NAMESPACE);
/* Clixon extension, content=all,config, or nonconfig */
if ((int)content != -1)
@ -1012,6 +1014,7 @@ clicon_rpc_get_pageable_list(clicon_handle h,
free(msg);
return retval;
}
#endif /* LIST_PAGINATION */
/*! Send a close a netconf user session. Socket is also closed if still open
*

View file

@ -199,8 +199,9 @@ ys_grouping_resolve(yang_stmt *yuses,
}
/*! This is an augment node, augment the original datamodel.
*
* @param[in] h Clicon handle
* @param[in] ys The augment statement
* @param[in] yspec Yang specification
* @see RFC7950 Sec 7.17
* The target node MUST be either a container, list, choice, case, input,
* output, or notification node.
@ -215,7 +216,8 @@ ys_grouping_resolve(yang_stmt *yuses,
* struct to the yang statements being inserted.
*/
static int
yang_augment_node(yang_stmt *ys)
yang_augment_node(clicon_handle h,
yang_stmt *ys)
{
int retval = -1;
char *schema_nodeid;
@ -352,6 +354,13 @@ yang_augment_node(yang_stmt *ys)
if (yang_when_nsc_set(yc, wnsc) < 0)
goto done;
}
/* Note: ys_populate2 called as a special case here since the inserted child is
* not covered by Step 9 in yang_parse_post
*/
if (ys_populate2(yc, h) < 0)
goto done;
if (yang_apply(yc, -1, ys_populate2, 1, (void*)h) < 0)
goto done;
}
ok:
retval = 0;
@ -362,6 +371,8 @@ yang_augment_node(yang_stmt *ys)
}
/*! Find all top-level augments in a module and change original datamodels.
*
* @param[in] h Clicon handle
* @param[in] ymod Yang statement of type module/sub-module
* @retval 0 OK
* @retval -1 Error
@ -369,7 +380,8 @@ yang_augment_node(yang_stmt *ys)
* another module not yet augmented.
*/
static int
yang_augment_module(yang_stmt *ymod)
yang_augment_module(clicon_handle h,
yang_stmt *ymod)
{
int retval = -1;
@ -379,7 +391,7 @@ yang_augment_module(yang_stmt *ymod)
while ((ys = yn_each(ymod, ys)) != NULL){
switch (yang_keyword_get(ys)){
case Y_AUGMENT: /* top-level */
if (yang_augment_node(ys) < 0)
if (yang_augment_node(h, ys) < 0)
goto done;
break;
default:
@ -1463,7 +1475,7 @@ yang_parse_post(clicon_handle h,
* another module not yet augmented.
*/
for (i=0; i<ylen; i++)
if (yang_augment_module(ylist[i]) < 0)
if (yang_augment_module(h, ylist[i]) < 0)
goto done;
/* 8: Check deviations: not-supported add/delete/replace statements
@ -1473,7 +1485,11 @@ yang_parse_post(clicon_handle h,
if (yang_apply(yang_child_i(yspec, i), -1, yang_deviation, 1, (void*)h) < 0)
goto done;
/* 9: Go through parse tree and do 2nd step populate (eg default) */
/* 9: Go through parse tree and do 2nd step populate (eg default)
* Note that augments in step 7 are not covered here since they apply to
* modules already loaded. Therefore the call to ys_populate2 is made inline in
* yang_augment_node()
*/
for (i=0; i<ylen; i++)
if (yang_apply(ylist[i], -1, ys_populate2, 1, (void*)h) < 0)
goto done;

View file

@ -10,10 +10,14 @@ cfg=$dir/conf.xml
fexample=$dir/example-module.yang
fstate=$dir/mystate.xml
# Define default restconfig config: RESTCONFIG
RESTCONFIG=$(restconf_config none false)
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
<CLICON_FEATURE>clixon-restconf:allow-auth-none</CLICON_FEATURE> <!-- Use auth-type=none -->
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
<CLICON_YANG_MAIN_DIR>$dir</CLICON_YANG_MAIN_DIR>
@ -26,6 +30,7 @@ cat <<EOF > $cfg
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
$RESTCONFIG
</clixon-config>
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 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><get-pageable-list xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination\"><datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore><list-target xmlns:exm=\"http://example.com/ns/example-module\">/exm:admins/exm:admin[exm:name='Bob']/exm:skill</list-target><count>2</count></get-pageable-list></rpc>]]>]]>" '<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><pageable-list xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination"><skill xmlns="http://example.com/ns/example-module"><name>Conflict Resolution</name><rank>93</rank></skill><skill xmlns="http://example.com/ns/example-module"><name>Management</name><rank>23</rank></skill></pageable-list></rpc-reply>]]>]]>$'
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><get-pageable-list xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination\"><datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore><list-target xmlns:exm=\"http://example.com/ns/example-module\">/exm:admins/exm:admin[exm:name='Bob']/exm:skill</list-target><count>2</count></get-pageable-list></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><pageable-list xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination\"><skill xmlns=\"http://example.com/ns/example-module\"><name>Conflict Resolution</name><rank>93</rank></skill><skill xmlns=\"http://example.com/ns/example-module\"><name>Management</name><rank>23</rank></skill></pageable-list></rpc-reply>]]>]]>$"
new "C.2. 'skip' Parameter NETCONF"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><get-pageable-list xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination\"><datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore><list-target xmlns:exm=\"http://example.com/ns/example-module\">/exm:admins/exm:admin[exm:name='Bob']/exm:skill</list-target><count>2</count><skip>2</skip></get-pageable-list></rpc>]]>]]>" '<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><pageable-list xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination"><skill xmlns="http://example.com/ns/example-module"><name>Organization</name><rank>44</rank></skill><skill xmlns="http://example.com/ns/example-module"><name>Problem Solving</name><rank>98</rank></skill></pageable-list></rpc-reply>]]>]]>$'
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><get-pageable-list xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination\"><datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore><list-target xmlns:exm=\"http://example.com/ns/example-module\">/exm:admins/exm:admin[exm:name='Bob']/exm:skill</list-target><count>2</count><skip>2</skip></get-pageable-list></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><pageable-list xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-list-pagination\"><skill xmlns=\"http://example.com/ns/example-module\"><name>Organization</name><rank>44</rank></skill><skill xmlns=\"http://example.com/ns/example-module\"><name>Problem Solving</name><rank>98</rank></skill></pageable-list></rpc-reply>]]>]]>$"
# 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 "<skill xmlns=\"http://example.com/ns/example-module\"><name>Conflict Resolution</name><rank>93</rank></skill>" "<skill xmlns=\"http://example.com/ns/example-module\"><name>Management</name><rank>23</rank></skill>" --not-- "<skill xmlns=\"http://example.com/ns/example-module\"><name>Organization</name><rank>44</rank></skill>"
echo "$clixon_cli -1 -f $cfg -l o show pagination"
expectpart "$($clixon_cli -1 -f $cfg -l o show pagination)" 0 "<skill xmlns=\"http://example.com/ns/example-module\">" "<name>Conflict Resolution</name>" "<rank>93</rank>" "<name>Management</name>" "<rank>23</rank>" --not-- "<name>Organization</name>" "<rank>44</rank></skill>"
# 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

View file

@ -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 '<input xmlns="urn:example:clixon"></input>' $proto://$addr/restconf/operations/clixon-example:empty)" 0 "HTTP/$HVER 204"

View file

@ -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

View file

@ -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: