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