From cc3344484f902dccad7471a1d4a7e238ec0cd3f7 Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Mon, 11 Dec 2023 15:46:24 -0800 Subject: [PATCH 1/4] Add mgmt test for testing fabric link isolation cli commands. --- tests/voq/test_fabric_cli_and_db.py | 260 ++++++++++++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 tests/voq/test_fabric_cli_and_db.py diff --git a/tests/voq/test_fabric_cli_and_db.py b/tests/voq/test_fabric_cli_and_db.py new file mode 100644 index 00000000000..3bb4591576f --- /dev/null +++ b/tests/voq/test_fabric_cli_and_db.py @@ -0,0 +1,260 @@ +from tests.common.helpers.assertions import pytest_assert +import logging +logger = logging.getLogger(__name__) + +# There are 12 asic on Supervisor now. +# Initialize the reference data dictionary for sup. +num_asics = 12 + +# Set the number of links to test for each test. If all +# links are tested these tests can take almost an hour! +num_links_to_test = 6 + +# This test iterates over the fabric links on a linecard +# It isolates and unisolates each fabric link. Each time the +# state of the link is changed the state is checked in both +# CONFIG_DB and APPL_DB. +# The values in CONFIG_DB are updated by the fabric CLI commands +# and the values in APPL_DB are updated by the fabric manager +# daemon. + +def test_fabric_cli_isolate_linecards(duthosts, enum_frontend_dut_hostname): + """compare the CLI output with the reference data""" + allPortsList = [] + + duthost = duthosts[enum_frontend_dut_hostname] + logger.info("duthost: {}".format(duthost.hostname)) + + # Testing on Linecards + num_asics = duthost.num_asics() + logger.info("num_asics: {}".format(num_asics)) + for asic in range(num_asics): + cmd = "show fabric reachability" + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + asicName = "asic{}".format(asic) + logger.info(asicName) + if num_asics > 1: + asicNamespaceOption = "-n {}".format(asicName) + else: + asicNamespaceOption = "" + + # Create list of ports + for line in cmd_output: + if not line: + continue + tokens = line.split() + if not tokens[0].isdigit(): + continue + + # tokens: [localPort, remoteModule, remotLink, localLinkStatus] + localPort = tokens[0] + allPortsList.append(localPort) + + # To test a few of the links + portList = [] + while len(portList) < num_links_to_test: + randomPort = random.choice(allPortsList) + if randomPort not in portList: + portList.append(randomPort) + + # Test each fabric link + for localPort in portList: + logger.info("localPort {}".format(localPort)) + #continue + # Get the current isolation status of the port + cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + originalIsolateStatus = tokens[0] + pytest_assert(originalIsolateStatus == "True" or originalIsolateStatus == "False", + "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) + + # If the port is isolated then temporarily unisolate it + if originalIsolateStatus == "True": + cmd = "sudo config fabric port unisolate {} {}".format(localPort, asicNamespaceOption) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert(len(stderr_output) <= 0, + "command: {} failed, error: {}".format(cmd, stderr_output)) + + # Check the isolateStatus in CONFIG_DB + cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + pytest_assert(len(tokens) > 0, + "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB".format(localPort)) + isolateStatus = tokens[0] + pytest_assert(isolateStatus == "False", + "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) + + # Check the isolateStatus in APPL_DB + cmd = "sonic-db-cli {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + pytest_assert(len(tokens) > 0, + "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB".format(localPort)) + isolateStatus = tokens[0] + pytest_assert(isolateStatus == "False", + "Port {} APPL_DB initial isolateStatus is True, expected False".format(localPort)) + + # Isolate the port + cmd = "sudo config fabric port isolate {} {}".format(localPort, asicNamespaceOption) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert(len(stderr_output) <= 0, + "command: {} failed, error: {}".format(cmd, stderr_output)) + + # Check the isolateStatus in CONFIG_DB + cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + pytest_assert(len(tokens) > 0, + "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB".format(localPort)) + isolateStatus = tokens[0] + pytest_assert(isolateStatus == "True", + "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) + + # Check the isolateStatus in APPL_DB + cmd = "sonic-db-cli {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + pytest_assert(len(tokens) > 0, + "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB".format(localPort)) + isolateStatus = tokens[0] + pytest_assert(isolateStatus == "True", + "Port {} APPL_DB initial isolateStatus is True, expected False".format(localPort)) + + # If the port was originally not isolsated then restore it + if originalIsolateStatus == "False": + cmd = "sudo config fabric port unisolate {} {}".format(localPort, asicNamespaceOption) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert(len(stderr_output) <= 0, + "command: {} failed, error: {}".format(cmd, stderr_output)) + + + +# This test iterates over the fabric links on each asic +# on the supervisor. +# It isolates and unisolates each fabric link. Each time the +# state of the link is changed the state is checked in both +# CONFIG_DB and APPL_DB. +# The values in CONFIG_DB are updated by the fabric CLI commands +# and the values in APPL_DB are updated by the fabric manager +# daemon. + +def test_fabric_cli_isolate_supervisor(duthosts, enum_supervisor_dut_hostname): + """compare the CLI output with the reference data for each asic""" + + duthost = duthosts[enum_supervisor_dut_hostname] + logger.info("duthost: {}".format(duthost.hostname)) + num_asics = duthost.num_asics() + logger.info("num_asics: {}".format(num_asics)) + for asic in range(num_asics): + allPortsList = [] + portList = [] + asicName = "asic{}".format(asic) + logger.info(asicName) + + # Create list of ports + cmd = "show fabric reachability -n asic{}".format(asic) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + for line in cmd_output: + if not line: + continue + tokens = line.split() + #(localPort, remoteModule, remotePort, status) + if not tokens[0].isdigit(): + continue + localPort = tokens[0] + allPortsList.append(localPort) + + # To test a few of the links + portList = [] + while len(portList) < num_links_to_test: + randomPort = random.choice(allPortsList) + if randomPort not in portList: + portList.append(randomPort) + + # Test each fabric link + for localPort in portList: + logger.info("local port {}".format(localPort)) + #continue + + # Get the current isolation status of the port + cmd = "sonic-db-cli -n {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicName, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + originalIsolateStatus = tokens[0] + pytest_assert(originalIsolateStatus == "True" or originalIsolateStatus == "False", + "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) + logger.debug("originalIsolateStatus: {}".format(originalIsolateStatus)) + + # If the port is isolated then temporarily unisolate it + if originalIsolateStatus == "True": + cmd = "sudo config fabric port unisolate {} -n {}".format(localPort, asicName) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert(len(stderr_output) <= 0, + "command: {} failed, error: {}".format(cmd, stderr_output)) + + # Check the isolateStatus in CONFIG_DB + cmd = "sonic-db-cli -n {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicName, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + originalIsolateStatus = tokens[0] + pytest_assert(len(tokens) > 0, + "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort, asicName)) + isolateStatus = tokens[0] + pytest_assert(isolateStatus == "False", + "Port {} CONFIG_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus)) + + # Check the isolateStatus in APPL_DB + cmd = "sonic-db-cli -n {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicName, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + originalIsolateStatus = tokens[0] + pytest_assert(len(tokens) > 0, + "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort, asicName)) + isolateStatus = tokens[0] + pytest_assert(isolateStatus == "False", + "Port {} APPL_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus)) + + # Isolate the port + cmd = "sudo config fabric port isolate {} -n {}".format(localPort, asicName) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert(len(stderr_output) <= 0, + "command: {} failed, error: {}".format(cmd, stderr_output)) + + # Check the isolateStatus in CONFIG_DB + cmd = "sonic-db-cli -n {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicName, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + originalIsolateStatus = tokens[0] + pytest_assert(len(tokens) > 0, + "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort, asicName)) + isolateStatus = tokens[0] + pytest_assert(isolateStatus == "True", + "Port {} CONFIG_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus)) + + # Check the isolateStatus in APPL_DB + cmd = "sonic-db-cli -n {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicName, localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + originalIsolateStatus = tokens[0] + pytest_assert(len(tokens) > 0, + "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort, asicName)) + isolateStatus = tokens[0] + pytest_assert(isolateStatus == "True", + "Port {} APPL_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus)) + + # If the port was originally not isolsated then restore it + if originalIsolateStatus == "False": + cmd = "sudo config fabric port unisolate {} -n {}".format(localPort, asicName) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert(len(stderr_output) <= 0, + "command: {} failed, error: {}".format(cmd, stderr_output)) + + From e38cda151c19e80d59b0403d75155ebe01c51a3f Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Mon, 11 Dec 2023 15:46:24 -0800 Subject: [PATCH 2/4] Add mgmt test for testing fabric link isolation cli commands. Signed-off-by: Jie Feng --- tests/voq/test_fabric_cli_and_db.py | 282 +++++++++++++++------------- 1 file changed, 155 insertions(+), 127 deletions(-) diff --git a/tests/voq/test_fabric_cli_and_db.py b/tests/voq/test_fabric_cli_and_db.py index 3bb4591576f..924d0bdf3ba 100644 --- a/tests/voq/test_fabric_cli_and_db.py +++ b/tests/voq/test_fabric_cli_and_db.py @@ -1,5 +1,6 @@ from tests.common.helpers.assertions import pytest_assert import logging +import random logger = logging.getLogger(__name__) # There are 12 asic on Supervisor now. @@ -8,7 +9,7 @@ # Set the number of links to test for each test. If all # links are tested these tests can take almost an hour! -num_links_to_test = 6 +num_links_to_test = 6 # This test iterates over the fabric links on a linecard # It isolates and unisolates each fabric link. Each time the @@ -18,6 +19,7 @@ # and the values in APPL_DB are updated by the fabric manager # daemon. + def test_fabric_cli_isolate_linecards(duthosts, enum_frontend_dut_hostname): """compare the CLI output with the reference data""" allPortsList = [] @@ -29,109 +31,122 @@ def test_fabric_cli_isolate_linecards(duthosts, enum_frontend_dut_hostname): num_asics = duthost.num_asics() logger.info("num_asics: {}".format(num_asics)) for asic in range(num_asics): - cmd = "show fabric reachability" - cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") - asicName = "asic{}".format(asic) - logger.info(asicName) - if num_asics > 1: - asicNamespaceOption = "-n {}".format(asicName) - else: - asicNamespaceOption = "" - - # Create list of ports - for line in cmd_output: - if not line: - continue - tokens = line.split() - if not tokens[0].isdigit(): - continue - - # tokens: [localPort, remoteModule, remotLink, localLinkStatus] - localPort = tokens[0] - allPortsList.append(localPort) - - # To test a few of the links - portList = [] - while len(portList) < num_links_to_test: - randomPort = random.choice(allPortsList) - if randomPort not in portList: - portList.append(randomPort) - - # Test each fabric link - for localPort in portList: - logger.info("localPort {}".format(localPort)) - #continue - # Get the current isolation status of the port - cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) - cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") - tokens = cmd_output[0].split() - originalIsolateStatus = tokens[0] - pytest_assert(originalIsolateStatus == "True" or originalIsolateStatus == "False", - "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) + cmd = "show fabric reachability" + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + asicName = "asic{}".format(asic) + logger.info(asicName) + if num_asics > 1: + asicNamespaceOption = "-n {}".format(asicName) + else: + asicNamespaceOption = "" - # If the port is isolated then temporarily unisolate it - if originalIsolateStatus == "True": - cmd = "sudo config fabric port unisolate {} {}".format(localPort, asicNamespaceOption) - cmd_output = duthost.shell(cmd, module_ignore_errors=True) - stderr_output = cmd_output["stderr"] - pytest_assert(len(stderr_output) <= 0, - "command: {} failed, error: {}".format(cmd, stderr_output)) - - # Check the isolateStatus in CONFIG_DB - cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) - cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") - tokens = cmd_output[0].split() - pytest_assert(len(tokens) > 0, - "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB".format(localPort)) - isolateStatus = tokens[0] - pytest_assert(isolateStatus == "False", - "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) + # Create list of ports + for line in cmd_output: + if not line: + continue + tokens = line.split() + if not tokens[0].isdigit(): + continue - # Check the isolateStatus in APPL_DB - cmd = "sonic-db-cli {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) - cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") - tokens = cmd_output[0].split() - pytest_assert(len(tokens) > 0, - "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB".format(localPort)) - isolateStatus = tokens[0] - pytest_assert(isolateStatus == "False", - "Port {} APPL_DB initial isolateStatus is True, expected False".format(localPort)) - - # Isolate the port - cmd = "sudo config fabric port isolate {} {}".format(localPort, asicNamespaceOption) - cmd_output = duthost.shell(cmd, module_ignore_errors=True) - stderr_output = cmd_output["stderr"] - pytest_assert(len(stderr_output) <= 0, - "command: {} failed, error: {}".format(cmd, stderr_output)) - - # Check the isolateStatus in CONFIG_DB - cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) - cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") - tokens = cmd_output[0].split() - pytest_assert(len(tokens) > 0, - "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB".format(localPort)) - isolateStatus = tokens[0] - pytest_assert(isolateStatus == "True", + # tokens: [localPort, remoteModule, remotLink, localLinkStatus] + localPort = tokens[0] + allPortsList.append(localPort) + + # To test a few of the links + portList = [] + while len(portList) < num_links_to_test: + randomPort = random.choice(allPortsList) + if randomPort not in portList: + portList.append(randomPort) + + # Test each fabric link + for localPort in portList: + logger.info("localPort {}".format(localPort)) + # continue + # Get the current isolation status of the port + cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption, + localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + originalIsolateStatus = tokens[0] + pytest_assert( + originalIsolateStatus == "True" or originalIsolateStatus == "False", "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) - # Check the isolateStatus in APPL_DB - cmd = "sonic-db-cli {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicNamespaceOption, localPort) - cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") - tokens = cmd_output[0].split() - pytest_assert(len(tokens) > 0, - "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB".format(localPort)) - isolateStatus = tokens[0] - pytest_assert(isolateStatus == "True", - "Port {} APPL_DB initial isolateStatus is True, expected False".format(localPort)) + # If the port is isolated then temporarily unisolate it + if originalIsolateStatus == "True": + cmd = "sudo config fabric port unisolate {} {}".format(localPort, asicNamespaceOption) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert( + len(stderr_output) <= 0, "command: {} failed, error: {}".format(cmd, stderr_output)) + + # Check the isolateStatus in CONFIG_DB + cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption, + localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + pytest_assert( + len(tokens) > 0, + "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB".format(localPort)) + isolateStatus = tokens[0] + pytest_assert( + isolateStatus == "False", + "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) - # If the port was originally not isolsated then restore it - if originalIsolateStatus == "False": - cmd = "sudo config fabric port unisolate {} {}".format(localPort, asicNamespaceOption) - cmd_output = duthost.shell(cmd, module_ignore_errors=True) - stderr_output = cmd_output["stderr"] - pytest_assert(len(stderr_output) <= 0, - "command: {} failed, error: {}".format(cmd, stderr_output)) + # Check the isolateStatus in APPL_DB + cmd = "sonic-db-cli {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicNamespaceOption, + localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + pytest_assert( + len(tokens) > 0, "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB".format(localPort)) + isolateStatus = tokens[0] + pytest_assert( + isolateStatus == "False", + "Port {} APPL_DB initial isolateStatus is True, expected False".format(localPort)) + # Isolate the port + cmd = "sudo config fabric port isolate {} {}".format(localPort, asicNamespaceOption) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert( + len(stderr_output) <= 0, "command: {} failed, error: {}".format(cmd, stderr_output)) + + # Check the isolateStatus in CONFIG_DB + cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption, + localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + pytest_assert( + len(tokens) > 0, + "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB".format(localPort)) + isolateStatus = tokens[0] + pytest_assert( + isolateStatus == "True", + "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) + + # Check the isolateStatus in APPL_DB + cmd = "sonic-db-cli {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicNamespaceOption, + localPort) + cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") + tokens = cmd_output[0].split() + pytest_assert( + len(tokens) > 0, + "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB".format(localPort)) + isolateStatus = tokens[0] + pytest_assert( + isolateStatus == "True", + "Port {} APPL_DB initial isolateStatus is True, expected False".format(localPort)) + + # If the port was originally not isolsated then restore it + if originalIsolateStatus == "False": + cmd = "sudo config fabric port unisolate {} {}".format(localPort, asicNamespaceOption) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert( + len(stderr_output) <= 0, + "command: {} failed, error: {}".format(cmd, stderr_output)) # This test iterates over the fabric links on each asic @@ -143,6 +158,7 @@ def test_fabric_cli_isolate_linecards(duthosts, enum_frontend_dut_hostname): # and the values in APPL_DB are updated by the fabric manager # daemon. + def test_fabric_cli_isolate_supervisor(duthosts, enum_supervisor_dut_hostname): """compare the CLI output with the reference data for each asic""" @@ -163,7 +179,7 @@ def test_fabric_cli_isolate_supervisor(duthosts, enum_supervisor_dut_hostname): if not line: continue tokens = line.split() - #(localPort, remoteModule, remotePort, status) + # (localPort, remoteModule, remotePort, status) if not tokens[0].isdigit(): continue localPort = tokens[0] @@ -172,59 +188,67 @@ def test_fabric_cli_isolate_supervisor(duthosts, enum_supervisor_dut_hostname): # To test a few of the links portList = [] while len(portList) < num_links_to_test: - randomPort = random.choice(allPortsList) - if randomPort not in portList: - portList.append(randomPort) + randomPort = random.choice(allPortsList) + if randomPort not in portList: + portList.append(randomPort) # Test each fabric link for localPort in portList: logger.info("local port {}".format(localPort)) - #continue + # continue # Get the current isolation status of the port cmd = "sonic-db-cli -n {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicName, localPort) cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") tokens = cmd_output[0].split() originalIsolateStatus = tokens[0] - pytest_assert(originalIsolateStatus == "True" or originalIsolateStatus == "False", + pytest_assert( + originalIsolateStatus == "True" or originalIsolateStatus == "False", "Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort)) logger.debug("originalIsolateStatus: {}".format(originalIsolateStatus)) # If the port is isolated then temporarily unisolate it if originalIsolateStatus == "True": - cmd = "sudo config fabric port unisolate {} -n {}".format(localPort, asicName) - cmd_output = duthost.shell(cmd, module_ignore_errors=True) - stderr_output = cmd_output["stderr"] - pytest_assert(len(stderr_output) <= 0, - "command: {} failed, error: {}".format(cmd, stderr_output)) + cmd = "sudo config fabric port unisolate {} -n {}".format(localPort, asicName) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert( + len(stderr_output) <= 0, + "command: {} failed, error: {}".format(cmd, stderr_output)) # Check the isolateStatus in CONFIG_DB cmd = "sonic-db-cli -n {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicName, localPort) cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") tokens = cmd_output[0].split() originalIsolateStatus = tokens[0] - pytest_assert(len(tokens) > 0, + pytest_assert( + len(tokens) > 0, "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort, asicName)) isolateStatus = tokens[0] - pytest_assert(isolateStatus == "False", + pytest_assert( + isolateStatus == "False", "Port {} CONFIG_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus)) # Check the isolateStatus in APPL_DB - cmd = "sonic-db-cli -n {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicName, localPort) + cmd = "sonic-db-cli -n {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicName, + localPort) cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") tokens = cmd_output[0].split() originalIsolateStatus = tokens[0] - pytest_assert(len(tokens) > 0, + pytest_assert( + len(tokens) > 0, "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort, asicName)) isolateStatus = tokens[0] - pytest_assert(isolateStatus == "False", + pytest_assert( + isolateStatus == "False", "Port {} APPL_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus)) # Isolate the port cmd = "sudo config fabric port isolate {} -n {}".format(localPort, asicName) cmd_output = duthost.shell(cmd, module_ignore_errors=True) stderr_output = cmd_output["stderr"] - pytest_assert(len(stderr_output) <= 0, + pytest_assert( + len(stderr_output) <= 0, "command: {} failed, error: {}".format(cmd, stderr_output)) # Check the isolateStatus in CONFIG_DB @@ -232,29 +256,33 @@ def test_fabric_cli_isolate_supervisor(duthosts, enum_supervisor_dut_hostname): cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") tokens = cmd_output[0].split() originalIsolateStatus = tokens[0] - pytest_assert(len(tokens) > 0, + pytest_assert( + len(tokens) > 0, "FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort, asicName)) isolateStatus = tokens[0] - pytest_assert(isolateStatus == "True", + pytest_assert( + isolateStatus == "True", "Port {} CONFIG_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus)) # Check the isolateStatus in APPL_DB - cmd = "sonic-db-cli -n {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicName, localPort) + cmd = "sonic-db-cli -n {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicName, + localPort) cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n") tokens = cmd_output[0].split() originalIsolateStatus = tokens[0] - pytest_assert(len(tokens) > 0, + pytest_assert( + len(tokens) > 0, "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort, asicName)) isolateStatus = tokens[0] - pytest_assert(isolateStatus == "True", + pytest_assert( + isolateStatus == "True", "Port {} APPL_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus)) # If the port was originally not isolsated then restore it if originalIsolateStatus == "False": - cmd = "sudo config fabric port unisolate {} -n {}".format(localPort, asicName) - cmd_output = duthost.shell(cmd, module_ignore_errors=True) - stderr_output = cmd_output["stderr"] - pytest_assert(len(stderr_output) <= 0, - "command: {} failed, error: {}".format(cmd, stderr_output)) - - + cmd = "sudo config fabric port unisolate {} -n {}".format(localPort, asicName) + cmd_output = duthost.shell(cmd, module_ignore_errors=True) + stderr_output = cmd_output["stderr"] + pytest_assert( + len(stderr_output) <= 0, + "command: {} failed, error: {}".format(cmd, stderr_output)) From 6ff61d2b00fd80061ef36cb39c17b1cead8d4bec Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Wed, 10 Jan 2024 20:27:15 -0800 Subject: [PATCH 3/4] only run the test on t2 topology --- tests/voq/test_fabric_cli_and_db.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/voq/test_fabric_cli_and_db.py b/tests/voq/test_fabric_cli_and_db.py index 924d0bdf3ba..de3e39891dd 100644 --- a/tests/voq/test_fabric_cli_and_db.py +++ b/tests/voq/test_fabric_cli_and_db.py @@ -1,7 +1,12 @@ +import pytest from tests.common.helpers.assertions import pytest_assert import logging import random logger = logging.getLogger(__name__) +# This test only runs on t2 systems. +pytestmark = [ + pytest.mark.topology('t2') +] # There are 12 asic on Supervisor now. # Initialize the reference data dictionary for sup. From bf270bd5123f4d3c83c9e1fb0804fb06e5a73d91 Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Thu, 11 Jan 2024 13:30:13 -0800 Subject: [PATCH 4/4] only run the test on t2 topolopy and supported testbed --- .../plugins/conditional_mark/tests_mark_conditions.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/common/plugins/conditional_mark/tests_mark_conditions.yaml b/tests/common/plugins/conditional_mark/tests_mark_conditions.yaml index ac673d2ee50..dc4607e059f 100644 --- a/tests/common/plugins/conditional_mark/tests_mark_conditions.yaml +++ b/tests/common/plugins/conditional_mark/tests_mark_conditions.yaml @@ -1215,6 +1215,12 @@ vlan/test_vlan_ping.py: ####################################### ##### voq ##### ####################################### +voq/test_fabric_cli_and_db.py: + skip: + reason: "Skip test_fabric_cli_and_db on unsupported testbed." + conditions: + - "('t2' not in topo_name) or (asic_subtype not in ['broadcom-dnx']) or ('arista_7800' not in platform)" + voq/test_fabric_reach.py: skip: reason: "Skip test_fabric_reach on unsupported testbed."