Skip to content

Commit

Permalink
fixing flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rawal01 committed Dec 13, 2024
1 parent 7a12311 commit 10cbc86
Showing 1 changed file with 60 additions and 49 deletions.
109 changes: 60 additions & 49 deletions tests/voq/test_fabric_cli_and_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from tests.common.helpers.assertions import pytest_assert
import logging
import random

logger = logging.getLogger(__name__)
# This test only runs on t2 systems.
pytestmark = [
Expand All @@ -16,6 +17,7 @@
# 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
Expand Down Expand Up @@ -84,65 +86,67 @@ def test_fabric_cli_isolate_linecards(duthosts, enum_frontend_dut_hostname):
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))
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))
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))
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 = "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))
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))
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))
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))
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))
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 = "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))
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))
isolateStatus == "True",
"Port {} APPL_DB initial isolateStatus is True, expected False".format(localPort))

finally:
# If the port was originally not isolsated then restore it
Expand All @@ -151,8 +155,8 @@ def test_fabric_cli_isolate_linecards(duthosts, enum_frontend_dut_hostname):
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))
len(stderr_output) <= 0,
"command: {} failed, error: {}".format(cmd, stderr_output))


# This test iterates over the fabric links on each asic
Expand Down Expand Up @@ -221,20 +225,22 @@ def test_fabric_cli_isolate_supervisor(duthosts, enum_supervisor_dut_hostname):
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))
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 = "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()
isolateStatus = tokens[0]
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort, asicName))
len(tokens) > 0,
"FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort, asicName))
pytest_assert(
isolateStatus == "False",
"Port {} CONFIG_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus))
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,
Expand All @@ -243,31 +249,35 @@ def test_fabric_cli_isolate_supervisor(duthosts, enum_supervisor_dut_hostname):
tokens = cmd_output[0].split()
isolateStatus = tokens[0]
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort, asicName))
len(tokens) > 0,
"FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort,
asicName))
pytest_assert(
isolateStatus == "False",
"Port {} APPL_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus))
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))
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 = "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()
isolateStatus = tokens[0]
pytest_assert(len(tokens) > 0,
"FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort,
asicName))
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort, asicName))
pytest_assert(
isolateStatus == "True",
"Port {} CONFIG_DB initial isolateStatus is '{}', expected True".format(localPort, isolateStatus))
isolateStatus == "True",
"Port {} CONFIG_DB initial isolateStatus is '{}', expected True".format(localPort,
isolateStatus))

# Check the isolateStatus in APPL_DB
cmd = "sonic-db-cli -n {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicName,
Expand All @@ -276,17 +286,18 @@ def test_fabric_cli_isolate_supervisor(duthosts, enum_supervisor_dut_hostname):
tokens = cmd_output[0].split()
isolateStatus = tokens[0]
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort, asicName))
pytest_assert(
isolateStatus == "True",
"Port {} APPL_DB initial isolateStatus is '{}', expected True".format(localPort, isolateStatus))
len(tokens) > 0,
"FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort,
asicName))
pytest_assert(isolateStatus == "True",
"Port {} APPL_DB initial isolateStatus is '{}', expected True".format(localPort,
isolateStatus))
finally:
# 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))
len(stderr_output) <= 0,
"command: {} failed, error: {}".format(cmd, stderr_output))

0 comments on commit 10cbc86

Please sign in to comment.