diff --git a/tests/platform_tests/daemon/test_fancontrol.py b/tests/platform_tests/daemon/test_fancontrol.py index 579dd901ffc..e00c55b8520 100644 --- a/tests/platform_tests/daemon/test_fancontrol.py +++ b/tests/platform_tests/daemon/test_fancontrol.py @@ -58,38 +58,6 @@ def teardown_module(duthosts, rand_one_dut_hostname): check_critical_processes(duthost, watch_secs=10) -@pytest.fixture(scope="module", autouse=True) -def disable_and_enable_autorestart(duthosts, rand_one_dut_hostname): - duthost = duthosts[rand_one_dut_hostname] - """Changes the autorestart of containers from `enabled` to `disabled` before testing. - and Rolls them back after testing. - Args: - duthost: Hostname of DUT. - Returns: - None. - """ - containers_autorestart_states = duthost.get_container_autorestart_states() - disabled_autorestart_containers = [] - - for container_name, state in containers_autorestart_states.items(): - if state == "enabled": - logger.info("Disabling the autorestart of container '{}'.".format(container_name)) - command_disable_autorestart = "sudo config feature autorestart {} disabled".format(container_name) - command_output = duthost.shell(command_disable_autorestart) - exit_code = command_output["rc"] - pytest_assert(exit_code == 0, "Failed to disable the autorestart of container '{}'".format(container_name)) - logger.info("The autorestart of container '{}' was disabled.".format(container_name)) - disabled_autorestart_containers.append(container_name) - - yield - - for container_name in disabled_autorestart_containers: - logger.info("Enabling the autorestart of container '{}'...".format(container_name)) - command_output = duthost.shell("sudo config feature autorestart {} enabled".format(container_name)) - exit_code = command_output["rc"] - pytest_assert(exit_code == 0, "Failed to enable the autorestart of container '{}'".format(container_name)) - logger.info("The autorestart of container '{}' is enabled.".format(container_name)) - @pytest.fixture() def check_daemon_status(duthosts, rand_one_dut_hostname): duthost = duthosts[rand_one_dut_hostname] @@ -106,9 +74,9 @@ def test_pmon_fancontrol_running_status(duthosts, rand_one_dut_hostname): daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) logger.info("{} daemon is {} with pid {}".format(daemon_name, daemon_status, daemon_pid)) pytest_assert(daemon_status == expected_running_status, - "Pcied expected running status is {} but is {}".format(expected_running_status, daemon_status)) + "{} expected running status is {} but is {}".format(daemon_name, expected_running_status, daemon_status)) pytest_assert(daemon_pid != -1, - "Pcied expected pid is a positive integer but is {}".format(daemon_pid)) + "{} expected pid is a positive integer but is {}".format(daemon_name, daemon_pid)) def test_pmon_fancontrol_stop_and_start_status(check_daemon_status, duthosts, rand_one_dut_hostname): @@ -124,18 +92,18 @@ def test_pmon_fancontrol_stop_and_start_status(check_daemon_status, duthosts, ra daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(daemon_status == expected_stopped_status, - "Pcied expected stopped status is {} but is {}".format(expected_stopped_status, daemon_status)) + "{} expected stopped status is {} but is {}".format(daemon_name, expected_stopped_status, daemon_status)) pytest_assert(daemon_pid == -1, - "Pcied expected pid is -1 but is {}".format(daemon_pid)) + "{} expected pid is -1 but is {}".format(daemon_name, daemon_pid)) duthost.start_pmon_daemon(daemon_name) time.sleep(10) post_daemon_status, post_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(post_daemon_status == expected_running_status, - "Pcied expected restarted status is {} but is {}".format(expected_running_status, post_daemon_status)) + "{} expected restarted status is {} but is {}".format(daemon_name, expected_running_status, post_daemon_status)) pytest_assert(post_daemon_pid != -1, - "Pcied expected pid is -1 but is {}".format(post_daemon_pid)) + "{} expected pid is a positive number not {}".format(daemon_name, post_daemon_pid)) pytest_assert(post_daemon_pid > pre_daemon_pid, "Restarted {} pid should be bigger than {} but it is {}".format(daemon_name, pre_daemon_pid, post_daemon_pid)) @@ -153,18 +121,18 @@ def test_pmon_fancontrol_term_and_start_status(check_daemon_status, duthosts, ra daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(daemon_status == expected_exited_status, - "Pcied expected terminated status is {} but is {}".format(expected_exited_status, daemon_status)) + "{} expected terminated status is {} but is {}".format(daemon_name, expected_exited_status, daemon_status)) pytest_assert(daemon_pid == -1, - "Pcied expected pid is -1 but is {}".format(daemon_pid)) + "{} expected pid is a positive number not {}".format(daemon_name, daemon_pid)) duthost.start_pmon_daemon(daemon_name) time.sleep(10) post_daemon_status, post_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(post_daemon_status == expected_running_status, - "Pcied expected restarted status is {} but is {}".format(expected_running_status, post_daemon_status)) + "{} expected restarted status is {} but is {}".format(daemon_name, expected_running_status, post_daemon_status)) pytest_assert(post_daemon_pid != -1, - "Pcied expected pid is -1 but is {}".format(post_daemon_pid)) + "{} expected pid is -1 but is {}".format(daemon_name, post_daemon_pid)) pytest_assert(post_daemon_pid > pre_daemon_pid, "Restarted {} pid should be bigger than {} but it is {}".format(daemon_name, pre_daemon_pid, post_daemon_pid)) @@ -182,14 +150,15 @@ def test_pmon_fancontrol_kill_and_start_status(check_daemon_status, duthosts, ra daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) logger.info("{} daemon got killed unexpectedly and it is {} with pid {}".format(daemon_name, daemon_status, daemon_pid)) pytest_assert(daemon_status != expected_running_status, - "Pcied unexpected killed status is not {}".format(daemon_status)) + "{} unexpected killed status is not {}".format(daemon_name, daemon_status)) time.sleep(10) post_daemon_status, post_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) + pytest_assert(post_daemon_status == expected_running_status, - "Pcied expected restarted status is {} but is {}".format(expected_running_status, post_daemon_status)) + "{} expected restarted status is {} but is {}".format(daemon_name, expected_running_status, post_daemon_status)) pytest_assert(post_daemon_pid != -1, - "Pcied expected pid is -1 but is {}".format(post_daemon_pid)) + "{} expected pid is a positive number not {}".format(daemon_name, post_daemon_pid)) pytest_assert(post_daemon_pid > pre_daemon_pid, "Restarted {} pid should be bigger than {} but it is {}".format(daemon_name, pre_daemon_pid, post_daemon_pid)) diff --git a/tests/platform_tests/daemon/test_ledd.py b/tests/platform_tests/daemon/test_ledd.py index f2faeacd3a8..0718a7ab1e0 100644 --- a/tests/platform_tests/daemon/test_ledd.py +++ b/tests/platform_tests/daemon/test_ledd.py @@ -58,38 +58,6 @@ def teardown_module(duthosts, rand_one_dut_hostname): check_critical_processes(duthost, watch_secs=10) -@pytest.fixture(scope="module", autouse=True) -def disable_and_enable_autorestart(duthosts, rand_one_dut_hostname): - duthost = duthosts[rand_one_dut_hostname] - """Changes the autorestart of containers from `enabled` to `disabled` before testing. - and Rolls them back after testing. - Args: - duthost: Hostname of DUT. - Returns: - None. - """ - containers_autorestart_states = duthost.get_container_autorestart_states() - disabled_autorestart_containers = [] - - for container_name, state in containers_autorestart_states.items(): - if state == "enabled": - logger.info("Disabling the autorestart of container '{}'.".format(container_name)) - command_disable_autorestart = "sudo config feature autorestart {} disabled".format(container_name) - command_output = duthost.shell(command_disable_autorestart) - exit_code = command_output["rc"] - pytest_assert(exit_code == 0, "Failed to disable the autorestart of container '{}'".format(container_name)) - logger.info("The autorestart of container '{}' was disabled.".format(container_name)) - disabled_autorestart_containers.append(container_name) - - yield - - for container_name in disabled_autorestart_containers: - logger.info("Enabling the autorestart of container '{}'...".format(container_name)) - command_output = duthost.shell("sudo config feature autorestart {} enabled".format(container_name)) - exit_code = command_output["rc"] - pytest_assert(exit_code == 0, "Failed to enable the autorestart of container '{}'".format(container_name)) - logger.info("The autorestart of container '{}' is enabled.".format(container_name)) - @pytest.fixture() def check_daemon_status(duthosts, rand_one_dut_hostname): duthost = duthosts[rand_one_dut_hostname] @@ -106,9 +74,9 @@ def test_pmon_ledd_running_status(duthosts, rand_one_dut_hostname): daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) logger.info("{} daemon is {} with pid {}".format(daemon_name, daemon_status, daemon_pid)) pytest_assert(daemon_status == expected_running_status, - "Pcied expected running status is {} but is {}".format(expected_running_status, daemon_status)) + "{} expected running status is {} but is {}".format(daemon_name, expected_running_status, daemon_status)) pytest_assert(daemon_pid != -1, - "Pcied expected pid is a positive integer but is {}".format(daemon_pid)) + "{} expected pid is a positive integer but is {}".format(daemon_name, daemon_pid)) def test_pmon_ledd_stop_and_start_status(check_daemon_status, duthosts, rand_one_dut_hostname): @@ -124,18 +92,18 @@ def test_pmon_ledd_stop_and_start_status(check_daemon_status, duthosts, rand_one daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(daemon_status == expected_stopped_status, - "Pcied expected stopped status is {} but is {}".format(expected_stopped_status, daemon_status)) + "{} expected stopped status is {} but is {}".format(daemon_name, expected_stopped_status, daemon_status)) pytest_assert(daemon_pid == -1, - "Pcied expected pid is -1 but is {}".format(daemon_pid)) + "{} expected pid is -1 but is {}".format(daemon_name, daemon_pid)) duthost.start_pmon_daemon(daemon_name) time.sleep(10) post_daemon_status, post_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(post_daemon_status == expected_running_status, - "Pcied expected restarted status is {} but is {}".format(expected_running_status, post_daemon_status)) + "{} expected restarted status is {} but is {}".format(daemon_name, expected_running_status, post_daemon_status)) pytest_assert(post_daemon_pid != -1, - "Pcied expected pid is -1 but is {}".format(post_daemon_pid)) + "{} expected pid is a positive integer but is {}".format(daemon_name, post_daemon_pid)) pytest_assert(post_daemon_pid > pre_daemon_pid, "Restarted {} pid should be bigger than {} but it is {}".format(daemon_name, pre_daemon_pid, post_daemon_pid)) @@ -145,26 +113,26 @@ def test_pmon_ledd_term_and_start_status(check_daemon_status, duthosts, rand_one @summary: This test case is to check the ledd terminated and restarted status """ duthost = duthosts[rand_one_dut_hostname] + + if "201811" in duthost.os_version or "201911" in duthost.os_version: + pytest.skip("Skip: SIG_TERM behaves differnetly in {} on {}".format(daemon_name, duthost.os_version)) + pre_daemon_status, pre_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) logger.info("{} daemon is {} with pid {}".format(daemon_name, pre_daemon_status, pre_daemon_pid)) duthost.stop_pmon_daemon(daemon_name, SIG_TERM, pre_daemon_pid) - time.sleep(2) daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) - pytest_assert(daemon_status == expected_exited_status, - "Pcied expected terminated status is {} but is {}".format(expected_exited_status, daemon_status)) - pytest_assert(daemon_pid == -1, - "Pcied expected pid is -1 but is {}".format(daemon_pid)) + pytest_assert(daemon_status != expected_running_status and pre_daemon_pid != daemon_pid, + "{} status for SIG_TERM should not be {} with pid:{}!".format(daemon_name, daemon_status, daemon_pid)) - duthost.start_pmon_daemon(daemon_name) time.sleep(10) post_daemon_status, post_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(post_daemon_status == expected_running_status, - "Pcied expected restarted status is {} but is {}".format(expected_running_status, post_daemon_status)) + "{} expected restarted status is {} but is {}".format(daemon_name, expected_running_status, post_daemon_status)) pytest_assert(post_daemon_pid != -1, - "Pcied expected pid is -1 but is {}".format(post_daemon_pid)) + "{} expected pid is a positive integer but is {}".format(daemon_name, post_daemon_pid)) pytest_assert(post_daemon_pid > pre_daemon_pid, "Restarted {} pid should be bigger than {} but it is {}".format(daemon_name, pre_daemon_pid, post_daemon_pid)) @@ -180,16 +148,16 @@ def test_pmon_ledd_kill_and_start_status(check_daemon_status, duthosts, rand_one duthost.stop_pmon_daemon(daemon_name, SIG_KILL, pre_daemon_pid) daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) - logger.info("{} daemon got killed unexpectedly and it is {} with pid {}".format(daemon_name, daemon_status, daemon_pid)) pytest_assert(daemon_status != expected_running_status, - "Pcied unexpected killed status is not {}".format(daemon_status)) + "{} unexpected killed status is not {}".format(daemon_name, daemon_status)) time.sleep(10) post_daemon_status, post_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) + pytest_assert(post_daemon_status == expected_running_status, - "Pcied expected restarted status is {} but is {}".format(expected_running_status, post_daemon_status)) + "{} expected restarted status is {} but is {}".format(daemon_name, expected_running_status, post_daemon_status)) pytest_assert(post_daemon_pid != -1, - "Pcied expected pid is -1 but is {}".format(post_daemon_pid)) + "{} expected pid is a positive integer but is {}".format(daemon_name, post_daemon_pid)) pytest_assert(post_daemon_pid > pre_daemon_pid, "Restarted {} pid should be bigger than {} but it is {}".format(daemon_name, pre_daemon_pid, post_daemon_pid)) diff --git a/tests/platform_tests/daemon/test_pcied.py b/tests/platform_tests/daemon/test_pcied.py index 9b79b23e683..2bd45489395 100644 --- a/tests/platform_tests/daemon/test_pcied.py +++ b/tests/platform_tests/daemon/test_pcied.py @@ -62,38 +62,6 @@ def teardown_module(duthosts, rand_one_dut_hostname): check_critical_processes(duthost, watch_secs=10) -@pytest.fixture(scope="module", autouse=True) -def disable_and_enable_autorestart(duthosts, rand_one_dut_hostname): - duthost = duthosts[rand_one_dut_hostname] - """Changes the autorestart of containers from `enabled` to `disabled` before testing. - and Rolls them back after testing. - Args: - duthost: Hostname of DUT. - Returns: - None. - """ - containers_autorestart_states = duthost.get_container_autorestart_states() - disabled_autorestart_containers = [] - - for container_name, state in containers_autorestart_states.items(): - if state == "enabled": - logger.info("Disabling the autorestart of container '{}'.".format(container_name)) - command_disable_autorestart = "sudo config feature autorestart {} disabled".format(container_name) - command_output = duthost.shell(command_disable_autorestart) - exit_code = command_output["rc"] - pytest_assert(exit_code == 0, "Failed to disable the autorestart of container '{}'".format(container_name)) - logger.info("The autorestart of container '{}' was disabled.".format(container_name)) - disabled_autorestart_containers.append(container_name) - - yield - - for container_name in disabled_autorestart_containers: - logger.info("Enabling the autorestart of container '{}'...".format(container_name)) - command_output = duthost.shell("sudo config feature autorestart {} enabled".format(container_name)) - exit_code = command_output["rc"] - pytest_assert(exit_code == 0, "Failed to enable the autorestart of container '{}'".format(container_name)) - logger.info("The autorestart of container '{}' is enabled.".format(container_name)) - @pytest.fixture() def check_daemon_status(duthosts, rand_one_dut_hostname): duthost = duthosts[rand_one_dut_hostname] @@ -110,16 +78,15 @@ def test_pmon_pcied_running_status(duthosts, rand_one_dut_hostname): daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) logger.info("{} daemon is {} with pid {}".format(daemon_name, daemon_status, daemon_pid)) pytest_assert(daemon_status == expected_running_status, - "Pcied expected running status is {} but is {}".format(expected_running_status, daemon_status)) + "{} expected running status is {} but is {}".format(daemon_name, expected_running_status, daemon_status)) pytest_assert(daemon_pid != -1, - "Pcied expected pid is a positive integer but is {}".format(daemon_pid)) + "{} expected pid is a positive integer but is {}".format(daemon_name, daemon_pid)) daemon_db_value = duthost.get_pmon_daemon_db_value(pcie_devices_status_tbl_key, status_field) pytest_assert(daemon_db_value == expected_pcied_devices_status, "Expected {} {} is {} but is {}".format(pcie_devices_status_tbl_key, status_field, expected_pcied_devices_status, daemon_db_value)) - def test_pmon_pcied_stop_and_start_status(check_daemon_status, duthosts, rand_one_dut_hostname): """ @summary: This test case is to check the pcied stopped and restarted status @@ -133,18 +100,18 @@ def test_pmon_pcied_stop_and_start_status(check_daemon_status, duthosts, rand_on daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(daemon_status == expected_stopped_status, - "Pcied expected stopped status is {} but is {}".format(expected_stopped_status, daemon_status)) + "{} expected stopped status is {} but is {}".format(daemon_name, expected_stopped_status, daemon_status)) pytest_assert(daemon_pid == -1, - "Pcied expected pid is -1 but is {}".format(daemon_pid)) + "{} expected pid is -1 but is {}".format(daemon_name, daemon_pid)) duthost.start_pmon_daemon(daemon_name) time.sleep(10) post_daemon_status, post_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(post_daemon_status == expected_running_status, - "Pcied expected restarted status is {} but is {}".format(expected_running_status, post_daemon_status)) + "{} expected restarted status is {} but is {}".format(daemon_name, expected_running_status, post_daemon_status)) pytest_assert(post_daemon_pid != -1, - "Pcied expected pid is -1 but is {}".format(post_daemon_pid)) + "{} expected pid is -1 but is {}".format(daemon_name, post_daemon_pid)) pytest_assert(post_daemon_pid > pre_daemon_pid, "Restarted {} pid should be bigger than {} but it is {}".format(daemon_name, pre_daemon_pid, post_daemon_pid)) @@ -154,26 +121,26 @@ def test_pmon_pcied_term_and_start_status(check_daemon_status, duthosts, rand_on @summary: This test case is to check the pcied terminated and restarted status """ duthost = duthosts[rand_one_dut_hostname] + + if "201811" in duthost.os_version or "201911" in duthost.os_version: + pytest.skip("Skip: SIG_TERM behaves differnetly in {} on {}".format(daemon_name, duthost.os_version)) + pre_daemon_status, pre_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) logger.info("{} daemon is {} with pid {}".format(daemon_name, pre_daemon_status, pre_daemon_pid)) duthost.stop_pmon_daemon(daemon_name, SIG_TERM, pre_daemon_pid) - time.sleep(2) daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) - pytest_assert(daemon_status == expected_exited_status, - "Pcied expected terminated status is {} but is {}".format(expected_exited_status, daemon_status)) - pytest_assert(daemon_pid == -1, - "Pcied expected pid is -1 but is {}".format(daemon_pid)) + pytest_assert(daemon_status != expected_running_status and pre_daemon_pid != daemon_pid, + "{} status for SIG_TERM should not be {} with pid:{}!".format(daemon_name, daemon_status, daemon_pid)) - duthost.start_pmon_daemon(daemon_name) time.sleep(10) post_daemon_status, post_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(post_daemon_status == expected_running_status, - "Pcied expected restarted status is {} but is {}".format(expected_running_status, post_daemon_status)) + "{} expected restarted status is {} but is {}".format(daemon_name, expected_running_status, post_daemon_status)) pytest_assert(post_daemon_pid != -1, - "Pcied expected pid is -1 but is {}".format(post_daemon_pid)) + "{} expected pid is -1 but is {}".format(daemon_name, post_daemon_pid)) pytest_assert(post_daemon_pid > pre_daemon_pid, "Restarted {} pid should be bigger than {} but it is {}".format(daemon_name, pre_daemon_pid, post_daemon_pid)) @@ -189,16 +156,15 @@ def test_pmon_pcied_kill_and_start_status(check_daemon_status, duthosts, rand_on duthost.stop_pmon_daemon(daemon_name, SIG_KILL, pre_daemon_pid) daemon_status, daemon_pid = duthost.get_pmon_daemon_status(daemon_name) - logger.info("{} daemon got killed unexpectedly and it is {} with pid {}".format(daemon_name, daemon_status, daemon_pid)) pytest_assert(daemon_status != expected_running_status, - "Pcied unexpected killed status is not {}".format(daemon_status)) + "{} unexpected killed status is not {}".format(daemon_name, daemon_status)) time.sleep(10) post_daemon_status, post_daemon_pid = duthost.get_pmon_daemon_status(daemon_name) pytest_assert(post_daemon_status == expected_running_status, - "Pcied expected restarted status is {} but is {}".format(expected_running_status, post_daemon_status)) + "{} expected restarted status is {} but is {}".format(daemon_name, expected_running_status, post_daemon_status)) pytest_assert(post_daemon_pid != -1, - "Pcied expected pid is -1 but is {}".format(post_daemon_pid)) + "{} expected pid is -1 but is {}".format(daemon_name, post_daemon_pid)) pytest_assert(post_daemon_pid > pre_daemon_pid, "Restarted {} pid should be bigger than {} but it is {}".format(daemon_name, pre_daemon_pid, post_daemon_pid))