- Fixed list pagination for CLI
This commit is contained in:
parent
a046306270
commit
28f58fb7d6
10 changed files with 919 additions and 362 deletions
|
|
@ -304,51 +304,38 @@ element2value(clicon_handle h,
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! Common get/get-config code for retrieving configuration and state information.
|
||||
/*! Specialized get for list-pagination
|
||||
*
|
||||
* It is specialized enough to have its own function. Specifically, extra attributes as well
|
||||
* as the list-paginaiton API
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] xe Request: <rpc><xn></rpc>
|
||||
* @param[in] content Get config/state/both
|
||||
* @param[in] db Database name
|
||||
* @param[in] xpath
|
||||
* @param[in] nsc
|
||||
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see from_client_get
|
||||
* @see from_client_get_config
|
||||
* @note pagination uses appending xpath with predicate, eg [position()<limit], this may not work
|
||||
* if there is an existing predicate
|
||||
* XXX Lots of this code (in particular at the end) is copy of get_common
|
||||
*/
|
||||
static int
|
||||
get_common(clicon_handle h,
|
||||
get_list_pagination(clicon_handle h,
|
||||
cxobj *xe,
|
||||
netconf_content content,
|
||||
char *db,
|
||||
int32_t depth,
|
||||
yang_stmt *yspec,
|
||||
char *xpath,
|
||||
cvec *nsc,
|
||||
char *username,
|
||||
cbuf *cbret
|
||||
)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xfilter;
|
||||
char *xpath = NULL;
|
||||
char *xpath2; /* With optional pageing predicate */
|
||||
cxobj *xret = NULL;
|
||||
cxobj **xvec = NULL;
|
||||
size_t xlen;
|
||||
cxobj **xvecnacm = NULL;
|
||||
size_t xlennacm;
|
||||
cxobj *xnacm = NULL;
|
||||
char *username;
|
||||
cvec *nsc = NULL; /* Create a netconf namespace context from filter */
|
||||
char *attr;
|
||||
int32_t depth = -1; /* Nr of levels to print, -1 is all, 0 is none */
|
||||
yang_stmt *yspec;
|
||||
int i;
|
||||
cxobj *xerr = NULL;
|
||||
int ret;
|
||||
char *reason = NULL;
|
||||
cbuf *cbmsg = NULL; /* For error msg */
|
||||
#ifdef LIST_PAGINATION
|
||||
uint32_t offset = 0;
|
||||
uint32_t limit = 0;
|
||||
uint32_t total = 0;
|
||||
|
|
@ -358,70 +345,21 @@ get_common(clicon_handle h,
|
|||
char *where = NULL;
|
||||
cbuf *cbpath = NULL;
|
||||
cxobj *x;
|
||||
int list_pagination = 0;
|
||||
int list_config;
|
||||
char *valstr;
|
||||
yang_stmt *ylist;
|
||||
cxobj *xcache = NULL;
|
||||
#endif /* LIST_PAGINATION */
|
||||
cxobj **xvec = NULL;
|
||||
size_t xlen;
|
||||
cxobj **xvecnacm = NULL;
|
||||
size_t xlennacm;
|
||||
cxobj *xerr = NULL;
|
||||
cbuf *cbmsg = NULL; /* For error msg */
|
||||
cxobj *xret = NULL;
|
||||
char *xpath2; /* With optional pageing predicate */
|
||||
int ret;
|
||||
int i;
|
||||
cxobj *xnacm = NULL;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
username = clicon_username_get(h);
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec9");
|
||||
goto done;
|
||||
}
|
||||
if ((xfilter = xml_find(xe, "filter")) != NULL){
|
||||
char *xpath0;
|
||||
cvec *nsc1 = NULL;
|
||||
cbuf *cbreason = NULL;
|
||||
|
||||
if ((xpath0 = xml_find_value(xfilter, "select"))==NULL)
|
||||
xpath0 = "/";
|
||||
/* Create namespace context for xpath from <filter>
|
||||
* The set of namespace declarations are those in scope on the
|
||||
* <filter> element.
|
||||
*/
|
||||
else
|
||||
if (xml_nsctx_node(xfilter, &nsc) < 0)
|
||||
goto done;
|
||||
if ((ret = xpath2canonical(xpath0, nsc, yspec, &xpath, &nsc1, &cbreason)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (netconf_bad_attribute(cbret, "application",
|
||||
"select", cbuf_get(cbreason)) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
if (cbreason)
|
||||
cbuf_free(cbreason);
|
||||
if (nsc)
|
||||
xml_nsctx_free(nsc);
|
||||
nsc = nsc1;
|
||||
}
|
||||
/* Clixon extensions: depth */
|
||||
if ((attr = xml_find_value(xe, "depth")) != NULL){
|
||||
if ((ret = parse_int32(attr, &depth, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_int32");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
if (netconf_bad_attribute(cbret, "application",
|
||||
"depth", "Unrecognized value of depth attribute") < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
#ifdef LIST_PAGINATION
|
||||
/* Check if list pagination */
|
||||
if ((x = xml_find_type(xe, NULL, "list-pagination", CX_ELMNT)) != NULL &&
|
||||
(valstr = xml_body(x)) != NULL &&
|
||||
strcmp(valstr,"true")==0)
|
||||
list_pagination = 1;
|
||||
/* Sanity check for list pagination: path must be a list/leaf-list, if it is,
|
||||
* check config/state
|
||||
*/
|
||||
if (list_pagination){
|
||||
/* Check if list/leaf-list */
|
||||
if (yang_path_arg(yspec, xpath, &ylist) < 0)
|
||||
goto done;
|
||||
|
|
@ -455,12 +393,17 @@ get_common(clicon_handle h,
|
|||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
#if 1 /* XXX For now state lists are not implemenetd */
|
||||
if (netconf_operation_not_supported(cbret, "protocol", "List pagination for state lists is not yet implemented") < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
#endif
|
||||
}
|
||||
/* offset */
|
||||
if (ret && (ret = element2value(h, xe, "offset", "none", cbret, &offset)) < 0)
|
||||
if ((ret = element2value(h, xe, "offset", "none", cbret, &offset)) < 0)
|
||||
goto done;
|
||||
/* limit */
|
||||
if ((ret = element2value(h, xe, "limit", "unbounded", cbret, &limit)) < 0)
|
||||
if (ret && (ret = element2value(h, xe, "limit", "unbounded", cbret, &limit)) < 0)
|
||||
goto done;
|
||||
/* direction */
|
||||
if (ret && (x = xml_find_type(xe, NULL, "direction", CX_ELMNT)) != NULL){
|
||||
|
|
@ -518,15 +461,10 @@ get_common(clicon_handle h,
|
|||
* 1. New api where state callback is registered, lock, iterative, unlock
|
||||
* 2. Read all here and count (fallback)
|
||||
*/
|
||||
|
||||
}
|
||||
/* Append predicate to original xpath and replace it */
|
||||
xpath2 = cbuf_get(cbpath);
|
||||
} /* list_pagination */
|
||||
else
|
||||
xpath2 = xpath;
|
||||
#endif /* LIST_PAGINATION */
|
||||
/* Read configuration */
|
||||
|
||||
switch (content){
|
||||
case CONTENT_CONFIG: /* config data only */
|
||||
/* specific xpath */
|
||||
|
|
@ -574,6 +512,289 @@ get_common(clicon_handle h,
|
|||
goto done;
|
||||
break;
|
||||
}/* switch content */
|
||||
if (content != CONTENT_CONFIG &&
|
||||
clicon_option_bool(h, "CLICON_VALIDATE_STATE_XML")){
|
||||
/* Check XML by validating it. return internal error with error cause
|
||||
* Primarily intended for user-supplied state-data.
|
||||
* The whole config tree must be present in case the state data references config data
|
||||
*/
|
||||
if ((ret = xml_yang_validate_all_top(h, xret, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret > 0 &&
|
||||
(ret = xml_yang_validate_add(h, xret, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (clicon_debug_get())
|
||||
clicon_log_xml(LOG_DEBUG, xret, "VALIDATE_STATE");
|
||||
if (clixon_netconf_internal_error(xerr,
|
||||
". Internal error, state callback returned invalid XML",
|
||||
NULL) < 0)
|
||||
goto done;
|
||||
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
} /* CLICON_VALIDATE_STATE_XML */
|
||||
|
||||
if (content == CONTENT_NONCONFIG){ /* state only, all config should be removed now */
|
||||
/* Keep state data only, remove everything that is config. Note that state data
|
||||
* may be a sub-part in a config tree, we need to traverse to find all
|
||||
*/
|
||||
if (xml_non_config_data(xret, NULL) < 0)
|
||||
goto done;
|
||||
if (xml_tree_prune_flagged_sub(xret, XML_FLAG_MARK, 1, NULL) < 0)
|
||||
goto done;
|
||||
if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)XML_FLAG_MARK) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Code complex to filter out anything that is outside of xpath
|
||||
* Actually this is a safety catch, should really be done in plugins
|
||||
* and modules_state functions.
|
||||
* But it is problematic, because defaults, at least of config data, is in place
|
||||
* and we need to re-add it.
|
||||
* Note original xpath
|
||||
*/
|
||||
if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
|
||||
goto done;
|
||||
|
||||
/* If vectors are specified then mark the nodes found and
|
||||
* then filter out everything else,
|
||||
* otherwise return complete tree.
|
||||
*/
|
||||
if (xvec != NULL){
|
||||
for (i=0; i<xlen; i++)
|
||||
xml_flag_set(xvec[i], XML_FLAG_MARK);
|
||||
}
|
||||
/* Remove everything that is not marked */
|
||||
if (!xml_flag(xret, XML_FLAG_MARK))
|
||||
if (xml_tree_prune_flagged_sub(xret, XML_FLAG_MARK, 1, NULL) < 0)
|
||||
goto done;
|
||||
/* reset flag */
|
||||
if (xml_apply(xret, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)XML_FLAG_MARK) < 0)
|
||||
goto done;
|
||||
/* Add default global values */
|
||||
if (xml_global_defaults(h, xret, nsc, xpath, yspec, 0) < 0)
|
||||
goto done;
|
||||
/* Add default recursive values */
|
||||
if (xml_default_recurse(xret, 0) < 0)
|
||||
goto done;
|
||||
|
||||
/* Add remaining attribute Sec 3.1.5:
|
||||
Any list or leaf-list that is limited includes, on the first element in the result set,
|
||||
a metadata value [RFC7952] called "remaining"*/
|
||||
if (limit && xlen){
|
||||
cxobj *xa;
|
||||
cbuf *cba = NULL;
|
||||
|
||||
/* Add remaining attribute */
|
||||
x = xvec[0];
|
||||
if ((xa = xml_new("remaining", x, CX_ATTR)) == NULL)
|
||||
goto done;
|
||||
if ((cba = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cba, "%u", remaining);
|
||||
if (xml_value_set(xa, cbuf_get(cba)) < 0)
|
||||
goto done;
|
||||
if (xml_prefix_set(xa, "cp") < 0)
|
||||
goto done;
|
||||
if (xmlns_set(x, "cp", "http://clicon.org/clixon-netconf-list-pagination") < 0)
|
||||
goto done;
|
||||
if (cba)
|
||||
cbuf_free(cba);
|
||||
}
|
||||
/* Pre-NACM access step */
|
||||
xnacm = clicon_nacm_cache(h);
|
||||
if (xnacm != NULL){ /* Do NACM validation */
|
||||
if (xpath_vec(xret, nsc, "%s", &xvecnacm, &xlennacm, xpath?xpath:"/") < 0)
|
||||
goto done;
|
||||
/* NACM datanode/module read validation */
|
||||
if (nacm_datanode_read(h, xret, xvecnacm, xlennacm, username, xnacm) < 0)
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbret, "<rpc-reply xmlns=\"%s\">", NETCONF_BASE_NAMESPACE); /* OK */
|
||||
if (xret==NULL)
|
||||
cprintf(cbret, "<data/>");
|
||||
else{
|
||||
if (xml_name_set(xret, NETCONF_OUTPUT_DATA) < 0)
|
||||
goto done;
|
||||
/* Top level is data, so add 1 to depth if significant */
|
||||
if (clicon_xml2cbuf(cbret, xret, 0, 0, depth>0?depth+1:depth) < 0)
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbret, "</rpc-reply>");
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
if (cbmsg)
|
||||
cbuf_free(cbmsg);
|
||||
if (cbpath)
|
||||
cbuf_free(cbpath);
|
||||
if (xerr)
|
||||
xml_free(xerr);
|
||||
if (xvec)
|
||||
free(xvec);
|
||||
if (xvecnacm)
|
||||
free(xvecnacm);
|
||||
if (xret)
|
||||
xml_free(xret);
|
||||
return retval;
|
||||
}
|
||||
#endif /* LIST_PAGINATION */
|
||||
|
||||
/*! Common get/get-config code for retrieving configuration and state information.
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] xe Request: <rpc><xn></rpc>
|
||||
* @param[in] content Get config/state/both
|
||||
* @param[in] db Database name
|
||||
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see from_client_get
|
||||
* @see from_client_get_config
|
||||
*/
|
||||
static int
|
||||
get_common(clicon_handle h,
|
||||
cxobj *xe,
|
||||
netconf_content content,
|
||||
char *db,
|
||||
cbuf *cbret
|
||||
)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xfilter;
|
||||
char *xpath = NULL;
|
||||
cxobj *xret = NULL;
|
||||
cxobj **xvec = NULL;
|
||||
size_t xlen;
|
||||
cxobj **xvecnacm = NULL;
|
||||
size_t xlennacm;
|
||||
cxobj *xnacm = NULL;
|
||||
char *username;
|
||||
cvec *nsc = NULL; /* Create a netconf namespace context from filter */
|
||||
char *attr;
|
||||
int32_t depth = -1; /* Nr of levels to print, -1 is all, 0 is none */
|
||||
yang_stmt *yspec;
|
||||
int i;
|
||||
cxobj *xerr = NULL;
|
||||
int ret;
|
||||
char *reason = NULL;
|
||||
cbuf *cbmsg = NULL; /* For error msg */
|
||||
char *xpath0;
|
||||
cvec *nsc1 = NULL;
|
||||
cbuf *cbreason = NULL;
|
||||
#ifdef LIST_PAGINATION
|
||||
int list_pagination = 0;
|
||||
char *valstr;
|
||||
cxobj *x;
|
||||
#endif /* LIST_PAGINATION */
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
username = clicon_username_get(h);
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec9");
|
||||
goto done;
|
||||
}
|
||||
if ((xfilter = xml_find(xe, "filter")) != NULL){
|
||||
if ((xpath0 = xml_find_value(xfilter, "select"))==NULL)
|
||||
xpath0 = "/";
|
||||
/* Create namespace context for xpath from <filter>
|
||||
* The set of namespace declarations are those in scope on the
|
||||
* <filter> element.
|
||||
*/
|
||||
else
|
||||
if (xml_nsctx_node(xfilter, &nsc) < 0)
|
||||
goto done;
|
||||
if ((ret = xpath2canonical(xpath0, nsc, yspec, &xpath, &nsc1, &cbreason)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (netconf_bad_attribute(cbret, "application",
|
||||
"select", cbuf_get(cbreason)) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
nsc = nsc1;
|
||||
}
|
||||
/* Clixon extensions: depth */
|
||||
if ((attr = xml_find_value(xe, "depth")) != NULL){
|
||||
if ((ret = parse_int32(attr, &depth, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_int32");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
if (netconf_bad_attribute(cbret, "application",
|
||||
"depth", "Unrecognized value of depth attribute") < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
#ifdef LIST_PAGINATION
|
||||
/* Check if list pagination */
|
||||
if ((x = xml_find_type(xe, NULL, "list-pagination", CX_ELMNT)) != NULL &&
|
||||
(valstr = xml_body(x)) != NULL &&
|
||||
strcmp(valstr,"true")==0)
|
||||
list_pagination = 1;
|
||||
/* Sanity check for list pagination: path must be a list/leaf-list, if it is,
|
||||
* check config/state
|
||||
*/
|
||||
if (list_pagination){
|
||||
if (get_list_pagination(h, xe, content, db,
|
||||
depth, yspec, xpath, nsc, username,
|
||||
cbret) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
#endif /* LIST_PAGINATION */
|
||||
/* Read configuration */
|
||||
switch (content){
|
||||
case CONTENT_CONFIG: /* config data only */
|
||||
/* specific xpath */
|
||||
if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, &xret, NULL, NULL) < 0) {
|
||||
if ((cbmsg = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
|
||||
if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
break;
|
||||
case CONTENT_ALL: /* both config and state */
|
||||
case CONTENT_NONCONFIG: /* state data only */
|
||||
if (clicon_option_bool(h, "CLICON_VALIDATE_STATE_XML")){
|
||||
/* Whole config tree, for validate debug */
|
||||
if (xmldb_get0(h, "running", YB_MODULE, nsc, NULL, 1, &xret, NULL, NULL) < 0) {
|
||||
if ((cbmsg = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
|
||||
if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
else if (content == CONTENT_ALL){
|
||||
/* specific xpath */
|
||||
if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, &xret, NULL, NULL) < 0) {
|
||||
if ((cbmsg = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason);
|
||||
if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
/* CONTENT_NONCONFIG */
|
||||
else if ((xret = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)/* Only top tree */
|
||||
goto done;
|
||||
break;
|
||||
}/* switch content */
|
||||
/* If not only config,
|
||||
* get state data from plugins as defined by plugin_statedata(), if any
|
||||
*/
|
||||
|
|
@ -583,7 +804,7 @@ get_common(clicon_handle h,
|
|||
break;
|
||||
case CONTENT_ALL: /* both config and state */
|
||||
case CONTENT_NONCONFIG: /* state data only */
|
||||
if ((ret = client_statedata(h, xpath2?xpath2:"/", nsc, &xret)) < 0)
|
||||
if ((ret = client_statedata(h, xpath?xpath:"/", nsc, &xret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){ /* Error from callback (error in xret) */
|
||||
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
|
||||
|
|
@ -659,34 +880,6 @@ get_common(clicon_handle h,
|
|||
/* Add default recursive values */
|
||||
if (xml_default_recurse(xret, 0) < 0)
|
||||
goto done;
|
||||
|
||||
#ifdef LIST_PAGINATION
|
||||
/* Add remaining attribute Sec 3.1.5:
|
||||
Any list or leaf-list that is limited includes, on the first element in the result set,
|
||||
a metadata value [RFC7952] called "remaining"*/
|
||||
if (list_pagination && limit && xlen){
|
||||
cxobj *xa;
|
||||
cbuf *cba = NULL;
|
||||
|
||||
/* Add remaining attribute */
|
||||
x = xvec[0];
|
||||
if ((xa = xml_new("remaining", x, CX_ATTR)) == NULL)
|
||||
goto done;
|
||||
if ((cba = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cba, "%u", remaining);
|
||||
if (xml_value_set(xa, cbuf_get(cba)) < 0)
|
||||
goto done;
|
||||
if (xml_prefix_set(xa, "cp") < 0)
|
||||
goto done;
|
||||
if (xmlns_set(x, "cp", "http://clicon.org/clixon-netconf-list-pagination") < 0)
|
||||
goto done;
|
||||
if (cba)
|
||||
cbuf_free(cba);
|
||||
}
|
||||
#endif /* LIST_PAGINATION */
|
||||
/* Pre-NACM access step */
|
||||
xnacm = clicon_nacm_cache(h);
|
||||
if (xnacm != NULL){ /* Do NACM validation */
|
||||
|
|
@ -711,10 +904,10 @@ get_common(clicon_handle h,
|
|||
retval = 0;
|
||||
done:
|
||||
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
|
||||
#ifdef LIST_PAGINATION
|
||||
if (cbpath)
|
||||
cbuf_free(cbpath);
|
||||
#endif
|
||||
if (cbreason)
|
||||
cbuf_free(cbreason);
|
||||
if (nsc)
|
||||
xml_nsctx_free(nsc);
|
||||
if (cbmsg)
|
||||
cbuf_free(cbmsg);
|
||||
if (reason)
|
||||
|
|
@ -727,8 +920,6 @@ get_common(clicon_handle h,
|
|||
free(xvec);
|
||||
if (xvecnacm)
|
||||
free(xvecnacm);
|
||||
if (nsc)
|
||||
xml_nsctx_free(nsc);
|
||||
if (xret)
|
||||
xml_free(xret);
|
||||
return retval;
|
||||
|
|
|
|||
|
|
@ -1312,99 +1312,3 @@ 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
|
||||
* @param[in] cvv Vector of cli string and instantiated variables
|
||||
* @param[in] argv Vector. Format: <xpath> <prefix> <namespace> <format>
|
||||
* Also, if there is a cligen variable called "xpath" it will override argv xpath arg
|
||||
*/
|
||||
int
|
||||
cli_pagination(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cbuf *cb = NULL;
|
||||
char *xpath = NULL;
|
||||
char *prefix = NULL;
|
||||
char *namespace = NULL;
|
||||
cxobj *xret = NULL;
|
||||
cxobj *xerr;
|
||||
cvec *nsc = NULL;
|
||||
char *formatstr;
|
||||
enum format_enum format;
|
||||
cxobj *xc;
|
||||
cg_var *cv;
|
||||
int i;
|
||||
const int win = 20;
|
||||
|
||||
if (cvec_len(argv) != 4){
|
||||
clicon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format>");
|
||||
goto done;
|
||||
}
|
||||
/* prefix:variable overrides argv */
|
||||
if ((cv = cvec_find(cvv, "xpath")) != NULL)
|
||||
xpath = cv_string_get(cv);
|
||||
else
|
||||
xpath = cvec_i_str(argv, 0);
|
||||
prefix = cvec_i_str(argv, 1);
|
||||
namespace = cvec_i_str(argv, 2);
|
||||
formatstr = cv_string_get(cvec_i(argv, 3)); /* Fourthformat: output format */
|
||||
if ((int)(format = format_str2int(formatstr)) < 0){
|
||||
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
||||
goto done;
|
||||
}
|
||||
if ((nsc = xml_nsctx_init(prefix, namespace)) == NULL)
|
||||
goto done;
|
||||
for (i = 0; i < 10; i++){
|
||||
if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc,
|
||||
CONTENT_NONCONFIG,
|
||||
-1, /* depth */
|
||||
win*i, /* offset */
|
||||
win*(i+1), /* limit */
|
||||
NULL, NULL, NULL, /* nyi */
|
||||
&xret) < 0){
|
||||
goto done;
|
||||
}
|
||||
if ((xerr = xpath_first(xret, NULL, "/rpc-error")) != NULL){
|
||||
clixon_netconf_error(xerr, "Get configuration", NULL);
|
||||
goto done;
|
||||
}
|
||||
xc = NULL;
|
||||
while ((xc = xml_child_each(xret, xc, CX_ELMNT)) != NULL)
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
clicon_xml2file_cb(stdout, xc, 0, 1, cligen_output);
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
xml2json_cb(stdout, xc, 1, cligen_output);
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
xml2txt_cb(stdout, xc, cligen_output); /* tree-formed text */
|
||||
break;
|
||||
case FORMAT_CLI:
|
||||
xml2cli_cb(stdout, xc, NULL, GT_HIDE, cligen_output); /* cli syntax */
|
||||
break;
|
||||
case FORMAT_NETCONF:
|
||||
break;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (xret)
|
||||
xml_free(xret);
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
return retval;
|
||||
}
|
||||
#else
|
||||
int
|
||||
cli_pagination(clicon_handle h, cvec *cvv, cvec *argv)
|
||||
{
|
||||
fprintf(stderr, "Not yet implemented\n");
|
||||
return 0;
|
||||
}
|
||||
#endif /* LIST_PAGINATION */
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
void cli_signal_block(clicon_handle h);
|
||||
void cli_signal_unblock(clicon_handle h);
|
||||
|
||||
/* If you do not find a function here it may be in clicon_cli_api.h which is
|
||||
/* If you do not find a function here it may be in clixon_cli_api.h which is
|
||||
the external API */
|
||||
|
||||
#endif /* _CLI_COMMON_H_ */
|
||||
|
|
|
|||
|
|
@ -891,3 +891,118 @@ cli_show_options(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
#ifdef LIST_PAGINATION
|
||||
|
||||
/*! Show pagination
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] cvv Vector of cli string and instantiated variables
|
||||
* @param[in] argv Vector. Format: <xpath> <prefix> <namespace> <format> <win>
|
||||
* Also, if there is a cligen variable called "xpath" it will override argv xpath arg
|
||||
*/
|
||||
int
|
||||
cli_pagination(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cbuf *cb = NULL;
|
||||
char *xpath = NULL;
|
||||
char *prefix = NULL;
|
||||
char *namespace = NULL;
|
||||
cxobj *xret = NULL;
|
||||
cxobj *xerr;
|
||||
cvec *nsc = NULL;
|
||||
char *str;
|
||||
enum format_enum format;
|
||||
cxobj *xc;
|
||||
cg_var *cv;
|
||||
int i;
|
||||
int j;
|
||||
int window = 0;
|
||||
cxobj **xvec = NULL;
|
||||
size_t xlen;
|
||||
|
||||
if (cvec_len(argv) != 5){
|
||||
clicon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <window>");
|
||||
goto done;
|
||||
}
|
||||
/* prefix:variable overrides argv */
|
||||
if ((cv = cvec_find(cvv, "xpath")) != NULL)
|
||||
xpath = cv_string_get(cv);
|
||||
else
|
||||
xpath = cvec_i_str(argv, 0);
|
||||
prefix = cvec_i_str(argv, 1);
|
||||
namespace = cvec_i_str(argv, 2);
|
||||
str = cv_string_get(cvec_i(argv, 3)); /* Fourthformat: output format */
|
||||
if ((int)(format = format_str2int(str)) < 0){
|
||||
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", str);
|
||||
goto done;
|
||||
}
|
||||
if ((str = cv_string_get(cvec_i(argv, 4))) != NULL){
|
||||
if (parse_int32(str, &window, NULL) < 1){
|
||||
clicon_err(OE_UNIX, errno, "error parsing window integer:%s", str);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (window == 0){
|
||||
clicon_err(OE_UNIX, EINVAL, "window is 0");
|
||||
goto done;
|
||||
}
|
||||
if ((nsc = xml_nsctx_init(prefix, namespace)) == NULL)
|
||||
goto done;
|
||||
for (i = 0;; i++){
|
||||
if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc,
|
||||
CONTENT_ALL,
|
||||
-1, /* depth */
|
||||
window*i, /* offset */
|
||||
window, /* limit */
|
||||
NULL, NULL, NULL, /* nyi */
|
||||
&xret) < 0){
|
||||
goto done;
|
||||
}
|
||||
if ((xerr = xpath_first(xret, NULL, "/rpc-error")) != NULL){
|
||||
clixon_netconf_error(xerr, "Get configuration", NULL);
|
||||
goto done;
|
||||
}
|
||||
if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0)
|
||||
goto done;
|
||||
for (j = 0; j<xlen; j++){
|
||||
xc = xvec[j];
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
clicon_xml2file_cb(stdout, xc, 0, 1, cligen_output);
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
xml2json_cb(stdout, xc, 1, cligen_output);
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
xml2txt_cb(stdout, xc, cligen_output); /* tree-formed text */
|
||||
break;
|
||||
case FORMAT_CLI:
|
||||
xml2cli_cb(stdout, xc, NULL, GT_HIDE, cligen_output); /* cli syntax */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (xlen != window) /* Break if fewer elements than requested */
|
||||
break;
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (xvec)
|
||||
free(xvec);
|
||||
if (xret)
|
||||
xml_free(xret);
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
return retval;
|
||||
}
|
||||
#else
|
||||
int
|
||||
cli_pagination(clicon_handle h, cvec *cvv, cvec *argv)
|
||||
{
|
||||
fprintf(stderr, "Not yet implemented\n");
|
||||
return 0;
|
||||
}
|
||||
#endif /* LIST_PAGINATION */
|
||||
|
|
|
|||
|
|
@ -147,4 +147,6 @@ int cli_auto_create(clicon_handle h, cvec *cvv, cvec *argv);
|
|||
int cli_auto_del(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
int cli_auto_sub_enter(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
|
||||
int cli_pagination(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
|
||||
#endif /* _CLIXON_CLI_API_H_ */
|
||||
|
|
|
|||
|
|
@ -77,7 +77,12 @@ show("Show a particular state of the system"){
|
|||
xml("Show comparison in xml"), compare_dbs((int32)0);
|
||||
text("Show comparison in text"), compare_dbs((int32)1);
|
||||
}
|
||||
pagination("Show list pagination"), cli_pagination("/exm:admins/exm:admin[exm:name='Bob']/exm:skill", "exm", "http://example.com/ns/example-module", "xml");
|
||||
pagination("Show list pagination") xpath("Show configuration") <xpath:string>("XPATH expression"){
|
||||
xml, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "xml", "10");
|
||||
cli, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "cli", "10");
|
||||
text, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "text", "10");
|
||||
json, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "json", "10");
|
||||
}
|
||||
configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", true, false);{
|
||||
xml("Show configuration as XML"), cli_auto_show("datamodel", "candidate", "xml", true, false);
|
||||
cli("Show configuration as CLI commands"), cli_auto_show("datamodel", "candidate", "cli", true, false, "set ");
|
||||
|
|
|
|||
|
|
@ -118,8 +118,8 @@ xp_yang_op_eq(xp_yang_ctx *xy1,
|
|||
|
||||
if ((xy = xy_dup(xy1)) == NULL)
|
||||
goto done;
|
||||
if(xy1 == NULL || xy2 == NULL || xy1->xy_node == NULL || xy2->xy_node == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "Error in xy1 or xy2 ");
|
||||
if (xy1 == NULL || xy2 == NULL || xy1->xy_node == NULL || xy2->xy_node == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "Invalid path-arg (Error in xy1 or xy2) ");
|
||||
goto done;
|
||||
}
|
||||
xy->xy_type = XT_BOOL;
|
||||
|
|
|
|||
174
test/test_pagination_config.sh
Executable file
174
test/test_pagination_config.sh
Executable file
|
|
@ -0,0 +1,174 @@
|
|||
#!/usr/bin/env bash
|
||||
# List pagination tests loosely based on draft-wwlh-netconf-list-pagination-00
|
||||
# The example-social yang file is used
|
||||
# This tests contains a large config list: members/member/favorites/uint8-numbers
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
echo "...skipped: Must run interactvely"
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
APPNAME=example
|
||||
|
||||
cfg=$dir/conf.xml
|
||||
fexample=$dir/example-social.yang
|
||||
|
||||
# Common example-module spec (fexample must be set)
|
||||
. ./example_social.sh
|
||||
|
||||
# Validate internal state xml
|
||||
: ${validatexml:=false}
|
||||
|
||||
# Number of audit-log entries
|
||||
#: ${perfnr:=20000}
|
||||
: ${perfnr:=200}
|
||||
|
||||
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>
|
||||
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_PIDFILE>$dir/restconf.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_XMLDB_FORMAT>xml</CLICON_XMLDB_FORMAT>
|
||||
<CLICON_STREAM_DISCOVERY_RFC8040>true</CLICON_STREAM_DISCOVERY_RFC8040>
|
||||
<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>
|
||||
<CLICON_VALIDATE_STATE_XML>$validatexml</CLICON_VALIDATE_STATE_XML>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
# Based on draft-wwlh-netconf-list-pagination-00 A.2 but bob has a generated uint8-numbers list
|
||||
# start file
|
||||
cat <<'EOF' > $dir/startup_db
|
||||
<config>
|
||||
<members xmlns="http://example.com/ns/example-social">
|
||||
<member>
|
||||
<member-id>alice</member-id>
|
||||
<email-address>alice@example.com</email-address>
|
||||
<password>$0$1543</password>
|
||||
<avatar>BASE64VALUE=</avatar>
|
||||
<tagline>Every day is a new day</tagline>
|
||||
<privacy-settings>
|
||||
<hide-network>false</hide-network>
|
||||
<post-visibility>public</post-visibility>
|
||||
</privacy-settings>
|
||||
<following>bob</following>
|
||||
<following>eric</following>
|
||||
<following>lin</following>
|
||||
<posts>
|
||||
<post>
|
||||
<timestamp>2020-07-08T13:12:45Z</timestamp>
|
||||
<title>My first post</title>
|
||||
<body>Hiya all!</body>
|
||||
</post>
|
||||
<post>
|
||||
<timestamp>2020-07-09T01:32:23Z</timestamp>
|
||||
<title>Sleepy...</title>
|
||||
<body>Catch y'all tomorrow.</body>
|
||||
</post>
|
||||
</posts>
|
||||
<favorites>
|
||||
<uint64-numbers>17</uint64-numbers>
|
||||
<uint64-numbers>13</uint64-numbers>
|
||||
<uint64-numbers>11</uint64-numbers>
|
||||
<uint64-numbers>7</uint64-numbers>
|
||||
<uint64-numbers>5</uint64-numbers>
|
||||
<uint64-numbers>3</uint64-numbers>
|
||||
<int8-numbers>-5</int8-numbers>
|
||||
<int8-numbers>-3</int8-numbers>
|
||||
<int8-numbers>-1</int8-numbers>
|
||||
<int8-numbers>1</int8-numbers>
|
||||
<int8-numbers>3</int8-numbers>
|
||||
<int8-numbers>5</int8-numbers>
|
||||
</favorites>
|
||||
</member>
|
||||
<member>
|
||||
<member-id>bob</member-id>
|
||||
<email-address>bob@example.com</email-address>
|
||||
<password>$0$1543</password>
|
||||
<avatar>BASE64VALUE=</avatar>
|
||||
<tagline>Here and now, like never before.</tagline>
|
||||
<privacy-settings>
|
||||
<post-visibility>public</post-visibility>
|
||||
</privacy-settings>
|
||||
<posts>
|
||||
<post>
|
||||
<timestamp>2020-08-14T03:32:25Z</timestamp>
|
||||
<body>Just got in.</body>
|
||||
</post>
|
||||
<post>
|
||||
<timestamp>2020-08-14T03:33:55Z</timestamp>
|
||||
<body>What's new?</body>
|
||||
</post>
|
||||
<post>
|
||||
<timestamp>2020-08-14T03:34:30Z</timestamp>
|
||||
<body>I'm bored...</body>
|
||||
</post>
|
||||
</posts>
|
||||
<favorites>
|
||||
EOF
|
||||
|
||||
new "generate config with $perfnr leaf-list entries"
|
||||
for (( i=0; i<$perfnr; i++ )); do
|
||||
echo " <uint64-numbers>$i</uint64-numbers>" >> $dir/startup_db
|
||||
done
|
||||
|
||||
# end file
|
||||
cat <<'EOF' >> $dir/startup_db
|
||||
<int8-numbers>-9</int8-numbers>
|
||||
<int8-numbers>2</int8-numbers>
|
||||
</favorites>
|
||||
</member>
|
||||
</members>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
new "test params: -f $cfg -s startup"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
sudo pkill -f clixon_backend # to be sure
|
||||
|
||||
new "start backend -s startup -f $cfg"
|
||||
start_backend -s startup -f $cfg
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
# XXX How to run without using a terminal?
|
||||
new "cli show"
|
||||
$clixon_cli -f $cfg -l o -1 show pagination xpath /es:members/es:member[es:member-id=\'bob\']/es:favorites/es:uint64-numbers cli
|
||||
#expectpart "$(echo "show pagination xpath /es:members/es:member[es:member-id=\'bob\']/es:favorites/es:uint64-numbers cli" | $clixon_cli -f $cfg -l o)" 0 foo
|
||||
#expectpart "$($clixon_cli -1 -f $cfg -l o show pagination xpath /es:members/es:member[es:member-id=\'bob\']/es:favorites/es:uint64-numbers cli)" 0 foo
|
||||
|
||||
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
|
||||
|
||||
unset validatexml
|
||||
unset perfnr
|
||||
|
||||
rm -rf $dir
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# List pagination tests according to draft-wwlh-netconf-list-pagination-00
|
||||
# Backlog items:
|
||||
# 1. "remaining" annotation RFC 7952
|
||||
# 2. pattern '.*[\n].*' { modifier invert-match;
|
||||
# XXX: handling of empty return ?
|
||||
# Follow the example-social example in the draft and the tests in Appendix A.2 + A.3.1/A.3.2
|
||||
# Basically only offset and limit supported
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
|
@ -23,10 +21,6 @@ RESTCONFIG=$(restconf_config none false)
|
|||
# Validate internal state xml
|
||||
: ${validatexml:=false}
|
||||
|
||||
# Number of list/leaf-list entries in file
|
||||
#: ${perfnr:=20000}
|
||||
: ${perfnr:=200}
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
|
|
@ -211,27 +205,59 @@ cat<<EOF > $fstate
|
|||
</stats>
|
||||
</member>
|
||||
</members>
|
||||
<audit-logs xmlns="http://example.com/ns/example-social">
|
||||
<audit-log>
|
||||
<timestamp>": "2020-10-11T06:47:59Z",</timestamp>
|
||||
<member-id>alice</member-id>
|
||||
<source-ip>192.168.0.92</source-ip>
|
||||
<request>POST /groups/group/2043</request>
|
||||
<outcome>true</outcome>
|
||||
</audit-log>
|
||||
<audit-log>
|
||||
<timestamp>2020-11-01T15:22:01Z</timestamp>
|
||||
<member-id>bob</member-id>
|
||||
<source-ip>192.168.2.16</source-ip>
|
||||
<request>POST /groups/group/123</request>
|
||||
<outcome>false</outcome>
|
||||
</audit-log>
|
||||
<audit-log>
|
||||
<timestamp>2020-12-12T21:00:28Z</timestamp>
|
||||
<member-id>eric</member-id>
|
||||
<source-ip>192.168.254.1</source-ip>
|
||||
<request>POST /groups/group/10</request>
|
||||
<outcome>true</outcome>
|
||||
</audit-log>
|
||||
<audit-log>
|
||||
<timestamp>2021-01-03T06:47:59Z</timestamp>
|
||||
<member-id>alice</member-id>
|
||||
<source-ip>192.168.0.92</source-ip>
|
||||
<request>POST /groups/group/333</request>
|
||||
<outcome>true</outcome>
|
||||
</audit-log>
|
||||
<audit-log>
|
||||
<timestamp>2021-01-21T10:00:00Z</timestamp>
|
||||
<member-id>bob</member-id>
|
||||
<source-ip>192.168.2.16</source-ip>
|
||||
<request>POST /groups/group/42</request>
|
||||
<outcome>true</outcome>
|
||||
</audit-log>
|
||||
<audit-log>
|
||||
<timestamp>2020-02-07T09:06:21Z</timestamp>
|
||||
<member-id>alice</member-id>
|
||||
<source-ip>192.168.0.92</source-ip>
|
||||
<request>POST /groups/group/1202</request>
|
||||
<outcome>true</outcome>
|
||||
</audit-log>
|
||||
<audit-log>
|
||||
<timestamp>2020-02-28T02:48:11Z</timestamp>
|
||||
<member-id>bob</member-id>
|
||||
<source-ip>192.168.2.16</source-ip>
|
||||
<request>POST /groups/group/345</request>
|
||||
<outcome>true</outcome>
|
||||
</audit-log>
|
||||
</audit-logs>
|
||||
EOF
|
||||
|
||||
# Check this later with committed data
|
||||
new "generate state with $perfnr list entries"
|
||||
echo "<audit-logs xmlns=\"http://example.com/ns/example-social\">" >> $fstate
|
||||
for (( i=0; i<$perfnr; i++ )); do
|
||||
echo " <audit-log>" >> $fstate
|
||||
mon=$(( ( RANDOM % 10 ) ))
|
||||
day=$(( ( RANDOM % 10 ) ))
|
||||
hour=$(( ( RANDOM % 10 ) ))
|
||||
echo " <timestamp>2020-0$mon-0$dayT0$hour:48:11Z</timestamp>" >> $fstate
|
||||
echo " <member-id>bob</member-id>" >> $fstate
|
||||
ip1=$(( ( RANDOM % 255 ) ))
|
||||
ip2=$(( ( RANDOM % 255 ) ))
|
||||
echo " <source-ip>192.168.$ip1.$ip2</source-ip>" >> $fstate
|
||||
echo " <request>POST</request>" >> $fstate
|
||||
echo " <outcome>true</outcome>" >> $fstate
|
||||
echo " </audit-log>" >> $fstate
|
||||
done
|
||||
echo -n "</audit-logs>" >> $fstate # No CR
|
||||
|
||||
# Run limit-only test with netconf, restconf+xml and restconf+json
|
||||
# Args:
|
||||
# 1. offset
|
||||
|
|
@ -382,16 +408,7 @@ testlimit 6 0 0 ""
|
|||
|
||||
# This is incomplete wrt the draft
|
||||
new "A.3.7. limit=2 offset=2"
|
||||
testlimitn 2 2 2 "11 7"
|
||||
|
||||
# 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>" "<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"
|
||||
#expectpart "$(curl $CURLOPTS -X GET -H "Accept: application/yang-collection+xml" $RCPROTO://localhost/restconf/data/example-module:get-list-pagination/library/artist=Foo%20Fighters/album/?count=2)" 0 "HTTP/1.1 200 OK" "application/yang-collection+xml" '<collection xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-collection"><album xmlns="http://example.com/ns/example-jukebox"><name>Crime and Punishment</name><year>1995</year></album><album xmlns="http://example.com/ns/example-jukebox"><name>One by One</name><year>2002</year></album></collection>'
|
||||
testlimit 2 2 2 "11 7"
|
||||
|
||||
if [ $RC -ne 0 ]; then
|
||||
new "Kill restconf daemon"
|
||||
|
|
@ -411,7 +428,6 @@ fi
|
|||
|
||||
unset RESTCONFIG
|
||||
unset validatexml
|
||||
unset perfnr
|
||||
|
||||
rm -rf $dir
|
||||
|
||||
150
test/test_pagination_state.sh
Executable file
150
test/test_pagination_state.sh
Executable file
|
|
@ -0,0 +1,150 @@
|
|||
#!/usr/bin/env bash
|
||||
# List pagination tests loosely based on draft-wwlh-netconf-list-pagination-00
|
||||
# The example-social yang file is used
|
||||
# This tests contains a large state list: audit-logs from the example
|
||||
# Only CLI is used
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
APPNAME=example
|
||||
|
||||
cfg=$dir/conf.xml
|
||||
fexample=$dir/example-social.yang
|
||||
fstate=$dir/mystate.xml
|
||||
|
||||
# Common example-module spec (fexample must be set)
|
||||
. ./example_social.sh
|
||||
|
||||
# Validate internal state xml
|
||||
: ${validatexml:=false}
|
||||
|
||||
# Number of audit-log entries
|
||||
#: ${perfnr:=20000}
|
||||
: ${perfnr:=200}
|
||||
|
||||
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>
|
||||
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_PIDFILE>$dir/restconf.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_XMLDB_FORMAT>json</CLICON_XMLDB_FORMAT>
|
||||
<CLICON_STREAM_DISCOVERY_RFC8040>true</CLICON_STREAM_DISCOVERY_RFC8040>
|
||||
<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>
|
||||
<CLICON_VALIDATE_STATE_XML>$validatexml</CLICON_VALIDATE_STATE_XML>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
# See draft-wwlh-netconf-list-pagination-00 A.2 (only stats and audit-log)
|
||||
# XXX members not currently used, only audit-logs as generated below
|
||||
cat<<EOF > $fstate
|
||||
<members xmlns="http://example.com/ns/example-social">
|
||||
<member>
|
||||
<member-id>alice</member-id>
|
||||
<stats>
|
||||
<joined>2020-07-08T12:38:32Z</joined>
|
||||
<membership-level>admin</membership-level>
|
||||
<last-activity>2021-04-01T02:51:11Z</last-activity>
|
||||
</stats>
|
||||
</member>
|
||||
<member>
|
||||
<member-id>bob</member-id>
|
||||
<stats>
|
||||
<joined>2020-08-14T03:30:00Z</joined>
|
||||
<membership-level>standard</membership-level>
|
||||
<last-activity>2020-08-14T03:34:30Z</last-activity>
|
||||
</stats>
|
||||
</member>
|
||||
<member>
|
||||
<member-id>eric</member-id>
|
||||
<stats>
|
||||
<joined>2020-09-17T19:38:32Z</joined>
|
||||
<membership-level>pro</membership-level>
|
||||
<last-activity>2020-09-17T18:02:04Z</last-activity>
|
||||
</stats>
|
||||
</member>
|
||||
<member>
|
||||
<member-id>lin</member-id>
|
||||
<stats>
|
||||
<joined>2020-07-09T12:38:32Z</joined>
|
||||
<membership-level>standard</membership-level>
|
||||
<last-activity>2021-04-01T02:51:11Z</last-activity>
|
||||
</stats>
|
||||
</member>
|
||||
<member>
|
||||
<member-id>joe</member-id>
|
||||
<stats>
|
||||
<joined>2020-10-08T12:38:32Z</joined>
|
||||
<membership-level>pro</membership-level>
|
||||
<last-activity>2021-04-01T02:51:11Z</last-activity>
|
||||
</stats>
|
||||
</member>
|
||||
</members>
|
||||
EOF
|
||||
|
||||
# Append generated state data to $fstate file
|
||||
new "generate state with $perfnr list entries"
|
||||
echo "<audit-logs xmlns=\"http://example.com/ns/example-social\">" >> $fstate
|
||||
for (( i=0; i<$perfnr; i++ )); do
|
||||
echo " <audit-log>" >> $fstate
|
||||
mon=$(( ( RANDOM % 10 ) ))
|
||||
day=$(( ( RANDOM % 10 ) ))
|
||||
hour=$(( ( RANDOM % 10 ) ))
|
||||
echo " <timestamp>2020-0$mon-0$dayT0$hour:48:11Z</timestamp>" >> $fstate
|
||||
echo " <member-id>bob</member-id>" >> $fstate
|
||||
ip1=$(( ( RANDOM % 255 ) ))
|
||||
ip2=$(( ( RANDOM % 255 ) ))
|
||||
echo " <source-ip>192.168.$ip1.$ip2</source-ip>" >> $fstate
|
||||
echo " <request>POST</request>" >> $fstate
|
||||
echo " <outcome>true</outcome>" >> $fstate
|
||||
echo " </audit-log>" >> $fstate
|
||||
done
|
||||
echo -n "</audit-logs>" >> $fstate # No CR
|
||||
|
||||
new "test params: -f $cfg -s init -- -sS $fstate"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
sudo pkill -f clixon_backend # to be sure
|
||||
|
||||
new "start backend -s init -f $cfg -- -sS $fstate"
|
||||
start_backend -s init -f $cfg -- -sS $fstate
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
new "cli show"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o show pagination xpath /es:audit-logs/es:audit-log cli)" 255 "Get configuration: protocol operation-not-supported List pagination for state lists is not yet implemented"
|
||||
|
||||
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
|
||||
|
||||
unset validatexml
|
||||
unset perfnr
|
||||
|
||||
rm -rf $dir
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
Loading…
Add table
Add a link
Reference in a new issue