From a0e716fc9c623c2eda4f4aceaf4d52e8b69b9a08 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Thu, 26 May 2022 10:10:09 +0000 Subject: [PATCH 1/4] Add UT to test show and sonic-installer not depends on database docker --- tests/kvmtest.sh | 2 + tests/platform_tests/cli/test_show.py | 28 +++++++++++ .../cli/test_sonic_installer.py | 49 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100755 tests/platform_tests/cli/test_show.py create mode 100755 tests/platform_tests/cli/test_sonic_installer.py diff --git a/tests/kvmtest.sh b/tests/kvmtest.sh index abbb89b04f7..b15435ecd36 100755 --- a/tests/kvmtest.sh +++ b/tests/kvmtest.sh @@ -166,6 +166,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" pushd $SONIC_MGMT_DIR/tests 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..f42b9c11729 --- /dev/null +++ b/tests/platform_tests/cli/test_sonic_installer.py @@ -0,0 +1,49 @@ +""" +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_START_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] + + # shutdown database docker before test + duthost.command("sudo docker stop database", module_ignore_errors=True) + + yield + + # start database docker after test + duthost.command("sudo docker start database", module_ignore_errors=True) + time.sleep(DOCKER_START_WAIT_TIME) + + # reload config, because some critical process not work after database docker restart + config_reload(duthost) + wait_critical_processes(duthost) + +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"])) From 4d41922c5a87269c0926b4aefe39ce7aa147d799 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Tue, 12 Jul 2022 06:38:12 +0000 Subject: [PATCH 2/4] Increast wait time --- tests/platform_tests/cli/test_sonic_installer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/platform_tests/cli/test_sonic_installer.py b/tests/platform_tests/cli/test_sonic_installer.py index f42b9c11729..a91ee7c51c9 100755 --- a/tests/platform_tests/cli/test_sonic_installer.py +++ b/tests/platform_tests/cli/test_sonic_installer.py @@ -18,6 +18,7 @@ ] DOCKER_START_WAIT_TIME = 10 +CONFIG_RELOAD_WAIT_TIME = 60 @pytest.fixture(scope='function') def stop_database_docker(duthosts, enum_rand_one_per_hwsku_hostname): @@ -34,6 +35,7 @@ def stop_database_docker(duthosts, enum_rand_one_per_hwsku_hostname): # reload config, because some critical process not work after database docker restart config_reload(duthost) + time.sleep(CONFIG_RELOAD_WAIT_TIME) wait_critical_processes(duthost) def test_sonic_installer_not_depends_on_database_docker(duthosts, enum_rand_one_per_hwsku_hostname, stop_database_docker): From 67d22e188098e94bc3bb48d7abc567f9e277c341 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Wed, 13 Jul 2022 02:50:06 +0000 Subject: [PATCH 3/4] Try fix UT --- tests/platform_tests/cli/test_sonic_installer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/platform_tests/cli/test_sonic_installer.py b/tests/platform_tests/cli/test_sonic_installer.py index a91ee7c51c9..3832591cedb 100755 --- a/tests/platform_tests/cli/test_sonic_installer.py +++ b/tests/platform_tests/cli/test_sonic_installer.py @@ -17,8 +17,7 @@ pytest.mark.device_type('vs') ] -DOCKER_START_WAIT_TIME = 10 -CONFIG_RELOAD_WAIT_TIME = 60 +DOCKER_WAIT_TIME = 10 @pytest.fixture(scope='function') def stop_database_docker(duthosts, enum_rand_one_per_hwsku_hostname): @@ -26,16 +25,17 @@ def stop_database_docker(duthosts, enum_rand_one_per_hwsku_hostname): # 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_START_WAIT_TIME) + time.sleep(DOCKER_WAIT_TIME) # reload config, because some critical process not work after database docker restart + duthost.shell('sudo config save -y') config_reload(duthost) - time.sleep(CONFIG_RELOAD_WAIT_TIME) wait_critical_processes(duthost) def test_sonic_installer_not_depends_on_database_docker(duthosts, enum_rand_one_per_hwsku_hostname, stop_database_docker): From 44039476b8368371955400448d12efacc6a53cda Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Mon, 25 Jul 2022 08:48:29 +0000 Subject: [PATCH 4/4] Use safe reload to restart key process --- tests/platform_tests/cli/test_sonic_installer.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/platform_tests/cli/test_sonic_installer.py b/tests/platform_tests/cli/test_sonic_installer.py index 3832591cedb..64ccaea2098 100755 --- a/tests/platform_tests/cli/test_sonic_installer.py +++ b/tests/platform_tests/cli/test_sonic_installer.py @@ -23,6 +23,9 @@ 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) @@ -34,9 +37,7 @@ def stop_database_docker(duthosts, enum_rand_one_per_hwsku_hostname): time.sleep(DOCKER_WAIT_TIME) # reload config, because some critical process not work after database docker restart - duthost.shell('sudo config save -y') - config_reload(duthost) - wait_critical_processes(duthost) + 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): """