tests: add test for new northbound get function

Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
Christian Hopps 2024-12-19 07:58:03 -06:00
parent 4379066fdd
commit e729676cfe
3 changed files with 52 additions and 4 deletions

View file

@ -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,

View file

@ -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": {

View file

@ -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 {