Merge pull request #18263 from cscarpitta/fix/add_no_form_for_static_sids_cli

staticd: Add `no` form for `static-sids` command
This commit is contained in:
Donald Sharp 2025-02-28 09:14:57 -05:00 committed by GitHub
commit 08af876bdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 107 additions and 2 deletions

View File

@ -184,6 +184,10 @@ int routing_control_plane_protocols_name_validate(
"frr-staticd:staticd/segment-routing/srv6" "frr-staticd:staticd/segment-routing/srv6"
/* srv6/static-sids */ /* srv6/static-sids */
#define FRR_STATIC_SRV6_STATIC_SIDS_XPATH \
FRR_STATIC_SRV6_INFO_KEY_XPATH \
"/static-sids"
#define FRR_STATIC_SRV6_SID_KEY_XPATH \ #define FRR_STATIC_SRV6_SID_KEY_XPATH \
FRR_STATIC_SRV6_INFO_KEY_XPATH \ FRR_STATIC_SRV6_INFO_KEY_XPATH \
"/static-sids/" \ "/static-sids/" \

View File

@ -1190,10 +1190,22 @@ DEFUN_YANG_NOSH (no_static_srv6, no_static_srv6_cmd,
return nb_cli_apply_changes(vty, "%s", xpath); return nb_cli_apply_changes(vty, "%s", xpath);
} }
DEFUN_NOSH (static_srv6_sids, static_srv6_sids_cmd, DEFPY_YANG_NOSH (static_srv6_sids, static_srv6_sids_cmd,
"static-sids", "[no] static-sids",
NO_STR
"Segment Routing SRv6 SIDs\n") "Segment Routing SRv6 SIDs\n")
{ {
char xpath[XPATH_MAXLEN];
if (no) {
snprintf(xpath, sizeof(xpath), FRR_STATIC_SRV6_STATIC_SIDS_XPATH,
"frr-staticd:staticd", "staticd", VRF_DEFAULT_NAME);
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, "%s", xpath);
}
VTY_PUSH_CONTEXT_NULL(SRV6_SIDS_NODE); VTY_PUSH_CONTEXT_NULL(SRV6_SIDS_NODE);
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -172,6 +172,85 @@ def test_srv6_static_sids_sid_readd():
check_srv6_static_sids(router, "expected_srv6_sids.json") check_srv6_static_sids(router, "expected_srv6_sids.json")
def test_srv6_static_sids_sid_delete_all():
"""
Remove all static SIDs and verify they get removed
"""
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
router = tgen.gears["r1"]
def _check_srv6_static_sids(router, expected_route_file):
logger.info("checking zebra srv6 static sids")
output = json.loads(router.vtysh_cmd("show ipv6 route static json"))
expected = open_json_file("{}/{}".format(CWD, expected_route_file))
return topotest.json_cmp(output, expected, exact=True)
def check_srv6_static_sids(router, expected_file):
func = functools.partial(_check_srv6_static_sids, router, expected_file)
_, result = topotest.run_and_expect(func, None, count=15, wait=1)
assert result is None, "Failed"
router.vtysh_cmd(
"""
configure terminal
segment-routing
srv6
no static-sids
"""
)
# FOR DEVELOPER:
# If you want to stop some specific line and start interactive shell,
# please use tgen.mininet_cli() to start it.
logger.info("Test for srv6 sids configuration")
check_srv6_static_sids(router, "expected_srv6_sids_delete_all.json")
def test_srv6_static_sids_sid_readd_all():
"""
Re-add the static SIDs and verify the routing table
"""
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
router = tgen.gears["r1"]
def _check_srv6_static_sids(router, expected_route_file):
logger.info("checking zebra srv6 static sids")
output = json.loads(router.vtysh_cmd("show ipv6 route static json"))
expected = open_json_file("{}/{}".format(CWD, expected_route_file))
return topotest.json_cmp(output, expected)
def check_srv6_static_sids(router, expected_file):
func = functools.partial(_check_srv6_static_sids, router, expected_file)
_, result = topotest.run_and_expect(func, None, count=15, wait=1)
assert result is None, "Failed"
router.vtysh_cmd(
"""
configure terminal
segment-routing
srv6
static-sids
sid fcbb:bbbb:1::/48 locator MAIN behavior uN
sid fcbb:bbbb:1:fe10::/64 locator MAIN behavior uDT4 vrf Vrf10
sid fcbb:bbbb:1:fe20::/64 locator MAIN behavior uDT6 vrf Vrf20
sid fcbb:bbbb:1:fe30::/64 locator MAIN behavior uDT46 vrf Vrf30
sid fcbb:bbbb:1:fe40::/64 locator MAIN behavior uA interface sr0 nexthop 2001::2
"""
)
# FOR DEVELOPER:
# If you want to stop some specific line and start interactive shell,
# please use tgen.mininet_cli() to start it.
logger.info("Test for srv6 sids configuration")
check_srv6_static_sids(router, "expected_srv6_sids.json")
if __name__ == "__main__": if __name__ == "__main__":
args = ["-s"] + sys.argv[1:] args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args)) sys.exit(pytest.main(args))

View File

@ -1708,6 +1708,14 @@ DEFUNSH(VTYSH_MGMTD, srv6_sids, srv6_sids_cmd,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
DEFUNSH(VTYSH_MGMTD, no_srv6_sids, no_srv6_sids_cmd,
"no static-sids",
NO_STR
"Segment-Routing SRv6 SIDs configuration\n")
{
return CMD_SUCCESS;
}
DEFUNSH(VTYSH_ZEBRA, srv6_locators, srv6_locators_cmd, DEFUNSH(VTYSH_ZEBRA, srv6_locators, srv6_locators_cmd,
"locators", "locators",
"Segment-Routing SRv6 locators configuration\n") "Segment-Routing SRv6 locators configuration\n")
@ -5543,6 +5551,7 @@ void vtysh_init_vty(void)
install_element(SRV6_NODE, &vtysh_end_all_cmd); install_element(SRV6_NODE, &vtysh_end_all_cmd);
install_element(SRV6_NODE, &srv6_encap_cmd); install_element(SRV6_NODE, &srv6_encap_cmd);
install_element(SRV6_NODE, &srv6_sids_cmd); install_element(SRV6_NODE, &srv6_sids_cmd);
install_element(SRV6_NODE, &no_srv6_sids_cmd);
install_element(SRV6_SIDS_NODE, &exit_srv6_sids_config_cmd); install_element(SRV6_SIDS_NODE, &exit_srv6_sids_config_cmd);
install_element(SRV6_SIDS_NODE, &vtysh_end_all_cmd); install_element(SRV6_SIDS_NODE, &vtysh_end_all_cmd);