Skip to content
Closed
3 changes: 2 additions & 1 deletion ansible/library/show_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ def _fetch_interface_type(self, line):
return ' '.join(line.split()[9:-1])

def collect_interface_status(self, namespace=None, include_internal_intfs=False, include_inband_intfs=False):
# W/A until Issue https://github.com/sonic-net/sonic-utilities/issues/3444 is fixed
regex_int_fec = re.compile(
r'(\S+)\s+[\d,N\/A]+\s+(\w+)\s+(\d+)\s+(rs|fc|N\/A|none)\s+([\w\/]+)\s+(\w+)\s+(\w+)\s+(\w+)')
r'(\S+)\s+[\d,N\/A]+\s+(\w+)\s+(\d+)\s+(rs|fc|N\/A|none)\s+([\w\/]+)\s+(\w+)\s+([\w\/]+)\s+(\w+)')
regex_int = re.compile(
r'(\S+)\s+[\d,N\/A]+\s+(\w+)\s+(\d+)\s+([\w\/]+)\s+(\w+)\s+(\w+)\s+(\w+)')
regex_int_internal = re.compile(
Expand Down
59 changes: 58 additions & 1 deletion tests/common/gu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def apply_patch(duthost, json_data, dest_file):
json_data: Source json patch to apply
dest_file: Destination file on duthost
"""
duthost.copy(content=json.dumps(json_data, indent=4), dest=dest_file)
patch_content = json.dumps(json_data, indent=4)
duthost.copy(content=patch_content, dest=dest_file)
logger.debug("Patch Content: {}".format(patch_content))

cmds = 'config apply-patch {}'.format(dest_file)

Expand Down Expand Up @@ -470,3 +472,58 @@ def expect_acl_rule_removed(duthost, rulename, setup):
removed = len(output) == 0

pytest_assert(removed, "'{}' showed a rule, this following rule should have been removed".format(cmds))


def save_backup_test_config(duthost, file_postfix="bkp"):
"""Save test env before a test case starts.

Back up the existing config_db.json file(s).

Args:
duthost: Device Under Test (DUT)
file_postfix: Postfix string to be used for the backup files.

Returns:
None.
"""
CONFIG_DB = "/etc/sonic/config_db.json"
CONFIG_DB_BACKUP = "/etc/sonic/config_db.json.{}".format(file_postfix)

logger.info("Backup {} to {} on {}".format(
CONFIG_DB, CONFIG_DB_BACKUP, duthost.hostname))
duthost.shell("cp {} {}".format(CONFIG_DB, CONFIG_DB_BACKUP))
if duthost.is_multi_asic:
for n in range(len(duthost.asics)):
asic_config_db = "/etc/sonic/config_db{}.json".format(n)
asic_config_db_backup = "/etc/sonic/config_db{}.json.{}".format(n, file_postfix)
logger.info("Backup {} to {} on {}".format(
asic_config_db, asic_config_db_backup, duthost.hostname))
duthost.shell("cp {} {}".format(asic_config_db, asic_config_db_backup))


def restore_backup_test_config(duthost, file_postfix="bkp", config_reload=True):
"""Restore test env after a test case finishes.

Args:
duthost: Device Under Test (DUT)
file_postfix: Postfix string to be used for restoring the saved backup files.

Returns:
None.
"""
CONFIG_DB = "/etc/sonic/config_db.json"
CONFIG_DB_BACKUP = "/etc/sonic/config_db.json.{}".format(file_postfix)

logger.info("Restore {} with {} on {}".format(
CONFIG_DB, CONFIG_DB_BACKUP, duthost.hostname))
duthost.shell("mv {} {}".format(CONFIG_DB_BACKUP, CONFIG_DB))
if duthost.is_multi_asic:
for n in range(len(duthost.asics)):
asic_config_db = "/etc/sonic/config_db{}.json".format(n)
asic_config_db_backup = "/etc/sonic/config_db{}.json.{}".format(n, file_postfix)
logger.info("Restore {} with {} on {}".format(
asic_config_db, asic_config_db_backup, duthost.hostname))
duthost.shell("mv {} {}".format(asic_config_db_backup, asic_config_db))

if config_reload:
config_reload(duthost)
13 changes: 9 additions & 4 deletions tests/common/helpers/dut_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,23 @@ def verify_features_state(duthost):
return True


def verify_orchagent_running_or_assert(duthost):
def verify_orchagent_running_or_assert(duthost, asic_id=None):
"""
Verifies that orchagent is running, asserts otherwise

Args:
duthost: Device Under Test (DUT)
asic_id: Asic ID to verify. If None verifies for all asics that duthost contains.
"""

def _orchagent_running():
cmds = 'docker exec swss supervisorctl status orchagent'
output = duthost.shell(cmds, module_ignore_errors=True)
pytest_assert(not output['rc'], "Unable to check orchagent status output")
asic_ids = duthost.get_asic_ids() if asic_id is None else [asic_id]
for asic in asic_ids:
cmd = 'docker exec swss supervisorctl status orchagent'
if asic is not None:
cmd = 'docker exec swss{} supervisorctl status orchagent'.format(asic)
output = duthost.shell(cmd, module_ignore_errors=True)
pytest_assert(not output['rc'], "Unable to check orchagent status output for asic_id {}".format(asic))
return 'RUNNING' in output['stdout']

pytest_assert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,9 @@ fib/test_fib.py::test_ipinip_hash:
#######################################
generic_config_updater:
skip:
reason: 'generic_config_updater is not a supported feature for T2'
reason: 'generic_config_updater is not a supported feature for T2 platform on older releases than 202205.'
conditions:
- "'t2' in topo_name"
- "('t2' in topo_name) and (release in ['201811', '201911', '202012', '202106', '202111'])"

generic_config_updater/test_dhcp_relay.py:
skip:
Expand Down
19 changes: 18 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,23 @@ def rand_one_dut_lossless_prio(request):
return lossless_prio_list[0]


@pytest.fixture(scope="module")
def rand_asic_namespace(duthosts, rand_one_dut_hostname):
"""
Return the randomly selected asic namespace in case of multi-asic duthost.
"""
duthost = duthosts[rand_one_dut_hostname]

asic_namespace = None
asic_index = None
if duthost.is_multi_asic:
namespace_list = duthost.get_asic_namespace_list()
asic_namespace = random.choice(namespace_list)
asic_index = duthost.get_asic_id_from_namespace(asic_namespace)

return asic_namespace, asic_index


@pytest.fixture(scope="module", autouse=True)
def reset_critical_services_list(duthosts):
"""
Expand Down Expand Up @@ -1933,7 +1950,7 @@ def dut_test_params_qos(duthosts, tbinfo, ptfhost, get_src_dst_asic_and_duts, lo
yield rtn_dict


@ pytest.fixture(scope='class')
@pytest.fixture(scope='class')
def dut_test_params(duthosts, enum_rand_one_per_hwsku_frontend_hostname, tbinfo,
ptf_portmap_file, lower_tor_host, creds): # noqa F811
"""
Expand Down
16 changes: 7 additions & 9 deletions tests/generic_config_updater/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

from tests.common.utilities import skip_release
from tests.common.config_reload import config_reload
from tests.common.gu_utils import apply_patch
from tests.common.gu_utils import apply_patch, restore_backup_test_config, save_backup_test_config
from tests.common.gu_utils import generate_tmpfile, delete_tmpfile


CONFIG_DB = "/etc/sonic/config_db.json"
CONFIG_DB_BACKUP = "/etc/sonic/config_db.json.before_gcu_test"

Expand All @@ -14,15 +15,16 @@

# Module Fixture
@pytest.fixture(scope="module")
def cfg_facts(duthosts, rand_one_dut_hostname):
def cfg_facts(duthosts, rand_one_dut_hostname, rand_asic_namespace):
"""
Config facts for selected DUT
Args:
duthosts: list of DUTs.
rand_one_dut_hostname: Hostname of a random chosen dut
"""
duthost = duthosts[rand_one_dut_hostname]
return duthost.config_facts(host=duthost.hostname, source="persistent")['ansible_facts']
asic_namespace, asic_id = rand_asic_namespace
return duthost.config_facts(host=duthost.hostname, source="persistent", namespace=asic_namespace)['ansible_facts']


@pytest.fixture(scope="module", autouse=True)
Expand Down Expand Up @@ -62,9 +64,7 @@ def reset_and_restore_test_environment(duthosts, rand_one_dut_hostname):
finally:
delete_tmpfile(duthost, tmpfile)

logger.info("Backup {} to {} on {}".format(
CONFIG_DB, CONFIG_DB_BACKUP, duthost.hostname))
duthost.shell("cp {} {}".format(CONFIG_DB, CONFIG_DB_BACKUP))
save_backup_test_config(duthost, file_postfix="before_gcu_test")

if output['rc'] or "Patch applied successfully" not in output['stdout']:
logger.info("Running config failed SONiC Yang validation. Reload minigraph. config: {}"
Expand All @@ -73,9 +73,7 @@ def reset_and_restore_test_environment(duthosts, rand_one_dut_hostname):

yield

logger.info("Restore {} with {} on {}".format(
CONFIG_DB, CONFIG_DB_BACKUP, duthost.hostname))
duthost.shell("mv {} {}".format(CONFIG_DB_BACKUP, CONFIG_DB))
restore_backup_test_config(duthost, file_postfix="before_gcu_test", config_reload=False)

if output['rc'] or "Patch applied successfully" not in output['stdout']:
logger.info("Restore Config after GCU test.")
Expand Down
Loading