From e729676cfe7d0074484bba3fab9840baa2192818 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Thu, 19 Dec 2024 07:58:03 -0600 Subject: [PATCH] tests: add test for new northbound get function Signed-off-by: Christian Hopps --- tests/lib/northbound/test_oper_data.c | 41 +++++++++++++++++++--- tests/lib/northbound/test_oper_data.refout | 12 +++++++ yang/frr-test-module.yang | 3 ++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/tests/lib/northbound/test_oper_data.c b/tests/lib/northbound/test_oper_data.c index 3d700d8a19..0b334c6522 100644 --- a/tests/lib/northbound/test_oper_data.c +++ b/tests/lib/northbound/test_oper_data.c @@ -119,6 +119,26 @@ static const void *frr_test_module_vrfs_vrf_interfaces_interface_get_next( return node; } +/* + * XPath: /frr-test-module:frr-test-module/vrfs/vrf/interfaces/interface-new + */ +static enum nb_error frr_test_module_vrfs_vrf_interfaces_interface_new_get( + const struct nb_node *nb_node, const void *parent_list_entry, struct lyd_node *parent) +{ + const struct lysc_node *snode = nb_node->snode; + const struct tvrf *vrf; + struct listnode *node; + const char *interface; + LY_ERR err; + + vrf = listgetdata((struct listnode *)parent_list_entry); + for (ALL_LIST_ELEMENTS_RO(vrf->interfaces, node, interface)) { + err = lyd_new_term(parent, snode->module, snode->name, interface, false, NULL); + assert(err == LY_SUCCESS); + } + return NB_OK; +} + /* * XPath: /frr-test-module:frr-test-module/vrfs/vrf/routes/route */ @@ -228,10 +248,19 @@ frr_test_module_c1value_get_elem(struct nb_cb_get_elem_args *args) /* * XPath: /frr-test-module:frr-test-module/c2cont/c2value */ -static struct yang_data * -frr_test_module_c2cont_c2value_get_elem(struct nb_cb_get_elem_args *args) +static enum nb_error frr_test_module_c2cont_c2value_get(const struct nb_node *nb_node, + const void *parent_list_entry, + struct lyd_node *parent) { - return yang_data_new_uint32(args->xpath, 0xAB010203); + const struct lysc_node *snode = nb_node->snode; + uint32_t value = 0xAB010203; + LY_ERR err; + + err = lyd_new_term_bin(parent, snode->module, snode->name, &value, sizeof(value), + LYD_NEW_PATH_UPDATE, NULL); + assert(err == LY_SUCCESS); + + return NB_OK; } /* clang-format off */ @@ -253,6 +282,10 @@ const struct frr_yang_module_info frr_test_module_info = { .cbs.get_elem = frr_test_module_vrfs_vrf_interfaces_interface_get_elem, .cbs.get_next = frr_test_module_vrfs_vrf_interfaces_interface_get_next, }, + { + .xpath = "/frr-test-module:frr-test-module/vrfs/vrf/interfaces/interface-new", + .cbs.get = frr_test_module_vrfs_vrf_interfaces_interface_new_get, + }, { .xpath = "/frr-test-module:frr-test-module/vrfs/vrf/routes/route", .cbs.get_next = frr_test_module_vrfs_vrf_routes_route_get_next, @@ -287,7 +320,7 @@ const struct frr_yang_module_info frr_test_module_info = { }, { .xpath = "/frr-test-module:frr-test-module/c2cont/c2value", - .cbs.get_elem = frr_test_module_c2cont_c2value_get_elem, + .cbs.get = frr_test_module_c2cont_c2value_get, }, { .xpath = NULL, diff --git a/tests/lib/northbound/test_oper_data.refout b/tests/lib/northbound/test_oper_data.refout index 7c56564143..eadb639645 100644 --- a/tests/lib/northbound/test_oper_data.refout +++ b/tests/lib/northbound/test_oper_data.refout @@ -11,6 +11,12 @@ test# show yang operational-data /frr-test-module:frr-test-module "eth1", "eth2", "eth3" + ], + "interface-new": [ + "eth0", + "eth1", + "eth2", + "eth3" ] }, "routes": { @@ -65,6 +71,12 @@ test# show yang operational-data /frr-test-module:frr-test-module "eth1", "eth2", "eth3" + ], + "interface-new": [ + "eth0", + "eth1", + "eth2", + "eth3" ] }, "routes": { diff --git a/yang/frr-test-module.yang b/yang/frr-test-module.yang index dcf204a956..90086d05a2 100644 --- a/yang/frr-test-module.yang +++ b/yang/frr-test-module.yang @@ -60,6 +60,9 @@ module frr-test-module { leaf-list interface { type frr-interface:interface-ref; } + leaf-list interface-new { + type frr-interface:interface-ref; + } } container routes { list route { -- 2.39.5