Skip to content

Commit

Permalink
using async mode to execut config reload cmd (sonic-net#13361)
Browse files Browse the repository at this point in the history
What is the motivation for this PR?
Case failed due to no response after execting cmd "config reload" with timeout threshold.
Ansible ssh timeout value is 60s.
        out = duthost.shell("sudo config reload -y",
                            executable="/bin/bash", module_ignore_errors=True)
>       assert "Retry later" in out['stdout']
E       KeyError: 'stdout'

out        = {'failed': True, 'msg': 'Timeout (62s) waiting for privilege escalation prompt: ', '_ansible_no_log': False}
How did you do it?
Using async mode to run the CMD

How did you verify/test it?
Run the case locally and with pipeline

Signed-off-by: xuliping <[email protected]>
  • Loading branch information
lipxu authored Jun 19, 2024
1 parent 8a00f2f commit f48d1ba
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions tests/platform_tests/test_reload_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
https://github.com/sonic-net/SONiC/blob/master/doc/pmon/sonic_platform_test_plan.md
"""
import logging

import time
import pytest

from tests.common.fixtures.conn_graph_facts import conn_graph_facts # noqa F401
Expand Down Expand Up @@ -110,6 +110,31 @@ def check_database_status(duthost):
return True


def execute_config_reload_cmd(duthost, timeout=120, check_interval=5):
start_time = time.time()
_, res = duthost.shell("sudo config reload -y",
executable="/bin/bash",
module_ignore_errors=True,
module_async=True)

while not res.ready():
elapsed_time = time.time() - start_time
if elapsed_time > timeout:
logging.info("Config reload command did not complete within {} seconds".format(timeout))
return False, None

logging.debug("Waiting for config reload command to complete. Elapsed time: {} seconds.".format(elapsed_time))
time.sleep(check_interval)

if res.successful():
result = res.get()
logging.debug("Config reload command result: {}".format(result))
return True, result
else:
logging.info("Config reload command execution failed: {}".format(res))
return False, None


def test_reload_configuration_checks(duthosts, enum_rand_one_per_hwsku_hostname, delayed_services,
localhost, conn_graph_facts, xcvr_skip_list): # noqa F811
"""
Expand All @@ -129,25 +154,22 @@ def test_reload_configuration_checks(duthosts, enum_rand_one_per_hwsku_hostname,
wait_until(360, 1, 0, check_database_status, duthost)

logging.info("Reload configuration check")
out = duthost.shell("sudo config reload -y",
executable="/bin/bash", module_ignore_errors=True)
result, out = execute_config_reload_cmd(duthost)
# config reload command shouldn't work immediately after system reboot
assert "Retry later" in out['stdout']
assert result and "Retry later" in out['stdout']

assert wait_until(300, 20, 0, config_system_checks_passed, duthost, delayed_services)

# After the system checks succeed the config reload command should not throw error
out = duthost.shell("sudo config reload -y",
executable="/bin/bash", module_ignore_errors=True)
assert "Retry later" not in out['stdout']
result, out = execute_config_reload_cmd(duthost)
assert result and "Retry later" not in out['stdout']

# Immediately after one config reload command, another shouldn't execute and wait for system checks
logging.info("Checking config reload after system is up")
# Check if all database containers have started
wait_until(60, 1, 0, check_database_status, duthost)
out = duthost.shell("sudo config reload -y",
executable="/bin/bash", module_ignore_errors=True)
assert "Retry later" in out['stdout']
result, out = execute_config_reload_cmd(duthost)
assert result and "Retry later" in out['stdout']
assert wait_until(300, 20, 0, config_system_checks_passed, duthost, delayed_services)

logging.info("Stopping swss docker and checking config reload")
Expand All @@ -158,9 +180,8 @@ def test_reload_configuration_checks(duthosts, enum_rand_one_per_hwsku_hostname,
duthost.shell("sudo service swss stop")

# Without swss running config reload option should not proceed
out = duthost.shell("sudo config reload -y",
executable="/bin/bash", module_ignore_errors=True)
assert "Retry later" in out['stdout']
result, out = execute_config_reload_cmd(duthost)
assert result and "Retry later" in out['stdout']

# However with force option config reload should proceed
logging.info("Performing force config reload")
Expand Down

0 comments on commit f48d1ba

Please sign in to comment.