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 utils.robot. It provides many |
| 5 | functions for communicating with the 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 On". |
Michael Walsh | 16cbb7f | 2017-02-02 15:54:16 -0600 | [diff] [blame] | 15 | gru.my_import_resource("utils.robot") |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 16 | |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 17 | |
| 18 | ############################################################################### |
| 19 | def bmc_power_on(): |
| 20 | |
| 21 | r""" |
| 22 | Power the Open BMC machine on 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 On", "wait=${0}"] |
| 33 | grp.rpissuing_keyword(cmd_buf) |
| 34 | power = BuiltIn().run_keyword(*cmd_buf) |
| 35 | |
Michael Walsh | 0957aaf | 2017-01-10 11:39:03 -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 | 0957aaf | 2017-01-10 11:39:03 -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=${1}", |
| 45 | "bmc=HOST_BOOTED", |
| 46 | "boot_progress=FW Progress, Starting OS"] |
| 47 | else: |
Michael Walsh | 65b1254 | 2017-02-03 15:34:38 -0600 | [diff] [blame] | 48 | # TODO: Add back boot_progress when ipmi is enabled on Witherspoon. |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 49 | cmd_buf = ["Create Dictionary", "chassis=On", |
Michael Walsh | 65b1254 | 2017-02-03 15:34:38 -0600 | [diff] [blame] | 50 | "bmc=Ready", |
| 51 | # "boot_progress=FW Progress, Starting OS", |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 52 | "host=Running"] |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 53 | grp.rdpissuing_keyword(cmd_buf) |
| 54 | final_state = BuiltIn().run_keyword(*cmd_buf) |
| 55 | |
Michael Walsh | 0957aaf | 2017-01-10 11:39:03 -0600 | [diff] [blame] | 56 | os_host = BuiltIn().get_variable_value("${OS_HOST}", default="") |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 57 | |
| 58 | if os_host != "": |
| 59 | final_state['os_ping'] = 1 |
| 60 | final_state['os_login'] = 1 |
| 61 | final_state['os_run_cmd'] = 1 |
| 62 | |
| 63 | final_state = state_mod.anchor_state(final_state) |
| 64 | |
| 65 | grp.rprintn() |
Michael Walsh | 0957aaf | 2017-01-10 11:39:03 -0600 | [diff] [blame] | 66 | power_on_timeout = BuiltIn().get_variable_value( |
| 67 | "${POWER_ON_TIMEOUT}", default="14 mins") |
| 68 | state_mod.wait_state(final_state, wait_time=power_on_timeout, |
Michael Walsh | 1ef7056 | 2016-12-13 15:53:34 -0600 | [diff] [blame] | 69 | interval="3 seconds") |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 70 | |
| 71 | ############################################################################### |