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

[SNMP]: Add snmp test case using link local as snmpagent address #9268

Merged
merged 15 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .azure-pipelines/pr_test_scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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
62 changes: 62 additions & 0 deletions tests/snmp/test_snmp_link_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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']
# 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(
'redis-cli -n 4 hset "MGMT_INTERFACE|eth0|{}" "gwaddr" "fe80::1"'
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 8, 2023

Choose a reason for hiding this comment

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

redis-cli -n 4

sonic-db-cli CONFIG_DB is better. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

udpated

.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 1.3.6.1.2.1.1.1.0"
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 8, 2023

Choose a reason for hiding this comment

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

1.3.6.1.2.1.1.1.0

Better to have a named constant, so audience could understand what is the OID meaning. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

.format(creds_all_duts[duthost.hostname]
['snmp_rocommunity'],
link_local_ip))['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)
Loading