]> git.puffer.fish Git - matthieu/frr.git/commitdiff
*: add errmsg to nb rpc
authorChirag Shah <chirag@nvidia.com>
Sat, 3 Oct 2020 22:34:33 +0000 (15:34 -0700)
committerChirag Shah <chirag@nvidia.com>
Mon, 5 Oct 2020 20:15:59 +0000 (13:15 -0700)
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>
lib/northbound.c
lib/northbound.h
lib/northbound_cli.c
lib/northbound_cli.h
lib/northbound_confd.c
lib/northbound_grpc.cpp
lib/northbound_sysrepo.c
ripd/rip_cli.c
ripngd/ripng_cli.c
zebra/zebra_vty.c

index 5816c162d8d7072f749ca106400e186d5cc7ab1f..c99f993ea5159a2715a95a405200fb7ff9df1020 100644 (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);
 }
 
index 01dc528aa4119e8570cedce75b0ed5f81933e59f..16f19b3d5b5336acb703b332572bca32c359b41a 100644 (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.
index 6ce520149ab058756860d6274b91ac5d4ee1a9f4..a7f3a1b305707ff3b286097368c3d34983c8e4b5 100644 (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;
        }
 }
index 112d62efda7d670b778138b51e1ecede18d8dc13..2290a76b8d41402b11388bd8b066fafaba7c6fd3 100644 (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);
 
 /*
index 1f480f3d02e4f94de6d7b93f13b08be64ed02225..c1cb0fc11d27e196c78dc4e28a6c49a087ae7bf8 100644 (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;
index f35b4bb31b2d6b469610dd4ce106b915e62c9d25..abdae993b10fe55ededc88f323a62a32e7f237ff 100644 (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",
index b5ef040a3fe2cf4d5d3bf4b738f2ddfeccd046e3..3cd310c5a7ecbd7a793f03897b0f85d616b32294 100644 (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;
index 5e64b7afdb5a36d25c45674f00827d2b544a736c..87098ece64574442219f51cd1ad19a1d0c15a22a 100644 (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);
 
index f66de175fa0a837180e75f2dd3db98ab4affb4aa..365082f8067d69374085fae117aafce8f9f77303 100644 (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);
 
index 67851517058fb238f3a44543a9c2292f24110e94..920fdd6baa58bcdb4927efd54adab0c0b00804e5 100644 (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);