summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChirag Shah <chirag@nvidia.com>2020-08-20 21:09:53 +0200
committerChirag Shah <chirag@nvidia.com>2020-08-20 23:12:04 +0200
commit390a886277ba3afc6b9371cc13587b9a30ce5bdb (patch)
tree4894f96aac6079993493eb818a159bcebab91052
parentlib: add yang modules to native module list (diff)
downloadfrr-390a886277ba3afc6b9371cc13587b9a30ce5bdb.tar.xz
frr-390a886277ba3afc6b9371cc13587b9a30ce5bdb.zip
*: 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>
-rw-r--r--lib/grammar_sandbox_main.c2
-rw-r--r--lib/libfrr.c2
-rw-r--r--lib/northbound.c8
-rw-r--r--lib/northbound.h5
-rw-r--r--tests/bgpd/test_peer_attr.c2
-rw-r--r--tests/helpers/c/main.c2
-rw-r--r--tests/lib/cli/common_cli.c2
-rw-r--r--tests/lib/cli/test_commands.c2
-rw-r--r--tests/lib/northbound/test_oper_data.c2
9 files changed, 17 insertions, 10 deletions
diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c
index fbb97d2dd..2066e4c96 100644
--- a/lib/grammar_sandbox_main.c
+++ b/lib/grammar_sandbox_main.c
@@ -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);
diff --git a/lib/libfrr.c b/lib/libfrr.c
index 2597eb61e..500a02aac 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -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",
diff --git a/lib/northbound.c b/lib/northbound.c
index 29e843a84..18500a8bd 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -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,
diff --git a/lib/northbound.h b/lib/northbound.h
index fa5ac5616..7b481273c 100644
--- a/lib/northbound.h
+++ b/lib/northbound.h
@@ -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
diff --git a/tests/bgpd/test_peer_attr.c b/tests/bgpd/test_peer_attr.c
index f6a892df4..0979622eb 100644
--- a/tests/bgpd/test_peer_attr.c
+++ b/tests/bgpd/test_peer_attr.c
@@ -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);
diff --git a/tests/helpers/c/main.c b/tests/helpers/c/main.c
index 68ed16d51..7f15996da 100644
--- a/tests/helpers/c/main.c
+++ b/tests/helpers/c/main.c
@@ -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();
diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c
index 3cade4a2c..44cc6efe8 100644
--- a/tests/lib/cli/common_cli.c
+++ b/tests/lib/cli/common_cli.c
@@ -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);
diff --git a/tests/lib/cli/test_commands.c b/tests/lib/cli/test_commands.c
index 2b345c91e..cb512211a 100644
--- a/tests/lib/cli/test_commands.c
+++ b/tests/lib/cli/test_commands.c
@@ -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);
diff --git a/tests/lib/northbound/test_oper_data.c b/tests/lib/northbound/test_oper_data.c
index 202a321e1..b5f257fa2 100644
--- a/tests/lib/northbound/test_oper_data.c
+++ b/tests/lib/northbound/test_oper_data.c
@@ -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);