Skip to content

Commit 1305b9f

Browse files
saiarcot895wangxin
authored andcommitted
Add an option to do a safe config reload (#5374)
* Add an option to do a safe config reload When doing a config reload, test cases cannot assume that the DUT is available immediately after `config_reload` returns. Instead, they need to wait on `duthost.critical_services_fully_started` to be true. Therefore, in `config_reload` add an option `safe_reload` (defaults to False to preserve current behavior) that will block on this so that the function returns when the DUT is ready. In addition, have two test cases (for now; other test cases will be checked later) use safe reload so that the DUT is guaranteed to be ready when the function returns. Otherwise, if the setup for the next test case is running while the DUT is still bringing up the containers, then some check there could fail. Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent f0737b9 commit 1305b9f

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

tests/arp/test_neighbor_mac.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import time
44

55
from tests.common.helpers.assertions import pytest_assert
6-
from tests.common.config_reload import config_reload
76

87
logger = logging.getLogger(__name__)
98

tests/arp/test_neighbor_mac_noptf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def setupDutConfig(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
7777
yield
7878

7979
logger.info("Reload Config DB")
80-
config_reload(duthost, config_source='config_db', wait=120)
80+
config_reload(duthost, config_source='config_db', safe_reload=True)
8181

8282
@pytest.fixture(params=[4, 6])
8383
def ipVersion(self, request):

tests/cacl/test_cacl_application.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def clean_scale_rules(duthosts, rand_one_dut_hostname, collect_ignored_rules):
106106
# delete the tmp file
107107
duthost.file(path=SCALE_ACL_FILE, state='absent')
108108
logger.info("Reload config to recover configuration.")
109-
config_reload(duthost)
109+
config_reload(duthost, safe_reload=True)
110110

111111
def is_acl_rule_empty(duthost):
112112
"""

tests/common/config_reload.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import time
22
import logging
33

4+
from tests.common.helpers.assertions import pytest_assert
5+
from tests.common.utilities import wait_until
6+
47
logger = logging.getLogger(__name__)
58

69
config_sources = ['config_db', 'minigraph']
@@ -36,7 +39,7 @@ def config_force_option_supported(duthost):
3639
return True
3740
return False
3841

39-
def config_reload(duthost, config_source='config_db', wait=120, start_bgp=True, start_dynamic_buffer=True):
42+
def config_reload(duthost, config_source='config_db', wait=120, start_bgp=True, start_dynamic_buffer=True, safe_reload=False):
4043
"""
4144
reload SONiC configuration
4245
:param duthost: DUT host object
@@ -77,4 +80,15 @@ def config_reload(duthost, config_source='config_db', wait=120, start_bgp=True,
7780
modular_chassis = duthost.get_facts().get("modular_chassis")
7881
wait = max(wait, 240) if modular_chassis else wait
7982

80-
time.sleep(wait)
83+
if safe_reload:
84+
# The wait time passed in might not be guaranteed to cover the actual
85+
# time it takes for containers to come back up. Therefore, add 5
86+
# minutes to the maximum wait time. If it's ready sooner, then the
87+
# function will return sooner.
88+
pytest_assert(wait_until(wait + 300, 20, 0, duthost.critical_services_fully_started),
89+
"All critical services should be fully started!")
90+
if config_source == 'minigraph':
91+
pytest_assert(wait_until(300, 20, 0, chk_for_pfc_wd, duthost),
92+
"PFC_WD is missing in CONFIG-DB")
93+
else:
94+
time.sleep(wait)

0 commit comments

Comments
 (0)