blob: d72fd81c1d1297c973e8b41d31c5f8c24793d3f7 [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:
47 cmd_buf = ["Create Dictionary", "chassis=Off",
48 "bmc=HOST_POWERED_OFF", "boot_progress=Off",
49 "host=Off"]
Michael Walshffee58a2016-11-22 11:28:33 -060050 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 Walsh476dd3e2017-01-10 11:40:31 -060056 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 Walshffee58a2016-11-22 11:28:33 -060060
61###############################################################################