diff --git a/tests/kvmtest.sh b/tests/kvmtest.sh index 4d3aa1ca89e..67452f6e3a2 100755 --- a/tests/kvmtest.sh +++ b/tests/kvmtest.sh @@ -170,6 +170,8 @@ test_t0() { generic_config_updater/test_vlan_interface.py \ process_monitoring/test_critical_process_monitoring.py \ show_techsupport/test_techsupport_no_secret.py \ + platform_tests/cli/test_sonic_installer.py \ + platform_tests/cli/test_show.py \ system_health/test_system_status.py \ radv/test_radv_ipv6_ra.py" diff --git a/tests/platform_tests/cli/test_show.py b/tests/platform_tests/cli/test_show.py new file mode 100755 index 00000000000..7ec6cade8d3 --- /dev/null +++ b/tests/platform_tests/cli/test_show.py @@ -0,0 +1,28 @@ +""" +Tests for the `show` commands in SONiC +""" +import logging +import paramiko +import pytest + +from tests.common.helpers.assertions import pytest_assert +from tests.common.utilities import skip_release +from .test_sonic_installer import stop_database_docker + +pytestmark = [ + pytest.mark.disable_loganalyzer, + pytest.mark.topology('any'), + pytest.mark.device_type('vs') +] + +def test_show_not_depends_on_database_docker(duthosts, enum_rand_one_per_hwsku_hostname, stop_database_docker): + """ + @summary: Test show command can work when database docker not running + """ + duthost = duthosts[enum_rand_one_per_hwsku_hostname] + skip_release(duthost, ["201811", "201911", "202012", "202106", "202111"]) + + # shutdown database docker before test + show_result = duthost.command("sudo show") + pytest_assert(show_result["stdout_lines"][0].startswith("Usage: show"), + "show command failed, stdout: {}, stderr: {}".format(show_result["stdout_lines"], show_result["stderr_lines"])) diff --git a/tests/platform_tests/cli/test_sonic_installer.py b/tests/platform_tests/cli/test_sonic_installer.py new file mode 100755 index 00000000000..64ccaea2098 --- /dev/null +++ b/tests/platform_tests/cli/test_sonic_installer.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 +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_sonic_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"]) + + # shutdown database docker before test + 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"]))