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 |
Michael Walsh | 16cbb7f | 2017-02-02 15:54:16 -0600 | [diff] [blame^] | 10 | import gen_robot_utils as gru |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 11 | |
| 12 | from robot.libraries.BuiltIn import BuiltIn |
| 13 | |
| 14 | # We need utils.robot to get keyword "Initiate Power Off". |
Michael Walsh | 16cbb7f | 2017-02-02 15:54:16 -0600 | [diff] [blame^] | 15 | gru.my_import_resource("utils.robot") |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 16 | |
| 17 | |
| 18 | ############################################################################### |
| 19 | def bmc_power_off(): |
| 20 | |
| 21 | r""" |
| 22 | Power the Open BMC machine off and monitor status to verify. |
| 23 | """ |
| 24 | |
| 25 | grp.rprint_timen("Refreshing state data.") |
| 26 | state = state_mod.get_state() |
| 27 | grp.rprint_var(state) |
| 28 | |
| 29 | match_state = state_mod.anchor_state(state) |
| 30 | |
| 31 | grp.rprintn() |
| 32 | cmd_buf = ["Initiate Power Off"] |
| 33 | grp.rpissuing_keyword(cmd_buf) |
| 34 | power = BuiltIn().run_keyword(*cmd_buf) |
| 35 | |
Michael Walsh | 476dd3e | 2017-01-10 11:40:31 -0600 | [diff] [blame] | 36 | state_change_timeout = BuiltIn().get_variable_value( |
| 37 | "${STATE_CHANGE_TIMEOUT}", default="1 min") |
| 38 | |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 39 | # Wait for the state to change in any way. |
Michael Walsh | 476dd3e | 2017-01-10 11:40:31 -0600 | [diff] [blame] | 40 | state_mod.wait_state(match_state, wait_time=state_change_timeout, |
| 41 | interval="3 seconds", invert=1) |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 42 | |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 43 | if state_mod.OBMC_STATES_VERSION == 0: |
| 44 | cmd_buf = ["Create Dictionary", "power=${0}", |
| 45 | "bmc=HOST_POWERED_OFF", "boot_progress=Off"] |
| 46 | else: |
| 47 | cmd_buf = ["Create Dictionary", "chassis=Off", |
| 48 | "bmc=HOST_POWERED_OFF", "boot_progress=Off", |
| 49 | "host=Off"] |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 50 | grp.rdpissuing_keyword(cmd_buf) |
| 51 | final_state = BuiltIn().run_keyword(*cmd_buf) |
| 52 | |
| 53 | final_state = state_mod.anchor_state(final_state) |
| 54 | |
| 55 | grp.rprintn() |
Michael Walsh | 476dd3e | 2017-01-10 11:40:31 -0600 | [diff] [blame] | 56 | power_off_timeout = BuiltIn().get_variable_value( |
| 57 | "${POWER_OFF_TIMEOUT}", default="2 mins") |
| 58 | state_mod.wait_state(final_state, wait_time=power_off_timeout, |
| 59 | interval="3 seconds") |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 60 | |
| 61 | ############################################################################### |