Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
75 changes: 62 additions & 13 deletions tests/gnmi/test_gnmi_countersdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ def test_gnmi_queue_buffer_cnt(duthosts, rand_one_dut_hostname, ptfhost):
path_list = ["/sonic-db:COUNTERS_DB/localhost/COUNTERS_QUEUE_NAME_MAP/" + iface + ":" + str(i)]
msg_list = gnmi_get(duthost, ptfhost, path_list)
result = msg_list[0]
pytest_assert("oid" in result, result)
pytest_assert("oid" in result, (
"OID not found in result. "
"Result: {}"
).format(result))

# Read invalid UC
path_list = ["/sonic-db:COUNTERS_DB/localhost/COUNTERS_QUEUE_NAME_MAP/" + iface + ":abc"]
try:
msg_list = gnmi_get(duthost, ptfhost, path_list)
except Exception as e:
assert "GRPC error" in str(e), str(e)
assert "GRPC error" in str(e), (
"Expected GRPC error, but got: {}. "
).format(str(e))

else:
pytest.fail("Should fail for invalid path: " + path_list[0])

Expand All @@ -56,14 +63,18 @@ def test_gnmi_output(duthosts, rand_one_dut_hostname, ptfhost):
dut_command = "sonic-db-cli COUNTERS_DB hget COUNTERS_PORT_NAME_MAP Ethernet0"
result = duthost.shell(dut_command, module_ignore_errors=True)
counter_key = result['stdout'].strip()
assert "oid" in counter_key, "Invalid oid: " + counter_key
assert "oid" in counter_key, (
"Invalid oid: {}."
).format(counter_key)

path_list = ["/sonic-db:COUNTERS_DB/localhost/COUNTERS/" + counter_key]
msg_list = gnmi_get(duthost, ptfhost, path_list)
result = msg_list[0]
logger.info("GNMI Server output")
logger.info(result)
pytest_assert("SAI_PORT_STAT_IF_IN_ERRORS" in result,
"SAI_PORT_STAT_IF_IN_ERRORS not found in gnmi_output: " + result)
pytest_assert("SAI_PORT_STAT_IF_IN_ERRORS" in result, (
"SAI_PORT_STAT_IF_IN_ERRORS not found in gnmi_output: {}."
).format(result))


test_data_counters_port_name_map = [
Expand All @@ -90,7 +101,11 @@ def test_gnmi_counterdb_polling_01(duthosts, rand_one_dut_hostname, ptfhost, tes
exp_cnt = 3
path_list = [test_data["path"]]
msg, _ = gnmi_subscribe_polling(duthost, ptfhost, path_list, 1000, exp_cnt)
assert msg.count("oid") >= exp_cnt, test_data["name"] + ": " + msg
assert msg.count("oid") >= exp_cnt, (
"{}: {}. "
"Expected count of 'oid': {}"
"Actual count of 'oid': {}"
).format(test_data["name"], msg, exp_cnt, msg.count("oid"))


def test_gnmi_counterdb_polling_02(duthosts, rand_one_dut_hostname, ptfhost):
Expand All @@ -106,19 +121,39 @@ def test_gnmi_counterdb_polling_02(duthosts, rand_one_dut_hostname, ptfhost):
dut_command = "sonic-db-cli COUNTERS_DB hget COUNTERS_PORT_NAME_MAP Ethernet0"
result = duthost.shell(dut_command, module_ignore_errors=True)
counter_key = result['stdout'].strip()
assert "oid" in counter_key, "Invalid oid: " + counter_key
assert "oid" in counter_key, (
"Invalid oid: {}. "
"Expected 'oid' in counter key"
).format(counter_key)

# Subscribe table
path_list = ["/sonic-db:COUNTERS_DB/localhost/COUNTERS/"]
msg, _ = gnmi_subscribe_polling(duthost, ptfhost, path_list, 1000, exp_cnt)
assert msg.count("SAI_PORT_STAT_IF_IN_ERRORS") >= exp_cnt, msg
assert msg.count("SAI_PORT_STAT_IF_IN_ERRORS") >= exp_cnt, (
"Expected count of 'SAI_PORT_STAT_IF_IN_ERRORS' not met. "
"Expected count: {}"
"Actual count: {}"
"Message: {}"
).format(exp_cnt, msg.count("SAI_PORT_STAT_IF_IN_ERRORS"), msg)

# Subscribe table key
path_list = ["/sonic-db:COUNTERS_DB/localhost/COUNTERS/" + counter_key]
msg, _ = gnmi_subscribe_polling(duthost, ptfhost, path_list, 1000, exp_cnt)
assert msg.count("SAI_PORT_STAT_IF_IN_ERRORS") >= exp_cnt, msg
assert msg.count("SAI_PORT_STAT_IF_IN_ERRORS") >= exp_cnt, (
"Expected count of 'SAI_PORT_STAT_IF_IN_ERRORS' not met. "
"Expected count: {}"
"Actual count: {}"
"Message: {}"
).format(exp_cnt, msg.count("SAI_PORT_STAT_IF_IN_ERRORS"), msg)
# Subscribe table field
path_list = ["/sonic-db:COUNTERS_DB/localhost/COUNTERS/" + counter_key + "/SAI_PORT_STAT_IF_IN_ERRORS"]
msg, _ = gnmi_subscribe_polling(duthost, ptfhost, path_list, 1000, exp_cnt)
assert msg.count("SAI_PORT_STAT_IF_IN_ERRORS") >= exp_cnt, msg
assert msg.count("SAI_PORT_STAT_IF_IN_ERRORS") >= exp_cnt, (
"Expected count of 'SAI_PORT_STAT_IF_IN_ERRORS' not met. "
"Expected count: {}"
"Actual count: {}"
"Message: {}"
).format(exp_cnt, msg.count("SAI_PORT_STAT_IF_IN_ERRORS"), msg)


@pytest.mark.parametrize('test_data', test_data_counters_port_name_map)
Expand All @@ -133,7 +168,12 @@ def test_gnmi_counterdb_streaming_sample_01(duthosts, rand_one_dut_hostname, ptf
exp_cnt = 3
path_list = [test_data["path"]]
msg, _ = gnmi_subscribe_streaming_sample(duthost, ptfhost, path_list, 0, exp_cnt)
assert msg.count("oid") >= exp_cnt, test_data["name"] + ": " + msg
assert msg.count("oid") >= exp_cnt, (
"Expected count of 'oid' not met. "
"Expected count: {}"
"Actual count: {}"
"Message: {}"
).format(exp_cnt, msg.count("oid"), msg)


def test_gnmi_counterdb_streaming_sample_02(duthosts, rand_one_dut_hostname, ptfhost):
Expand All @@ -149,8 +189,17 @@ def test_gnmi_counterdb_streaming_sample_02(duthosts, rand_one_dut_hostname, ptf
dut_command = "sonic-db-cli COUNTERS_DB hget COUNTERS_PORT_NAME_MAP Ethernet0"
result = duthost.shell(dut_command, module_ignore_errors=True)
counter_key = result['stdout'].strip()
assert "oid" in counter_key, "Invalid oid: " + counter_key
assert "oid" in counter_key, (
"Invalid oid: {}. "
"Expected 'oid' in counter key"
).format(counter_key)

# Subscribe table field
path_list = ["/sonic-db:COUNTERS_DB/localhost/COUNTERS/" + counter_key + "/SAI_PORT_STAT_IF_IN_ERRORS"]
msg, _ = gnmi_subscribe_streaming_sample(duthost, ptfhost, path_list, 0, exp_cnt)
assert msg.count("SAI_PORT_STAT_IF_IN_ERRORS") >= exp_cnt, msg
assert msg.count("SAI_PORT_STAT_IF_IN_ERRORS") >= exp_cnt, (
"Expected count of 'SAI_PORT_STAT_IF_IN_ERRORS' not met. "
"Expected count: {}"
"Actual count: {}"
"Message: {}"
).format(exp_cnt, msg.count("SAI_PORT_STAT_IF_IN_ERRORS"), msg)
47 changes: 39 additions & 8 deletions tests/snmp/test_snmp_lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,30 @@ def test_snmp_lldp(duthosts, enum_rand_one_per_hwsku_hostname, localhost, creds_

logger.info('snmp_lldp: {}'.format(snmp_facts['snmp_lldp']))
for k in ['lldpLocChassisIdSubtype', 'lldpLocChassisId', 'lldpLocSysName', 'lldpLocSysDesc']:
assert snmp_facts['snmp_lldp'][k]
assert "No Such Object currently exists" not in snmp_facts['snmp_lldp'][k]
assert snmp_facts['snmp_lldp'][k], (
"LLDP fact not found for key: {}. "
"SNMP facts: {}"
).format(k, snmp_facts['snmp_lldp'])

assert "No Such Object currently exists" not in snmp_facts['snmp_lldp'][k], (
"LLDP fact contains 'No Such Object currently exists' error for key: {}. "
"SNMP facts: {}"
).format(k, snmp_facts['snmp_lldp'])

# Check if lldpLocPortTable is present for all ports
for k, v in list(snmp_facts['snmp_interfaces'].items()):
if "Ethernet" in v['name'] or "eth" in v['name']:
for oid in ['lldpLocPortIdSubtype', 'lldpLocPortId', 'lldpLocPortDesc']:
assert oid in v
assert "No Such Object currently exists" not in v[oid]
assert oid in v, (
"OID not found in value: {}. "
"OID: {} "
).format(v, oid)

assert "No Such Object currently exists" not in v[oid], (
"OID contains 'No Such Object currently exists' error. "
"OID: {} "
"Value: {}"
).format(oid, v[oid])

# Check if lldpLocManAddrTable is present
if not duthost.facts['modular_chassis']:
Expand All @@ -71,8 +86,15 @@ def test_snmp_lldp(duthosts, enum_rand_one_per_hwsku_hostname, localhost, creds_
'lldpLocManAddrIfSubtype',
'lldpLocManAddrIfId',
'lldpLocManAddrOID']:
assert snmp_facts['snmp_lldp'][k]
assert "No Such Object currently exists" not in snmp_facts['snmp_lldp'][k]
assert snmp_facts['snmp_lldp'][k], (
"LLDP fact is empty or None for key: {}. "
"SNMP facts: {}"
).format(k, snmp_facts['snmp_lldp'])

assert "No Such Object currently exists" not in snmp_facts['snmp_lldp'][k], (
"LLDP fact contains 'No Such Object currently exists' error for key: {}. "
"SNMP facts: {}"
).format(k, snmp_facts['snmp_lldp'][k])

minigraph_lldp_nei = []
for k, v in list(mg_facts.items()):
Expand All @@ -95,7 +117,12 @@ def test_snmp_lldp(duthosts, enum_rand_one_per_hwsku_hostname, localhost, creds_
active_intf.append(k)
logger.info('lldpRemTable: {}'.format(active_intf))

assert len(active_intf) >= len(minigraph_lldp_nei) * 0.8
assert len(active_intf) >= len(minigraph_lldp_nei) * 0.8, (
"Number of active interfaces is less than expected. "
"Expected at least 80% of minigraph LLDP neighbors to be active. "
"Active interfaces: {} "
"Minigraph LLDP neighbors: {}"
).format(len(active_intf), len(minigraph_lldp_nei))

# skip neighbors that do not send chassis information via lldp
lldp_facts = {}
Expand All @@ -120,4 +147,8 @@ def test_snmp_lldp(duthosts, enum_rand_one_per_hwsku_hostname, localhost, creds_
active_intf.append(k)
logger.info('lldpRemManAddrTable: {}'.format(active_intf))

assert len(active_intf) == len(nei)
assert len(active_intf) == len(nei), (
"Number of active interfaces does not match expected number of neighbors. "
"Active interfaces: {} "
"Neighbors: {}"
).format(len(active_intf), len(nei))
Loading