Skip to content

Commit e8efb7e

Browse files
SuvarnaMeenakshimssonicbld
authored andcommitted
[SNMP]: Add snmp test case using link local as snmpagent address (sonic-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,.
1 parent 12fbb87 commit e8efb7e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

.azure-pipelines/pr_test_scripts.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ t0:
4747
- snmp/test_snmp_cpu.py
4848
- snmp/test_snmp_default_route.py
4949
- snmp/test_snmp_interfaces.py
50+
- snmp/test_snmp_link_local_ip.py
5051
- snmp/test_snmp_lldp.py
5152
- snmp/test_snmp_loopback.py
5253
- snmp/test_snmp_pfc_counters.py
@@ -111,6 +112,7 @@ multi-asic-t1-lag:
111112
- bgp/test_bgp_fact.py
112113
- bgp/test_bgp_update_timer.py
113114
- snmp/test_snmp_default_route.py
115+
- snmp/test_snmp_link_local_ip.py
114116
- snmp/test_snmp_loopback.py
115117
- snmp/test_snmp_pfc_counters.py
116118
- snmp/test_snmp_queue.py

tests/snmp/test_snmp_link_local.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import pytest
2+
from tests.common.helpers.snmp_helpers import get_snmp_facts
3+
from tests.common import config_reload
4+
5+
pytestmark = [
6+
pytest.mark.topology('t0', 't1', 't2', 'm0', 'mx'),
7+
pytest.mark.device_type('vs')
8+
]
9+
10+
11+
@pytest.fixture(autouse=True, scope='module')
12+
def config_reload_after_test(duthosts,
13+
enum_rand_one_per_hwsku_frontend_hostname):
14+
yield
15+
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
16+
config_reload(duthost, config_source='config_db')
17+
18+
19+
@pytest.mark.bsl
20+
def test_snmp_link_local_ip(duthosts,
21+
enum_rand_one_per_hwsku_frontend_hostname,
22+
nbrhosts, tbinfo, localhost, creds_all_duts):
23+
"""
24+
Test SNMP query to DUT over link local IP
25+
- Send SNMP query over link local IP from one of the BGP Neighbors
26+
- Get SysDescr from snmpfacts
27+
- compare result from snmp query over link local IP and snmpfacts
28+
"""
29+
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
30+
hostip = duthost.host.options['inventory_manager'].get_host(
31+
duthost.hostname).vars['ansible_host']
32+
snmp_facts = get_snmp_facts(
33+
localhost, host=hostip, version="v2c",
34+
community=creds_all_duts[duthost.hostname]["snmp_rocommunity"],
35+
wait=True)['ansible_facts']
36+
# Get link local IP of mamangement interface
37+
ip_cmd = 'ip addr show eth0 | grep "inet6" | grep "link"\
38+
| awk "{print $2}" | cut -d/ -f1'
39+
link_local_ips = duthost.shell(ip_cmd)['stdout_lines']
40+
sysdescr_oid = '1.3.6.1.2.1.1.1.0'
41+
# configure link local IP in config_db
42+
for ip in link_local_ips:
43+
if ip.split()[1].lower().startswith('fe80'):
44+
link_local_ip = ip.split()[1]
45+
break
46+
# configure link local IP in config_db
47+
duthost.shell(
48+
'sonic-db-cli CONFIG_DB hset "MGMT_INTERFACE|eth0|{}" \
49+
"gwaddr" "fe80::1"'
50+
.format(link_local_ip))
51+
# Restart snmp service to regenerate snmpd.conf with
52+
# link local IP configured in MGMT_INTERFACE
53+
duthost.shell("systemctl restart snmp")
54+
stdout_lines = duthost.shell("docker exec snmp snmpget \
55+
-v2c -c {} {}%eth0 {}"
56+
.format(creds_all_duts[duthost.hostname]
57+
['snmp_rocommunity'],
58+
link_local_ip,
59+
sysdescr_oid))['stdout_lines'][0]
60+
assert "SONiC Software Version" in stdout_lines,\
61+
"Sysdescr not found in SNMP result from Link Local IP {}".format(
62+
link_local_ip)
63+
assert snmp_facts['ansible_sysdescr'] in stdout_lines,\
64+
"Sysdescr from IP{} not matching with result from Mgmt IPv4.".format(
65+
link_local_ip)

0 commit comments

Comments
 (0)