]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: simplify handling of the sysrepo startup configuration
authorRenato Westphal <renato@opensourcerouting.org>
Sat, 12 Sep 2020 01:39:50 +0000 (22:39 -0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Tue, 6 Oct 2020 12:54:24 +0000 (15:54 +0300)
In the new Sysrepo, all SR_EV_ENABLED notifications are followed by
SR_EV_DONE notifications (assuming no errors occur), so there's no
need to special case the SR_EV_ENABLED event anymore (e.g. do full
transactions in one step).

While here, add a few more guarded debug messages to facilitate
troubleshooting.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/northbound_sysrepo.c

index 856af306e69e49e8ef6eab18960792353d9ebaae..b5ef040a3fe2cf4d5d3bf4b738f2ddfeccd046e3 100644 (file)
@@ -174,6 +174,9 @@ static int frr_sr_process_change(struct nb_config *candidate,
 
        xpath = sr_data->xpath;
 
+       DEBUGD(&nb_dbg_client_sysrepo, "sysrepo: processing change [xpath %s]",
+              xpath);
+
        /* Non-presence container - nothing to do. */
        if (sr_data->type == SR_CONTAINER_T)
                return NB_OK;
@@ -235,8 +238,7 @@ static int frr_sr_process_change(struct nb_config *candidate,
 }
 
 static int frr_sr_config_change_cb_prepare(sr_session_ctx_t *session,
-                                          const char *module_name,
-                                          bool startup_config)
+                                          const char *module_name)
 {
        sr_change_iter_t *it;
        int ret;
@@ -275,33 +277,17 @@ static int frr_sr_config_change_cb_prepare(sr_session_ctx_t *session,
 
        transaction = NULL;
        context.client = NB_CLIENT_SYSREPO;
-       if (startup_config) {
-               /*
-                * sysrepod sends the entire startup configuration using a
-                * single event (SR_EV_ENABLED). This means we need to perform
-                * the full two-phase commit protocol in one go here.
-                */
-               ret = nb_candidate_commit(&context, candidate, true, NULL, NULL,
-                                         errmsg, sizeof(errmsg));
-               if (ret != NB_OK && ret != NB_ERR_NO_CHANGES)
-                       flog_warn(
-                               EC_LIB_LIBSYSREPO,
-                               "%s: failed to apply startup configuration: %s (%s)",
-                               __func__, nb_err_name(ret), errmsg);
-       } else {
-               /*
-                * Validate the configuration changes and allocate all resources
-                * required to apply them.
-                */
-               ret = nb_candidate_commit_prepare(&context, candidate, NULL,
-                                                 &transaction, errmsg,
-                                                 sizeof(errmsg));
-               if (ret != NB_OK && ret != NB_ERR_NO_CHANGES)
-                       flog_warn(
-                               EC_LIB_LIBSYSREPO,
-                               "%s: failed to prepare configuration transaction: %s (%s)",
-                               __func__, nb_err_name(ret), errmsg);
-       }
+       /*
+        * Validate the configuration changes and allocate all resources
+        * required to apply them.
+        */
+       ret = nb_candidate_commit_prepare(&context, candidate, NULL,
+                                         &transaction, errmsg, sizeof(errmsg));
+       if (ret != NB_OK && ret != NB_ERR_NO_CHANGES)
+               flog_warn(
+                       EC_LIB_LIBSYSREPO,
+                       "%s: failed to prepare configuration transaction: %s (%s)",
+                       __func__, nb_err_name(ret), errmsg);
 
        if (!transaction)
                nb_config_free(candidate);
@@ -360,11 +346,8 @@ static int frr_sr_config_change_cb(sr_session_ctx_t *session,
 {
        switch (sr_ev) {
        case SR_EV_ENABLED:
-               return frr_sr_config_change_cb_prepare(session, module_name,
-                                                      true);
        case SR_EV_CHANGE:
-               return frr_sr_config_change_cb_prepare(session, module_name,
-                                                      false);
+               return frr_sr_config_change_cb_prepare(session, module_name);
        case SR_EV_DONE:
                return frr_sr_config_change_cb_apply(session, module_name);
        case SR_EV_ABORT:
@@ -563,6 +546,10 @@ static void frr_sr_subscribe_config(struct yang_module *module)
 {
        int ret;
 
+       DEBUGD(&nb_dbg_client_sysrepo,
+              "sysrepo: subscribing for configuration changes made in the '%s' module",
+              module->name);
+
        ret = sr_module_change_subscribe(
                session, module->name, NULL, frr_sr_config_change_cb, NULL, 0,
                SR_SUBSCR_DEFAULT | SR_SUBSCR_ENABLED | SR_SUBSCR_NO_THREAD,
@@ -586,7 +573,7 @@ static int frr_sr_subscribe_state(const struct lys_node *snode, void *arg)
 
        nb_node = snode->priv;
 
-       DEBUGD(&nb_dbg_client_sysrepo, "%s: providing data to '%s'", __func__,
+       DEBUGD(&nb_dbg_client_sysrepo, "sysrepo: providing data to '%s'",
               nb_node->xpath);
 
        ret = sr_oper_get_items_subscribe(
@@ -610,7 +597,7 @@ static int frr_sr_subscribe_rpc(const struct lys_node *snode, void *arg)
 
        nb_node = snode->priv;
 
-       DEBUGD(&nb_dbg_client_sysrepo, "%s: providing RPC to '%s'", __func__,
+       DEBUGD(&nb_dbg_client_sysrepo, "sysrepo: providing RPC to '%s'",
               nb_node->xpath);
 
        ret = sr_rpc_subscribe(session, nb_node->xpath, frr_sr_config_rpc_cb,