Skip to content

Commit d7c79dd

Browse files
committed
Add keepenv
Signed-off-by: Ze Gan <[email protected]>
1 parent fdc0dc3 commit d7c79dd

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

tests/conftest.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,21 @@ def pytest_addoption(parser):
9494
default=False,
9595
help="Stop swss before stopping a conatainer")
9696

97+
parser.addoption("--keepenv",
98+
action="store_true",
99+
default=False,
100+
help="Keep the current environment to skip validations and restart")
101+
97102

98103
def random_string(size=4, chars=string.ascii_uppercase + string.digits):
99104
return "".join(random.choice(chars) for x in range(size))
100105

101106

102107
class AsicDbValidator(DVSDatabase):
103-
def __init__(self, db_id: int, connector: str):
108+
def __init__(self, db_id: int, connector: str, wait_for_init = True):
104109
DVSDatabase.__init__(self, db_id, connector)
105-
self._wait_for_asic_db_to_initialize()
110+
if wait_for_init:
111+
self._wait_for_asic_db_to_initialize()
106112
self._populate_default_asic_db_values()
107113
self._generate_oid_to_interface_mapping()
108114

@@ -270,6 +276,7 @@ def __init__(
270276
newctnname: str = None,
271277
ctnmounts: Dict[str, str] = None,
272278
buffer_model: str = None,
279+
keepenv: bool = False
273280
):
274281
self.basicd = ["redis-server", "rsyslogd"]
275282
self.swssd = [
@@ -298,6 +305,7 @@ def __init__(
298305
ctn_sw_name = None
299306

300307
self.persistent = False
308+
self.keepenv = keepenv
301309

302310
self.client = docker.from_env()
303311

@@ -349,8 +357,9 @@ def __init__(
349357
# As part of https://github.com/Azure/sonic-buildimage/pull/4499
350358
# VS support dynamically create Front-panel ports so save the orginal
351359
# config db for persistent DVS
352-
self.runcmd("mv /etc/sonic/config_db.json /etc/sonic/config_db.json.orig")
353-
self.ctn_restart()
360+
if not self.keepenv:
361+
self.runcmd("mv /etc/sonic/config_db.json /etc/sonic/config_db.json.orig")
362+
self.ctn_restart()
354363

355364
# Dynamically create a DVS container and servers
356365
else:
@@ -463,8 +472,9 @@ def check_ready_status_and_init_db(self) -> None:
463472
self.init_appl_db_validator()
464473
self.reset_dbs()
465474

466-
# Verify that SWSS has finished initializing.
467-
self.check_swss_ready()
475+
if not self.keepenv:
476+
# Verify that SWSS has finished initializing.
477+
self.check_swss_ready()
468478

469479
except Exception:
470480
self.get_logs()
@@ -497,7 +507,7 @@ def _polling_function():
497507
wait_for_result(_polling_function, service_polling_config)
498508

499509
def init_asic_db_validator(self) -> None:
500-
self.asicdb = AsicDbValidator(self.ASIC_DB_ID, self.redis_sock)
510+
self.asicdb = AsicDbValidator(self.ASIC_DB_ID, self.redis_sock, wait_for_init = not self.keepenv)
501511

502512
def init_appl_db_validator(self) -> None:
503513
self.appldb = ApplDbValidator(self.APPL_DB_ID, self.redis_sock)
@@ -1736,6 +1746,7 @@ def manage_dvs(request) -> str:
17361746
buffer_model = request.config.getoption("--buffer_model")
17371747
force_recreate = request.config.getoption("--force-recreate-dvs")
17381748
graceful_stop = request.config.getoption("--graceful-stop")
1749+
keepenv = request.config.getoption("--keepenv")
17391750

17401751
dvs = None
17411752
curr_dvs_env = [] # lgtm[py/unused-local-variable]
@@ -1767,7 +1778,7 @@ def update_dvs(log_path, new_dvs_env=[]):
17671778
dvs.get_logs()
17681779
dvs.destroy()
17691780

1770-
dvs = DockerVirtualSwitch(name, imgname, keeptb, new_dvs_env, log_path, max_cpu, forcedvs, buffer_model = buffer_model)
1781+
dvs = DockerVirtualSwitch(name, imgname, keeptb, new_dvs_env, log_path, max_cpu, forcedvs, buffer_model = buffer_model, keepenv = keepenv)
17711782

17721783
curr_dvs_env = new_dvs_env
17731784

@@ -1790,7 +1801,7 @@ def update_dvs(log_path, new_dvs_env=[]):
17901801
dvs.get_logs()
17911802
dvs.destroy()
17921803

1793-
if dvs.persistent:
1804+
if dvs.persistent and not keepenv:
17941805
dvs.runcmd("mv /etc/sonic/config_db.json.orig /etc/sonic/config_db.json")
17951806
dvs.ctn_restart()
17961807

tests/test_dash_acl.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __delitem__(self, key: str):
3030
class Table(object):
3131
def __init__(self, database, table_name: str):
3232
self.table_name = table_name
33-
self.table = swsscommon.Table(database, self.table_name)
33+
self.table = swsscommon.Table(database.db_connection, self.table_name)
3434

3535
def __getitem__(self, key: str):
3636
exists, result = self.table.get(str(key))
@@ -106,13 +106,11 @@ def unbind_acl_out(self, eni, stage):
106106

107107

108108
class TestAcl(object):
109-
def __init__(self):
109+
def create_ctx(self, dvs):
110110
self.vnet_name = "vnet1"
111111
self.eni_name = "eth0"
112112
self.vni = "1"
113113
self.mac_address = "00:00:00:00:00:00"
114-
115-
def create_ctx(self, dvs):
116114
ctx = DashAcl(dvs)
117115
ctx.create_vnet(self.vnet_name, {"vni": self.vni})
118116
ctx.create_eni(self.eni_name, {"vnet": self.vnet_name,

0 commit comments

Comments
 (0)