blob: af9044df9b6f5c5da46b19a3341be1008a8b604c [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
George Keishingb2a8dea2018-07-20 10:25:51 -050020 # Description of argument(s):
Michael Walsh67ef6222017-03-21 14:48:26 -050021 # 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?
George Keishing0628c4f2025-06-24 23:58:47 +053028 IF '${wait}' == '${0}' Return From Keyword
Michael Walsh67ef6222017-03-21 14:48:26 -050029
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
George Keishingb2a8dea2018-07-20 10:25:51 -050040 # Description of argument(s):
Michael Walsh67ef6222017-03-21 14:48:26 -050041 # 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?
George Keishing0628c4f2025-06-24 23:58:47 +053048 IF '${wait}' == '${0}' Return From Keyword
Michael Walsh67ef6222017-03-21 14:48:26 -050049
George Keishingfbea6042017-08-01 06:31:51 -050050 ${status}= Run Keyword And Return Status Wait For PowerOff
51
George Keishing0628c4f2025-06-24 23:58:47 +053052 IF '${status}' == '${False}' Hard Power Off
George Keishingfbea6042017-08-01 06:31:51 -050053
54
55Wait For PowerOff
56 [Documentation] Wait for power off state.
57
George Keishing2c54e692017-07-10 13:07:02 -050058 # Revert to 3 minutes once fixed.
George Keishingfbea6042017-08-01 06:31:51 -050059 Wait Until Keyword Succeeds 6 min 10 sec Is Host Off
60
61
62Hard Power Off
63 [Documentation] Do a hard power off.
Michael Walsh245db7c2017-09-05 15:45:03 -050064 [Arguments] ${wait}=${1}
65
66 # Description of argument(s):
67 # wait Indicates that this keyword should wait for host off state.
George Keishingfbea6042017-08-01 06:31:51 -050068
69 ${args}= Create Dictionary data=${CHASSIS_POWEROFF_TRANS}
70 Write Attribute
71 ... ${CHASSIS_STATE_URI} RequestedPowerTransition data=${args}
72
Michael Walsh245db7c2017-09-05 15:45:03 -050073 # Does caller want to wait for status?
George Keishing0628c4f2025-06-24 23:58:47 +053074 IF '${wait}' == '${0}' Return From Keyword
Michael Walsh245db7c2017-09-05 15:45:03 -050075
George Keishingb88df3d2017-01-10 07:28:08 -060076 Wait Until Keyword Succeeds
George Keishingfbea6042017-08-01 06:31:51 -050077 ... 1 min 10 sec Run Keywords Is Chassis Off AND Is Host Off
George Keishingb88df3d2017-01-10 07:28:08 -060078
79
Rahul Maheshwarif7ead242017-02-14 01:59:42 -060080Initiate Host Reboot
81 [Documentation] Initiate host reboot via REST.
George Keishingb2a8dea2018-07-20 10:25:51 -050082 [Arguments] ${wait}=${1}
83
84 # Description of argument(s):
85 # wait Indicates that this keyword should wait for host reboot state.
Rahul Maheshwarif7ead242017-02-14 01:59:42 -060086
87 ${args}= Create Dictionary data=${HOST_REBOOT_TRANS}
88 Write Attribute
89 ... ${HOST_STATE_URI} RequestedHostTransition data=${args}
George Keishingb2a8dea2018-07-20 10:25:51 -050090
91 # Does caller want to wait for host booted status?
George Keishing0628c4f2025-06-24 23:58:47 +053092 IF '${wait}' == '${0}' Return From Keyword
George Keishingb2a8dea2018-07-20 10:25:51 -050093
Rahul Maheshwarif7ead242017-02-14 01:59:42 -060094 Is Host Rebooted
95
96
George Keishingb88df3d2017-01-10 07:28:08 -060097Is Host Running
Rahul Maheshwarif7ead242017-02-14 01:59:42 -060098 [Documentation] Check if host state is "Running".
George Keishing13cc2102017-07-25 07:48:58 -050099 # Chassis state should be "On" before we check the host state.
100 Is Chassis On
George Keishingb88df3d2017-01-10 07:28:08 -0600101 ${host_state}= Get Host State
George Keishing59d6cb42017-01-19 08:26:03 -0600102 Should Be Equal Running ${host_state}
George Keishing13cc2102017-07-25 07:48:58 -0500103 # Check to verify that the host is really booted.
George Keishing2bd6fc02017-08-10 01:15:16 -0500104 Is OS Booted
105
106
107Get Host State Attribute
108 [Documentation] Return the state of the host as a string.
109 [Arguments] ${host_attribute} ${quiet}=${QUIET}
110
111 # Description of argument(s):
112 # host_attribute Host attribute name.
113 # quiet Suppress REST output logging to console.
114
Tim Lee29e073a2022-04-12 12:07:17 +0800115 ${HOST_STATE_URI}= Set Variable If '${PLATFORM_ARCH_TYPE}' == 'x86' and '${host_attribute}' == 'OperatingSystemState'
116 ... ${OS_STATE_URI} ${HOST_STATE_URI}
117
George Keishing2bd6fc02017-08-10 01:15:16 -0500118 ${state}=
119 ... Read Attribute ${HOST_STATE_URI} ${host_attribute} quiet=${quiet}
George Keishing409df052024-01-17 22:36:14 +0530120 RETURN ${state}
George Keishing2bd6fc02017-08-10 01:15:16 -0500121
122
123Is OS Booted
124 [Documentation] Check OS status.
125
126 # Example:
127 # "/xyz/openbmc_project/state/host0": {
128 # "AttemptsLeft": 0,
129 # "BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart",
130 # "CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Running",
131 # "OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete",
132 # "RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.On"
133 # }
134
George Keishing2bd6fc02017-08-10 01:15:16 -0500135 ${boot_stage}= Get Host State Attribute BootProgress
136 Should Be Equal ${OS_BOOT_START} ${boot_stage}
137
138 ${os_state}= Get Host State Attribute OperatingSystemState
139 Should Be Equal ${OS_BOOT_COMPLETE} ${os_state}
George Keishingb88df3d2017-01-10 07:28:08 -0600140
141
142Is Host Off
Rahul Maheshwarif7ead242017-02-14 01:59:42 -0600143 [Documentation] Check if host state is "Off".
Sridevi Ramesh6ba6b222025-03-19 11:00:24 -0500144
George Keishing13cc2102017-07-25 07:48:58 -0500145 # Chassis state should be "Off" before we check the host state.
146 Is Chassis Off
George Keishingb88df3d2017-01-10 07:28:08 -0600147 ${host_state}= Get Host State
George Keishing59d6cb42017-01-19 08:26:03 -0600148 Should Be Equal Off ${host_state}
George Keishingb88df3d2017-01-10 07:28:08 -0600149
Rahul Maheshwarif7ead242017-02-14 01:59:42 -0600150
151Is Host Rebooted
152 [Documentation] Checks if host rebooted.
153
154 ${host_trans_state}= Get Host Trans State
155 Should Be Equal ${host_trans_state} Reboot
156 Is Host Running
157
158
159Is Chassis On
160 [Documentation] Check if chassis state is "On".
161 ${power_state}= Get Chassis Power State
162 Should Be Equal On ${power_state}
163
164
165Is Chassis Off
166 [Documentation] Check if chassis state is "Off".
167 ${power_state}= Get Chassis Power State
168 Should Be Equal Off ${power_state}
169
Rahul Maheshwarid01596e2017-02-20 00:04:42 -0600170Is Host Quiesced
171 [Documentation] Check if host state is quiesced.
172 ${host_state}= Get Host State
Rahul Maheshwarid01596e2017-02-20 00:04:42 -0600173 ${status}= Run Keyword And Return Status Should Be Equal
174 ... ${host_state} Quiesced
George Keishing409df052024-01-17 22:36:14 +0530175 RETURN ${status}
Rahul Maheshwarid01596e2017-02-20 00:04:42 -0600176
George Keishingb88df3d2017-01-10 07:28:08 -0600177
Rahul Maheshwari09439a22017-02-23 01:10:05 -0600178Recover Quiesced Host
179 [Documentation] Recover host from quisced state.
180
181 ${resp}= Run Keyword And Return Status Is Host Quiesced
George Keishing0628c4f2025-06-24 23:58:47 +0530182 IF '${resp}' == 'True'
183 Initiate Host PowerOff
184 Log HOST is recovered from quiesced state
185 END
Rahul Maheshwari09439a22017-02-23 01:10:05 -0600186
187
George Keishingb88df3d2017-01-10 07:28:08 -0600188Get Host State
189 [Documentation] Return the state of the host as a string.
190 [Arguments] ${quiet}=${QUIET}
191 # quiet - Suppress REST output logging to console.
192 ${state}=
193 ... Read Attribute ${HOST_STATE_URI} CurrentHostState
194 ... quiet=${quiet}
George Keishing409df052024-01-17 22:36:14 +0530195 RETURN ${state.rsplit('.', 1)[1]}
George Keishingb88df3d2017-01-10 07:28:08 -0600196
Rahul Maheshwarif7ead242017-02-14 01:59:42 -0600197Get Host Trans State
198 [Documentation] Return the transition state of host as a string.
199 ... e.g. On, Off, Reboot
200 [Arguments] ${quiet}=${QUIET}
201 # Description of arguments:
202 # quiet Suppress REST output logging to console.
203
204 ${state}=
205 ... Read Attribute ${HOST_STATE_URI} RequestedHostTransition
206 ... quiet=${quiet}
George Keishing409df052024-01-17 22:36:14 +0530207 RETURN ${state.rsplit('.', 1)[1]}
George Keishingb88df3d2017-01-10 07:28:08 -0600208
209Get Chassis Power State
210 [Documentation] Return the power state of the Chassis
211 ... as a string.
212 [Arguments] ${quiet}=${QUIET}
213 # quiet - Suppress REST output logging to console.
214 ${state}=
215 ... Read Attribute ${CHASSIS_STATE_URI} CurrentPowerState
216 ... quiet=${quiet}
George Keishing409df052024-01-17 22:36:14 +0530217 RETURN ${state.rsplit('.', 1)[1]}
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600218
219
220Get BMC State
221 [Documentation] Return the state of the BMC.
222 [Arguments] ${quiet}=${QUIET}
223 # quiet - Suppress REST output logging to console.
224 ${state}=
225 ... Read Attribute ${BMC_STATE_URI} CurrentBMCState quiet=${quiet}
George Keishing409df052024-01-17 22:36:14 +0530226 RETURN ${state.rsplit('.', 1)[1]}
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600227
228
229Put BMC State
230 [Documentation] Put BMC in given state.
231 [Arguments] ${expected_state}
232 # expected_state - expected BMC state
233
234 ${bmc_state}= Get BMC State
George Keishing0628c4f2025-06-24 23:58:47 +0530235 IF '${bmc_state}' == '${expected_state}'
236 Log BMC is already in ${expected_state} state
237 ELSE
238 OBMC Reboot (off)
239 END
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600240
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600241Initiate BMC Reboot
242 [Documentation] Initiate BMC reboot.
Michael Walsh8b388682017-09-08 10:57:45 -0500243 [Arguments] ${wait}=${1}
244
245 # Description of argument(s):
246 # wait Indicates that this keyword should wait for ending state..
247
248 ${args}= Create Dictionary data=${BMC_REBOOT_TRANS}
Rahul Maheshwari55a68e22017-04-20 04:36:21 -0500249
250 Run Keyword And Ignore Error Write Attribute
Michael Walsh8b388682017-09-08 10:57:45 -0500251 ... ${BMC_STATE_URI} RequestedBMCTransition data=${args}
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600252
Michael Walsh8b388682017-09-08 10:57:45 -0500253 # Does caller want to wait for status?
George Keishing0628c4f2025-06-24 23:58:47 +0530254 IF '${wait}' == '${0}' Return From Keyword
Michael Walsh8b388682017-09-08 10:57:45 -0500255
256 ${session_active}= Check If BMC Reboot Is Initiated
George Keishing0628c4f2025-06-24 23:58:47 +0530257 IF '${session_active}' == '${True}'
Michael Walsh8b388682017-09-08 10:57:45 -0500258 ... Fail msg=BMC Reboot didn't occur.
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600259
260 Check If BMC is Up
261
262Check If BMC Reboot Is Initiated
263 [Documentation] Checks whether BMC Reboot is initiated by checking
264 ... BMC connection loss.
265 # Reboot adds 3 seconds delay before forcing reboot
266 # To minimize race conditions, we wait for 7 seconds
267 Sleep 7s
268 ${alive}= Run Keyword and Return Status
269 ... Open Connection And Log In
270 Return From Keyword If '${alive}' == '${False}' ${False}
George Keishing409df052024-01-17 22:36:14 +0530271 RETURN ${True}
Rahul Maheshwari2f8de6c2017-01-17 07:00:22 -0600272
273Is BMC Ready
274 [Documentation] Check if BMC state is Ready.
275 ${bmc_state}= Get BMC State
276 Should Be Equal ${BMC_READY_STATE} ${bmc_state}
277
278Is BMC Not Ready
279 [Documentation] Check if BMC state is Not Ready.
280 ${bmc_state}= Get BMC State
281 Should Be Equal ${BMC_NOT_READY_STATE} ${bmc_state}
282
283Wait for BMC state
284 [Documentation] Wait until given BMC state is reached.
285 [Arguments] ${state}
286 # state - BMC state to wait for
George Keishing0628c4f2025-06-24 23:58:47 +0530287 IF '${state}' == '${BMC_READY_STATE}'
288 Wait Until Keyword Succeeds 10 min 10 sec Is BMC Ready
289 ELSE IF '${state}' == '${BMC_NOT_READY_STATE}'
290 Wait Until Keyword Succeeds 10 min 10 sec Is BMC Not Ready
291 ELSE
292 Fail msg=Invalid BMC state
293 END
George Keishing43a021f2017-01-30 11:10:13 -0600294
295
296Set State Interface Version
297 [Documentation] Set version to indicate which interface to use.
Rahul Maheshwari073f8ad2017-03-02 00:55:22 -0600298 ${resp}= Openbmc Get Request ${CHASSIS_STATE_URI}
George Keishing43a021f2017-01-30 11:10:13 -0600299 ${status}= Run Keyword And Return Status
300 ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishing0628c4f2025-06-24 23:58:47 +0530301 IF '${status}' == '${True}'
302 Set Global Variable ${OBMC_STATES_VERSION} ${1}
303 ELSE
304 Set Global Variable ${OBMC_STATES_VERSION} ${0}
305 END
George Keishing43a021f2017-01-30 11:10:13 -0600306
307
308Power Off Request
309 [Documentation] Select appropriate poweroff keyword.
George Keishing0628c4f2025-06-24 23:58:47 +0530310 IF '${OBMC_STATES_VERSION}' == '${0}'
311 Initiate Power Off
312 ELSE
313 Initiate Host PowerOff
314 END
George Keishing43a021f2017-01-30 11:10:13 -0600315
316
317Wait For BMC Ready
318 [Documentation] Check BMC state and wait for BMC Ready.
George Keishingb2a8dea2018-07-20 10:25:51 -0500319 Wait Until Keyword Succeeds 10 min 10 sec Is BMC Ready
chithraga6be41e2022-03-01 13:20:23 +0000320
321
322Get Host State Via Redfish
323 [Documentation] Return the state of the host Via Redfish as a string.
324
325 ${powerstate}=
326 ... Redfish.Get Attribute ${REDFISH_CHASSIS_URI}/${CHASSIS_ID} PowerState
327
George Keishing409df052024-01-17 22:36:14 +0530328 RETURN ${powerstate}