From 625b70e3da7b1ec163607cc7354404904eacf36e Mon Sep 17 00:00:00 2001 From: Emanuele Di Pascale Date: Fri, 9 Nov 2018 16:13:12 +0100 Subject: lib: add NB phase-specific error codes As suggested by Renato, add error codes that are specific to the various phases of a northbound callback. These can be used by the daemons when logging an error. The reasoning is that validation errors typically mean that there is an inconsistency in the configuration, a prepare error means that we are running out of resources, and abort/apply errors are bugs that need to be reported to the devs. Signed-off-by: Emanuele Di Pascale --- lib/northbound.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'lib/northbound.c') diff --git a/lib/northbound.c b/lib/northbound.c index 09aa60b1d..a7f9c8620 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -719,6 +719,7 @@ static int nb_configuration_callback(const enum nb_event event, const struct lyd_node *dnode = change->cb.dnode; union nb_resource *resource; int ret = NB_ERR; + enum lib_log_refs ref; if (debug_northbound) { const char *value = "(none)"; @@ -751,12 +752,36 @@ static int nb_configuration_callback(const enum nb_event event, break; } - if (ret != NB_OK) - flog_warn( - EC_LIB_NB_CB_CONFIG, - "%s: error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]", - __func__, nb_err_name(ret), nb_event_name(event), - nb_operation_name(operation), xpath); + if (ret != NB_OK) { + switch (event) { + case NB_EV_VALIDATE: + ref = EC_LIB_NB_CB_CONFIG_VALIDATE; + break; + case NB_EV_PREPARE: + ref = EC_LIB_NB_CB_CONFIG_PREPARE; + break; + case NB_EV_ABORT: + ref = EC_LIB_NB_CB_CONFIG_ABORT; + break; + case NB_EV_APPLY: + ref = EC_LIB_NB_CB_CONFIG_APPLY; + break; + } + if (event == NB_EV_VALIDATE || event == NB_EV_PREPARE) + flog_warn( + ref, + "%s: error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]", + __func__, nb_err_name(ret), + nb_event_name(event), + nb_operation_name(operation), xpath); + else + flog_err( + ref, + "%s: error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]", + __func__, nb_err_name(ret), + nb_event_name(event), + nb_operation_name(operation), xpath); + } return ret; } -- cgit v1.2.3