Skip to content

Commit

Permalink
[SNMP]: Add snmp test case using link local as snmpagent address (son…
Browse files Browse the repository at this point in the history
…ic-net#9268)

What is the motivation for this PR?
Test added to use link local IP address as snmpagent address.

How did you do it?
Use ink local IP of eth0 IP address, configure that as MGMT address.
Restart SNMP service so that snmpd.conf uses newly assigned MGMT address as snmpagent address
Query using link local address
Check if snmpresult is as expected.
reload config to remove the MGMT link local IP assignment.

How did you verify/test it?
Verified on VS testbed,.
  • Loading branch information
SuvarnaMeenakshi authored and mssonicbld committed Aug 28, 2023
1 parent 12fbb87 commit e8efb7e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .azure-pipelines/pr_test_scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ t0:
- snmp/test_snmp_cpu.py
- snmp/test_snmp_default_route.py
- snmp/test_snmp_interfaces.py
- snmp/test_snmp_link_local_ip.py
- snmp/test_snmp_lldp.py
- snmp/test_snmp_loopback.py
- snmp/test_snmp_pfc_counters.py
Expand Down Expand Up @@ -111,6 +112,7 @@ multi-asic-t1-lag:
- bgp/test_bgp_fact.py
- bgp/test_bgp_update_timer.py
- snmp/test_snmp_default_route.py
- snmp/test_snmp_link_local_ip.py
- snmp/test_snmp_loopback.py
- snmp/test_snmp_pfc_counters.py
- snmp/test_snmp_queue.py
Expand Down
65 changes: 65 additions & 0 deletions tests/snmp/test_snmp_link_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pytest
from tests.common.helpers.snmp_helpers import get_snmp_facts
from tests.common import config_reload

pytestmark = [
pytest.mark.topology('t0', 't1', 't2', 'm0', 'mx'),
pytest.mark.device_type('vs')
]


@pytest.fixture(autouse=True, scope='module')
def config_reload_after_test(duthosts,
enum_rand_one_per_hwsku_frontend_hostname):
yield
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
config_reload(duthost, config_source='config_db')


@pytest.mark.bsl
def test_snmp_link_local_ip(duthosts,
enum_rand_one_per_hwsku_frontend_hostname,
nbrhosts, tbinfo, localhost, creds_all_duts):
"""
Test SNMP query to DUT over link local IP
- Send SNMP query over link local IP from one of the BGP Neighbors
- Get SysDescr from snmpfacts
- compare result from snmp query over link local IP and snmpfacts
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
hostip = duthost.host.options['inventory_manager'].get_host(
duthost.hostname).vars['ansible_host']
snmp_facts = get_snmp_facts(
localhost, host=hostip, version="v2c",
community=creds_all_duts[duthost.hostname]["snmp_rocommunity"],
wait=True)['ansible_facts']
# Get link local IP of mamangement interface
ip_cmd = 'ip addr show eth0 | grep "inet6" | grep "link"\
| awk "{print $2}" | cut -d/ -f1'
link_local_ips = duthost.shell(ip_cmd)['stdout_lines']
sysdescr_oid = '1.3.6.1.2.1.1.1.0'
# configure link local IP in config_db
for ip in link_local_ips:
if ip.split()[1].lower().startswith('fe80'):
link_local_ip = ip.split()[1]
break
# configure link local IP in config_db
duthost.shell(
'sonic-db-cli CONFIG_DB hset "MGMT_INTERFACE|eth0|{}" \
"gwaddr" "fe80::1"'
.format(link_local_ip))
# Restart snmp service to regenerate snmpd.conf with
# link local IP configured in MGMT_INTERFACE
duthost.shell("systemctl restart snmp")
stdout_lines = duthost.shell("docker exec snmp snmpget \
-v2c -c {} {}%eth0 {}"
.format(creds_all_duts[duthost.hostname]
['snmp_rocommunity'],
link_local_ip,
sysdescr_oid))['stdout_lines'][0]
assert "SONiC Software Version" in stdout_lines,\
"Sysdescr not found in SNMP result from Link Local IP {}".format(
link_local_ip)
assert snmp_facts['ansible_sysdescr'] in stdout_lines,\
"Sysdescr from IP{} not matching with result from Mgmt IPv4.".format(
link_local_ip)

0 comments on commit e8efb7e

Please sign in to comment.