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

[action] [PR:3215] Fix to use IPv6 linklocal address as snmp agent address (#3215) #3487

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3460,7 +3460,10 @@ def add_snmp_agent_address(ctx, agentip, port, vrf):
"""Add the SNMP agent listening IP:Port%Vrf configuration"""

#Construct SNMP_AGENT_ADDRESS_CONFIG table key in the format ip|<port>|<vrf>
if not clicommon.is_ipaddress(agentip):
# Link local IP address should be provided along with zone id
# <link_local_ip>%<zone_id> for ex fe80::1%eth0
agent_ip_addr = agentip.split('%')[0]
if not clicommon.is_ipaddress(agent_ip_addr):
click.echo("Invalid IP address")
return False
config_db = ctx.obj['db']
Expand All @@ -3470,7 +3473,7 @@ def add_snmp_agent_address(ctx, agentip, port, vrf):
click.echo("ManagementVRF is Enabled. Provide vrf.")
return False
found = 0
ip = ipaddress.ip_address(agentip)
ip = ipaddress.ip_address(agent_ip_addr)
for intf in netifaces.interfaces():
ipaddresses = netifaces.ifaddresses(intf)
if ip_family[ip.version] in ipaddresses:
Expand Down
28 changes: 28 additions & 0 deletions tests/config_snmp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,34 @@ def test_config_snmp_community_add_new_community_with_invalid_type_yang_validati
assert result.exit_code != 0
assert 'SNMP community configuration failed' in result.output

@patch('netifaces.interfaces', mock.Mock(return_value=['eth0']))
@patch('netifaces.ifaddresses', mock.Mock(return_value={2:
[{'addr': '10.1.0.32', 'netmask': '255.255.255.0',
'broadcast': '10.1.0.255'}],
10: [{'addr': 'fe80::1%eth0', 'netmask': 'ffff:ffff:ffff:ffff::/64'}]}))
@patch('os.system', mock.Mock(return_value=0))
def test_config_snmpagentaddress_add_linklocal(self):
db = Db()
obj = {'db': db.cfgdb}
runner = CliRunner()
runner.invoke(config.config.commands["snmpagentaddress"].commands["add"], ["fe80::1%eth0"], obj=obj)
assert ('fe80::1%eth0', '', '') in db.cfgdb.get_keys('SNMP_AGENT_ADDRESS_CONFIG')
assert db.cfgdb.get_entry("SNMP_AGENT_ADDRESS_CONFIG", "fe80::1%eth0||") == {}

@patch('netifaces.interfaces', mock.Mock(return_value=['eth0']))
@patch('netifaces.ifaddresses', mock.Mock(return_value={2:
[{'addr': '10.1.0.32', 'netmask': '255.255.255.0',
'broadcast': '10.1.0.255'}],
10: [{'addr': 'fe80::1', 'netmask': 'ffff:ffff:ffff:ffff::/64'}]}))
@patch('os.system', mock.Mock(return_value=0))
def test_config_snmpagentaddress_add_ipv4(self):
db = Db()
obj = {'db': db.cfgdb}
runner = CliRunner()
runner.invoke(config.config.commands["snmpagentaddress"].commands["add"], ["10.1.0.32"], obj=obj)
assert ('10.1.0.32', '', '') in db.cfgdb.get_keys('SNMP_AGENT_ADDRESS_CONFIG')
assert db.cfgdb.get_entry("SNMP_AGENT_ADDRESS_CONFIG", "10.1.0.32||") == {}

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down
Loading