// ID of the created configuration transaction (when the phase is APPLY
// or ALL).
uint32 transaction_id = 1;
+
+ // Human-readable error or warning message(s).
+ string error_message = 2;
}
//
errmsg_len);
}
-void nb_candidate_commit_abort(struct nb_transaction *transaction)
+void nb_candidate_commit_abort(struct nb_transaction *transaction, char *errmsg,
+ size_t errmsg_len)
{
- char errmsg[BUFSIZ] = {0};
-
(void)nb_transaction_process(NB_EV_ABORT, transaction, errmsg,
- sizeof(errmsg));
+ errmsg_len);
nb_transaction_free(transaction);
}
void nb_candidate_commit_apply(struct nb_transaction *transaction,
- bool save_transaction, uint32_t *transaction_id)
+ bool save_transaction, uint32_t *transaction_id,
+ char *errmsg, size_t errmsg_len)
{
- char errmsg[BUFSIZ] = {0};
-
(void)nb_transaction_process(NB_EV_APPLY, transaction, errmsg,
- sizeof(errmsg));
- nb_transaction_apply_finish(transaction, errmsg, sizeof(errmsg));
+ errmsg_len);
+ nb_transaction_apply_finish(transaction, errmsg, errmsg_len);
/* Replace running by candidate. */
transaction->config->version++;
*/
if (ret == NB_OK)
nb_candidate_commit_apply(transaction, save_transaction,
- transaction_id);
+ transaction_id, errmsg, errmsg_len);
else if (transaction != NULL)
- nb_candidate_commit_abort(transaction);
+ nb_candidate_commit_abort(transaction, errmsg, errmsg_len);
return ret;
}
*
* transaction
* Candidate configuration to abort. It's consumed by this function.
+ *
+ * errmsg
+ * Buffer to store human-readable error message in case of error.
+ *
+ * errmsg_len
+ * Size of errmsg.
*/
-extern void nb_candidate_commit_abort(struct nb_transaction *transaction);
+extern void nb_candidate_commit_abort(struct nb_transaction *transaction,
+ char *errmsg, size_t errmsg_len);
/*
* Commit a previously created configuration transaction.
*
* transaction_id
* Optional output parameter providing the ID of the committed transaction.
+ *
+ * errmsg
+ * Buffer to store human-readable error message in case of error.
+ *
+ * errmsg_len
+ * Size of errmsg.
*/
extern void nb_candidate_commit_apply(struct nb_transaction *transaction,
bool save_transaction,
- uint32_t *transaction_id);
+ uint32_t *transaction_id, char *errmsg,
+ size_t errmsg_len);
/*
* Create a new transaction to commit a candidate configuration. This is a
/* Regenerate candidate for consistency. */
nb_config_replace(vty->candidate_config, running_config, true);
return CMD_WARNING_CONFIG_FAILED;
- }
+ } else if (strlen(errmsg) > 0)
+ /* Successful commit. Print warnings (if any). */
+ vty_out(vty, "%s\n", errmsg);
return CMD_SUCCESS;
}
&context, vty->confirmed_commit_rollback, true,
"Rollback to previous configuration - confirmed commit has timed out",
&transaction_id, errmsg, sizeof(errmsg));
- if (ret == NB_OK)
+ if (ret == NB_OK) {
vty_out(vty,
"Rollback performed successfully (Transaction ID #%u).\n",
transaction_id);
- else {
+ /* Print warnings (if any). */
+ if (strlen(errmsg) > 0)
+ vty_out(vty, "%s\n", errmsg);
+ } else {
vty_out(vty,
"Failed to rollback to previous configuration.\n\n");
vty_show_nb_errors(vty, ret, errmsg);
vty_out(vty,
"%% Configuration committed successfully (Transaction ID #%u).\n\n",
transaction_id);
+ /* Print warnings (if any). */
+ if (strlen(errmsg) > 0)
+ vty_out(vty, "%s\n", errmsg);
return CMD_SUCCESS;
case NB_ERR_NO_CHANGES:
vty_out(vty, "%% No configuration changes to commit.\n\n");
case NB_OK:
vty_out(vty,
"%% Configuration was successfully rolled back.\n\n");
+ /* Print warnings (if any). */
+ if (strlen(errmsg) > 0)
+ vty_out(vty, "%s\n", errmsg);
return CMD_SUCCESS;
case NB_ERR_NO_CHANGES:
vty_out(vty,
/* Apply the transaction. */
if (transaction) {
struct nb_config *candidate = transaction->config;
+ char errmsg[BUFSIZ] = {0};
- nb_candidate_commit_apply(transaction, true, NULL);
+ nb_candidate_commit_apply(transaction, true, NULL, errmsg,
+ sizeof(errmsg));
nb_config_free(candidate);
}
/* Abort the transaction. */
if (transaction) {
struct nb_config *candidate = transaction->config;
+ char errmsg[BUFSIZ] = {0};
- nb_candidate_commit_abort(transaction);
+ nb_candidate_commit_abort(transaction, errmsg, sizeof(errmsg));
nb_config_free(candidate);
}
break;
case frr::CommitRequest::ABORT:
nb_candidate_commit_abort(
- candidate->transaction);
+ candidate->transaction, errmsg,
+ sizeof(errmsg));
break;
case frr::CommitRequest::APPLY:
nb_candidate_commit_apply(
candidate->transaction, true,
- &transaction_id);
+ &transaction_id, errmsg,
+ sizeof(errmsg));
break;
case frr::CommitRequest::ALL:
ret = nb_candidate_commit(
tag->response.set_transaction_id(
transaction_id);
}
+ if (strlen(errmsg) > 0)
+ tag->response.set_error_message(errmsg);
tag->responder.Finish(tag->response, status, tag);
tag->state = FINISH;
void delete_candidate(struct candidate *candidate)
{
+ char errmsg[BUFSIZ] = {0};
+
_candidates.erase(candidate->id);
nb_config_free(candidate->config);
if (candidate->transaction)
- nb_candidate_commit_abort(candidate->transaction);
+ nb_candidate_commit_abort(candidate->transaction,
+ errmsg, sizeof(errmsg));
}
struct candidate *get_candidate(uint32_t candidate_id)
/* Apply the transaction. */
if (transaction) {
struct nb_config *candidate = transaction->config;
+ char errmsg[BUFSIZ] = {0};
- nb_candidate_commit_apply(transaction, true, NULL);
+ nb_candidate_commit_apply(transaction, true, NULL, errmsg,
+ sizeof(errmsg));
nb_config_free(candidate);
}
/* Abort the transaction. */
if (transaction) {
struct nb_config *candidate = transaction->config;
+ char errmsg[BUFSIZ] = {0};
- nb_candidate_commit_abort(transaction);
+ nb_candidate_commit_abort(transaction, errmsg, sizeof(errmsg));
nb_config_free(candidate);
}