diff options
| author | Renato Westphal <renato@opensourcerouting.org> | 2020-05-14 12:30:34 -0300 | 
|---|---|---|
| committer | Renato Westphal <renato@opensourcerouting.org> | 2020-05-28 19:22:54 -0300 | 
| commit | df5eda3d8783a3436f43821a2840911d610fd89d (patch) | |
| tree | 49cef5931b240472e6ac5b1c78da9fad2ccee0cf /lib/northbound_sysrepo.c | |
| parent | 13d6b9c1343a1f925e3ffd7be0938bf1f395b461 (diff) | |
lib: return human-readable error messages to the northbound clients
Instead of returning only error codes (e.g. NB_ERR_VALIDATION)
to the northbound clients, do better than that and also return
a human-readable error message. This should make FRR more
automation-friendly since operators won't need to dig into system
logs to find out what went wrong in the case of an error.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/northbound_sysrepo.c')
| -rw-r--r-- | lib/northbound_sysrepo.c | 18 | 
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c index 4d15c80a2b..500203173c 100644 --- a/lib/northbound_sysrepo.c +++ b/lib/northbound_sysrepo.c @@ -247,6 +247,7 @@ static int frr_sr_config_change_cb_verify(sr_session_ctx_t *session,  	char xpath[XPATH_MAXLEN];  	struct nb_context context = {};  	struct nb_config *candidate; +	char errmsg[BUFSIZ] = {0};  	snprintf(xpath, sizeof(xpath), "/%s:*", module_name);  	ret = sr_get_changes_iter(session, xpath, &it); @@ -284,15 +285,26 @@ static int frr_sr_config_change_cb_verify(sr_session_ctx_t *session,  		 * 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); +		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); +						  &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);  	}  	/* Map northbound return code to sysrepo return code. */  | 
