Skip to content
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

[config] Fix snmpagentaddress doesn't support the uppercase letters for ipv6 address #1989

Merged
merged 3 commits into from
Feb 16, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,8 @@ def snmpagentaddress(ctx):
def add_snmp_agent_address(ctx, agentip, port, vrf):
"""Add the SNMP agent listening IP:Port%Vrf configuration"""

#Convert agentip to lower to match netifaces addresses
agentip = agentip.lower()
#Construct SNMP_AGENT_ADDRESS_CONFIG table key in the format ip|<port>|<vrf>
if not clicommon.is_ipaddress(agentip):
click.echo("Invalid IP address")
Expand All @@ -2490,11 +2492,11 @@ def add_snmp_agent_address(ctx, agentip, port, vrf):
for ipaddr in ipaddresses[ip_family[ip.version]]:
if agentip == ipaddr['addr']:
Copy link
Contributor

@qiluo-msft qiluo-msft Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ipaddr['addr']

Currently the ConfigDB has no way to enforce the lowercase for SNMP_AGENT_ADDRESS_CONFIG key. So there may be already lowercase entries.

Suggest you compare ipv6 address case insensitive. This library may help https://docs.python.org/3/library/ipaddress.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, it's better to compare the lowercase of IPv6 addresses, and I have modified my PR, thanks.

found = 1
break;
break
if found == 1:
break;
break
else:
click.echo("IP addfress is not available")
click.echo("IP address is not available")
return

key = agentip+'|'
Expand Down