Skip to content

Commit

Permalink
Update test so they only run on arista modular systems, and error out if
Browse files Browse the repository at this point in the history
reference data is not provided.
  • Loading branch information
jfeng-arista committed May 2, 2023
1 parent ca357b5 commit 5feab4d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -996,13 +996,13 @@ voq/test_fabric_reach.py:
skip:
reason: "Skip test_fabric_reach on unsupported testbed."
conditions:
- "('t2' not in topo_name) or (asic_subtype not in ['broadcom-dnx'])"
- "('t2' not in topo_name) or (asic_subtype not in ['broadcom-dnx']) or ('arista_7800' not in platform)"

voq/test_voq_fabric_status_all.py:
skip:
reason: "Skip test_voq_fabric_status_all on unsupported testbed."
conditions:
- "('t2' not in topo_name) or (asic_subtype not in ['broadcom-dnx'])"
- "('t2' not in topo_name) or (asic_subtype not in ['broadcom-dnx']) or ('arista_7800' not in platform)"

#######################################
##### vrf #####
Expand Down
77 changes: 50 additions & 27 deletions tests/voq/test_fabric_reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,56 @@
pytest.mark.topology('t2')
]

supReferenceData = {}
localModule = 0
supervisorAsicBase = 1

# Added a function to setup the reference data for sup.
# Try to get the reference data, and if the reference data files
# not updated, error out the test rather than fail it.
@pytest.fixture()
def refData(duthosts):
# Get hwSku for Fabriccards from the supervisor.
if len(duthosts.supervisor_nodes) == 0:
logger.info("Please run the test on modular systems")
return {}
duthost = duthosts.supervisor_nodes[0]
logger.info("duthost: {}".format(duthost.hostname))
fabric_sku = None
fabric_sku = duthost.facts['hwsku']
pytest_assert(fabric_sku, "Need to add hwSku information for sup")

# Check reference data found, error out the test.
referenceData = {}
for duthost in duthosts.frontend_nodes:
slot = duthost.facts['slot_num']
lc_sku = duthost.facts['hwsku']
fileName = lc_sku + "_" + fabric_sku + "_" + "LC" + str(slot) + ".yaml"
f = open("voq/fabric_data/{}".format(fileName))
pytest_assert(f, "Need to update expected data for {}".format(fileName))
referenceData[slot] = yaml.load(f)
return referenceData

# Try to load the setup information for supvisor.
@pytest.fixture()
def supData(duthosts):
if len(duthosts.supervisor_nodes) == 0:
logger.info("Please run the test on modular systems")
return {}
duthost = duthosts.supervisor_nodes[0]
logger.info("duthost: {}".format(duthost.hostname))
fabric_sku = None
fabric_sku = duthost.facts['hwsku']
fileName = fabric_sku + ".yaml"
f = open("voq/fabric_data/{}".format(fileName))
pytest_assert(f, "Need to update expected data for {}".format(fileName))
supData = yaml.load(f)
f.close()
return supData

def test_setup_reference_data(duthosts):
# Added a function to setup fabric links reference data for sup.
@pytest.fixture()
def supReferenceData(duthosts):
# supReferenceData has the expected data for sup
global supReferenceData
supReferenceData = {}
keys = []
if len(duthosts.supervisor_nodes) == 0:
logger.info("Please run the test on modular systems")
Expand All @@ -31,16 +71,17 @@ def test_setup_reference_data(duthosts):
for asic in range(num_asics):
keys.append('asic' + str(asic))
supReferenceData = {key: {} for key in keys}
return supReferenceData

# This test checks the output of the "show fabric reachability" command
# on one linecard. It is called once for each linecard in the chassis.
# It loads the reference data for the linecard, runs the CLI command,
# and compares the output.


def test_fabric_reach_linecards(duthosts, enum_frontend_dut_hostname):
def test_fabric_reach_linecards(duthosts, enum_frontend_dut_hostname,
supReferenceData, refData, supData):
"""compare the CLI output with the reference data"""
global supReferenceData
global localModule
global supervisorAsicBase

Expand All @@ -51,28 +92,11 @@ def test_fabric_reach_linecards(duthosts, enum_frontend_dut_hostname):
duthost = duthosts.supervisor_nodes[0]
logger.info("duthost: {}".format(duthost.hostname))

# Get hwSku for Fabriccards from the supervisor.
fabric_sku = None
fabric_sku = duthost.facts['hwsku']
pytest_assert(fabric_sku, "Need to add hwSku information for sup")

# Load the reference data file.
duthost = duthosts[enum_frontend_dut_hostname]
logger.info("duthost: {}".format(duthost.hostname))
lc_sku = duthost.facts['hwsku']
slot = duthost.facts['slot_num']
fileName = lc_sku + "_" + fabric_sku + "_" + "LC" + str(slot) + ".yaml"
f = open("voq/fabric_data/{}".format(fileName))
pytest_assert(f, "Need to update expected data for {}".format(fileName))
referenceData = yaml.load(f)
f.close()

# Load supervisor reference data
fileName = fabric_sku + ".yaml"
f = open("voq/fabric_data/{}".format(fileName))
pytest_assert(f, "Need to update expected data for {}".format(fileName))
supData = yaml.load(f)
f.close()
referenceData = refData[slot]

# base module Id for asics on supervisor
supervisorAsicBase = int(supData['moduleIdBase'])
Expand Down Expand Up @@ -119,7 +143,7 @@ def test_fabric_reach_linecards(duthosts, enum_frontend_dut_hostname):
fabricAsic = 'asic' + str(remoteMod - supervisorAsicBase)
lkData = {'peer slot': slot, 'peer lk': localPortName, 'peer asic': asic, 'peer mod': localModule}
supReferenceData[fabricAsic].update({referenceRemotePort: lkData})
# the module number increased by 2
# the module number increased by number of asics per slot.
localModule += asicPerSlot

# This test checks the output of the "show fabric reachability -n asic<n>"
Expand All @@ -133,11 +157,10 @@ def test_fabric_reach_linecards(duthosts, enum_frontend_dut_hostname):
# and compares the output.


def test_fabric_reach_supervisor(duthosts, enum_supervisor_dut_hostname):
def test_fabric_reach_supervisor(duthosts, enum_supervisor_dut_hostname, supReferenceData, refData):
"""compare the CLI output with the reference data for each asic"""

# supReferenceData has the expected data
global supReferenceData
duthost = duthosts[enum_supervisor_dut_hostname]
logger.info("duthost: {}".format(duthost.hostname))
num_asics = duthost.num_asics()
Expand Down
75 changes: 60 additions & 15 deletions tests/voq/test_voq_fabric_status_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,73 @@
# and runs the CLI command to get the link status
# on the system and compares the output.

# Try to get the reference data. If the reference data files
# not updated, error out the test rather than fail it.
@pytest.fixture()
def refData(duthosts):
# Get hwSku for Fabriccards from the supervisor.
if len(duthosts.supervisor_nodes) == 0:
logger.info("Please run the test on modular systems")
return {}
duthost = duthosts.supervisor_nodes[0]
logger.info("duthost: {}".format(duthost.hostname))
fabric_sku = None
fabric_sku = duthost.facts['hwsku']
pytest_assert(fabric_sku, "Need to add hwSku information for sup")

# Check reference data found, error out the test.
referenceData = {}
for duthost in duthosts.frontend_nodes:
slot = duthost.facts['slot_num']
lc_sku = duthost.facts['hwsku']
fileName = lc_sku + "_" + fabric_sku + "_" + "LC" + str(slot) + ".yaml"
f = open("voq/fabric_data/{}".format(fileName))
pytest_assert(f, "Need to update expected data for {}".format(fileName))
referenceData[slot] = yaml.load(f)
return referenceData


# Get the slot number of inserted Fabric cards
@pytest.fixture()
def fabricSlots(duthosts):
# Get the slot number of inserted fabric cards.
if len(duthosts.supervisor_nodes) == 0:
logger.info("Please run the test on modular systems")
return {}
duthost = duthosts.supervisor_nodes[0]
totalAsics = duthost.num_asics()
fabricslots = []
for i in range(totalAsics):
key = 'CHASSIS_FABRIC_ASIC_TABLE|asic' + str(i)

cmd = "sonic-db-cli CHASSIS_STATE_DB hget '{}' 'name'".format(key)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
slot = cmd_output[0]
if slot.startswith("FABRIC-CARD"):
slot = slot.lstrip("FABRIC-CARD")
slotNum = int(slot) + 1
if slotNum not in fabricslots:
fabricslots.append(slotNum)
return fabricslots


def test_voq_fabric_link_status(duthosts):
# Test fabric link status
def test_voq_fabric_link_status(duthosts, refData, fabricSlots):
"""Check if the fabric serdes links are all up
"""
logger.info("Checking fabric serdes links")

# Get hwSku for Fabriccards from the supervisor.
# The test needs to run on a modular system.
if len(duthosts.supervisor_nodes) == 0:
logger.info("Please run the test on modular systems")
return
duthost = duthosts.supervisor_nodes[0]
logger.info("duthost: {}".format(duthost.hostname))
fabric_sku = None
fabric_sku = duthost.facts['hwsku']
pytest_assert(fabric_sku, "Need to add hwSku information for sup")

# Test fabric links status in Linecards, and get the expected link
# information for Fabriccards.
keys = []
# There are 12 asic on Supervisor now.

# Get the number of asics on supervisor.
totalAsics = duthost.num_asics()
for i in range(totalAsics):
keys.append('asic' + str(i))
Expand All @@ -43,12 +90,7 @@ def test_voq_fabric_link_status(duthosts):
# skip supervisors, on Linecards now:
for duthost in duthosts.frontend_nodes:
slot = duthost.facts['slot_num']
slot = duthost.facts['slot_num']
lc_sku = duthost.facts['hwsku']
fileName = lc_sku + "_" + fabric_sku + "_" + "LC" + str(slot) + ".yaml"
f = open("voq/fabric_data/{}".format(fileName))
pytest_assert(f, "Need to update expected data for {}".format(fileName))
referenceData = yaml.load(f)
referenceData = refData[slot]
output_cli = duthost.shell("show fabric counters port")['stdout_lines']
logger.info(duthost.facts['hwsku'])
logger.info(duthost.facts['slot_num'])
Expand All @@ -75,8 +117,6 @@ def test_voq_fabric_link_status(duthosts):
pytest_assert(False, "{} is not expected to be up.".format(asic))
if lk not in referenceData[asic]:
pytest_assert(False, "link {} is not expected to be up.".format(lk))
pytest_assert(status.lower() == 'up',
"link {}. is expected to be up.".format(lk))

# update link information on suppervisor
lkData = {'peer slot': slot, 'peer lk': lk, 'peer asic': asic}
Expand All @@ -90,6 +130,11 @@ def test_voq_fabric_link_status(duthosts):
logger.info("Fabric: {}".format(fabricAsic))
logger.info(" data: {}".format(asicData))
supReferenceData[fabricAsic].update({fabricLk: lkData})

if status.lower() != 'up':
if fabricSlot in fabricSlots:
pytest_assert(status.lower() == 'up',
"link {}. is expected to be up.".format(lk))
else:
logger.info("Header line {}".format(content))

Expand Down

0 comments on commit 5feab4d

Please sign in to comment.