*: add errmsg to nb rpc

Display human readable error message in northbound rpc
transaction failure. In case of vtysh nb client, the error
message will be displayed to user.

Testing:

bharat# clear evpn dup-addr vni 1002 ip 11.11.11.11
Error type: generic error
Error description: Requested IP's associated MAC aa:aa:aa:aa:aa:aa is still
in duplicate state

Signed-off-by: Chirag Shah <chirag@nvidia.com>
This commit is contained in:
Chirag Shah 2020-10-03 15:34:33 -07:00
parent 002bac8b5b
commit f63f5f1947
10 changed files with 37 additions and 11 deletions

View File

@ -1142,7 +1142,8 @@ const void *nb_callback_lookup_entry(const struct nb_node *nb_node,
}
int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath,
const struct list *input, struct list *output)
const struct list *input, struct list *output, char *errmsg,
size_t errmsg_len)
{
struct nb_cb_rpc_args args = {};
@ -1151,6 +1152,8 @@ int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath,
args.xpath = xpath;
args.input = input;
args.output = output;
args.errmsg = errmsg;
args.errmsg_len = errmsg_len;
return nb_node->cbs.rpc(&args);
}

View File

@ -258,6 +258,12 @@ struct nb_cb_rpc_args {
/* List of output parameters to be populated by the callback. */
struct list *output;
/* Buffer to store human-readable error message in case of error. */
char *errmsg;
/* Size of errmsg. */
size_t errmsg_len;
};
/*
@ -689,7 +695,8 @@ extern const void *nb_callback_lookup_entry(const struct nb_node *nb_node,
const void *parent_list_entry,
const struct yang_list_keys *keys);
extern int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath,
const struct list *input, struct list *output);
const struct list *input, struct list *output,
char *errmsg, size_t errmsg_len);
/*
* Create a northbound node for all YANG schema nodes.

View File

@ -284,10 +284,12 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
return CMD_SUCCESS;
}
int nb_cli_rpc(const char *xpath, struct list *input, struct list *output)
int nb_cli_rpc(struct vty *vty, const char *xpath, struct list *input,
struct list *output)
{
struct nb_node *nb_node;
int ret;
char errmsg[BUFSIZ] = {0};
nb_node = nb_node_find(xpath);
if (!nb_node) {
@ -296,11 +298,14 @@ int nb_cli_rpc(const char *xpath, struct list *input, struct list *output)
return CMD_WARNING;
}
ret = nb_callback_rpc(nb_node, xpath, input, output);
ret = nb_callback_rpc(nb_node, xpath, input, output, errmsg,
sizeof(errmsg));
switch (ret) {
case NB_OK:
return CMD_SUCCESS;
default:
if (strlen(errmsg))
vty_show_nb_errors(vty, ret, errmsg);
return CMD_WARNING;
}
}

View File

@ -75,6 +75,9 @@ extern int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt,
/*
* Execute a YANG RPC or Action.
*
* vty
* The vty terminal to dump any error.
*
* xpath
* XPath of the YANG RPC or Action node.
*
@ -90,7 +93,7 @@ extern int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt,
* Returns:
* CMD_SUCCESS on success, CMD_WARNING otherwise.
*/
extern int nb_cli_rpc(const char *xpath, struct list *input,
extern int nb_cli_rpc(struct vty *vty, const char *xpath, struct list *input,
struct list *output);
/*

View File

@ -1068,6 +1068,7 @@ static int frr_confd_action_execute(struct confd_user_info *uinfo,
struct yang_data *data;
confd_tag_value_t *reply;
int ret = CONFD_OK;
char errmsg[BUFSIZ] = {0};
/* Getting the XPath is tricky. */
if (kp) {
@ -1115,7 +1116,9 @@ static int frr_confd_action_execute(struct confd_user_info *uinfo,
}
/* Execute callback registered for this XPath. */
if (nb_callback_rpc(nb_node, xpath, input, output) != NB_OK) {
if (nb_callback_rpc(nb_node, xpath, input, output, errmsg,
sizeof(errmsg))
!= NB_OK) {
flog_warn(EC_LIB_NB_CB_RPC, "%s: rpc callback failed: %s",
__func__, xpath);
ret = CONFD_ERR;

View File

@ -962,6 +962,7 @@ class NorthboundImpl
struct listnode *node;
struct yang_data *data;
const char *xpath;
char errmsg[BUFSIZ] = {0};
switch (tag->state) {
case CREATE:
@ -1012,7 +1013,7 @@ class NorthboundImpl
// Execute callback registered for this XPath.
if (nb_callback_rpc(nb_node, xpath, input_list,
output_list)
output_list, errmsg, sizeof(errmsg))
!= NB_OK) {
flog_warn(EC_LIB_NB_CB_RPC,
"%s: rpc callback failed: %s",

View File

@ -414,6 +414,7 @@ static int frr_sr_config_rpc_cb(sr_session_ctx_t *session, const char *xpath,
struct yang_data *data;
size_t cb_output_cnt;
int ret = SR_ERR_OK;
char errmsg[BUFSIZ] = {0};
nb_node = nb_node_find(xpath);
if (!nb_node) {
@ -436,7 +437,9 @@ static int frr_sr_config_rpc_cb(sr_session_ctx_t *session, const char *xpath,
}
/* Execute callback registered for this XPath. */
if (nb_callback_rpc(nb_node, xpath, input, output) != NB_OK) {
if (nb_callback_rpc(nb_node, xpath, input, output, errmsg,
sizeof(errmsg))
!= NB_OK) {
flog_warn(EC_LIB_NB_CB_RPC, "%s: rpc callback failed: %s",
__func__, xpath);
ret = SR_ERR_OPERATION_FAILED;

View File

@ -1012,7 +1012,7 @@ DEFPY_YANG (clear_ip_rip,
listnode_add(input, yang_vrf);
}
ret = nb_cli_rpc("/frr-ripd:clear-rip-route", input, NULL);
ret = nb_cli_rpc(vty, "/frr-ripd:clear-rip-route", input, NULL);
list_delete(&input);

View File

@ -496,7 +496,7 @@ DEFPY_YANG (clear_ipv6_rip,
listnode_add(input, yang_vrf);
}
ret = nb_cli_rpc("/frr-ripngd:clear-ripng-route", input, NULL);
ret = nb_cli_rpc(vty, "/frr-ripngd:clear-ripng-route", input, NULL);
list_delete(&input);

View File

@ -3264,7 +3264,8 @@ DEFPY (clear_evpn_dup_addr,
if (yang_dup) {
listnode_add(input, yang_dup);
ret = nb_cli_rpc("/frr-zebra:clear-evpn-dup-addr", input, NULL);
ret = nb_cli_rpc(vty, "/frr-zebra:clear-evpn-dup-addr", input,
NULL);
}
list_delete(&input);