Skip to content

[SNMP]: Fix SNMP test case over Loopback IP to check result of sysDescr#2918

Merged
lguohan merged 3 commits intosonic-net:masterfrom
SuvarnaMeenakshi:snmp_lo_fix
Feb 5, 2021
Merged

[SNMP]: Fix SNMP test case over Loopback IP to check result of sysDescr#2918
lguohan merged 3 commits intosonic-net:masterfrom
SuvarnaMeenakshi:snmp_lo_fix

Conversation

@SuvarnaMeenakshi
Copy link
Copy Markdown
Contributor

Fix SNMP test case over Loopback IP to check result of sysDescr.
Currently the test case only checks if SNMP result from Loopback
IP matches with result from Management IP.

Signed-off-by: SuvarnaMeenakshi sumeenak@microsoft.com

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Approach

What is the motivation for this PR?

Current testcase checks if SNMP result over Loopback IP matches with the result from Management IP.
It does not check for the correctness of the result.
If the SNMP result of sysDescr is wrong from both SNMP query over Loopback and Management IPs, this testcase did not catch it.

How did you do it?

  1. Additional check to see if sysDescr has the string "SONiC Software Version".
  2. Additional check to see if the result from Loopback IP is NOT None.

How did you verify/test it?

Run this test on single-asic VS testbed :
pytest --testbed=vms-kvm-t0 --inventory=veos_vtb --testbed_file=vtestbed.csv --host-pattern=vlab-01 --module-path=../ansible/library "snmp/test_snmp_loopback.py" --show-capture=no --disable_loganalyzer --skip_sanity -v
/usr/local/lib/python2.7/dist-packages/ansible/parsing/vault/init.py:44: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
from cryptography.exceptions import InvalidSignature
=============================================================================== test session starts ===============================================================================
platform linux2 -- Python 2.7.17, pytest-4.6.5, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python
cachedir: .pytest_cache
metadata: {'Python': '2.7.17', 'Platform': 'Linux-5.4.0-53-generic-x86_64-with-Ubuntu-18.04-bionic', 'Packages': {'py': '1.10.0', 'pytest': '4.6.5', 'pluggy': '0.13.1'}, 'Plugins': {u'repeat': u'0.9.1', u'ansible': u'2.2.2', u'xdist': u'1.28.0', u'html': u'1.22.1', u'forked': u'1.3.0', u'metadata': u'1.11.0'}}
ansible: 2.8.12
rootdir: /data/sonic-mgmt/tests, inifile: pytest.ini
plugins: xdist-1.28.0, html-1.22.1, repeat-0.9.1, forked-1.3.0, metadata-1.11.0, ansible-2.2.2
collected 1 item

snmp/test_snmp_loopback.py::test_snmp_loopback PASSED

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

result of sysDescr is correct.
Currently the test case only checks if SNMP result from Loopback
IP matches with result from Management IP.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@SuvarnaMeenakshi SuvarnaMeenakshi requested a review from a team as a code owner February 4, 2021 00:59
Comment thread tests/snmp/test_snmp_loopback.py Outdated
result = get_snmp_output(loip, duthost, nbr, creds)
if result is None:
# TODO: Fix SNMP query over IPv6 and remove the below check.
if (isinstance(loip, ipaddress.IPv4Address)) == False:
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Feb 4, 2021

Choose a reason for hiding this comment

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

( [](start = 11, length = 1)

remove the outside (), and use not instead of == False.
Hint: use linter to find this issue automatically, better integrated with an editor. #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed as per comment.

Comment thread tests/snmp/test_snmp_loopback.py Outdated
assert len(result[u'stdout_lines']) > 0, 'No result from snmpget'
assert snmp_facts['ansible_sysdescr'] in result[u'stdout_lines'][0][0], "Sysdescr not found in SNMP result from IP {}".format(ip)
result = get_snmp_output(loip, duthost, nbr, creds)
assert result != None, 'No result from snmpget'
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Feb 4, 2021

Choose a reason for hiding this comment

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

!= [](start = 22, length = 2)

is not #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed as per comment.

Comment thread tests/snmp/test_snmp_loopback.py Outdated
assert snmp_facts['ansible_sysdescr'] in result[u'stdout_lines'][0][0], "Sysdescr not found in SNMP result from IP {}".format(ip)
result = get_snmp_output(loip, duthost, nbr, creds)
assert result != None, 'No result from snmpget'
if result != None:
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Feb 4, 2021

Choose a reason for hiding this comment

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

if result != None: [](start = 8, length = 18)

You already assert it, so no need to check #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed this check.

Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

As comments

@lgtm-com
Copy link
Copy Markdown

lgtm-com Bot commented Feb 5, 2021

This pull request fixes 1 alert when merging ecc871b into 182b6d3 - view on LGTM.com

fixed alerts:

  • 1 for Unused import

@lguohan lguohan merged commit 2d87193 into sonic-net:master Feb 5, 2021
kazinator-arista pushed a commit to kazinator-arista/sonic-mgmt that referenced this pull request Mar 4, 2026
…atically (sonic-net#16110)

src/sonic-utilities

* 0f001c56 - (HEAD -> 202205, origin/202205) UT change: for db_migrator test do not check for RESTAPI cert values (sonic-net#2919) (4 hours ago) [Vaibhav Hemant Dixit]
* 69d348d1 - [CLI][Show][BGP] Show BGP Change for no neighbor scenario (sonic-net#2885) (6 hours ago) [Dev Ojha]
* 4c6af3c3 - [multi-asic] Refine [override config table] for corner cases (sonic-net#2918) (6 hours ago) [wenyiz2021]
* bef3ffeb - [db_migrator] Set docker_routing_config_mode to the value obtained from minigraph parser (sonic-net#2890) (sonic-net#2922) (7 hours ago) [Vaibhav Hemant Dixit]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants