-
Notifications
You must be signed in to change notification settings - Fork 664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VRF]Adding CLI checks to ensure Vrf is valid in interface bind and static route commands #2333
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,6 +369,19 @@ def get_interface_ipaddresses(config_db, interface_name): | |
|
||
return ipaddresses | ||
|
||
def is_vrf_exists(config_db, vrf_name): | ||
"""Check if VRF exists | ||
""" | ||
keys = config_db.get_keys("VRF") | ||
if vrf_name in keys: | ||
return True | ||
elif vrf_name == "mgmt": | ||
entry = config_db.get_entry("MGMT_VRF_CONFIG", "vrf_global") | ||
if entry and entry.get("mgmtVrfEnabled") == "true": | ||
return True | ||
|
||
return False | ||
|
||
def is_interface_bind_to_vrf(config_db, interface_name): | ||
"""Get interface if bind to vrf or not | ||
""" | ||
|
@@ -986,6 +999,7 @@ def cli_sroute_to_config(ctx, command_str, strict_nh = True): | |
nexthop_str = None | ||
config_entry = {} | ||
vrf_name = "" | ||
config_db = ctx.obj['config_db'] | ||
|
||
if "nexthop" in command_str: | ||
idx = command_str.index("nexthop") | ||
|
@@ -998,6 +1012,8 @@ def cli_sroute_to_config(ctx, command_str, strict_nh = True): | |
if 'prefix' in prefix_str and 'vrf' in prefix_str: | ||
# prefix_str: ['prefix', 'vrf', Vrf-name, ip] | ||
vrf_name = prefix_str[2] | ||
if not is_vrf_exists(config_db, vrf_name): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have check to ensure vrf is removed only after all interface bindings are removed? Otherwise this is only a check in the add-path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only a check in the add path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact the current vrf removal logic removes all these bindings implicitly using the function del_interface_bind_to_vrf |
||
ctx.fail("VRF %s does not exist!"%(vrf_name)) | ||
ip_prefix = prefix_str[3] | ||
elif 'prefix' in prefix_str: | ||
# prefix_str: ['prefix', ip] | ||
|
@@ -1009,6 +1025,8 @@ def cli_sroute_to_config(ctx, command_str, strict_nh = True): | |
if 'nexthop' in nexthop_str and 'vrf' in nexthop_str: | ||
# nexthop_str: ['nexthop', 'vrf', Vrf-name, ip] | ||
config_entry["nexthop"] = nexthop_str[3] | ||
if not is_vrf_exists(config_db, nexthop_str[2]): | ||
ctx.fail("VRF %s does not exist!"%(nexthop_str[2])) | ||
config_entry["nexthop-vrf"] = nexthop_str[2] | ||
elif 'nexthop' in nexthop_str and 'dev' in nexthop_str: | ||
# nexthop_str: ['nexthop', 'dev', ifname] | ||
|
@@ -4883,6 +4901,9 @@ def bind(ctx, interface_name, vrf_name): | |
if interface_name is None: | ||
ctx.fail("'interface_name' is None!") | ||
|
||
if not is_vrf_exists(config_db, vrf_name): | ||
ctx.fail("VRF %s does not exist!"%(vrf_name)) | ||
|
||
table_name = get_interface_table_name(interface_name) | ||
if table_name == "": | ||
ctx.fail("'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan/Loopback]") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we prevent from using non-existing VRF in the INTERFACE table during config load? this seems to address only in the Click CLI.
If we can do the YANG level validation for all north bound interfaces (CLick, config load..etc), it would be an one time check in the back-end rather than doing it on all front-end (e.g this check in Click), what is your thought?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @venkatmahalingam
Your comment is applicable for any table in config_db.json.
This PR is focussed on only the Click CLI. I believe we have a separate discussion on using yang for validation which is the work in progress and would take sometime.
For now It is expected of the end user to use Click CLI to make any incremental configuration changes.
Let me know if the changes look good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any update we do with config-db should be YANG validated is what the expectation but the infra is not ready yet, we can merge this code for now.