Confirmation check for mgmtvrf should only be for mgmt IP and not check for loopback#24
Confirmation check for mgmtvrf should only be for mgmt IP and not check for loopback#24irene-pan1202 wants to merge 1 commit into
Conversation
…ck for loopback Signed-off-by: irene_pan irene_pan@edge-core.com
There was a problem hiding this comment.
Pull Request Overview
This PR updates the mgmtVRF confirmation check in the SNMP agent address addition workflow so that it only validates against management interface IPs and excludes loopback IPs.
- Added retrieval of all management interface keys via _get_all_mgmtinterface_keys().
- Introduced an IP-based check that compares the provided agent IP (stripped of its mask) against the management IPs.
| if entry and entry['mgmtVrfEnabled'] == 'true' : | ||
| click.echo("ManagementVRF is Enabled. Provide vrf.") | ||
| return False | ||
| mgmtintf_key_list = _get_all_mgmtinterface_keys() |
There was a problem hiding this comment.
Verify that _get_all_mgmtinterface_keys() returns only management interface IPs and excludes any loopback interfaces. Consider adding a comment or validation to clarify its expected output.
| mgmtintf_key_list = _get_all_mgmtinterface_keys() | |
| mgmtintf_key_list = _get_all_mgmtinterface_keys() | |
| # Filter out loopback interfaces to ensure only management interface IPs are included | |
| mgmtintf_key_list = [key for key in mgmtintf_key_list if not key[0].startswith('lo')] |
| click.echo("ManagementVRF is Enabled. Provide vrf.") | ||
| return False | ||
| mgmtintf_key_list = _get_all_mgmtinterface_keys() | ||
| if any(ip.split('/')[0].lower() == agentip.lower() for _, ip in mgmtintf_key_list): |
There was a problem hiding this comment.
Using string splitting for IP comparison may lead to issues if the IP format changes; consider using the ipaddress module for robust IP address comparisons (e.g., comparing ipaddress.ip_address values).
| if any(ip.split('/')[0].lower() == agentip.lower() for _, ip in mgmtintf_key_list): | |
| if any(str(ipaddress.ip_interface(ip).ip).lower() == agentip.lower() for _, ip in mgmtintf_key_list): |
There was a problem hiding this comment.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
config/main.py:3186
- The condition assumes that all IP strings include a '/' for subnet separation, which might lead to an error if an IP is provided in a different format. Consider adding validation or error handling to ensure the split operation is safe.
if any(ip.split('/')[0].lower() == agentip.lower() for _, ip in mgmtintf_key_list):
config/main.py:3185
- Ensure that there are corresponding unit tests for _get_all_mgmtinterface_keys() and this new check to verify the behavior when the agent IP belongs or does not belong to the management interface list.
mgmtintf_key_list = _get_all_mgmtinterface_keys()
What I did
Confirmation check for mgmtvrf should only be for mgmt IP and not check for loopback
How I did it
How to verify it
Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)