diff --git a/tests/kvmtest.sh b/tests/kvmtest.sh index 4d3aa1ca89e..cfdc5127754 100755 --- a/tests/kvmtest.sh +++ b/tests/kvmtest.sh @@ -201,6 +201,7 @@ test_t0_sonic() { # TODO: Use a marker to select these tests rather than providing a hard-coded list here. tgname=t0-sonic tests="\ + platform_tests/cli/test_not_depends_on_database.py \ bgp/test_bgp_fact.py \ macsec/test_macsec.py" diff --git a/tests/platform_tests/cli/test_not_depends_on_database.py b/tests/platform_tests/cli/test_not_depends_on_database.py new file mode 100755 index 00000000000..bf43b810c64 --- /dev/null +++ b/tests/platform_tests/cli/test_not_depends_on_database.py @@ -0,0 +1,52 @@ +""" +Tests for the `sonic_installer` commands in SONiC +""" +import logging +import paramiko +import pytest +import time + +from tests.common.helpers.assertions import pytest_assert +from tests.common.utilities import skip_release, wait_until +from tests.common.platform.processes_utils import wait_critical_processes +from tests.common.config_reload import config_reload + +pytestmark = [ + pytest.mark.disable_loganalyzer, + pytest.mark.topology('any'), + pytest.mark.device_type('vs') +] + +DOCKER_WAIT_TIME = 10 + +@pytest.fixture(scope='function') +def stop_database_docker(duthosts, enum_rand_one_per_hwsku_hostname): + duthost = duthosts[enum_rand_one_per_hwsku_hostname] + + # save config for reload later + duthost.shell('sudo config save -y') + + # shutdown database docker before test + duthost.command("sudo docker stop database", module_ignore_errors=True) + time.sleep(DOCKER_WAIT_TIME) + + yield + + # start database docker after test + duthost.command("sudo docker start database", module_ignore_errors=True) + time.sleep(DOCKER_WAIT_TIME) + + # reload config, because some critical process not work after database docker restart + config_reload(duthost, config_source='config_db', safe_reload=True) + +def test_installer_not_depends_on_database_docker(duthosts, enum_rand_one_per_hwsku_hostname, stop_database_docker): + """ + @summary: Test sonic-installer command can work when database docker not running + """ + duthost = duthosts[enum_rand_one_per_hwsku_hostname] + skip_release(duthost, ["201811", "201911", "202012", "202106", "202111"]) + + # test installer command + sonic_installer_result = duthost.command("sudo sonic-installer list") + pytest_assert(sonic_installer_result["stdout_lines"][0].startswith("Current:"), + "sonic-installer command failed, stdout: {}, stderr: {}".format(sonic_installer_result["stdout_lines"], sonic_installer_result["stderr_lines"]))