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
44 changes: 36 additions & 8 deletions tests/common/platform/interface_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import logging
import json
from collections import defaultdict
from natsort import natsorted
from .transceiver_utils import all_transceivers_detected

Expand Down Expand Up @@ -196,14 +197,19 @@ def get_physical_port_indices(duthost, logical_intfs=None):
# Get interfaces of this asic
interface_list = get_port_map(duthost, asic_index)
interfaces_per_asic = {k: v for k, v in list(interface_list.items()) if k in logical_intfs}
# logging.info("ASIC index={} interfaces = {}".format(asic_index, interfaces_per_asic))
for intf in interfaces_per_asic:
if asic_index is not None:
cmd = 'sonic-db-cli -n asic{} CONFIG_DB HGET "PORT|{}" index'.format(asic_index, intf)
else:
cmd = 'sonic-db-cli CONFIG_DB HGET "PORT|{}" index'.format(intf)
index = duthost.command(cmd)["stdout"]
physical_port_index_dict[intf] = (int(index))
logging.debug("ASIC index={} interfaces = {}".format(asic_index, interfaces_per_asic))
asic_subcommand = f'-n asic{asic_index}' if asic_index is not None else ''
cmd_keys = f'sonic-db-cli {asic_subcommand} CONFIG_DB KEYS "PORT|Ethernet*"'
cmd_hget = f'sonic-db-cli {asic_subcommand} CONFIG_DB HGET $key index'
cmd = f'for key in $({cmd_keys}); do echo "$key : $({cmd_hget})" ; done'
cmd_out = duthost.command(cmd, _uses_shell=True)["stdout_lines"]
cmd_out_dict = {}
for line in cmd_out:
key, index = line.split(':')
intf_name = key.split('|')[1].strip()
cmd_out_dict[intf_name] = int(index.strip())
for logical_intf in logical_intfs:
physical_port_index_dict[logical_intf] = cmd_out_dict.get(logical_intf, None)

return physical_port_index_dict

Expand Down Expand Up @@ -264,3 +270,25 @@ def get_fec_eligible_interfaces(duthost, supported_speeds):
logging.info(f"Skip for {intf_name}: oper_state:{oper} speed:{speed}")

return interfaces


def get_physical_to_logical_port_mapping(physical_port_indices):
"""
@summary: Returns dictionary map of physical ports to corresponding logical port indices
"""
pport_to_lport_mapping = defaultdict(list)
for k, v in physical_port_indices.items():
pport_to_lport_mapping[v].append(k)
logging.debug("Physical to Logical Port Mapping: {}".format(pport_to_lport_mapping))
return pport_to_lport_mapping


def get_lport_to_first_subport_mapping(duthost, logical_intfs=None):
"""
@summary: Returns the first subport of logical ports.
"""
physical_port_indices = get_physical_port_indices(duthost, logical_intfs)
pport_to_lport_mapping = get_physical_to_logical_port_mapping(physical_port_indices)
first_subport_dict = {k: pport_to_lport_mapping[v][0] for k, v in physical_port_indices.items()}
logging.debug("First subports mapping: {}".format(first_subport_dict))
return first_subport_dict
64 changes: 48 additions & 16 deletions tests/common/platform/transceiver_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,29 @@ def check_transceiver_details(dut, asic_index, interfaces, xcvr_skip_list):
else:
expected_fields = ["type", "vendor_rev", "serial", "manufacturer", "model"]

cmd_keys = 'sonic-db-cli STATE_DB KEYS "TRANSCEIVER_INFO|Ethernet*"'
cmd_hgetall = 'sonic-db-cli STATE_DB HGETALL $key'
docker_cmd_keys = asichost.get_docker_cmd(cmd_keys, "database")
docker_cmd_hgetall = asichost.get_docker_cmd(cmd_hgetall, "database")

docker_cmd = f'for key in $({docker_cmd_keys}); do echo "$key : $({docker_cmd_hgetall})" ; done'
port_xcvr_info = dut.command(docker_cmd, _uses_shell=True)
port_xcvr_info_dict = {}
for line in port_xcvr_info["stdout_lines"]:
key, value = line.split(":", 1)
intf_name = key.split('|')[1].strip()
port_xcvr_info_dict[intf_name] = value.strip()

for intf in interfaces:
if intf not in xcvr_skip_list[dut.hostname]:
cmd = 'redis-cli -n 6 hgetall "TRANSCEIVER_INFO|%s"' % intf
docker_cmd = asichost.get_docker_cmd(cmd, "database")
port_xcvr_info = dut.command(docker_cmd)
port_xcvr_info_value = port_xcvr_info_dict[intf]
for field in expected_fields:
assert port_xcvr_info["stdout"].find(field) >= 0, \
"Expected field %s is not found in %s while checking %s" % (field, port_xcvr_info["stdout"], intf)
assert port_xcvr_info_value.find(field) >= 0, \
"Expected field %s is not found in %s while checking %s" % (field, port_xcvr_info_value, intf)


def check_transceiver_dom_sensor_basic(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory):
def check_transceiver_dom_sensor_basic(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory,
lport_to_first_subport_mapping):
"""
@summary: Check whether all the specified interface are in TRANSCEIVER_DOM_SENSOR redis DB.
@param dut: The AnsibleHost object of DUT. For interacting with DUT.
Expand All @@ -112,10 +124,13 @@ def check_transceiver_dom_sensor_basic(dut, asic_index, interfaces, xcvr_skip_li
parsed_xcvr_dom_sensor = parse_transceiver_dom_sensor(xcvr_dom_sensor["stdout_lines"])
for intf in interfaces:
if intf not in xcvr_skip_list[dut.hostname] + port_list_with_flat_memory[dut.hostname]:
assert intf in parsed_xcvr_dom_sensor, "TRANSCEIVER_DOM_SENSOR of %s is not found in DB" % intf
assert lport_to_first_subport_mapping[intf] in parsed_xcvr_dom_sensor,\
"TRANSCEIVER_DOM_SENSOR of subport %s of %s port is not found in DB" \
% (lport_to_first_subport_mapping[intf], intf)


def check_transceiver_dom_sensor_details(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory):
def check_transceiver_dom_sensor_details(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory,
lport_to_first_subport_mapping):
"""
@summary: Check the detailed TRANSCEIVER_DOM_SENSOR content of all the specified interfaces.
@param dut: The AnsibleHost object of DUT. For interacting with DUT.
Expand All @@ -125,27 +140,44 @@ def check_transceiver_dom_sensor_details(dut, asic_index, interfaces, xcvr_skip_
asichost = dut.asic_instance(asic_index)
expected_fields = ["temperature", "voltage", "rx1power", "rx2power", "rx3power", "rx4power", "tx1bias",
"tx2bias", "tx3bias", "tx4bias", "tx1power", "tx2power", "tx3power", "tx4power"]

cmd_keys = 'sonic-db-cli STATE_DB KEYS "TRANSCEIVER_DOM_SENSOR|Ethernet*"'
cmd_hgetall = 'sonic-db-cli STATE_DB HGETALL $key'
docker_cmd_keys = asichost.get_docker_cmd(cmd_keys, "database")
docker_cmd_hgetall = asichost.get_docker_cmd(cmd_hgetall, "database")

docker_cmd = f'for key in $({docker_cmd_keys}); do echo "$key : $({docker_cmd_hgetall})" ; done'
port_xcvr_dom_sensor = dut.command(docker_cmd, _uses_shell=True)

port_xcvr_dom_dict = {}
for line in port_xcvr_dom_sensor["stdout_lines"]:
key, value = line.split(":", 1)
intf_name = key.split('|')[1].strip()
port_xcvr_dom_dict[intf_name] = value.strip()

for intf in interfaces:
if intf not in xcvr_skip_list[dut.hostname] + port_list_with_flat_memory[dut.hostname]:
cmd = 'redis-cli -n 6 hgetall "TRANSCEIVER_DOM_SENSOR|%s"' % intf
docker_cmd = asichost.get_docker_cmd(cmd, "database")
port_xcvr_dom_sensor = dut.command(docker_cmd)
first_subport = lport_to_first_subport_mapping[intf]
port_xcvr_dom_value = port_xcvr_dom_dict[first_subport]
for field in expected_fields:
assert port_xcvr_dom_sensor["stdout"].find(field) >= 0, \
assert port_xcvr_dom_value.find(field) >= 0, \
"Expected field %s is not found in %s while checking %s" % (
field, port_xcvr_dom_sensor["stdout"], intf)
field, port_xcvr_dom_value, intf)


def check_transceiver_status(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory):
def check_transceiver_status(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory,
lport_to_first_subport_mapping):
"""
@summary: Check transceiver information of all the specified interfaces in redis DB.
@param dut: The AnsibleHost object of DUT. For interacting with DUT.
@param interfaces: List of interfaces that need to be checked.
"""
check_transceiver_basic(dut, asic_index, interfaces, xcvr_skip_list)
check_transceiver_details(dut, asic_index, interfaces, xcvr_skip_list)
check_transceiver_dom_sensor_basic(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory)
check_transceiver_dom_sensor_details(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory)
check_transceiver_dom_sensor_basic(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory,
lport_to_first_subport_mapping)
check_transceiver_dom_sensor_details(dut, asic_index, interfaces, xcvr_skip_list, port_list_with_flat_memory,
lport_to_first_subport_mapping)


def get_sfp_eeprom_map_per_port(eeprom_infos):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,12 @@ pc/test_po_voq.py:
conditions:
- "'t2' not in topo_name or num_asic == 0 or len(minigraph_portchannels[list(minigraph_portchannels.keys())[0]]['members']) == 0 or asic_type in ['cisco-8000']"

pc/test_retry_count.py::test_retry_count:
xfail:
reason: "Test set up is failing. Need owner to fix it."
conditions:
- "https://github.com/sonic-net/sonic-mgmt/issues/19400"

#######################################
##### pfc #####
#######################################
Expand Down
8 changes: 5 additions & 3 deletions tests/platform_tests/test_xcvr_info_in_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
import pytest
from tests.common.platform.transceiver_utils import check_transceiver_status
from tests.common.platform.interface_utils import get_port_map
from tests.common.platform.interface_utils import get_port_map, get_lport_to_first_subport_mapping
from tests.common.fixtures.conn_graph_facts import conn_graph_facts # noqa F401

pytestmark = [
Expand All @@ -34,5 +34,7 @@ def test_xcvr_info_in_db(duthosts, enum_rand_one_per_hwsku_frontend_hostname,
logging.info("ASIC {} interface_list {}".format(
enum_frontend_asic_index, all_interfaces))

check_transceiver_status(
duthost, enum_frontend_asic_index, all_interfaces, xcvr_skip_list, port_list_with_flat_memory)
# Get the first subport of the logical port since DOM is returned only for first subport.
lport_to_first_subport_mapping = get_lport_to_first_subport_mapping(duthost, all_interfaces)
check_transceiver_status(duthost, enum_frontend_asic_index, all_interfaces, xcvr_skip_list,
port_list_with_flat_memory, lport_to_first_subport_mapping)
Loading