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 |
| 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 On". |
| 18 | BuiltIn().import_resource("utils.robot") |
| 19 | |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 20 | BuiltIn().set_global_variable("${quiet}", quiet) |
| 21 | |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 22 | |
| 23 | ############################################################################### |
| 24 | def bmc_power_on(): |
| 25 | |
| 26 | r""" |
| 27 | Power the Open BMC machine on and monitor status to verify. |
| 28 | """ |
| 29 | |
| 30 | grp.rprint_timen("Refreshing state data.") |
| 31 | state = state_mod.get_state() |
| 32 | grp.rprint_var(state) |
| 33 | |
| 34 | match_state = state_mod.anchor_state(state) |
| 35 | |
| 36 | grp.rprintn() |
| 37 | cmd_buf = ["Initiate Power On", "wait=${0}"] |
| 38 | grp.rpissuing_keyword(cmd_buf) |
| 39 | power = BuiltIn().run_keyword(*cmd_buf) |
| 40 | |
Michael Walsh | 0957aaf | 2017-01-10 11:39:03 -0600 | [diff] [blame] | 41 | state_change_timeout = BuiltIn().get_variable_value( |
| 42 | "${STATE_CHANGE_TIMEOUT}", default="1 min") |
| 43 | |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 44 | # Wait for the state to change in any way. |
Michael Walsh | 0957aaf | 2017-01-10 11:39:03 -0600 | [diff] [blame] | 45 | state_mod.wait_state(match_state, wait_time=state_change_timeout, |
| 46 | interval="3 seconds", invert=1) |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 47 | |
Michael Walsh | 341c21e | 2017-01-17 16:25:20 -0600 | [diff] [blame] | 48 | if state_mod.OBMC_STATES_VERSION == 0: |
| 49 | cmd_buf = ["Create Dictionary", "power=${1}", |
| 50 | "bmc=HOST_BOOTED", |
| 51 | "boot_progress=FW Progress, Starting OS"] |
| 52 | else: |
| 53 | cmd_buf = ["Create Dictionary", "chassis=On", |
| 54 | "bmc=HOST_BOOTED", |
| 55 | "boot_progress=FW Progress, Starting OS", |
| 56 | "host=Running"] |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 57 | grp.rdpissuing_keyword(cmd_buf) |
| 58 | final_state = BuiltIn().run_keyword(*cmd_buf) |
| 59 | |
Michael Walsh | 0957aaf | 2017-01-10 11:39:03 -0600 | [diff] [blame] | 60 | os_host = BuiltIn().get_variable_value("${OS_HOST}", default="") |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 61 | |
| 62 | if os_host != "": |
| 63 | final_state['os_ping'] = 1 |
| 64 | final_state['os_login'] = 1 |
| 65 | final_state['os_run_cmd'] = 1 |
| 66 | |
| 67 | final_state = state_mod.anchor_state(final_state) |
| 68 | |
| 69 | grp.rprintn() |
Michael Walsh | 0957aaf | 2017-01-10 11:39:03 -0600 | [diff] [blame] | 70 | power_on_timeout = BuiltIn().get_variable_value( |
| 71 | "${POWER_ON_TIMEOUT}", default="14 mins") |
| 72 | state_mod.wait_state(final_state, wait_time=power_on_timeout, |
Michael Walsh | 1ef7056 | 2016-12-13 15:53:34 -0600 | [diff] [blame] | 73 | interval="3 seconds") |
Michael Walsh | ffee58a | 2016-11-22 11:28:33 -0600 | [diff] [blame] | 74 | |
| 75 | ############################################################################### |