-
Notifications
You must be signed in to change notification settings - Fork 716
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
Use device loopback IP address to send SNMP query from neighboring ceos or vsonic #8802
Changes from 9 commits
6cef81b
2617ef4
6d9fba0
f6404ae
30e9ea6
ac2fcfb
cd06cf8
0d502b7
a917d80
bd4dfb4
fa06473
23fe59d
ba56719
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import pytest | ||
import logging | ||
import re | ||
import ipaddress | ||
|
||
from tests.common.utilities import wait_until | ||
from tests.common.devices.eos import EosHost | ||
|
@@ -132,11 +133,33 @@ def test_snmp(self, duthost, ctrl_links, upstream_links, creds, wait_mka_establi | |
commands=['show snmp community | include name']) | ||
community = re.search(r'Community name: (\S+)', | ||
result['stdout'][0]).groups()[0] | ||
up_link = upstream_links[ctrl_port] | ||
nbr_ip = up_link["local_ipv4_addr"] | ||
else: # vsonic neighbour | ||
community = creds['snmp_rocommunity'] | ||
# Use LoopbackIP to query from vsonic neighbor | ||
result = nbr["host"].config_facts(host=nbr["host"].hostname, | ||
source="running")[ | ||
"ansible_facts"].get( | ||
"LOOPBACK_INTERFACE", | ||
{}).get('Loopback0', {}) | ||
for ip in result: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
if isinstance(ipaddress.ip_address(ip.split('/')[0]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to split, you can directly parse There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
ipaddress.IPv4Address): | ||
nbr_ip = ip.split('/')[0] | ||
nbr["host"].command("sudo iptables -I INPUT 1 -p udp \ | ||
--dport 161 -d {} -j ACCEPT". | ||
format(nbr_ip)) | ||
break | ||
|
||
up_link = upstream_links[ctrl_port] | ||
sysDescr = ".1.3.6.1.2.1.1.1.0" | ||
command = "docker exec snmp snmpwalk -v 2c -c {} {} {}".format( | ||
community, up_link["local_ipv4_addr"], sysDescr) | ||
assert not duthost.command(command)["failed"] | ||
community, nbr_ip, sysDescr) | ||
result = duthost.command(command) | ||
|
||
if not isinstance(nbr["host"], EosHost): | ||
nbr["host"].command("sudo iptables -D INPUT -p udp \ | ||
--dport 161 -d {} -j \ | ||
ACCEPT".format(nbr_ip)) | ||
|
||
assert not result["failed"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the code comment, could you be more specific about ipv4 or ipv6? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed