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. |
Michael Walsh | 67ef622 | 2017-03-21 14:48:26 -0500 | [diff] [blame] | 36 | [Arguments] ${wait}=${1} |
| 37 | |
| 38 | # Description of arguments: |
| 39 | # wait Indicates that this keyword should wait for host off state. |
| 40 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 41 | ${args}= Create Dictionary data=${HOST_POWEROFF_TRANS} |
| 42 | Write Attribute |
| 43 | ... ${HOST_STATE_URI} RequestedHostTransition data=${args} |
| 44 | |
Michael Walsh | 67ef622 | 2017-03-21 14:48:26 -0500 | [diff] [blame] | 45 | # Does caller want to wait for status? |
| 46 | Run Keyword If '${wait}' == '${0}' Return From Keyword |
| 47 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 48 | Wait Until Keyword Succeeds |
| 49 | ... 3 min 10 sec Is Host Off |
| 50 | |
| 51 | |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 52 | Initiate Host Reboot |
| 53 | [Documentation] Initiate host reboot via REST. |
| 54 | |
| 55 | ${args}= Create Dictionary data=${HOST_REBOOT_TRANS} |
| 56 | Write Attribute |
| 57 | ... ${HOST_STATE_URI} RequestedHostTransition data=${args} |
| 58 | Is Host Rebooted |
| 59 | |
| 60 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 61 | Is Host Running |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 62 | [Documentation] Check if host state is "Running". |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 63 | ${host_state}= Get Host State |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 64 | Should Be Equal Running ${host_state} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 65 | |
| 66 | |
| 67 | Is Host Off |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 68 | [Documentation] Check if host state is "Off". |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 69 | ${host_state}= Get Host State |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 70 | Should Be Equal Off ${host_state} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 71 | |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 72 | |
| 73 | Is Host Rebooted |
| 74 | [Documentation] Checks if host rebooted. |
| 75 | |
| 76 | ${host_trans_state}= Get Host Trans State |
| 77 | Should Be Equal ${host_trans_state} Reboot |
| 78 | Is Host Running |
| 79 | |
| 80 | |
| 81 | Is Chassis On |
| 82 | [Documentation] Check if chassis state is "On". |
| 83 | ${power_state}= Get Chassis Power State |
| 84 | Should Be Equal On ${power_state} |
| 85 | |
| 86 | |
| 87 | Is Chassis Off |
| 88 | [Documentation] Check if chassis state is "Off". |
| 89 | ${power_state}= Get Chassis Power State |
| 90 | Should Be Equal Off ${power_state} |
| 91 | |
Rahul Maheshwari | d01596e | 2017-02-20 00:04:42 -0600 | [diff] [blame] | 92 | Is Host Quiesced |
| 93 | [Documentation] Check if host state is quiesced. |
| 94 | ${host_state}= Get Host State |
Rahul Maheshwari | d01596e | 2017-02-20 00:04:42 -0600 | [diff] [blame] | 95 | ${status}= Run Keyword And Return Status Should Be Equal |
| 96 | ... ${host_state} Quiesced |
| 97 | [Return] ${status} |
| 98 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 99 | |
Rahul Maheshwari | 09439a2 | 2017-02-23 01:10:05 -0600 | [diff] [blame] | 100 | Recover Quiesced Host |
| 101 | [Documentation] Recover host from quisced state. |
| 102 | |
| 103 | ${resp}= Run Keyword And Return Status Is Host Quiesced |
| 104 | Run Keyword If '${resp}' == 'True' |
| 105 | ... Run Keywords Initiate Host PowerOff AND |
| 106 | ... Log HOST is recovered from quiesced state |
| 107 | |
| 108 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 109 | Get Host State |
| 110 | [Documentation] Return the state of the host as a string. |
| 111 | [Arguments] ${quiet}=${QUIET} |
| 112 | # quiet - Suppress REST output logging to console. |
| 113 | ${state}= |
| 114 | ... Read Attribute ${HOST_STATE_URI} CurrentHostState |
| 115 | ... quiet=${quiet} |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 116 | [Return] ${state.rsplit('.', 1)[1]} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 117 | |
Rahul Maheshwari | f7ead24 | 2017-02-14 01:59:42 -0600 | [diff] [blame] | 118 | Get Host Trans State |
| 119 | [Documentation] Return the transition state of host as a string. |
| 120 | ... e.g. On, Off, Reboot |
| 121 | [Arguments] ${quiet}=${QUIET} |
| 122 | # Description of arguments: |
| 123 | # quiet Suppress REST output logging to console. |
| 124 | |
| 125 | ${state}= |
| 126 | ... Read Attribute ${HOST_STATE_URI} RequestedHostTransition |
| 127 | ... quiet=${quiet} |
| 128 | [Return] ${state.rsplit('.', 1)[1]} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 129 | |
| 130 | Get Chassis Power State |
| 131 | [Documentation] Return the power state of the Chassis |
| 132 | ... as a string. |
| 133 | [Arguments] ${quiet}=${QUIET} |
| 134 | # quiet - Suppress REST output logging to console. |
| 135 | ${state}= |
| 136 | ... Read Attribute ${CHASSIS_STATE_URI} CurrentPowerState |
| 137 | ... quiet=${quiet} |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 138 | [Return] ${state.rsplit('.', 1)[1]} |
Rahul Maheshwari | 2f8de6c | 2017-01-17 07:00:22 -0600 | [diff] [blame] | 139 | |
| 140 | |
| 141 | Get BMC State |
| 142 | [Documentation] Return the state of the BMC. |
| 143 | [Arguments] ${quiet}=${QUIET} |
| 144 | # quiet - Suppress REST output logging to console. |
| 145 | ${state}= |
| 146 | ... Read Attribute ${BMC_STATE_URI} CurrentBMCState quiet=${quiet} |
| 147 | [Return] ${state.rsplit('.', 1)[1]} |
| 148 | |
| 149 | |
| 150 | Put BMC State |
| 151 | [Documentation] Put BMC in given state. |
| 152 | [Arguments] ${expected_state} |
| 153 | # expected_state - expected BMC state |
| 154 | |
| 155 | ${bmc_state}= Get BMC State |
| 156 | Run Keyword If '${bmc_state}' == '${expected_state}' |
| 157 | ... Log BMC is already in ${expected_state} state |
| 158 | ... ELSE Run Keywords Initiate BMC Reboot AND |
| 159 | ... Wait for BMC state ${expected_state} |
| 160 | |
| 161 | |
| 162 | Initiate BMC Reboot |
| 163 | [Documentation] Initiate BMC reboot. |
| 164 | ${args}= Create Dictionary data=${BMC_REBOOT_TRANS} |
| 165 | Write Attribute |
| 166 | ... ${BMC_STATE_URI} RequestedBMCTransition data=${args} |
| 167 | |
| 168 | ${session_active}= Check If BMC Reboot Is Initiated |
| 169 | Run Keyword If '${session_active}' == '${True}' |
| 170 | ... Fail msg=BMC Reboot didn't occur |
| 171 | |
| 172 | Check If BMC is Up |
| 173 | |
| 174 | Check If BMC Reboot Is Initiated |
| 175 | [Documentation] Checks whether BMC Reboot is initiated by checking |
| 176 | ... BMC connection loss. |
| 177 | # Reboot adds 3 seconds delay before forcing reboot |
| 178 | # To minimize race conditions, we wait for 7 seconds |
| 179 | Sleep 7s |
| 180 | ${alive}= Run Keyword and Return Status |
| 181 | ... Open Connection And Log In |
| 182 | Return From Keyword If '${alive}' == '${False}' ${False} |
| 183 | [Return] ${True} |
| 184 | |
| 185 | Is BMC Ready |
| 186 | [Documentation] Check if BMC state is Ready. |
| 187 | ${bmc_state}= Get BMC State |
| 188 | Should Be Equal ${BMC_READY_STATE} ${bmc_state} |
| 189 | |
| 190 | Is BMC Not Ready |
| 191 | [Documentation] Check if BMC state is Not Ready. |
| 192 | ${bmc_state}= Get BMC State |
| 193 | Should Be Equal ${BMC_NOT_READY_STATE} ${bmc_state} |
| 194 | |
| 195 | Wait for BMC state |
| 196 | [Documentation] Wait until given BMC state is reached. |
| 197 | [Arguments] ${state} |
| 198 | # state - BMC state to wait for |
| 199 | Run Keyword If '${state}' == '${BMC_READY_STATE}' |
| 200 | ... Wait Until Keyword Succeeds |
| 201 | ... 10 min 10 sec Is BMC Ready |
| 202 | ... ELSE IF '${state}' == '${BMC_NOT_READY_STATE}' |
| 203 | ... Wait Until Keyword Succeeds |
| 204 | ... 10 min 10 sec Is BMC Not Ready |
| 205 | ... ELSE Fail msg=Invalid BMC state |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 206 | |
| 207 | |
| 208 | Set State Interface Version |
| 209 | [Documentation] Set version to indicate which interface to use. |
Rahul Maheshwari | 073f8ad | 2017-03-02 00:55:22 -0600 | [diff] [blame] | 210 | ${resp}= Openbmc Get Request ${CHASSIS_STATE_URI} |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 211 | ${status}= Run Keyword And Return Status |
| 212 | ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 213 | Run Keyword If '${status}' == '${True}' |
| 214 | ... Set Global Variable ${OBMC_STATES_VERSION} ${1} |
| 215 | ... ELSE |
| 216 | ... Set Global Variable ${OBMC_STATES_VERSION} ${0} |
| 217 | |
| 218 | |
| 219 | Power Off Request |
| 220 | [Documentation] Select appropriate poweroff keyword. |
Rahul Maheshwari | 073f8ad | 2017-03-02 00:55:22 -0600 | [diff] [blame] | 221 | Run Keyword If '${OBMC_STATES_VERSION}' == '${0}' |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 222 | ... Initiate Power Off |
| 223 | ... ELSE |
| 224 | ... Initiate Host PowerOff |
| 225 | |
| 226 | |
| 227 | Wait For BMC Ready |
| 228 | [Documentation] Check BMC state and wait for BMC Ready. |
| 229 | @{states}= Create List BMC_READY HOST_POWERED_OFF |
Rahul Maheshwari | 073f8ad | 2017-03-02 00:55:22 -0600 | [diff] [blame] | 230 | Run Keyword If '${OBMC_STATES_VERSION}' == '${0}' |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 231 | ... Wait Until Keyword Succeeds 10 min 10 sec |
| 232 | ... Verify BMC State ${states} |
| 233 | ... ELSE |
| 234 | ... Wait Until Keyword Succeeds 10 min 10 sec |
| 235 | ... Is BMC Ready |
| 236 | |
| 237 | |