blob: 75b1048f193c88821d72b887edf18863ab79e3d9 [file] [log] [blame]
George Keishingb88df3d2017-01-10 07:28:08 -06001*** Settings ***
George Keishingbec365b2017-01-19 01:28:41 -06002Resource ../lib/utils.robot
3Variables ../data/variables.py
George Keishingb88df3d2017-01-10 07:28:08 -06004
5*** Variables ***
6
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -06007${BMC_READY_STATE} Ready
8${BMC_NOT_READY_STATE} NotReady
George Keishingb88df3d2017-01-10 07:28:08 -06009${QUIET} ${0}
10
Michael Walshb2869542017-04-12 15:41:02 -050011# "1" indicates that the new "xyz" interface should be used.
12${OBMC_STATES_VERSION} ${1}
George Keishing43a021f2017-01-30 11:10:13 -060013
George Keishingb88df3d2017-01-10 07:28:08 -060014*** Keywords ***
15
16Initiate Host Boot
17 [Documentation] Initiate host power on.
Michael Walsh67ef6222017-03-21 14:48:26 -050018 [Arguments] ${wait}=${1}
19
20 # Description of arguments:
21 # wait Indicates that this keyword should wait for host running state.
22
George Keishingb88df3d2017-01-10 07:28:08 -060023 ${args}= Create Dictionary data=${HOST_POWERON_TRANS}
24 Write Attribute
25 ... ${HOST_STATE_URI} RequestedHostTransition data=${args}
26
Michael Walsh67ef6222017-03-21 14:48:26 -050027 # Does caller want to wait for status?
28 Run Keyword If '${wait}' == '${0}' Return From Keyword
29
George Keishingb88df3d2017-01-10 07:28:08 -060030 Wait Until Keyword Succeeds
31 ... 10 min 10 sec Is Host Running
32
33
34Initiate Host PowerOff
35 [Documentation] Initiate host power off.
George Keishingfbea6042017-08-01 06:31:51 -050036 # 1. Request soft power off
37 # 2. Hard power off, if failed.
Michael Walsh67ef6222017-03-21 14:48:26 -050038 [Arguments] ${wait}=${1}
39
40 # Description of arguments:
41 # wait Indicates that this keyword should wait for host off state.
42
George Keishingb88df3d2017-01-10 07:28:08 -060043 ${args}= Create Dictionary data=${HOST_POWEROFF_TRANS}
44 Write Attribute
45 ... ${HOST_STATE_URI} RequestedHostTransition data=${args}
46
Michael Walsh67ef6222017-03-21 14:48:26 -050047 # Does caller want to wait for status?
48 Run Keyword If '${wait}' == '${0}' Return From Keyword
49
George Keishingfbea6042017-08-01 06:31:51 -050050 ${status}= Run Keyword And Return Status Wait For PowerOff
51
52 Run Keyword if '${status}' == '${False}' Hard Power Off
53
54
55Wait For PowerOff
56 [Documentation] Wait for power off state.
57
George Keishing2c54e692017-07-10 13:07:02 -050058 # TODO: Reference to open-power/skiboot#81.
59 # Revert to 3 minutes once fixed.
George Keishingfbea6042017-08-01 06:31:51 -050060 Wait Until Keyword Succeeds 6 min 10 sec Is Host Off
61
62
63Hard Power Off
64 [Documentation] Do a hard power off.
Michael Walsh245db7c2017-09-05 15:45:03 -050065 [Arguments] ${wait}=${1}
66
67 # Description of argument(s):
68 # wait Indicates that this keyword should wait for host off state.
George Keishingfbea6042017-08-01 06:31:51 -050069
70 ${args}= Create Dictionary data=${CHASSIS_POWEROFF_TRANS}
71 Write Attribute
72 ... ${CHASSIS_STATE_URI} RequestedPowerTransition data=${args}
73
Michael Walsh245db7c2017-09-05 15:45:03 -050074 # Does caller want to wait for status?
75 Run Keyword If '${wait}' == '${0}' Return From Keyword
76
George Keishingb88df3d2017-01-10 07:28:08 -060077 Wait Until Keyword Succeeds
George Keishingfbea6042017-08-01 06:31:51 -050078 ... 1 min 10 sec Run Keywords Is Chassis Off AND Is Host Off
George Keishingb88df3d2017-01-10 07:28:08 -060079
80
Rahul Maheshwarif7ead242017-02-14 01:59:42 -060081Initiate Host Reboot
82 [Documentation] Initiate host reboot via REST.
83
84 ${args}= Create Dictionary data=${HOST_REBOOT_TRANS}
85 Write Attribute
86 ... ${HOST_STATE_URI} RequestedHostTransition data=${args}
87 Is Host Rebooted
88
89
George Keishingb88df3d2017-01-10 07:28:08 -060090Is Host Running
Rahul Maheshwarif7ead242017-02-14 01:59:42 -060091 [Documentation] Check if host state is "Running".
George Keishing13cc2102017-07-25 07:48:58 -050092 # Chassis state should be "On" before we check the host state.
93 Is Chassis On
George Keishingb88df3d2017-01-10 07:28:08 -060094 ${host_state}= Get Host State
George Keishing59d6cb42017-01-19 08:26:03 -060095 Should Be Equal Running ${host_state}
George Keishing13cc2102017-07-25 07:48:58 -050096 # Check to verify that the host is really booted.
George Keishing2bd6fc02017-08-10 01:15:16 -050097 Is OS Booted
98
99
100Get Host State Attribute
101 [Documentation] Return the state of the host as a string.
102 [Arguments] ${host_attribute} ${quiet}=${QUIET}
103
104 # Description of argument(s):
105 # host_attribute Host attribute name.
106 # quiet Suppress REST output logging to console.
107
108 ${state}=
109 ... Read Attribute ${HOST_STATE_URI} ${host_attribute} quiet=${quiet}
110 [Return] ${state}
111
112
113Is OS Booted
114 [Documentation] Check OS status.
115
116 # Example:
117 # "/xyz/openbmc_project/state/host0": {
118 # "AttemptsLeft": 0,
119 # "BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart",
120 # "CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Running",
121 # "OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete",
122 # "RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.On"
123 # }
124
George Keishing2bd6fc02017-08-10 01:15:16 -0500125 ${boot_stage}= Get Host State Attribute BootProgress
126 Should Be Equal ${OS_BOOT_START} ${boot_stage}
127
128 ${os_state}= Get Host State Attribute OperatingSystemState
129 Should Be Equal ${OS_BOOT_COMPLETE} ${os_state}
George Keishingb88df3d2017-01-10 07:28:08 -0600130
131
132Is Host Off
Rahul Maheshwarif7ead242017-02-14 01:59:42 -0600133 [Documentation] Check if host state is "Off".
George Keishing13cc2102017-07-25 07:48:58 -0500134 # Chassis state should be "Off" before we check the host state.
135 Is Chassis Off
George Keishingb88df3d2017-01-10 07:28:08 -0600136 ${host_state}= Get Host State
George Keishing59d6cb42017-01-19 08:26:03 -0600137 Should Be Equal Off ${host_state}
George Keishing13cc2102017-07-25 07:48:58 -0500138 # Check to verify that the host shutdown completely.
Andrew Geissler854e9fe2017-07-29 09:51:13 -0500139 # TODO openbmc/openbmc#2049 - boot sensor not cleared on power off
140 #Is OS Off
George Keishingb88df3d2017-01-10 07:28:08 -0600141
Rahul Maheshwarif7ead242017-02-14 01:59:42 -0600142
143Is Host Rebooted
144 [Documentation] Checks if host rebooted.
145
146 ${host_trans_state}= Get Host Trans State
147 Should Be Equal ${host_trans_state} Reboot
148 Is Host Running
149
150
151Is Chassis On
152 [Documentation] Check if chassis state is "On".
153 ${power_state}= Get Chassis Power State
154 Should Be Equal On ${power_state}
155
156
157Is Chassis Off
158 [Documentation] Check if chassis state is "Off".
159 ${power_state}= Get Chassis Power State
160 Should Be Equal Off ${power_state}
161
Rahul Maheshwarid01596e2017-02-20 00:04:42 -0600162Is Host Quiesced
163 [Documentation] Check if host state is quiesced.
164 ${host_state}= Get Host State
Rahul Maheshwarid01596e2017-02-20 00:04:42 -0600165 ${status}= Run Keyword And Return Status Should Be Equal
166 ... ${host_state} Quiesced
167 [Return] ${status}
168
George Keishingb88df3d2017-01-10 07:28:08 -0600169
Rahul Maheshwari09439a22017-02-23 01:10:05 -0600170Recover Quiesced Host
171 [Documentation] Recover host from quisced state.
172
173 ${resp}= Run Keyword And Return Status Is Host Quiesced
174 Run Keyword If '${resp}' == 'True'
175 ... Run Keywords Initiate Host PowerOff AND
176 ... Log HOST is recovered from quiesced state
177
178
George Keishingb88df3d2017-01-10 07:28:08 -0600179Get Host State
180 [Documentation] Return the state of the host as a string.
181 [Arguments] ${quiet}=${QUIET}
182 # quiet - Suppress REST output logging to console.
183 ${state}=
184 ... Read Attribute ${HOST_STATE_URI} CurrentHostState
185 ... quiet=${quiet}
George Keishing59d6cb42017-01-19 08:26:03 -0600186 [Return] ${state.rsplit('.', 1)[1]}
George Keishingb88df3d2017-01-10 07:28:08 -0600187
Rahul Maheshwarif7ead242017-02-14 01:59:42 -0600188Get Host Trans State
189 [Documentation] Return the transition state of host as a string.
190 ... e.g. On, Off, Reboot
191 [Arguments] ${quiet}=${QUIET}
192 # Description of arguments:
193 # quiet Suppress REST output logging to console.
194
195 ${state}=
196 ... Read Attribute ${HOST_STATE_URI} RequestedHostTransition
197 ... quiet=${quiet}
198 [Return] ${state.rsplit('.', 1)[1]}
George Keishingb88df3d2017-01-10 07:28:08 -0600199
200Get Chassis Power State
201 [Documentation] Return the power state of the Chassis
202 ... as a string.
203 [Arguments] ${quiet}=${QUIET}
204 # quiet - Suppress REST output logging to console.
205 ${state}=
206 ... Read Attribute ${CHASSIS_STATE_URI} CurrentPowerState
207 ... quiet=${quiet}
George Keishing59d6cb42017-01-19 08:26:03 -0600208 [Return] ${state.rsplit('.', 1)[1]}
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600209
210
211Get BMC State
212 [Documentation] Return the state of the BMC.
213 [Arguments] ${quiet}=${QUIET}
214 # quiet - Suppress REST output logging to console.
215 ${state}=
216 ... Read Attribute ${BMC_STATE_URI} CurrentBMCState quiet=${quiet}
217 [Return] ${state.rsplit('.', 1)[1]}
218
219
220Put BMC State
221 [Documentation] Put BMC in given state.
222 [Arguments] ${expected_state}
223 # expected_state - expected BMC state
224
225 ${bmc_state}= Get BMC State
226 Run Keyword If '${bmc_state}' == '${expected_state}'
227 ... Log BMC is already in ${expected_state} state
228 ... ELSE Run Keywords Initiate BMC Reboot AND
229 ... Wait for BMC state ${expected_state}
230
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600231Initiate BMC Reboot
232 [Documentation] Initiate BMC reboot.
Michael Walsh8b388682017-09-08 10:57:45 -0500233 [Arguments] ${wait}=${1}
234
235 # Description of argument(s):
236 # wait Indicates that this keyword should wait for ending state..
237
238 ${args}= Create Dictionary data=${BMC_REBOOT_TRANS}
Rahul Maheshwari55a68e22017-04-20 04:36:21 -0500239
240 Run Keyword And Ignore Error Write Attribute
Michael Walsh8b388682017-09-08 10:57:45 -0500241 ... ${BMC_STATE_URI} RequestedBMCTransition data=${args}
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600242
Michael Walsh8b388682017-09-08 10:57:45 -0500243 # Does caller want to wait for status?
244 Run Keyword If '${wait}' == '${0}' Return From Keyword
245
246 ${session_active}= Check If BMC Reboot Is Initiated
247 Run Keyword If '${session_active}' == '${True}'
248 ... Fail msg=BMC Reboot didn't occur.
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600249
250 Check If BMC is Up
251
252Check If BMC Reboot Is Initiated
253 [Documentation] Checks whether BMC Reboot is initiated by checking
254 ... BMC connection loss.
255 # Reboot adds 3 seconds delay before forcing reboot
256 # To minimize race conditions, we wait for 7 seconds
257 Sleep 7s
258 ${alive}= Run Keyword and Return Status
259 ... Open Connection And Log In
260 Return From Keyword If '${alive}' == '${False}' ${False}
261 [Return] ${True}
262
263Is BMC Ready
264 [Documentation] Check if BMC state is Ready.
265 ${bmc_state}= Get BMC State
266 Should Be Equal ${BMC_READY_STATE} ${bmc_state}
267
268Is BMC Not Ready
269 [Documentation] Check if BMC state is Not Ready.
270 ${bmc_state}= Get BMC State
271 Should Be Equal ${BMC_NOT_READY_STATE} ${bmc_state}
272
273Wait for BMC state
274 [Documentation] Wait until given BMC state is reached.
275 [Arguments] ${state}
276 # state - BMC state to wait for
277 Run Keyword If '${state}' == '${BMC_READY_STATE}'
278 ... Wait Until Keyword Succeeds
279 ... 10 min 10 sec Is BMC Ready
280 ... ELSE IF '${state}' == '${BMC_NOT_READY_STATE}'
281 ... Wait Until Keyword Succeeds
282 ... 10 min 10 sec Is BMC Not Ready
283 ... ELSE Fail msg=Invalid BMC state
George Keishing43a021f2017-01-30 11:10:13 -0600284
285
286Set State Interface Version
287 [Documentation] Set version to indicate which interface to use.
Rahul Maheshwari073f8ad2017-03-02 00:55:22 -0600288 ${resp}= Openbmc Get Request ${CHASSIS_STATE_URI}
George Keishing43a021f2017-01-30 11:10:13 -0600289 ${status}= Run Keyword And Return Status
290 ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
291 Run Keyword If '${status}' == '${True}'
292 ... Set Global Variable ${OBMC_STATES_VERSION} ${1}
293 ... ELSE
294 ... Set Global Variable ${OBMC_STATES_VERSION} ${0}
295
296
297Power Off Request
298 [Documentation] Select appropriate poweroff keyword.
Rahul Maheshwari073f8ad2017-03-02 00:55:22 -0600299 Run Keyword If '${OBMC_STATES_VERSION}' == '${0}'
George Keishing43a021f2017-01-30 11:10:13 -0600300 ... Initiate Power Off
301 ... ELSE
302 ... Initiate Host PowerOff
303
304
305Wait For BMC Ready
306 [Documentation] Check BMC state and wait for BMC Ready.
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500307 Wait Until Keyword Succeeds 10 min 10 sec Is BMC Ready