From 664f6aad005207f7f6ae73f24e4da4022a7b5bbb Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Sat, 13 Jan 2024 14:31:53 +0000 Subject: [PATCH] lib: mgmtd: convert affinitymap to mgmtd Signed-off-by: Christian Hopps --- isisd/isis_affinitymap.c | 2 -- lib/affinitymap_cli.c | 35 ++++++++------------- lib/affinitymap_northbound.c | 1 - lib/subdir.am | 1 - mgmtd/mgmt_be_adapter.c | 18 ++++++++--- mgmtd/mgmt_main.c | 14 ++++----- mgmtd/mgmt_vty.c | 4 +++ mgmtd/subdir.am | 4 +++ tests/topotests/example_munet/test_munet.py | 20 +++++++++++- vtysh/vtysh.h | 4 +-- zebra/zebra_affinitymap.c | 2 -- 11 files changed, 62 insertions(+), 43 deletions(-) diff --git a/isisd/isis_affinitymap.c b/isisd/isis_affinitymap.c index 41bad0a7d934..062d74bebd7d 100644 --- a/isisd/isis_affinitymap.c +++ b/isisd/isis_affinitymap.c @@ -88,8 +88,6 @@ static void isis_affinity_map_update(const char *affmap_name, uint16_t old_pos, void isis_affinity_map_init(void) { - affinity_map_init(); - affinity_map_set_check_use_hook(isis_affinity_map_check_use); affinity_map_set_update_hook(isis_affinity_map_update); } diff --git a/lib/affinitymap_cli.c b/lib/affinitymap_cli.c index d417ae195156..b4cacfebe54b 100644 --- a/lib/affinitymap_cli.c +++ b/lib/affinitymap_cli.c @@ -30,13 +30,18 @@ #include "lib/affinitymap.h" #include "lib/affinitymap_cli_clippy.c" -/* Route map node structure. */ -static int affinity_map_config_write(struct vty *vty); -static struct cmd_node affinitymap_node = { - .name = "affinity-map", - .node = AFFMAP_NODE, - .prompt = "", - .config_write = affinity_map_config_write, +/* clang-format off */ +const struct frr_yang_module_info frr_affinity_map_info = { + .name = "frr-affinity-map", + .nodes = { + { + .xpath = "/frr-affinity-map:lib/affinity-maps/affinity-map", + .cbs.cli_show = cli_show_affinity_map, + }, + { + .xpath = NULL, + }, + } }; /* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */ @@ -75,20 +80,6 @@ DEFPY_YANG_NOSH(no_affinity_map, no_affinity_map_cmd, return nb_cli_apply_changes(vty, NULL); } -static int affinity_map_config_write(struct vty *vty) -{ - const struct lyd_node *dnode; - int written = 0; - - dnode = yang_dnode_get(running_config->dnode, "/frr-affinity-map:lib"); - if (dnode) { - nb_cli_show_dnode_cmds(vty, dnode, false); - written = 1; - } - - return written; -} - void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode, bool show_defaults __attribute__((__unused__))) { @@ -101,7 +92,7 @@ void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode, void affinity_map_init(void) { /* CLI commands. */ - install_node(&affinitymap_node); + // install_node(&affinitymap_node); install_element(CONFIG_NODE, &affinity_map_cmd); install_element(CONFIG_NODE, &no_affinity_map_cmd); } diff --git a/lib/affinitymap_northbound.c b/lib/affinitymap_northbound.c index 331075f5c111..bb679aafcc08 100644 --- a/lib/affinitymap_northbound.c +++ b/lib/affinitymap_northbound.c @@ -119,7 +119,6 @@ const struct frr_yang_module_info frr_affinity_map_info = { .cbs = { .create = lib_affinity_map_create, .destroy = lib_affinity_map_destroy, - .cli_show = cli_show_affinity_map, } }, { diff --git a/lib/subdir.am b/lib/subdir.am index 4f203c0c842f..7afa199c52ee 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -9,7 +9,6 @@ lib_libfrr_la_LIBADD = $(LIBCAP) $(UNWIND_LIBS) $(LIBYANG_LIBS) $(LUA_LIB) $(UST lib_libfrr_la_SOURCES = \ lib/admin_group.c \ lib/affinitymap.c \ - lib/affinitymap_cli.c \ lib/affinitymap_northbound.c \ lib/agg_table.c \ lib/atomlist.c \ diff --git a/mgmtd/mgmt_be_adapter.c b/mgmtd/mgmt_be_adapter.c index eb6e79f2a5e9..954eb2457b34 100644 --- a/mgmtd/mgmt_be_adapter.c +++ b/mgmtd/mgmt_be_adapter.c @@ -58,6 +58,15 @@ struct mgmt_be_xpath_map { * Each client gets their own map, but also union all the strings into the * above map as well. */ + + +static const char *const zebra_config_xpaths[] = { + "/frr-affinity-map:lib/affinity-maps/affinity-map", + "/frr-interface:lib", + "/frr-vrf:lib", + NULL, +}; + #if HAVE_STATICD static const char *const staticd_xpaths[] = { "/frr-vrf:lib", @@ -67,8 +76,8 @@ static const char *const staticd_xpaths[] = { }; #endif -static const char *const *be_client_xpaths[MGMTD_BE_CLIENT_ID_MAX] = { - +static const char *const *be_client_config_xpaths[MGMTD_BE_CLIENT_ID_MAX] = { + [MGMTD_BE_CLIENT_ID_ZEBRA] = zebra_config_xpaths, #ifdef HAVE_STATICD [MGMTD_BE_CLIENT_ID_STATICD] = staticd_xpaths, #endif @@ -190,7 +199,7 @@ static void mgmt_be_xpath_map_init(void) FOREACH_MGMTD_BE_CLIENT_ID (id) { /* Initialize the common config init map */ - for (init = be_client_xpaths[id]; init && *init; init++) { + for (init = be_client_config_xpaths[id]; init && *init; init++) { MGMTD_BE_ADAPTER_DBG(" - CFG XPATH: '%s'", *init); mgmt_register_client_xpath(id, *init, true); } @@ -843,7 +852,8 @@ static bool be_is_client_interested(const char *xpath, MGMTD_BE_ADAPTER_DBG("Checking client: %s for xpath: '%s'", mgmt_be_client_id2name(id), xpath); - xpaths = config ? be_client_xpaths[id] : be_client_oper_xpaths[id]; + xpaths = config ? be_client_config_xpaths[id] + : be_client_oper_xpaths[id]; if (xpaths) { for (; *xpaths; xpaths++) { if (mgmt_be_xpath_prefix(*xpaths, xpath)) { diff --git a/mgmtd/mgmt_main.c b/mgmtd/mgmt_main.c index a70235717f21..db985566964d 100644 --- a/mgmtd/mgmt_main.c +++ b/mgmtd/mgmt_main.c @@ -185,15 +185,19 @@ static void mgmt_vrf_terminate(void) vrf_terminate(); } +extern const struct frr_yang_module_info frr_affinity_map_info; #ifdef HAVE_STATICD extern const struct frr_yang_module_info frr_staticd_info; #endif - /* * These are stub info structs that are used to load the modules used by backend * clients into mgmtd. The modules are used by libyang in order to support * parsing binary data returns from the backend. + * + * These are only needed if `cli_show` commands are not defined for the module. + * When `cli_show` callbacks are defined then the non-stub frr_yang_module_info + * that contains pointers to them should be included here instead. */ const struct frr_yang_module_info zebra_info = { .name = "frr-zebra", @@ -201,12 +205,6 @@ const struct frr_yang_module_info zebra_info = { .nodes = { { .xpath = NULL } }, }; -const struct frr_yang_module_info affinity_map_info = { - .name = "frr-affinity-map", - .ignore_cfg_cbs = true, - .nodes = { { .xpath = NULL } }, -}; - const struct frr_yang_module_info zebra_route_map_info = { .name = "frr-zebra-route-map", .ignore_cfg_cbs = true, @@ -218,6 +216,7 @@ const struct frr_yang_module_info zebra_route_map_info = { * MGMTd. */ static const struct frr_yang_module_info *const mgmt_yang_modules[] = { + &frr_affinity_map_info, &frr_filter_info, &frr_interface_info, &frr_route_map_info, @@ -229,7 +228,6 @@ static const struct frr_yang_module_info *const mgmt_yang_modules[] = { */ &zebra_info, - &affinity_map_info, &zebra_route_map_info, #ifdef HAVE_STATICD diff --git a/mgmtd/mgmt_vty.c b/mgmtd/mgmt_vty.c index 2591930e4a89..d709f4acbdb4 100644 --- a/mgmtd/mgmt_vty.c +++ b/mgmtd/mgmt_vty.c @@ -556,6 +556,10 @@ void mgmt_vty_init(void) * backend components that are moved to new MGMTD infra * here one by one. */ + extern void affinity_map_init(void); + affinity_map_init(); + if_cmd_init(NULL); + #if HAVE_STATICD extern void static_vty_init(void); static_vty_init(); diff --git a/mgmtd/subdir.am b/mgmtd/subdir.am index 89a6596f49f2..2f8677cee9d5 100644 --- a/mgmtd/subdir.am +++ b/mgmtd/subdir.am @@ -61,3 +61,7 @@ nodist_mgmtd_mgmtd_SOURCES += \ # end nodist_mgmtd_libmgmt_be_nb_la_SOURCES += staticd/static_vty.c endif + +# Unconditionally YANG support +nodist_mgmtd_mgmtd_SOURCES += yang/frr-affinity-map.yang.c +nodist_mgmtd_libmgmt_be_nb_la_SOURCES += lib/affinitymap_cli.c diff --git a/tests/topotests/example_munet/test_munet.py b/tests/topotests/example_munet/test_munet.py index 0d9599fa541d..31dd5c81606d 100644 --- a/tests/topotests/example_munet/test_munet.py +++ b/tests/topotests/example_munet/test_munet.py @@ -5,6 +5,24 @@ # # Copyright (c) 2023, LabN Consulting, L.L.C. # +import pytest +from munet.base import get_event_loop + +pytestmark = [pytest.mark.asyncio] + + +@pytest.fixture(scope="function") +def event_loop(): + """Create an instance of the default event loop for the session.""" + loop = get_event_loop() + try: + # logging.info("event_loop_fixture: yielding with new event loop watcher") + yield loop + finally: + loop.close() + + async def test_native_test(unet): - o = unet.hosts["r1"].cmd_nostatus("ip addr") + # o = unet.hosts["r1"].cmd_nostatus("ip addr") + o = "Hello World" print(o) diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 65733ca61b4c..b9555dad5ad8 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -50,13 +50,13 @@ extern struct event_loop *master; VTYSH_SHARPD | VTYSH_PBRD | VTYSH_STATICD | VTYSH_BFDD | \ VTYSH_FABRICD | VTYSH_VRRPD | VTYSH_PATHD | VTYSH_MGMTD #define VTYSH_ACL VTYSH_BFDD|VTYSH_BABELD|VTYSH_BGPD|VTYSH_EIGRPD|VTYSH_ISISD|VTYSH_FABRICD|VTYSH_LDPD|VTYSH_NHRPD|VTYSH_OSPF6D|VTYSH_OSPFD|VTYSH_PBRD|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_VRRPD|VTYSH_ZEBRA -#define VTYSH_AFFMAP VTYSH_ZEBRA | VTYSH_ISISD +#define VTYSH_AFFMAP VTYSH_MGMTD #define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_FABRICD #define VTYSH_INTERFACE_SUBSET \ VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D | \ VTYSH_ISISD | VTYSH_PIMD | VTYSH_PIM6D | VTYSH_NHRPD | \ VTYSH_EIGRPD | VTYSH_BABELD | VTYSH_PBRD | VTYSH_FABRICD | \ - VTYSH_VRRPD + VTYSH_VRRPD | VTYSH_MGMTD #define VTYSH_INTERFACE VTYSH_INTERFACE_SUBSET | VTYSH_BGPD #define VTYSH_VRF VTYSH_INTERFACE_SUBSET | VTYSH_MGMTD #define VTYSH_KEYS VTYSH_RIPD | VTYSH_EIGRPD | VTYSH_OSPF6D | VTYSH_OSPFD diff --git a/zebra/zebra_affinitymap.c b/zebra/zebra_affinitymap.c index ae0f9a8a354d..3ffe99b2d930 100644 --- a/zebra/zebra_affinitymap.c +++ b/zebra/zebra_affinitymap.c @@ -136,8 +136,6 @@ static void zebra_affinity_map_update(const char *affmap_name, uint16_t old_pos, void zebra_affinity_map_init(void) { - affinity_map_init(); - affinity_map_set_check_use_hook(zebra_affinity_map_check_use); affinity_map_set_check_update_hook(zebra_affinity_map_check_update); affinity_map_set_update_hook(zebra_affinity_map_update);