* Removed cli_debug(). Use cli_debug_backend() or cli_debug_restconf() instead.

* Created restconf debug rpc stub function and documented restconf debugging
This commit is contained in:
Olof hagsand 2021-03-22 14:56:05 +01:00
parent 6d23963d8b
commit 709459304f
10 changed files with 132 additions and 36 deletions

View file

@ -1164,6 +1164,57 @@ clicon_rpc_debug(clicon_handle h,
return retval;
}
/*! Send a debug request to backend server to set restconf debug
* @param[in] h CLICON handle
* @param[in] level Debug level
* @retval 0 OK
* @retval -1 Error and logged to syslog
* @note The following must hold:
* 1. clixon-restconf.yang is used (so that debug config can be set)
* 2. AND the <restconf> XML is in running db not in clixon-config (so that restconf reads the new config from backend)
* 3 CLICON_BACKEND_RESTCONF_PROCESS is true (so that backend restarts restconf)
*/
int
clicon_rpc_restconf_debug(clicon_handle h,
int level)
{
int retval = -1;
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
char *username;
uint32_t session_id;
if (session_id_check(h, &session_id) < 0)
goto done;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode(session_id,
"<rpc xmlns=\"%s\" username=\"%s\"><edit-config><target><candidate/></target><config><restconf xmlns=\"%s\"><debug>%d</debug></restconf></config></edit-config></rpc>",
NETCONF_BASE_NAMESPACE,
username?username:"",
CLIXON_RESTCONF_NS,
level)) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
clixon_netconf_error(xerr, "Debug", NULL);
goto done;
}
if (xpath_first(xret, NULL, "//rpc-reply/ok") == NULL){
clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
goto done;
}
if ((retval = clicon_rpc_commit(h)) < 0)
goto done;
done:
if (msg)
free(msg);
if (xret)
xml_free(xret);
return retval;
}
/*! Send a hello request to the backend server
* @param[in] h CLICON handle
* @param[in] level Debug level

View file

@ -1466,6 +1466,40 @@ yang_print(FILE *f,
return yang_print_cb(f, yn, fprintf);
}
/* Log/debug info about top-level (sub)modules no recursion
* @param[in] f File to print to.
* @param[in] yspec Yang spec
*/
int
yang_spec_dump(yang_stmt *yspec,
int dbglevel)
{
int retval = -1;
yang_stmt *ym = NULL;
yang_stmt *yrev;
cbuf *cb = NULL;
if ((cb = cbuf_new()) ==NULL){
clicon_err(OE_YANG, errno, "cbuf_new");
goto done;
}
while ((ym = yn_each(yspec, ym)) != NULL) {
cprintf(cb, "%s", yang_key2str(ym->ys_keyword));
cprintf(cb, " %s", ym->ys_argument);
if ((yrev = yang_find(ym, Y_REVISION, NULL)) != NULL){
cprintf(cb, "@%u", cv_uint32_get(yang_cv_get(yrev)));
}
cprintf(cb, ".yang");
clicon_debug(dbglevel, "%s", cbuf_get(cb));
cbuf_reset(cb);
}
retval = 0;
done:
if (cb)
cbuf_free(cb);
return retval;
}
/*! Print yang specification to cligen buf
* @param[in] cb Cligen buffer. This is where the pretty print is.
* @param[in] yn Yang node to print