blob: b6d8959b9262fbd53c5c11a3e63ba5bdbb3888ec [file] [log] [blame]
Michael Walshffee58a2016-11-22 11:28:33 -06001#!/usr/bin/env python
2
3r"""
4This module is the python counterpart to poweroffs.robot. It provides
5functions for powering off an open bmc machine.
6"""
7
8import gen_robot_print as grp
9import state as state_mod
10
11from robot.libraries.BuiltIn import BuiltIn
12
13# We need utils.robot to get keyword "Initiate Power Off".
14BuiltIn().import_resource("utils.robot")
15
16
17###############################################################################
18def bmc_power_off():
19
20 r"""
21 Power the Open BMC machine off and monitor status to verify.
22 """
23
24 grp.rprint_timen("Refreshing state data.")
25 state = state_mod.get_state()
26 grp.rprint_var(state)
27
28 match_state = state_mod.anchor_state(state)
29
30 grp.rprintn()
31 cmd_buf = ["Initiate Power Off"]
32 grp.rpissuing_keyword(cmd_buf)
33 power = BuiltIn().run_keyword(*cmd_buf)
34
Michael Walsh476dd3e2017-01-10 11:40:31 -060035 state_change_timeout = BuiltIn().get_variable_value(
36 "${STATE_CHANGE_TIMEOUT}", default="1 min")
37
Michael Walshffee58a2016-11-22 11:28:33 -060038 # Wait for the state to change in any way.
Michael Walsh476dd3e2017-01-10 11:40:31 -060039 state_mod.wait_state(match_state, wait_time=state_change_timeout,
40 interval="3 seconds", invert=1)
Michael Walshffee58a2016-11-22 11:28:33 -060041
42 cmd_buf = ["Create Dictionary", "power=${0}",
43 "bmc=HOST_POWERED_OFF", "boot_progress=Off"]
44 grp.rdpissuing_keyword(cmd_buf)
45 final_state = BuiltIn().run_keyword(*cmd_buf)
46
47 final_state = state_mod.anchor_state(final_state)
48
49 grp.rprintn()
Michael Walsh476dd3e2017-01-10 11:40:31 -060050 power_off_timeout = BuiltIn().get_variable_value(
51 "${POWER_OFF_TIMEOUT}", default="2 mins")
52 state_mod.wait_state(final_state, wait_time=power_off_timeout,
53 interval="3 seconds")
Michael Walshffee58a2016-11-22 11:28:33 -060054
55###############################################################################