blob: ec2673c5b95bcf1ff68c956a8ac75360bdaa9c48 [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
Michael Walsh16cbb7f2017-02-02 15:54:16 -060010import gen_robot_utils as gru
Michael Walshffee58a2016-11-22 11:28:33 -060011
12from robot.libraries.BuiltIn import BuiltIn
13
14# We need utils.robot to get keyword "Initiate Power Off".
Michael Walsh16cbb7f2017-02-02 15:54:16 -060015gru.my_import_resource("utils.robot")
Michael Walshffee58a2016-11-22 11:28:33 -060016
17
18###############################################################################
19def 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 Walsh476dd3e2017-01-10 11:40:31 -060036 state_change_timeout = BuiltIn().get_variable_value(
37 "${STATE_CHANGE_TIMEOUT}", default="1 min")
38
Michael Walshffee58a2016-11-22 11:28:33 -060039 # Wait for the state to change in any way.
Michael Walsh476dd3e2017-01-10 11:40:31 -060040 state_mod.wait_state(match_state, wait_time=state_change_timeout,
41 interval="3 seconds", invert=1)
Michael Walshffee58a2016-11-22 11:28:33 -060042
Michael Walsh341c21e2017-01-17 16:25:20 -060043 if state_mod.OBMC_STATES_VERSION == 0:
44 cmd_buf = ["Create Dictionary", "power=${0}",
45 "bmc=HOST_POWERED_OFF", "boot_progress=Off"]
46 else:
Michael Walsh65b12542017-02-03 15:34:38 -060047 # TODO: Add back boot_progress when ipmi is enabled on Witherspoon.
Michael Walsh341c21e2017-01-17 16:25:20 -060048 cmd_buf = ["Create Dictionary", "chassis=Off",
Michael Walsh65b12542017-02-03 15:34:38 -060049 "bmc=Ready",
50 # "boot_progress=Off",
Michael Walsh341c21e2017-01-17 16:25:20 -060051 "host=Off"]
Michael Walshffee58a2016-11-22 11:28:33 -060052 grp.rdpissuing_keyword(cmd_buf)
53 final_state = BuiltIn().run_keyword(*cmd_buf)
54
55 final_state = state_mod.anchor_state(final_state)
56
57 grp.rprintn()
Michael Walsh476dd3e2017-01-10 11:40:31 -060058 power_off_timeout = BuiltIn().get_variable_value(
59 "${POWER_OFF_TIMEOUT}", default="2 mins")
60 state_mod.wait_state(final_state, wait_time=power_off_timeout,
61 interval="3 seconds")
Michael Walshffee58a2016-11-22 11:28:33 -060062
63###############################################################################