netconf error handling and test summary script
This commit is contained in:
parent
f872c7e295
commit
861300d6c0
23 changed files with 331 additions and 189 deletions
|
|
@ -44,6 +44,7 @@
|
|||
* (Duplicated. Also in netconf_*.h)
|
||||
*/
|
||||
int netconf_output(int s, cbuf *xf, char *msg);
|
||||
int netconf_output_encap(int s, cbuf *xf, char *msg);
|
||||
|
||||
int netconf_xpath(cxobj *xsearch,
|
||||
cxobj *xfilter,
|
||||
|
|
|
|||
|
|
@ -182,9 +182,9 @@ netconf_get_target(cxobj *xn,
|
|||
* @param[in] s
|
||||
* @param[in] cb Cligen buffer that contains the XML message
|
||||
* @param[in] msg Only for debug
|
||||
* @note Assumes "cb" contains valid XML, ie encoding is correct. This is done
|
||||
* if it is output by a xml render routine (xml_print et al), but NOT
|
||||
* otherwise.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see netconf_output_encap for function with encapsulation
|
||||
*/
|
||||
int
|
||||
netconf_output(int s,
|
||||
|
|
@ -216,3 +216,34 @@ netconf_output(int s,
|
|||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*! Encapsulate and send outgoing netconf packet as cbuf on socket
|
||||
* @param[in] s
|
||||
* @param[in] cb Cligen buffer that contains the XML message
|
||||
* @param[in] msg Only for debug
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @note Assumes "cb" contains valid XML
|
||||
* @see netconf_output without encapsulation
|
||||
*/
|
||||
int
|
||||
netconf_output_encap(int s,
|
||||
cbuf *cb,
|
||||
char *msg)
|
||||
{
|
||||
int retval = -1;
|
||||
cbuf *cb1 = NULL;
|
||||
|
||||
if ((cb1 = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
add_preamble(cb1);
|
||||
cprintf(cb1, "%s", cbuf_get(cb));
|
||||
add_postamble(cb1);
|
||||
retval = netconf_output(s, cb1, msg);
|
||||
done:
|
||||
if (cb1)
|
||||
cbuf_free(cb1);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,5 +75,6 @@ int add_error_preamble(cbuf *xf, char *reason);
|
|||
char *netconf_get_target(cxobj *xn, char *path);
|
||||
int add_error_postamble(cbuf *xf);
|
||||
int netconf_output(int s, cbuf *xf, char *msg);
|
||||
int netconf_output_encap(int s, cbuf *cb, char *msg);
|
||||
|
||||
#endif /* _NETCONF_LIB_H_ */
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ process_incoming_packet(clicon_handle h,
|
|||
free(str0);
|
||||
if (netconf_operation_failed(cbret, "rpc", "internal error")< 0)
|
||||
goto done;
|
||||
netconf_output(1, cbret, "rpc-error");
|
||||
netconf_output_encap(1, cbret, "rpc-error");
|
||||
goto done;
|
||||
}
|
||||
free(str0);
|
||||
|
|
@ -121,7 +121,7 @@ process_incoming_packet(clicon_handle h,
|
|||
if ((ret = xml_yang_validate_rpc(xrpc, cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
netconf_output(1, cbret, "rpc-error");
|
||||
netconf_output_encap(1, cbret, "rpc-error");
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
|
|
@ -157,11 +157,8 @@ process_incoming_packet(clicon_handle h,
|
|||
if (xml_addsub(xc, xa2) < 0)
|
||||
goto done;
|
||||
}
|
||||
add_preamble(cbret);
|
||||
|
||||
clicon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0);
|
||||
add_postamble(cbret);
|
||||
if (netconf_output(1, cbret, "rpc-reply") < 0){
|
||||
if (netconf_output_encap(1, cbret, "rpc-reply") < 0){
|
||||
cbuf_free(cbret);
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -776,12 +776,10 @@ netconf_notification_cb(int s,
|
|||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
add_preamble(cb); /* Make it well-formed netconf xml */
|
||||
if (clicon_xml2cbuf(cb, xn, 0, 0) < 0)
|
||||
goto done;
|
||||
add_postamble(cb);
|
||||
/* Send it to listening client on stdout */
|
||||
if (netconf_output(1, cb, "notification") < 0){
|
||||
if (netconf_output_encap(1, cb, "notification") < 0){
|
||||
cbuf_free(cb);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -925,13 +923,13 @@ netconf_application_rpc(clicon_handle h,
|
|||
if ((ret = xml_yang_validate_all_top(xn, cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
netconf_output(1, cbret, "rpc-error");
|
||||
netconf_output_encap(1, cbret, "rpc-error");
|
||||
goto ok;
|
||||
}
|
||||
if ((ret = xml_yang_validate_add(xn, cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
netconf_output(1, cbret, "rpc-error");
|
||||
netconf_output_encap(1, cbret, "rpc-error");
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -450,10 +450,12 @@ api_return_err(clicon_handle h,
|
|||
else
|
||||
if (xml2json_cbuf(cb, xerr, pretty) < 0)
|
||||
goto done;
|
||||
clicon_debug(1, "%s code:%d err:%s", __FUNCTION__, code, cbuf_get(cb));
|
||||
FCGX_SetExitStatus(code, r->out); /* Created */
|
||||
FCGX_FPrintF(r->out, "Status: %d %s\r\n", code, reason_phrase);
|
||||
FCGX_FPrintF(r->out, "Content-Type: application/yang-data+%s\r\n\r\n",
|
||||
use_xml?"xml":"json");
|
||||
|
||||
if (use_xml){
|
||||
if (pretty){
|
||||
FCGX_FPrintF(r->out, " <errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\">\n", cbuf_get(cb));
|
||||
|
|
|
|||
|
|
@ -1118,15 +1118,8 @@ api_operations_post(clicon_handle h,
|
|||
goto ok;
|
||||
}
|
||||
if ((yrpc = yang_find((yang_node*)ys, Y_RPC, id)) == NULL){
|
||||
if (netconf_operation_failed_xml(&xerr, "protocol", "yang node not found") < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, "rpc-error")) != NULL)
|
||||
if (api_return_err(h, r, xe, pretty, use_xml) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
if (yrpc == NULL){
|
||||
if (netconf_operation_failed_xml(&xerr, "protocol", "yang node not found") < 0)
|
||||
clicon_debug(1, "%s rpc %s not found", __FUNCTION__, id);
|
||||
if (netconf_missing_element_xml(&xerr, "application", id, "RPC not defined") < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, "rpc-error")) != NULL)
|
||||
if (api_return_err(h, r, xe, pretty, use_xml) < 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue