forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SNMP]: Add snmp test case using link local as snmpagent address (son…
…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
1 parent
12fbb87
commit e8efb7e
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |