Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | This module is the python counterpart to poweroffs.robot. It provides |
| 5 | functions for powering off an open bmc machine. |
| 6 | """ |
| 7 | |
| 8 | import gen_robot_print as grp |
| 9 | import state as state_mod |
| 10 | |
| 11 | from robot.libraries.BuiltIn import BuiltIn |
| 12 | |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 13 | # We don't want global variable getting changed when an import is done |
| 14 | # so we'll save it and restore it. |
| 15 | quiet = int(BuiltIn().get_variable_value("${quiet}")) |
| 16 | |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 17 | # We need utils.robot to get keyword "Initiate Power Off". |
| 18 | BuiltIn().import_resource("utils.robot") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 19 | BuiltIn().set_global_variable("${quiet}", quiet) |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 20 | |
| 21 | |
| 22 | ############################################################################### |
| 23 | def bmc_power_off(): |
| 24 | |
| 25 | r""" |
| 26 | Power the Open BMC machine off and monitor status to verify. |
| 27 | """ |
| 28 | |
| 29 | grp.rprint_timen("Refreshing state data.") |
| 30 | state = state_mod.get_state() |
| 31 | grp.rprint_var(state) |
| 32 | |
| 33 | match_state = state_mod.anchor_state(state) |
| 34 | |
| 35 | grp.rprintn() |
| 36 | cmd_buf = ["Initiate Power Off"] |
| 37 | grp.rpissuing_keyword(cmd_buf) |
| 38 | power = BuiltIn().run_keyword(*cmd_buf) |
| 39 | |
Michael Walsh | 476dd3e | 2017-01-10 11:40:31 -0600 | [diff] [blame] | 40 | state_change_timeout = BuiltIn().get_variable_value( |
| 41 | "${STATE_CHANGE_TIMEOUT}", default="1 min") |
| 42 | |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 43 | # Wait for the state to change in any way. |
Michael Walsh | 476dd3e | 2017-01-10 11:40:31 -0600 | [diff] [blame] | 44 | state_mod.wait_state(match_state, wait_time=state_change_timeout, |
| 45 | interval="3 seconds", invert=1) |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 46 | |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 47 | if state_mod.OBMC_STATES_VERSION == 0: |
| 48 | cmd_buf = ["Create Dictionary", "power=${0}", |
| 49 | "bmc=HOST_POWERED_OFF", "boot_progress=Off"] |
| 50 | else: |
| 51 | cmd_buf = ["Create Dictionary", "chassis=Off", |
| 52 | "bmc=HOST_POWERED_OFF", "boot_progress=Off", |
| 53 | "host=Off"] |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 54 | grp.rdpissuing_keyword(cmd_buf) |
| 55 | final_state = BuiltIn().run_keyword(*cmd_buf) |
| 56 | |
| 57 | final_state = state_mod.anchor_state(final_state) |
| 58 | |
| 59 | grp.rprintn() |
Michael Walsh | 476dd3e | 2017-01-10 11:40:31 -0600 | [diff] [blame] | 60 | power_off_timeout = BuiltIn().get_variable_value( |
| 61 | "${POWER_OFF_TIMEOUT}", default="2 mins") |
| 62 | state_mod.wait_state(final_state, wait_time=power_off_timeout, |
| 63 | interval="3 seconds") |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 64 | |
| 65 | ############################################################################### |