From 122c6817e7e12ba934ab26c9f0f23d3c72cd445d Mon Sep 17 00:00:00 2001 From: Stephen Sun Date: Wed, 21 Aug 2019 08:33:58 +0300 Subject: [PATCH 1/5] [tests/platform/test_reboot.py] add testcases for reboot cause --- tests/platform/test_reboot.py | 140 +++++++++++++++++++++++++++++----- 1 file changed, 119 insertions(+), 21 deletions(-) diff --git a/tests/platform/test_reboot.py b/tests/platform/test_reboot.py index f266876b11e..2afc55b4659 100644 --- a/tests/platform/test_reboot.py +++ b/tests/platform/test_reboot.py @@ -21,35 +21,65 @@ from check_interface_status import check_interface_status from check_transceiver_status import check_transceiver_basic from check_transceiver_status import all_transceivers_detected +from psu_controller import psu_controller +def check_reboot_cause(dut, reboot_cause_expected): + """ + @summary: Check the reboot cause on DUT. + @param dut: The AnsibleHost object of DUT. + """ + logging.info("Check the reboot cause") + output = dut.shell("show reboot-cause") + reboot_cause_got = output["stdout"] + logging.debug("show reboot-cause returns {}".format(reboot_cause_got)) + m = re.search(reboot_cause_expected, reboot_cause_got) + assert m is not None, "got reboot-cause %s after rebooted by %s" % (reboot_cause_got, reboot_cause_expected) -def reboot_and_check(localhost, dut, interfaces, reboot_type="cold"): + +def reboot_and_check(localhost, dut, interfaces, reboot_type="cold", reboot_helper=None, reboot_argu=None): """ Perform the specified type of reboot and check platform status. """ logging.info("Run %s reboot on DUT" % reboot_type) - if reboot_type == "cold": - reboot_cmd = "reboot" + + if reboot_type == "power off": + assert reboot_helper is not None, "A reboot function must be provided for hardware reboot" reboot_timeout = 300 - elif reboot_type == "fast": - reboot_cmd = "fast-reboot" - reboot_timeout = 180 - elif reboot_type == "warm": - reboot_cmd = "warm-reboot" - reboot_timeout = 180 + reboot_cause = "Power Loss" + reboot_helper(reboot_argu) + + localhost.wait_for(host=dut.hostname, port=22, state="stopped", delay=10, timeout=120) else: - assert False, "Reboot type %s is not supported" % reboot_type - process, queue = dut.command(reboot_cmd, module_async=True) - - logging.info("Wait for DUT to go down") - res = localhost.wait_for(host=dut.hostname, port=22, state="stopped", delay=10, timeout=120, - module_ignore_errors=True) - if "failed" in res: - if process.is_alive(): - logging.error("Command '%s' is not completed" % reboot_cmd) - process.terminate() - logging.error("reboot result %s" % str(queue.get())) - assert False, "DUT did not go down" + if reboot_type == "cold": + reboot_cmd = "reboot" + reboot_cause = reboot_cmd + reboot_timeout = 300 + elif reboot_type == "fast": + reboot_cmd = "fast-reboot" + reboot_cause = reboot_cmd + reboot_timeout = 180 + elif reboot_type == "warm": + reboot_cmd = "warm-reboot" + reboot_cause = reboot_cmd + reboot_timeout = 180 + elif reboot_type == "watchdog": + reboot_timeout = 300 + reboot_cmd = "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog().arm(5); exit()\"" + reboot_cause = "Watchdog" + else: + assert False, "Reboot type %s is not supported" % reboot_type + + process, queue = dut.command(reboot_cmd, module_async=True) + + logging.info("Wait for DUT to go down") + res = localhost.wait_for(host=dut.hostname, port=22, state="stopped", delay=10, timeout=120, + module_ignore_errors=True) + if "failed" in res: + if process.is_alive(): + logging.error("Command '%s' is not completed" % reboot_cmd) + process.terminate() + logging.error("reboot result %s" % str(queue.get())) + assert False, "DUT did not go down" logging.info("Wait for DUT to come back") localhost.wait_for(host=dut.hostname, port=22, state="started", delay=10, timeout=reboot_timeout) @@ -57,6 +87,9 @@ def reboot_and_check(localhost, dut, interfaces, reboot_type="cold"): logging.info("Wait until all critical services are fully started") check_critical_services(dut) + logging.info("Check reboot cause") + check_reboot_cause(dut, reboot_cause) + logging.info("Wait some time for all the transceivers to be detected") assert wait_until(300, 20, all_transceivers_detected, dut, interfaces), \ "Not all transceivers are detected in 300 seconds" @@ -117,3 +150,68 @@ def test_warm_reboot(testbed_devices, conn_graph_facts): pytest.skip("ISSU is not supported on this DUT, skip this test case") reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type="warm") + + +@pytest.fixture(params=[15, 5]) +def power_off_delay(request): + """ + used to parametrized test cases on power_off_delay + :param request: pytest request object + :return: power_off_delay + """ + return request.param + + +def _power_off_reboot_helper(args): + psu_ctrl = args["psu_ctrl"] + all_psu = args["all_psu"] + power_on_seq = args["power_on_seq"] + delay_time = args["delay_time"] + + for psu in all_psu: + logging.debug("turning off {}".format(psu)) + psu_ctrl.turn_off_psu(psu["psu_id"]) + time.sleep(delay_time) + logging.info("Power on {}".format(power_on_seq)) + for psu in power_on_seq: + logging.debug("turning on {}".format(psu)) + psu_ctrl.turn_on_psu(psu["psu_id"]) + + +def test_power_off_reboot(testbed_devices, conn_graph_facts, psu_controller, power_off_delay): + ans_host = testbed_devices["dut"] + localhost = testbed_devices["localhost"] + + psu_ctrl = psu_controller(ans_host.hostname, ans_host.facts["asic_type"]) + if psu_ctrl is None: + pytest.skip("No PSU controller for %s, skip rest of the testing in this case" % ans_host.hostname) + + all_psu = psu_ctrl.get_psu_status() + if all_psu: + power_on_seq_list = [[item] for item in all_psu] + power_on_seq_list.append(all_psu) + + logging.info("Got all power on sequences {}".format(power_on_seq_list)) + + delay_time_list = [15, 5] + poweroff_reboot_argu = {} + poweroff_reboot_argu["dut"] = ans_host + + for power_on_seq in power_on_seq_list: + poweroff_reboot_argu["psu_ctrl"] = psu_ctrl + poweroff_reboot_argu["all_psu"] = all_psu + poweroff_reboot_argu["power_on_seq"] = power_on_seq + poweroff_reboot_argu["delay_time"] = power_off_delay + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], "power off", _power_off_reboot_helper, poweroff_reboot_argu) + +def test_watchdog_reboot(testbed_devices, conn_graph_facts): + ans_host = testbed_devices["dut"] + localhost = testbed_devices["localhost"] + + watchdog_reboot_command = "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog().arm(5); exit()\"" + + watchdog_reboot_argu = {} + watchdog_reboot_argu["dut"] = ans_host + watchdog_reboot_argu["cause"] = "Watchdog" + watchdog_reboot_argu["command"] = watchdog_reboot_command + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], "watchdog") From 01379e89b7a60166f964cabcac4de5c09148d412 Mon Sep 17 00:00:00 2001 From: Stephen Sun Date: Mon, 26 Aug 2019 08:34:03 +0300 Subject: [PATCH 2/5] [test_reboot.py]don't run watchdog reboot test on DUTs that not supporting it. --- tests/platform/test_reboot.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/platform/test_reboot.py b/tests/platform/test_reboot.py index 2afc55b4659..1add82a23ac 100644 --- a/tests/platform/test_reboot.py +++ b/tests/platform/test_reboot.py @@ -209,6 +209,11 @@ def test_watchdog_reboot(testbed_devices, conn_graph_facts): localhost = testbed_devices["localhost"] watchdog_reboot_command = "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog().arm(5); exit()\"" + test_watchdog_supported = "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog(); exit()\"" + + watchdog_supported = ans_host.command(test_watchdog_supported)["stderr"] + if "" != watchdog_supported: + pytest.skip("Watchdog is not supported on this DUT, skip this test case") watchdog_reboot_argu = {} watchdog_reboot_argu["dut"] = ans_host From 8be28ad38b5446ad67813c08ca4c909fe5835ee8 Mon Sep 17 00:00:00 2001 From: Stephen Sun Date: Thu, 19 Sep 2019 04:05:02 +0300 Subject: [PATCH 3/5] [platform/test_reboot.py] Use dictionary to represent the arguments of reboot test --- tests/platform/test_reboot.py | 107 ++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 30 deletions(-) diff --git a/tests/platform/test_reboot.py b/tests/platform/test_reboot.py index 1add82a23ac..7407c64c466 100644 --- a/tests/platform/test_reboot.py +++ b/tests/platform/test_reboot.py @@ -23,10 +23,49 @@ from check_transceiver_status import all_transceivers_detected from psu_controller import psu_controller +REBOOT_COMMAND = "command" +REBOOT_CAUSE = "cause" +REBOOT_TIMEOUT = "timeout" +REBOOT_HELPER = "helper" + +REBOOT_TYPE_WARMREBOOT = "warm" +REBOOT_TYPE_COLDREBOOT = "cold" +REBOOT_TYPE_FASTREBOOT = "fast" +REBOOT_TYPE_REBOOT_BY_POWEROFF = "power off" +REBOOT_TYPE_REBOOT_BY_WATCHDOG = "watchdog" + +reboot_ctrl_dict = { + REBOOT_TYPE_REBOOT_BY_POWEROFF : { + REBOOT_TIMEOUT : 300, + REBOOT_CAUSE : "Power Loss" + }, + REBOOT_TYPE_COLDREBOOT : { + REBOOT_COMMAND : "reboot", + REBOOT_TIMEOUT : 300, + REBOOT_CAUSE : "reboot" + }, + REBOOT_TYPE_FASTREBOOT : { + REBOOT_COMMAND : "fast-reboot", + REBOOT_TIMEOUT : 180, + REBOOT_CAUSE : "fast-reboot" + }, + REBOOT_TYPE_WARMREBOOT : { + REBOOT_COMMAND : "warm-reboot", + REBOOT_TIMEOUT : 180, + REBOOT_CAUSE : "warm-reboot" + }, + REBOOT_TYPE_REBOOT_BY_WATCHDOG : { + REBOOT_COMMAND : "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog().arm(5); exit()\"", + REBOOT_TIMEOUT : 300, + REBOOT_CAUSE : "Watchdog" + } +} + def check_reboot_cause(dut, reboot_cause_expected): """ @summary: Check the reboot cause on DUT. @param dut: The AnsibleHost object of DUT. + @param reboot_cause_expected: The expected reboot cause. """ logging.info("Check the reboot cause") output = dut.shell("show reboot-cause") @@ -39,35 +78,30 @@ def check_reboot_cause(dut, reboot_cause_expected): def reboot_and_check(localhost, dut, interfaces, reboot_type="cold", reboot_helper=None, reboot_argu=None): """ Perform the specified type of reboot and check platform status. + @param dut: The AnsibleHost object of DUT. + @param interfaces: DUT's interfaces defined by minigraph + @param reboot_type: The reboot type, pre-defined const that has name convention of REBOOT_TYPE_XXX. + @param reboot_helper: The helper function used only by power off reboot + @param reboot_argu: The argument used by reboot_helper """ logging.info("Run %s reboot on DUT" % reboot_type) - if reboot_type == "power off": - assert reboot_helper is not None, "A reboot function must be provided for hardware reboot" - reboot_timeout = 300 - reboot_cause = "Power Loss" + reboot_ctrl_element = reboot_ctrl_dict.get(reboot_type) + if reboot_ctrl_element is None: + assert False, "Unknown reboot type %s" % reboot_type + + reboot_timeout = reboot_ctrl_element[REBOOT_TIMEOUT] + reboot_cause = reboot_ctrl_element[REBOOT_CAUSE] + if reboot_type == REBOOT_TYPE_REBOOT_BY_POWEROFF: + assert reboot_helper is not None, "A reboot function must be provided for power off reboot" + if reboot_helper is None: + assert False, "reboot_helper must be provided for power off reboot" + reboot_helper(reboot_argu) localhost.wait_for(host=dut.hostname, port=22, state="stopped", delay=10, timeout=120) else: - if reboot_type == "cold": - reboot_cmd = "reboot" - reboot_cause = reboot_cmd - reboot_timeout = 300 - elif reboot_type == "fast": - reboot_cmd = "fast-reboot" - reboot_cause = reboot_cmd - reboot_timeout = 180 - elif reboot_type == "warm": - reboot_cmd = "warm-reboot" - reboot_cause = reboot_cmd - reboot_timeout = 180 - elif reboot_type == "watchdog": - reboot_timeout = 300 - reboot_cmd = "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog().arm(5); exit()\"" - reboot_cause = "Watchdog" - else: - assert False, "Reboot type %s is not supported" % reboot_type + reboot_cmd = reboot_ctrl_element[REBOOT_COMMAND] process, queue = dut.command(reboot_cmd, module_async=True) @@ -123,7 +157,7 @@ def test_cold_reboot(testbed_devices, conn_graph_facts): ans_host = testbed_devices["dut"] localhost = testbed_devices["localhost"] - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type="cold") + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_COLDREBOOT) def test_fast_reboot(testbed_devices, conn_graph_facts): @@ -133,7 +167,7 @@ def test_fast_reboot(testbed_devices, conn_graph_facts): ans_host = testbed_devices["dut"] localhost = testbed_devices["localhost"] - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type="fast") + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_FASTREBOOT) def test_warm_reboot(testbed_devices, conn_graph_facts): @@ -149,20 +183,24 @@ def test_warm_reboot(testbed_devices, conn_graph_facts): if "disabled" in issu_capability: pytest.skip("ISSU is not supported on this DUT, skip this test case") - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type="warm") + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_WARMREBOOT) @pytest.fixture(params=[15, 5]) def power_off_delay(request): """ - used to parametrized test cases on power_off_delay - :param request: pytest request object - :return: power_off_delay + @summary: used to parametrized test cases on power_off_delay + @param request: pytest request object + @return: power_off_delay """ return request.param def _power_off_reboot_helper(args): + """ + @summary: used to parametrized test cases on power_off_delay + @param args: the delay time between turning off and on the PSU + """ psu_ctrl = args["psu_ctrl"] all_psu = args["all_psu"] power_on_seq = args["power_on_seq"] @@ -179,6 +217,11 @@ def _power_off_reboot_helper(args): def test_power_off_reboot(testbed_devices, conn_graph_facts, psu_controller, power_off_delay): + """ + @summary: This test case is to perform reboot via powercycle and check platform status + @param psu_controller: The python object of psu controller + @param power_off_delay: Pytest fixture. The delay between turning off and on the PSU + """ ans_host = testbed_devices["dut"] localhost = testbed_devices["localhost"] @@ -202,9 +245,13 @@ def test_power_off_reboot(testbed_devices, conn_graph_facts, psu_controller, pow poweroff_reboot_argu["all_psu"] = all_psu poweroff_reboot_argu["power_on_seq"] = power_on_seq poweroff_reboot_argu["delay_time"] = power_off_delay - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], "power off", _power_off_reboot_helper, poweroff_reboot_argu) + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], REBOOT_TYPE_REBOOT_BY_POWEROFF, _power_off_reboot_helper, poweroff_reboot_argu) + def test_watchdog_reboot(testbed_devices, conn_graph_facts): + """ + @summary: This test case is to perform reboot via watchdog and check platform status + """ ans_host = testbed_devices["dut"] localhost = testbed_devices["localhost"] @@ -219,4 +266,4 @@ def test_watchdog_reboot(testbed_devices, conn_graph_facts): watchdog_reboot_argu["dut"] = ans_host watchdog_reboot_argu["cause"] = "Watchdog" watchdog_reboot_argu["command"] = watchdog_reboot_command - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], "watchdog") + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], REBOOT_TYPE_REBOOT_BY_WATCHDOG) From 7a14d1dda35f7775ee180e1ed484120d72b3ce18 Mon Sep 17 00:00:00 2001 From: Stephen Sun Date: Thu, 19 Sep 2019 14:49:15 +0300 Subject: [PATCH 4/5] [test_reboot.py] address Xin's comments. simplify code. --- tests/platform/test_reboot.py | 99 +++++++++++++++-------------------- 1 file changed, 43 insertions(+), 56 deletions(-) diff --git a/tests/platform/test_reboot.py b/tests/platform/test_reboot.py index 7407c64c466..012f82fe78d 100644 --- a/tests/platform/test_reboot.py +++ b/tests/platform/test_reboot.py @@ -23,41 +23,36 @@ from check_transceiver_status import all_transceivers_detected from psu_controller import psu_controller -REBOOT_COMMAND = "command" -REBOOT_CAUSE = "cause" -REBOOT_TIMEOUT = "timeout" -REBOOT_HELPER = "helper" - -REBOOT_TYPE_WARMREBOOT = "warm" -REBOOT_TYPE_COLDREBOOT = "cold" -REBOOT_TYPE_FASTREBOOT = "fast" -REBOOT_TYPE_REBOOT_BY_POWEROFF = "power off" -REBOOT_TYPE_REBOOT_BY_WATCHDOG = "watchdog" +REBOOT_TYPE_WARM = "warm" +REBOOT_TYPE_COLD = "cold" +REBOOT_TYPE_FAST = "fast" +REBOOT_TYPE_POWEROFF = "power off" +REBOOT_TYPE_WATCHDOG = "watchdog" reboot_ctrl_dict = { - REBOOT_TYPE_REBOOT_BY_POWEROFF : { - REBOOT_TIMEOUT : 300, - REBOOT_CAUSE : "Power Loss" + REBOOT_TYPE_POWEROFF : { + "timeout" : 300, + "cause" : "Power Loss" }, - REBOOT_TYPE_COLDREBOOT : { - REBOOT_COMMAND : "reboot", - REBOOT_TIMEOUT : 300, - REBOOT_CAUSE : "reboot" + REBOOT_TYPE_COLD : { + "command" : "reboot", + "timeout" : 300, + "cause" : "reboot" }, - REBOOT_TYPE_FASTREBOOT : { - REBOOT_COMMAND : "fast-reboot", - REBOOT_TIMEOUT : 180, - REBOOT_CAUSE : "fast-reboot" + REBOOT_TYPE_FAST : { + "command" : "fast-reboot", + "timeout" : 180, + "cause" : "fast-reboot" }, - REBOOT_TYPE_WARMREBOOT : { - REBOOT_COMMAND : "warm-reboot", - REBOOT_TIMEOUT : 180, - REBOOT_CAUSE : "warm-reboot" + REBOOT_TYPE_WARM : { + "command" : "warm-reboot", + "timeout" : 180, + "cause" : "warm-reboot" }, - REBOOT_TYPE_REBOOT_BY_WATCHDOG : { - REBOOT_COMMAND : "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog().arm(5); exit()\"", - REBOOT_TIMEOUT : 300, - REBOOT_CAUSE : "Watchdog" + REBOOT_TYPE_WATCHDOG : { + "command" : "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog().arm(5); exit()\"", + "timeout" : 300, + "cause" : "Watchdog" } } @@ -75,33 +70,29 @@ def check_reboot_cause(dut, reboot_cause_expected): assert m is not None, "got reboot-cause %s after rebooted by %s" % (reboot_cause_got, reboot_cause_expected) -def reboot_and_check(localhost, dut, interfaces, reboot_type="cold", reboot_helper=None, reboot_argu=None): +def reboot_and_check(localhost, dut, interfaces, reboot_type=REBOOT_TYPE_COLD, reboot_helper=None, reboot_kwargs=None): """ Perform the specified type of reboot and check platform status. @param dut: The AnsibleHost object of DUT. @param interfaces: DUT's interfaces defined by minigraph @param reboot_type: The reboot type, pre-defined const that has name convention of REBOOT_TYPE_XXX. @param reboot_helper: The helper function used only by power off reboot - @param reboot_argu: The argument used by reboot_helper + @param reboot_kwargs: The argument used by reboot_helper """ logging.info("Run %s reboot on DUT" % reboot_type) - reboot_ctrl_element = reboot_ctrl_dict.get(reboot_type) - if reboot_ctrl_element is None: - assert False, "Unknown reboot type %s" % reboot_type + assert reboot_type in reboot_ctrl_dict.keys(), "Unknown reboot type %s" % reboot_type - reboot_timeout = reboot_ctrl_element[REBOOT_TIMEOUT] - reboot_cause = reboot_ctrl_element[REBOOT_CAUSE] - if reboot_type == REBOOT_TYPE_REBOOT_BY_POWEROFF: + reboot_timeout = reboot_ctrl_dict[reboot_type]["timeout"] + reboot_cause = reboot_ctrl_dict[reboot_type]["cause"] + if reboot_type == REBOOT_TYPE_POWEROFF: assert reboot_helper is not None, "A reboot function must be provided for power off reboot" - if reboot_helper is None: - assert False, "reboot_helper must be provided for power off reboot" - reboot_helper(reboot_argu) + reboot_helper(reboot_kwargs) localhost.wait_for(host=dut.hostname, port=22, state="stopped", delay=10, timeout=120) else: - reboot_cmd = reboot_ctrl_element[REBOOT_COMMAND] + reboot_cmd = reboot_ctrl_dict[reboot_type]["command"] process, queue = dut.command(reboot_cmd, module_async=True) @@ -157,7 +148,7 @@ def test_cold_reboot(testbed_devices, conn_graph_facts): ans_host = testbed_devices["dut"] localhost = testbed_devices["localhost"] - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_COLDREBOOT) + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_COLD) def test_fast_reboot(testbed_devices, conn_graph_facts): @@ -167,7 +158,7 @@ def test_fast_reboot(testbed_devices, conn_graph_facts): ans_host = testbed_devices["dut"] localhost = testbed_devices["localhost"] - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_FASTREBOOT) + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_FAST) def test_warm_reboot(testbed_devices, conn_graph_facts): @@ -183,7 +174,7 @@ def test_warm_reboot(testbed_devices, conn_graph_facts): if "disabled" in issu_capability: pytest.skip("ISSU is not supported on this DUT, skip this test case") - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_WARMREBOOT) + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_WARM) @pytest.fixture(params=[15, 5]) @@ -237,15 +228,15 @@ def test_power_off_reboot(testbed_devices, conn_graph_facts, psu_controller, pow logging.info("Got all power on sequences {}".format(power_on_seq_list)) delay_time_list = [15, 5] - poweroff_reboot_argu = {} - poweroff_reboot_argu["dut"] = ans_host + poweroff_reboot_kwargs = {} + poweroff_reboot_kwargs["dut"] = ans_host for power_on_seq in power_on_seq_list: - poweroff_reboot_argu["psu_ctrl"] = psu_ctrl - poweroff_reboot_argu["all_psu"] = all_psu - poweroff_reboot_argu["power_on_seq"] = power_on_seq - poweroff_reboot_argu["delay_time"] = power_off_delay - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], REBOOT_TYPE_REBOOT_BY_POWEROFF, _power_off_reboot_helper, poweroff_reboot_argu) + poweroff_reboot_kwargs["psu_ctrl"] = psu_ctrl + poweroff_reboot_kwargs["all_psu"] = all_psu + poweroff_reboot_kwargs["power_on_seq"] = power_on_seq + poweroff_reboot_kwargs["delay_time"] = power_off_delay + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], REBOOT_TYPE_POWEROFF, _power_off_reboot_helper, poweroff_reboot_kwargs) def test_watchdog_reboot(testbed_devices, conn_graph_facts): @@ -262,8 +253,4 @@ def test_watchdog_reboot(testbed_devices, conn_graph_facts): if "" != watchdog_supported: pytest.skip("Watchdog is not supported on this DUT, skip this test case") - watchdog_reboot_argu = {} - watchdog_reboot_argu["dut"] = ans_host - watchdog_reboot_argu["cause"] = "Watchdog" - watchdog_reboot_argu["command"] = watchdog_reboot_command - reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], REBOOT_TYPE_REBOOT_BY_WATCHDOG) + reboot_and_check(localhost, ans_host, conn_graph_facts["device_conn"], REBOOT_TYPE_WATCHDOG) From 6d9fccc4e2561575c6c5b6b8f252f74e6251e189 Mon Sep 17 00:00:00 2001 From: Stephen Sun Date: Fri, 20 Sep 2019 09:09:08 +0300 Subject: [PATCH 5/5] [tests/platform/test_reboot.py]address comments --- tests/platform/test_reboot.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/platform/test_reboot.py b/tests/platform/test_reboot.py index 501ee0dc3c9..d18ba18b856 100644 --- a/tests/platform/test_reboot.py +++ b/tests/platform/test_reboot.py @@ -187,15 +187,15 @@ def power_off_delay(request): return request.param -def _power_off_reboot_helper(args): +def _power_off_reboot_helper(kwargs): """ @summary: used to parametrized test cases on power_off_delay - @param args: the delay time between turning off and on the PSU + @param kwargs: the delay time between turning off and on the PSU """ - psu_ctrl = args["psu_ctrl"] - all_psu = args["all_psu"] - power_on_seq = args["power_on_seq"] - delay_time = args["delay_time"] + psu_ctrl = kwargs["psu_ctrl"] + all_psu = kwargs["all_psu"] + power_on_seq = kwargs["power_on_seq"] + delay_time = kwargs["delay_time"] for psu in all_psu: logging.debug("turning off {}".format(psu)) @@ -246,7 +246,6 @@ def test_watchdog_reboot(testbed_devices, conn_graph_facts): ans_host = testbed_devices["dut"] localhost = testbed_devices["localhost"] - watchdog_reboot_command = "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog().arm(5); exit()\"" test_watchdog_supported = "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog(); exit()\"" watchdog_supported = ans_host.command(test_watchdog_supported)["stderr"]