George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 1 | *** Settings *** |
George Keishing | bec365b | 2017-01-19 01:28:41 -0600 | [diff] [blame] | 2 | Resource ../lib/utils.robot |
| 3 | Variables ../data/variables.py |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 4 | |
| 5 | *** Variables *** |
| 6 | |
Rahul Maheshwari | 2f8de6c | 2017-01-17 07:00:22 -0600 | [diff] [blame] | 7 | ${BMC_READY_STATE} Ready |
| 8 | ${BMC_NOT_READY_STATE} NotReady |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 9 | ${QUIET} ${0} |
| 10 | |
Michael Walsh | b286954 | 2017-04-12 15:41:02 -0500 | [diff] [blame] | 11 | # "1" indicates that the new "xyz" interface should be used. |
| 12 | ${OBMC_STATES_VERSION} ${1} |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 13 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 14 | *** Keywords *** |
| 15 | |
| 16 | Initiate Host Boot |
| 17 | [Documentation] Initiate host power on. |
Michael Walsh | 67ef622 | 2017-03-21 14:48:26 -0500 | [diff] [blame] | 18 | [Arguments] ${wait}=${1} |
| 19 | |
| 20 | # Description of arguments: |
| 21 | # wait Indicates that this keyword should wait for host running state. |
| 22 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 23 | ${args}= Create Dictionary data=${HOST_POWERON_TRANS} |
| 24 | Write Attribute |
| 25 | ... ${HOST_STATE_URI} RequestedHostTransition data=${args} |
| 26 | |
Michael Walsh | 67ef622 | 2017-03-21 14:48:26 -0500 | [diff] [blame] | 27 | # Does caller want to wait for status? |
| 28 | Run Keyword If '${wait}' == '${0}' Return From Keyword |
| 29 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 30 | Wait Until Keyword Succeeds |
| 31 | ... 10 min 10 sec Is Host Running |
| 32 | |
| 33 | |
| 34 | Initiate Host PowerOff |
| 35 | [Documentation] Initiate host power off. |
George Keishing | fbea604 | 2017-08-01 06:31:51 -0500 | [diff] [blame] | 36 | # 1. Request soft power off |
| 37 | # 2. Hard power off, if failed. |
Michael Walsh | 67ef622 | 2017-03-21 14:48:26 -0500 | [diff] [blame] | 38 | [Arguments] ${wait}=${1} |
| 39 | |
| 40 | # Description of arguments: |
| 41 | # wait Indicates that this keyword should wait for host off state. |
| 42 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 43 | ${args}= Create Dictionary data=${HOST_POWEROFF_TRANS} |
| 44 | Write Attribute |
| 45 | ... ${HOST_STATE_URI} RequestedHostTransition data=${args} |
| 46 | |
Michael Walsh | 67ef622 | 2017-03-21 14:48:26 -0500 | [diff] [blame] | 47 | # Does caller want to wait for status? |
| 48 | Run Keyword If '${wait}' == '${0}' Return From Keyword |
| 49 | |
George Keishing | fbea604 | 2017-08-01 06:31:51 -0500 | [diff] [blame] | 50 | ${status}= Run Keyword And Return Status Wait For PowerOff |
| 51 | |
| 52 | Run Keyword if '${status}' == '${False}' Hard Power Off |
| 53 | |
| 54 | |
| 55 | Wait For PowerOff |
| 56 | [Documentation] Wait for power off state. |
| 57 | |
George Keishing | 2c54e69 | 2017-07-10 13:07:02 -0500 | [diff] [blame] | 58 | # TODO: Reference to open-power/skiboot#81. |
| 59 | # Revert to 3 minutes once fixed. |
George Keishing | fbea604 | 2017-08-01 06:31:51 -0500 | [diff] [blame] | 60 | Wait Until Keyword Succeeds 6 min 10 sec Is Host Off |
| 61 | |
| 62 | |
| 63 | Hard Power Off |
| 64 | [Documentation] Do a hard power off. |
| 65 | |
| 66 | ${args}= Create Dictionary data=${CHASSIS_POWEROFF_TRANS} |
| 67 | Write Attribute |
| 68 | ... ${CHASSIS_STATE_URI} RequestedPowerTransition data=${args} |
| 69 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 70 | Wait Until Keyword Succeeds |
George Keishing | fbea604 | 2017-08-01 06:31:51 -0500 | [diff] [blame] | 71 | ... 1 min 10 sec Run Keywords Is Chassis Off AND Is Host Off |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 72 | |
| 73 | |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 74 | Initiate Host Reboot |
| 75 | [Documentation] Initiate host reboot via REST. |
| 76 | |
| 77 | ${args}= Create Dictionary data=${HOST_REBOOT_TRANS} |
| 78 | Write Attribute |
| 79 | ... ${HOST_STATE_URI} RequestedHostTransition data=${args} |
| 80 | Is Host Rebooted |
| 81 | |
| 82 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 83 | Is Host Running |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 84 | [Documentation] Check if host state is "Running". |
George Keishing | 13cc210 | 2017-07-25 07:48:58 -0500 | [diff] [blame] | 85 | # Chassis state should be "On" before we check the host state. |
| 86 | Is Chassis On |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 87 | ${host_state}= Get Host State |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 88 | Should Be Equal Running ${host_state} |
George Keishing | 13cc210 | 2017-07-25 07:48:58 -0500 | [diff] [blame] | 89 | # Check to verify that the host is really booted. |
George Keishing | 2bd6fc0 | 2017-08-10 01:15:16 -0500 | [diff] [blame] | 90 | Is OS Booted |
| 91 | |
| 92 | |
| 93 | Get Host State Attribute |
| 94 | [Documentation] Return the state of the host as a string. |
| 95 | [Arguments] ${host_attribute} ${quiet}=${QUIET} |
| 96 | |
| 97 | # Description of argument(s): |
| 98 | # host_attribute Host attribute name. |
| 99 | # quiet Suppress REST output logging to console. |
| 100 | |
| 101 | ${state}= |
| 102 | ... Read Attribute ${HOST_STATE_URI} ${host_attribute} quiet=${quiet} |
| 103 | [Return] ${state} |
| 104 | |
| 105 | |
| 106 | Is OS Booted |
| 107 | [Documentation] Check OS status. |
| 108 | |
| 109 | # Example: |
| 110 | # "/xyz/openbmc_project/state/host0": { |
| 111 | # "AttemptsLeft": 0, |
| 112 | # "BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart", |
| 113 | # "CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Running", |
| 114 | # "OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete", |
| 115 | # "RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.On" |
| 116 | # } |
| 117 | |
| 118 | # TODO: Remove this logic once migration is complete. |
| 119 | ${status}= Run Keyword And Return Status Is OS Starting |
| 120 | Return From Keyword If '${status}' == '${True}' ${True} |
| 121 | |
| 122 | ${boot_stage}= Get Host State Attribute BootProgress |
| 123 | Should Be Equal ${OS_BOOT_START} ${boot_stage} |
| 124 | |
| 125 | ${os_state}= Get Host State Attribute OperatingSystemState |
| 126 | Should Be Equal ${OS_BOOT_COMPLETE} ${os_state} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 127 | |
| 128 | |
| 129 | Is Host Off |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 130 | [Documentation] Check if host state is "Off". |
George Keishing | 13cc210 | 2017-07-25 07:48:58 -0500 | [diff] [blame] | 131 | # Chassis state should be "Off" before we check the host state. |
| 132 | Is Chassis Off |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 133 | ${host_state}= Get Host State |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 134 | Should Be Equal Off ${host_state} |
George Keishing | 13cc210 | 2017-07-25 07:48:58 -0500 | [diff] [blame] | 135 | # Check to verify that the host shutdown completely. |
Andrew Geissler | 854e9fe | 2017-07-29 09:51:13 -0500 | [diff] [blame] | 136 | # TODO openbmc/openbmc#2049 - boot sensor not cleared on power off |
| 137 | #Is OS Off |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 138 | |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 139 | |
| 140 | Is Host Rebooted |
| 141 | [Documentation] Checks if host rebooted. |
| 142 | |
| 143 | ${host_trans_state}= Get Host Trans State |
| 144 | Should Be Equal ${host_trans_state} Reboot |
| 145 | Is Host Running |
| 146 | |
| 147 | |
| 148 | Is Chassis On |
| 149 | [Documentation] Check if chassis state is "On". |
| 150 | ${power_state}= Get Chassis Power State |
| 151 | Should Be Equal On ${power_state} |
| 152 | |
| 153 | |
| 154 | Is Chassis Off |
| 155 | [Documentation] Check if chassis state is "Off". |
| 156 | ${power_state}= Get Chassis Power State |
| 157 | Should Be Equal Off ${power_state} |
| 158 | |
Rahul Maheshwari | d01596e | 2017-02-20 00:04:42 -0600 | [diff] [blame] | 159 | Is Host Quiesced |
| 160 | [Documentation] Check if host state is quiesced. |
| 161 | ${host_state}= Get Host State |
Rahul Maheshwari | d01596e | 2017-02-20 00:04:42 -0600 | [diff] [blame] | 162 | ${status}= Run Keyword And Return Status Should Be Equal |
| 163 | ... ${host_state} Quiesced |
| 164 | [Return] ${status} |
| 165 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 166 | |
Rahul Maheshwari | 09439a2 | 2017-02-23 01:10:05 -0600 | [diff] [blame] | 167 | Recover Quiesced Host |
| 168 | [Documentation] Recover host from quisced state. |
| 169 | |
| 170 | ${resp}= Run Keyword And Return Status Is Host Quiesced |
| 171 | Run Keyword If '${resp}' == 'True' |
| 172 | ... Run Keywords Initiate Host PowerOff AND |
| 173 | ... Log HOST is recovered from quiesced state |
| 174 | |
| 175 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 176 | Get Host State |
| 177 | [Documentation] Return the state of the host as a string. |
| 178 | [Arguments] ${quiet}=${QUIET} |
| 179 | # quiet - Suppress REST output logging to console. |
| 180 | ${state}= |
| 181 | ... Read Attribute ${HOST_STATE_URI} CurrentHostState |
| 182 | ... quiet=${quiet} |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 183 | [Return] ${state.rsplit('.', 1)[1]} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 184 | |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 185 | Get Host Trans State |
| 186 | [Documentation] Return the transition state of host as a string. |
| 187 | ... e.g. On, Off, Reboot |
| 188 | [Arguments] ${quiet}=${QUIET} |
| 189 | # Description of arguments: |
| 190 | # quiet Suppress REST output logging to console. |
| 191 | |
| 192 | ${state}= |
| 193 | ... Read Attribute ${HOST_STATE_URI} RequestedHostTransition |
| 194 | ... quiet=${quiet} |
| 195 | [Return] ${state.rsplit('.', 1)[1]} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 196 | |
| 197 | Get Chassis Power State |
| 198 | [Documentation] Return the power state of the Chassis |
| 199 | ... as a string. |
| 200 | [Arguments] ${quiet}=${QUIET} |
| 201 | # quiet - Suppress REST output logging to console. |
| 202 | ${state}= |
| 203 | ... Read Attribute ${CHASSIS_STATE_URI} CurrentPowerState |
| 204 | ... quiet=${quiet} |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 205 | [Return] ${state.rsplit('.', 1)[1]} |
Rahul Maheshwari | 2f8de6c | 2017-01-17 07:00:22 -0600 | [diff] [blame] | 206 | |
| 207 | |
| 208 | Get BMC State |
| 209 | [Documentation] Return the state of the BMC. |
| 210 | [Arguments] ${quiet}=${QUIET} |
| 211 | # quiet - Suppress REST output logging to console. |
| 212 | ${state}= |
| 213 | ... Read Attribute ${BMC_STATE_URI} CurrentBMCState quiet=${quiet} |
| 214 | [Return] ${state.rsplit('.', 1)[1]} |
| 215 | |
| 216 | |
| 217 | Put BMC State |
| 218 | [Documentation] Put BMC in given state. |
| 219 | [Arguments] ${expected_state} |
| 220 | # expected_state - expected BMC state |
| 221 | |
| 222 | ${bmc_state}= Get BMC State |
| 223 | Run Keyword If '${bmc_state}' == '${expected_state}' |
| 224 | ... Log BMC is already in ${expected_state} state |
| 225 | ... ELSE Run Keywords Initiate BMC Reboot AND |
| 226 | ... Wait for BMC state ${expected_state} |
| 227 | |
| 228 | |
| 229 | Initiate BMC Reboot |
| 230 | [Documentation] Initiate BMC reboot. |
| 231 | ${args}= Create Dictionary data=${BMC_REBOOT_TRANS} |
Rahul Maheshwari | 55a68e2 | 2017-04-20 04:36:21 -0500 | [diff] [blame] | 232 | |
| 233 | Run Keyword And Ignore Error Write Attribute |
Rahul Maheshwari | 2f8de6c | 2017-01-17 07:00:22 -0600 | [diff] [blame] | 234 | ... ${BMC_STATE_URI} RequestedBMCTransition data=${args} |
| 235 | |
| 236 | ${session_active}= Check If BMC Reboot Is Initiated |
| 237 | Run Keyword If '${session_active}' == '${True}' |
| 238 | ... Fail msg=BMC Reboot didn't occur |
| 239 | |
| 240 | Check If BMC is Up |
| 241 | |
| 242 | Check If BMC Reboot Is Initiated |
| 243 | [Documentation] Checks whether BMC Reboot is initiated by checking |
| 244 | ... BMC connection loss. |
| 245 | # Reboot adds 3 seconds delay before forcing reboot |
| 246 | # To minimize race conditions, we wait for 7 seconds |
| 247 | Sleep 7s |
| 248 | ${alive}= Run Keyword and Return Status |
| 249 | ... Open Connection And Log In |
| 250 | Return From Keyword If '${alive}' == '${False}' ${False} |
| 251 | [Return] ${True} |
| 252 | |
| 253 | Is BMC Ready |
| 254 | [Documentation] Check if BMC state is Ready. |
| 255 | ${bmc_state}= Get BMC State |
| 256 | Should Be Equal ${BMC_READY_STATE} ${bmc_state} |
| 257 | |
| 258 | Is BMC Not Ready |
| 259 | [Documentation] Check if BMC state is Not Ready. |
| 260 | ${bmc_state}= Get BMC State |
| 261 | Should Be Equal ${BMC_NOT_READY_STATE} ${bmc_state} |
| 262 | |
| 263 | Wait for BMC state |
| 264 | [Documentation] Wait until given BMC state is reached. |
| 265 | [Arguments] ${state} |
| 266 | # state - BMC state to wait for |
| 267 | Run Keyword If '${state}' == '${BMC_READY_STATE}' |
| 268 | ... Wait Until Keyword Succeeds |
| 269 | ... 10 min 10 sec Is BMC Ready |
| 270 | ... ELSE IF '${state}' == '${BMC_NOT_READY_STATE}' |
| 271 | ... Wait Until Keyword Succeeds |
| 272 | ... 10 min 10 sec Is BMC Not Ready |
| 273 | ... ELSE Fail msg=Invalid BMC state |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 274 | |
| 275 | |
| 276 | Set State Interface Version |
| 277 | [Documentation] Set version to indicate which interface to use. |
Rahul Maheshwari | 073f8ad | 2017-03-02 00:55:22 -0600 | [diff] [blame] | 278 | ${resp}= Openbmc Get Request ${CHASSIS_STATE_URI} |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 279 | ${status}= Run Keyword And Return Status |
| 280 | ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 281 | Run Keyword If '${status}' == '${True}' |
| 282 | ... Set Global Variable ${OBMC_STATES_VERSION} ${1} |
| 283 | ... ELSE |
| 284 | ... Set Global Variable ${OBMC_STATES_VERSION} ${0} |
| 285 | |
| 286 | |
| 287 | Power Off Request |
| 288 | [Documentation] Select appropriate poweroff keyword. |
Rahul Maheshwari | 073f8ad | 2017-03-02 00:55:22 -0600 | [diff] [blame] | 289 | Run Keyword If '${OBMC_STATES_VERSION}' == '${0}' |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 290 | ... Initiate Power Off |
| 291 | ... ELSE |
| 292 | ... Initiate Host PowerOff |
| 293 | |
| 294 | |
| 295 | Wait For BMC Ready |
| 296 | [Documentation] Check BMC state and wait for BMC Ready. |
| 297 | @{states}= Create List BMC_READY HOST_POWERED_OFF |
Rahul Maheshwari | 073f8ad | 2017-03-02 00:55:22 -0600 | [diff] [blame] | 298 | Run Keyword If '${OBMC_STATES_VERSION}' == '${0}' |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 299 | ... Wait Until Keyword Succeeds 10 min 10 sec |
| 300 | ... Verify BMC State ${states} |
| 301 | ... ELSE |
| 302 | ... Wait Until Keyword Succeeds 10 min 10 sec |
| 303 | ... Is BMC Ready |
| 304 | |
| 305 | |