]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib, tools: silence harmless warnings in the northbound tools
authorRenato Westphal <renato@opensourcerouting.org>
Fri, 3 Apr 2020 22:43:02 +0000 (19:43 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 4 Apr 2020 01:34:55 +0000 (22:34 -0300)
Our two northbound tools don't have embedded YANG modules like the
other FRR binaries. As such, ly_ctx_set_module_imp_clb() shouldn't be
called when the YANG subsystem it being initialized by a northbound
tool. To make that possible, add a new "embedded_modules" parameter
to the yang_init() function to control whether libyang should look
for embedded modules or not.

With this fix, "gen_northbound_callbacks" and "gen_yang_deviations"
won't emit "YANG model X not embedded, trying external file"
warnings anymore.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
12 files changed:
lib/grammar_sandbox_main.c
lib/libfrr.c
lib/yang.c
lib/yang.h
lib/yang_translator.c
tests/bgpd/test_peer_attr.c
tests/helpers/c/main.c
tests/lib/cli/common_cli.c
tests/lib/cli/test_commands.c
tests/lib/northbound/test_oper_data.c
tools/gen_northbound_callbacks.c
tools/gen_yang_deviations.c

index 5d3f6675a354ea13dfc5b5bc8df72f72c87606e5..aa54720dabe9e1c9a26990c1a3442d7da5e4523c 100644 (file)
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
 
        vty_init(master, true);
        lib_cmd_init();
-       yang_init();
+       yang_init(true);
        nb_init(master, NULL, 0);
 
        vty_stdio(vty_do_exit);
index 3622890e46585bd3dec2640af4bba159144f103c..9a681103d4ec24f1a28572dc9b7903f00e841083 100644 (file)
@@ -717,7 +717,7 @@ struct thread_master *frr_init(void)
        log_ref_vty_init();
        lib_error_init();
 
-       yang_init();
+       yang_init(true);
 
        debug_init_cli();
 
index 93e6db3055302dd9d39445c5b2d16dc12061e525..0502d4952d5d1d0db2d3a2d6eb857baf2cd8bf85 100644 (file)
@@ -628,7 +628,7 @@ void yang_debugging_set(bool enable)
        }
 }
 
-struct ly_ctx *yang_ctx_new_setup(void)
+struct ly_ctx *yang_ctx_new_setup(bool embedded_modules)
 {
        struct ly_ctx *ctx;
        const char *yang_models_path = YANG_MODELS_PATH;
@@ -647,18 +647,21 @@ struct ly_ctx *yang_ctx_new_setup(void)
        ctx = ly_ctx_new(yang_models_path, LY_CTX_DISABLE_SEARCHDIR_CWD);
        if (!ctx)
                return NULL;
-       ly_ctx_set_module_imp_clb(ctx, yang_module_imp_clb, NULL);
+
+       if (embedded_modules)
+               ly_ctx_set_module_imp_clb(ctx, yang_module_imp_clb, NULL);
+
        return ctx;
 }
 
-void yang_init(void)
+void yang_init(bool embedded_modules)
 {
        /* Initialize libyang global parameters that affect all containers. */
        ly_set_log_clb(ly_log_cb, 1);
        ly_log_options(LY_LOLOG | LY_LOSTORE);
 
        /* Initialize libyang container for native models. */
-       ly_native_ctx = yang_ctx_new_setup();
+       ly_native_ctx = yang_ctx_new_setup(embedded_modules);
        if (!ly_native_ctx) {
                flog_err(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
                exit(1);
index 6892e36019731b6fd4dfdc9f6c8b7e2fbc0fa90b..8af440d3ed3c7dfaaaba32446675d4446b6e7e04 100644 (file)
@@ -482,8 +482,11 @@ extern struct yang_data *yang_data_list_find(const struct list *list,
 
 /*
  * Create and set up a libyang context (for use by the translator)
+ *
+ * embedded_modules
+ *    Specify whether libyang should attempt to look for embedded YANG modules.
  */
-extern struct ly_ctx *yang_ctx_new_setup(void);
+extern struct ly_ctx *yang_ctx_new_setup(bool embedded_modules);
 
 /*
  * Enable or disable libyang verbose debugging.
@@ -496,8 +499,11 @@ extern void yang_debugging_set(bool enable);
 /*
  * Initialize the YANG subsystem. Should be called only once during the
  * daemon initialization process.
+ *
+ * embedded_modules
+ *    Specify whether libyang should attempt to look for embedded YANG modules.
  */
-extern void yang_init(void);
+extern void yang_init(bool embedded_modules);
 
 /*
  * Finish the YANG subsystem gracefully. Should be called only when the daemon
index 341420eeda45e2360f143420f1c8c11c3c49591b..7dbb1f3f1a10bae2ffb28d5e052b3f23eecdbf9b 100644 (file)
@@ -171,7 +171,7 @@ struct yang_translator *yang_translator_load(const char *path)
        RB_INSERT(yang_translators, &yang_translators, translator);
 
        /* Initialize the translator libyang context. */
-       translator->ly_ctx = yang_ctx_new_setup();
+       translator->ly_ctx = yang_ctx_new_setup(false);
        if (!translator->ly_ctx) {
                flog_warn(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
                goto error;
@@ -511,7 +511,7 @@ static unsigned int yang_module_nodes_count(const struct lys_module *module)
 
 void yang_translator_init(void)
 {
-       ly_translator_ctx = yang_ctx_new_setup();
+       ly_translator_ctx = yang_ctx_new_setup(true);
        if (!ly_translator_ctx) {
                flog_err(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
                exit(1);
index 422d397479f10dbb4bb90b2e5183de66aab5553a..490b0ee73b82b8b65c9a19c58bc00d641d152ba5 100644 (file)
@@ -1387,7 +1387,7 @@ static void bgp_startup(void)
        zprivs_init(&bgpd_privs);
 
        master = thread_master_create(NULL);
-       yang_init();
+       yang_init(true);
        nb_init(master, NULL, 0);
        bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE);
        bgp_option_set(BGP_OPT_NO_LISTEN);
index 2de29cbdbcdbc0da9426d32be09e42c61d002e58..68ed16d513eb302ffce80110be46a37976e3349a 100644 (file)
@@ -155,7 +155,7 @@ int main(int argc, char **argv)
        cmd_init(1);
        vty_init(master, false);
        lib_cmd_init();
-       yang_init();
+       yang_init(true);
        nb_init(master, NULL, 0);
 
        /* OSPF vty inits. */
index e091372ab8766bee6d3eaf0a4760f61a997c1f84..bd81656ca971dd48ae0d0c885f11b2f7d8370d9d 100644 (file)
@@ -84,7 +84,7 @@ int main(int argc, char **argv)
 
        vty_init(master, false);
        lib_cmd_init();
-       yang_init();
+       yang_init(true);
        nb_init(master, NULL, 0);
 
        test_init(argc, argv);
index bbdc8b238d45e077d464ef6211e42064ca72be29..779a7539e991e15ca07a7be48b419143c1824a7d 100644 (file)
@@ -142,7 +142,7 @@ static void test_init(void)
        struct cmd_element *cmd;
 
        cmd_init(1);
-       yang_init();
+       yang_init(true);
        nb_init(master, NULL, 0);
 
        install_node(&bgp_node, NULL);
index 18d3180889b406b6054fcd58f7563838b11c6a66..786fce33f95e8855d1f59687360df14c027c74d7 100644 (file)
@@ -413,7 +413,7 @@ int main(int argc, char **argv)
        cmd_hostname_set("test");
        vty_init(master, false);
        lib_cmd_init();
-       yang_init();
+       yang_init(true);
        nb_init(master, modules, array_size(modules));
 
        /* Create artificial data. */
index cbdf01e7b80804f663f5c0b0f201c3de792c524a..7118986854de3b6f232a2ddee1dbbcda4d305092 100644 (file)
@@ -358,7 +358,7 @@ int main(int argc, char *argv[])
        if (argc != 1)
                usage(EXIT_FAILURE);
 
-       yang_init();
+       yang_init(false);
 
        if (search_path)
                ly_ctx_set_searchdir(ly_native_ctx, search_path);
index f611f1c57e898d787d18b2690932769f18a9bddf..f908e1fc691b9a32969f8220cfec715abedf2e88 100644 (file)
@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
        if (argc != 1)
                usage(EXIT_FAILURE);
 
-       yang_init();
+       yang_init(false);
 
        /* Load YANG module. */
        module = yang_module_load(argv[0]);