*: record transaction based on control flag

In case of config rollback is enabled,
record northbound transaction based on a control flag.
The actual frr daemons would set the flag to true via
nb_init from frr_init.
This will allow test daemon to bypass recording
transacation to db.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
This commit is contained in:
Chirag Shah 2020-08-20 12:09:53 -07:00
parent 6a7fb29c19
commit 390a886277
9 changed files with 17 additions and 10 deletions

View File

@ -55,7 +55,7 @@ int main(int argc, char **argv)
vty_init(master, true);
lib_cmd_init();
yang_init(true);
nb_init(master, NULL, 0);
nb_init(master, NULL, 0, false);
vty_stdio(vty_do_exit);

View File

@ -719,7 +719,7 @@ struct thread_master *frr_init(void)
debug_init_cli();
nb_init(master, di->yang_modules, di->n_yang_modules);
nb_init(master, di->yang_modules, di->n_yang_modules, true);
if (nb_db_init() != NB_OK)
flog_warn(EC_LIB_NB_DATABASE,
"%s: failed to initialize northbound database",

View File

@ -57,6 +57,8 @@ static struct {
const void *owner_user;
} running_config_mgmt_lock;
/* Knob to record config transaction */
static bool nb_db_enabled;
/*
* Global lock used to prevent multiple configuration transactions from
* happening concurrently.
@ -732,7 +734,7 @@ void nb_candidate_commit_apply(struct nb_transaction *transaction,
nb_config_replace(running_config, transaction->config, true);
/* Record transaction. */
if (save_transaction
if (save_transaction && nb_db_enabled
&& nb_db_transaction_save(transaction, transaction_id) != NB_OK)
flog_warn(EC_LIB_NB_TRANSACTION_RECORD_FAILED,
"%s: failed to record transaction", __func__);
@ -2216,7 +2218,7 @@ static void nb_load_callbacks(const struct frr_yang_module_info *module)
void nb_init(struct thread_master *tm,
const struct frr_yang_module_info *const modules[],
size_t nmodules)
size_t nmodules, bool db_enabled)
{
unsigned int errors = 0;
@ -2241,6 +2243,8 @@ void nb_init(struct thread_master *tm,
exit(1);
}
nb_db_enabled = db_enabled;
/* Create an empty running configuration. */
running_config = nb_config_new(NULL);
running_config_entries = hash_create(running_config_entry_key_make,

View File

@ -1239,10 +1239,13 @@ extern const char *nb_client_name(enum nb_client client);
*
* nmodules
* Size of the modules array.
*
* db_enabled
* Set this to record the transactions in the transaction log.
*/
extern void nb_init(struct thread_master *tm,
const struct frr_yang_module_info *const modules[],
size_t nmodules);
size_t nmodules, bool db_enabled);
/*
* Finish the northbound layer gracefully. Should be called only when the daemon

View File

@ -1387,7 +1387,7 @@ static void bgp_startup(void)
master = thread_master_create(NULL);
yang_init(true);
nb_init(master, NULL, 0);
nb_init(master, NULL, 0, false);
bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE);
bgp_option_set(BGP_OPT_NO_LISTEN);
vrf_init(NULL, NULL, NULL, NULL, NULL);

View File

@ -156,7 +156,7 @@ int main(int argc, char **argv)
vty_init(master, false);
lib_cmd_init();
yang_init(true);
nb_init(master, NULL, 0);
nb_init(master, NULL, 0, false);
/* OSPF vty inits. */
test_vty_init();

View File

@ -80,7 +80,7 @@ int main(int argc, char **argv)
vty_init(master, false);
lib_cmd_init();
yang_init(true);
nb_init(master, NULL, 0);
nb_init(master, NULL, 0, false);
test_init(argc, argv);

View File

@ -209,7 +209,7 @@ static void test_init(void)
cmd_init(1);
yang_init(true);
nb_init(master, NULL, 0);
nb_init(master, NULL, 0, false);
install_node(&bgp_node);
install_node(&rip_node);

View File

@ -400,7 +400,7 @@ int main(int argc, char **argv)
vty_init(master, false);
lib_cmd_init();
yang_init(true);
nb_init(master, modules, array_size(modules));
nb_init(master, modules, array_size(modules), false);
/* Create artificial data. */
create_data(num_vrfs, num_interfaces, num_routes);