Skip to content

Commit bc87f3a

Browse files
Fix test container_checker monit flaky issue. (#21218)
These changes fix the sonic-mgmt test "container_checker.py" flaky issue by fixing the following issues in pytest fixture "update_monit_service": - fixing bug updating monit conf "/etc/monit/conf.d/sonic-host" for container_checker periodicity. (Currently the sed commands are updating the last line rule, which does not correctly update the container_checker alert periodicity rule.) - Adds wait_until after monit restart, to ensure tests are running when monit is properly up. related bug: aristanetworks/sonic-qual.msft#906
1 parent 62d0c77 commit bc87f3a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tests/container_checker/test_container_checker.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def check_image_version(duthosts, selected_rand_one_per_hwsku_hostname):
7878
"Test was not supported for 201911 and older image version!")
7979

8080

81+
def check_monit_running(duthost):
82+
monit_services_status = duthost.get_monit_services_status()
83+
return monit_services_status
84+
85+
8186
@pytest.fixture(autouse=True, scope="module")
8287
def update_monit_service(duthosts, selected_rand_one_per_hwsku_hostname):
8388
"""Update Monit configuration and restart it.
@@ -99,14 +104,20 @@ def update_monit_service(duthosts, selected_rand_one_per_hwsku_hostname):
99104
duthost.shell("sudo cp -f /etc/monit/monitrc /tmp/")
100105
duthost.shell("sudo cp -f /etc/monit/conf.d/sonic-host /tmp/")
101106

102-
temp_config_line = " if status != 0 for 1 times within 1 cycles then alert repeat every 1 cycles"
107+
cmd_reduce_container_checker_alert_cycle = (
108+
"sudo sed -i '/check program container_checker/, /^[ \t]*if status != 0/ { "
109+
"/^[ \t]*if status != 0/ { s/^/#/; a\\ if status != 0 "
110+
"for 1 times within 1 cycles then alert repeat every 1 cycles\n } } ' "
111+
"/etc/monit/conf.d/sonic-host"
112+
)
103113
logger.info("Reduce the monitoring interval of container_checker.")
104-
duthost.shell("sudo sed -i '$s/^./#/' /etc/monit/conf.d/sonic-host")
105-
duthost.shell("echo '{}' | sudo tee -a /etc/monit/conf.d/sonic-host".format(temp_config_line))
114+
duthost.shell(cmd_reduce_container_checker_alert_cycle)
106115
duthost.shell("sudo sed -i 's/with start delay 300/with start delay 10/' /etc/monit/monitrc")
107116
duthost.shell("sudo sed -i 's/set daemon 60/set daemon 10/' /etc/monit/monitrc")
108117
logger.info("Restart the Monit service without delaying to monitor.")
109118
duthost.shell("sudo systemctl restart monit")
119+
is_monit_running = wait_until(320, 5, 5, check_monit_running, duthost)
120+
pytest_assert(is_monit_running, "Monit is not running after restart!")
110121

111122
yield
112123

0 commit comments

Comments
 (0)