From 19fc82b1449cbe0c4f323822822da53ed8c8f1fc Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Fri, 23 Sep 2022 01:44:51 +0000 Subject: [PATCH 1/7] Add UT for show and installer command. --- tests/kvmtest.sh | 2 + tests/platform_tests/cli/test_show.py | 28 ++++++++++ .../cli/test_sonic_installer.py | 52 +++++++++++++++++++ 3 files changed, 82 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 4d3aa1ca89e..4fe874260c4 100755 --- a/tests/kvmtest.sh +++ b/tests/kvmtest.sh @@ -126,6 +126,8 @@ test_t0() { pc/test_po_update.py \ platform_tests/test_advanced_reboot.py::test_warm_reboot \ platform_tests/test_cpu_memory_usage.py \ + platform_tests/cli/test_sonic_installer.py \ + platform_tests/cli/test_show.py \ route/test_default_route.py \ route/test_static_route.py \ snmp/test_snmp_cpu.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"])) From 5e078c35877b5b91db47b68382b9628b5979cf43 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Fri, 23 Sep 2022 02:36:28 +0000 Subject: [PATCH 2/7] Improve UT --- tests/kvmtest.sh | 3 +- ...ler.py => test_not_depends_on_database.py} | 11 ++++++-- tests/platform_tests/cli/test_show.py | 28 ------------------- 3 files changed, 9 insertions(+), 33 deletions(-) rename tests/platform_tests/cli/{test_sonic_installer.py => test_not_depends_on_database.py} (74%) delete mode 100755 tests/platform_tests/cli/test_show.py diff --git a/tests/kvmtest.sh b/tests/kvmtest.sh index 4fe874260c4..80aaf95680a 100755 --- a/tests/kvmtest.sh +++ b/tests/kvmtest.sh @@ -105,6 +105,7 @@ test_t0() { tgname=1vlan if [ x$section == x"part-1" ]; then tests="\ + platform_tests/cli/test_not_depends_on_database.py \ arp/test_arp_dualtor.py \ arp/test_neighbor_mac.py \ arp/test_neighbor_mac_noptf.py\ @@ -126,8 +127,6 @@ test_t0() { pc/test_po_update.py \ platform_tests/test_advanced_reboot.py::test_warm_reboot \ platform_tests/test_cpu_memory_usage.py \ - platform_tests/cli/test_sonic_installer.py \ - platform_tests/cli/test_show.py \ route/test_default_route.py \ route/test_static_route.py \ snmp/test_snmp_cpu.py \ diff --git a/tests/platform_tests/cli/test_sonic_installer.py b/tests/platform_tests/cli/test_not_depends_on_database.py similarity index 74% rename from tests/platform_tests/cli/test_sonic_installer.py rename to tests/platform_tests/cli/test_not_depends_on_database.py index 64ccaea2098..83d34cea570 100755 --- a/tests/platform_tests/cli/test_sonic_installer.py +++ b/tests/platform_tests/cli/test_not_depends_on_database.py @@ -34,19 +34,24 @@ def stop_database_docker(duthosts, enum_rand_one_per_hwsku_hostname): # start database docker after test duthost.command("sudo docker start database", module_ignore_errors=True) - time.sleep(DOCKER_WAIT_TIME) + assert wait_until(300, 20, 0, duthost.is_service_fully_started, "database"), "database service is not running" # 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): +def test_show_and_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 + # test show command + 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"])) + + # 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"])) diff --git a/tests/platform_tests/cli/test_show.py b/tests/platform_tests/cli/test_show.py deleted file mode 100755 index 7ec6cade8d3..00000000000 --- a/tests/platform_tests/cli/test_show.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -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"])) From 7485c37c47da4b543fab0aa64bff72bf72fbec6e Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Fri, 23 Sep 2022 06:05:47 +0000 Subject: [PATCH 3/7] Move UT to t0 sonic to improve test performance --- tests/kvmtest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/kvmtest.sh b/tests/kvmtest.sh index 80aaf95680a..cfdc5127754 100755 --- a/tests/kvmtest.sh +++ b/tests/kvmtest.sh @@ -105,7 +105,6 @@ test_t0() { tgname=1vlan if [ x$section == x"part-1" ]; then tests="\ - platform_tests/cli/test_not_depends_on_database.py \ arp/test_arp_dualtor.py \ arp/test_neighbor_mac.py \ arp/test_neighbor_mac_noptf.py\ @@ -202,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" From 40b962b0eeb9cbe821d012dc2c1b69895d3043d9 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Fri, 23 Sep 2022 07:41:05 +0000 Subject: [PATCH 4/7] Remove show command because gearbox command need check Config DB --- tests/platform_tests/cli/test_not_depends_on_database.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/platform_tests/cli/test_not_depends_on_database.py b/tests/platform_tests/cli/test_not_depends_on_database.py index 83d34cea570..a300c998089 100755 --- a/tests/platform_tests/cli/test_not_depends_on_database.py +++ b/tests/platform_tests/cli/test_not_depends_on_database.py @@ -39,18 +39,13 @@ 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, config_source='config_db', safe_reload=True) -def test_show_and_installer_not_depends_on_database_docker(duthosts, enum_rand_one_per_hwsku_hostname, stop_database_docker): +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 show command - 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"])) - # test installer command sonic_installer_result = duthost.command("sudo sonic-installer list") pytest_assert(sonic_installer_result["stdout_lines"][0].startswith("Current:"), From 961178dbe6b557853a26aa7600d8ecac78e02f9a Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Fri, 23 Sep 2022 08:38:53 +0000 Subject: [PATCH 5/7] Fix code issue --- tests/platform_tests/cli/test_not_depends_on_database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/platform_tests/cli/test_not_depends_on_database.py b/tests/platform_tests/cli/test_not_depends_on_database.py index a300c998089..0194c7bddce 100755 --- a/tests/platform_tests/cli/test_not_depends_on_database.py +++ b/tests/platform_tests/cli/test_not_depends_on_database.py @@ -7,7 +7,7 @@ import time from tests.common.helpers.assertions import pytest_assert -from tests.common.utilities import skip_release +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 From 1ed89ef2a42df8eadc05311b8baa9281c0dc3103 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Fri, 23 Sep 2022 09:45:48 +0000 Subject: [PATCH 6/7] Fix code issue --- tests/platform_tests/cli/test_not_depends_on_database.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/platform_tests/cli/test_not_depends_on_database.py b/tests/platform_tests/cli/test_not_depends_on_database.py index 0194c7bddce..e0cf921df1e 100755 --- a/tests/platform_tests/cli/test_not_depends_on_database.py +++ b/tests/platform_tests/cli/test_not_depends_on_database.py @@ -7,7 +7,7 @@ import time from tests.common.helpers.assertions import pytest_assert -from tests.common.utilities import skip_release, wait_until +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 @@ -34,10 +34,11 @@ def stop_database_docker(duthosts, enum_rand_one_per_hwsku_hostname): # start database docker after test duthost.command("sudo docker start database", module_ignore_errors=True) - assert wait_until(300, 20, 0, duthost.is_service_fully_started, "database"), "database service is not running" + 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) + config_reload(duthost) + wait_critical_processes(duthost) def test_installer_not_depends_on_database_docker(duthosts, enum_rand_one_per_hwsku_hostname, stop_database_docker): """ From 814bda569ae7dd3ab9f33d98d75af87bf3752d07 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Fri, 23 Sep 2022 11:45:20 +0000 Subject: [PATCH 7/7] Fix code issue --- tests/platform_tests/cli/test_not_depends_on_database.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/platform_tests/cli/test_not_depends_on_database.py b/tests/platform_tests/cli/test_not_depends_on_database.py index e0cf921df1e..bf43b810c64 100755 --- a/tests/platform_tests/cli/test_not_depends_on_database.py +++ b/tests/platform_tests/cli/test_not_depends_on_database.py @@ -7,7 +7,7 @@ import time from tests.common.helpers.assertions import pytest_assert -from tests.common.utilities import skip_release +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 @@ -37,8 +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 - config_reload(duthost) - wait_critical_processes(duthost) + 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): """