From ee4fa519fdc8259609c43fa866747cb63355467c Mon Sep 17 00:00:00 2001 From: Mykola Faryma Date: Wed, 17 Jun 2020 17:39:43 +0000 Subject: [PATCH 1/3] [snmp_interfaces] add snmp interface countes check Change-Id: Iead56ba71845ee90a65f521d8a1069102cc59112 Signed-off-by: Mykola Faryma --- tests/snmp/test_snmp_interfaces.py | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/snmp/test_snmp_interfaces.py b/tests/snmp/test_snmp_interfaces.py index 4e9771dfdeb..65c468a232b 100644 --- a/tests/snmp/test_snmp_interfaces.py +++ b/tests/snmp/test_snmp_interfaces.py @@ -24,3 +24,35 @@ def test_snmp_interfaces(duthost, localhost, creds): # Verify management port in snmp interface list for name in config_facts.get('MGMT_INTERFACE', {}): assert name in snmp_ifnames + + # Verify Vlan interfaces in snmp interface list + for name in config_facts.get('VLAN_INTERFACE', {}): + assert name in snmp_ifnames + + +def test_snmp_interface_counters(duthost, localhost, creds): + """Make sure Interface MIB has counters available""" + + hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] + + snmp_facts = localhost.snmp_facts(host=hostip, version="v2c", community=creds["snmp_rocommunity"])['ansible_facts'] + + for k, v in snmp_facts['snmp_interfaces'].items(): + if "Ethernet" in v['name'] or "PortChannel" in v['name']: + if not v.has_key('ifInErrors') or \ + not v.has_key('ifOutErrors') or \ + not v.has_key('ifInDiscards') or \ + not v.has_key('ifHCInOctets') or \ + not v.has_key('ifOutDiscards') or \ + not v.has_key('ifHCOutOctets') or \ + not v.has_key('ifInUcastPkts') or \ + not v.has_key('ifOutUcastPkts'): + pytest.fail("interface %s does not have counters" % v['name']) + + # Vlan interface being a l3 interface, has limited counter support + elif "Vlan" in v['name']: + if not v.has_key('ifInErrors') or \ + not v.has_key('ifOutErrors') or \ + not v.has_key('ifInUcastPkts') or \ + not v.has_key('ifOutUcastPkts'): + pytest.fail("interface %s does not have counters" % v['name']) From 106091c5254054b873417b35a08e231cdb064cd2 Mon Sep 17 00:00:00 2001 From: Mykola Faryma Date: Thu, 18 Jun 2020 12:38:21 +0000 Subject: [PATCH 2/3] expect l3vlan counters only on Mellanox Change-Id: Iaccb49c13e9b2260fee6f5a1e78dbd30311c2c80 Signed-off-by: Mykola Faryma --- tests/snmp/test_snmp_interfaces.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/snmp/test_snmp_interfaces.py b/tests/snmp/test_snmp_interfaces.py index 65c468a232b..c27eea97dba 100644 --- a/tests/snmp/test_snmp_interfaces.py +++ b/tests/snmp/test_snmp_interfaces.py @@ -32,9 +32,7 @@ def test_snmp_interfaces(duthost, localhost, creds): def test_snmp_interface_counters(duthost, localhost, creds): """Make sure Interface MIB has counters available""" - hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] - snmp_facts = localhost.snmp_facts(host=hostip, version="v2c", community=creds["snmp_rocommunity"])['ansible_facts'] for k, v in snmp_facts['snmp_interfaces'].items(): @@ -49,8 +47,17 @@ def test_snmp_interface_counters(duthost, localhost, creds): not v.has_key('ifOutUcastPkts'): pytest.fail("interface %s does not have counters" % v['name']) - # Vlan interface being a l3 interface, has limited counter support - elif "Vlan" in v['name']: + +def test_snmp_l3vlan_counters(duthost, localhost, creds): + """Make sure Interface MIB has counters available for l3vlan""" + if duthost.facts["asic_type"] not in ["mellanox"]: + pytest.skip("Skip test due to RIF counter not supported{}".format(duthost.facts["platform"])) + + hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] + snmp_facts = localhost.snmp_facts(host=hostip, version="v2c", community=creds["snmp_rocommunity"])['ansible_facts'] + + for k, v in snmp_facts['snmp_interfaces'].items(): + if "Vlan" in v['name']: if not v.has_key('ifInErrors') or \ not v.has_key('ifOutErrors') or \ not v.has_key('ifInUcastPkts') or \ From 32cf545be2c3f6a47d76d108659e369ced66b9c2 Mon Sep 17 00:00:00 2001 From: Mykola Faryma Date: Wed, 1 Jul 2020 20:53:08 +0000 Subject: [PATCH 3/3] fix pep8 warnings Change-Id: Ie64d0e856ff94bdbc30c73ba610643ba5126bc2d Signed-off-by: Mykola Faryma --- tests/snmp/test_snmp_interfaces.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/snmp/test_snmp_interfaces.py b/tests/snmp/test_snmp_interfaces.py index c27eea97dba..619b41aa618 100644 --- a/tests/snmp/test_snmp_interfaces.py +++ b/tests/snmp/test_snmp_interfaces.py @@ -8,9 +8,9 @@ def test_snmp_interfaces(duthost, localhost, creds): hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] snmp_facts = localhost.snmp_facts(host=hostip, version="v2c", community=creds["snmp_rocommunity"])['ansible_facts'] - config_facts = duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts'] + config_facts = duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts'] - snmp_ifnames = [ v['name'] for k, v in snmp_facts['snmp_interfaces'].items() ] + snmp_ifnames = [v['name'] for k, v in snmp_facts['snmp_interfaces'].items()] print snmp_ifnames # Verify all physical ports in snmp interface list @@ -37,29 +37,29 @@ def test_snmp_interface_counters(duthost, localhost, creds): for k, v in snmp_facts['snmp_interfaces'].items(): if "Ethernet" in v['name'] or "PortChannel" in v['name']: - if not v.has_key('ifInErrors') or \ - not v.has_key('ifOutErrors') or \ - not v.has_key('ifInDiscards') or \ - not v.has_key('ifHCInOctets') or \ - not v.has_key('ifOutDiscards') or \ - not v.has_key('ifHCOutOctets') or \ - not v.has_key('ifInUcastPkts') or \ - not v.has_key('ifOutUcastPkts'): + if ('ifInErrors' not in v or \ + 'ifOutErrors' not in v or \ + 'ifInDiscards' not in v or \ + 'ifHCInOctets' not in v or \ + 'ifOutDiscards' not in v or \ + 'ifHCOutOctets' not in v or \ + 'ifInUcastPkts' not in v or \ + 'ifOutUcastPkts' not in v): pytest.fail("interface %s does not have counters" % v['name']) def test_snmp_l3vlan_counters(duthost, localhost, creds): """Make sure Interface MIB has counters available for l3vlan""" if duthost.facts["asic_type"] not in ["mellanox"]: - pytest.skip("Skip test due to RIF counter not supported{}".format(duthost.facts["platform"])) + pytest.skip("Skip test due to RIF counter not supported on {}".format(duthost.facts["platform"])) hostip = duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'] snmp_facts = localhost.snmp_facts(host=hostip, version="v2c", community=creds["snmp_rocommunity"])['ansible_facts'] for k, v in snmp_facts['snmp_interfaces'].items(): if "Vlan" in v['name']: - if not v.has_key('ifInErrors') or \ - not v.has_key('ifOutErrors') or \ - not v.has_key('ifInUcastPkts') or \ - not v.has_key('ifOutUcastPkts'): + if ('ifInErrors' not in v or \ + 'ifOutErrors' not in v or \ + 'ifInUcastPkts' not in v or \ + 'ifOutUcastPkts' not in v): pytest.fail("interface %s does not have counters" % v['name'])