blob: e776bfb9fff309f6c9b25b2dd3c4dffec1b96329 [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
Michael Walsh341c21e2017-01-17 16:25:20 -060013# We don't want global variable getting changed when an import is done
14# so we'll save it and restore it.
15quiet = int(BuiltIn().get_variable_value("${quiet}"))
16
Michael Walshffee58a2016-11-22 11:28:33 -060017# We need utils.robot to get keyword "Initiate Power Off".
18BuiltIn().import_resource("utils.robot")
Michael Walsh341c21e2017-01-17 16:25:20 -060019BuiltIn().set_global_variable("${quiet}", quiet)
Michael Walshffee58a2016-11-22 11:28:33 -060020
21
22###############################################################################
23def bmc_power_off():
24
25 r"""
26 Power the Open BMC machine off and monitor status to verify.
27 """
28
29 grp.rprint_timen("Refreshing state data.")
30 state = state_mod.get_state()
31 grp.rprint_var(state)
32
33 match_state = state_mod.anchor_state(state)
34
35 grp.rprintn()
36 cmd_buf = ["Initiate Power Off"]
37 grp.rpissuing_keyword(cmd_buf)
38 power = BuiltIn().run_keyword(*cmd_buf)
39
Michael Walsh476dd3e2017-01-10 11:40:31 -060040 state_change_timeout = BuiltIn().get_variable_value(
41 "${STATE_CHANGE_TIMEOUT}", default="1 min")
42
Michael Walshffee58a2016-11-22 11:28:33 -060043 # Wait for the state to change in any way.
Michael Walsh476dd3e2017-01-10 11:40:31 -060044 state_mod.wait_state(match_state, wait_time=state_change_timeout,
45 interval="3 seconds", invert=1)
Michael Walshffee58a2016-11-22 11:28:33 -060046
Michael Walsh341c21e2017-01-17 16:25:20 -060047 if state_mod.OBMC_STATES_VERSION == 0:
48 cmd_buf = ["Create Dictionary", "power=${0}",
49 "bmc=HOST_POWERED_OFF", "boot_progress=Off"]
50 else:
51 cmd_buf = ["Create Dictionary", "chassis=Off",
52 "bmc=HOST_POWERED_OFF", "boot_progress=Off",
53 "host=Off"]
Michael Walshffee58a2016-11-22 11:28:33 -060054 grp.rdpissuing_keyword(cmd_buf)
55 final_state = BuiltIn().run_keyword(*cmd_buf)
56
57 final_state = state_mod.anchor_state(final_state)
58
59 grp.rprintn()
Michael Walsh476dd3e2017-01-10 11:40:31 -060060 power_off_timeout = BuiltIn().get_variable_value(
61 "${POWER_OFF_TIMEOUT}", default="2 mins")
62 state_mod.wait_state(final_state, wait_time=power_off_timeout,
63 interval="3 seconds")
Michael Walshffee58a2016-11-22 11:28:33 -060064
65###############################################################################