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 | |
| 36 | Is Host Running |
| 37 | [Documentation] Check if Chassis and Host state is ON. |
| 38 | ${power_state}= Get Chassis Power State |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 39 | Should Be Equal On ${power_state} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 40 | ${host_state}= Get Host State |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 41 | Should Be Equal Running ${host_state} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 42 | |
| 43 | |
| 44 | Is Host Off |
| 45 | [Documentation] Check if Chassis and Host state is OFF. |
| 46 | ${power_state}= Get Chassis Power State |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 47 | Should Be Equal Off ${power_state} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 48 | ${host_state}= Get Host State |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 49 | Should Be Equal Off ${host_state} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 50 | |
Rahul Maheshwari | d01596e | 2017-02-20 00:04:42 -0600 | [diff] [blame] | 51 | Is Host Quiesced |
| 52 | [Documentation] Check if host state is quiesced. |
| 53 | ${host_state}= Get Host State |
| 54 | Should Be Equal Quiesced ${host_state} |
| 55 | ${status}= Run Keyword And Return Status Should Be Equal |
| 56 | ... ${host_state} Quiesced |
| 57 | [Return] ${status} |
| 58 | |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 59 | |
| 60 | Get Host State |
| 61 | [Documentation] Return the state of the host as a string. |
| 62 | [Arguments] ${quiet}=${QUIET} |
| 63 | # quiet - Suppress REST output logging to console. |
| 64 | ${state}= |
| 65 | ... Read Attribute ${HOST_STATE_URI} CurrentHostState |
| 66 | ... quiet=${quiet} |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 67 | [Return] ${state.rsplit('.', 1)[1]} |
George Keishing | b88df3d | 2017-01-10 07:28:08 -0600 | [diff] [blame] | 68 | |
| 69 | |
| 70 | Get Chassis Power State |
| 71 | [Documentation] Return the power state of the Chassis |
| 72 | ... as a string. |
| 73 | [Arguments] ${quiet}=${QUIET} |
| 74 | # quiet - Suppress REST output logging to console. |
| 75 | ${state}= |
| 76 | ... Read Attribute ${CHASSIS_STATE_URI} CurrentPowerState |
| 77 | ... quiet=${quiet} |
George Keishing | 59d6cb4 | 2017-01-19 08:26:03 -0600 | [diff] [blame] | 78 | [Return] ${state.rsplit('.', 1)[1]} |
Rahul Maheshwari | 2f8de6c | 2017-01-17 07:00:22 -0600 | [diff] [blame] | 79 | |
| 80 | |
| 81 | Get BMC State |
| 82 | [Documentation] Return the state of the BMC. |
| 83 | [Arguments] ${quiet}=${QUIET} |
| 84 | # quiet - Suppress REST output logging to console. |
| 85 | ${state}= |
| 86 | ... Read Attribute ${BMC_STATE_URI} CurrentBMCState quiet=${quiet} |
| 87 | [Return] ${state.rsplit('.', 1)[1]} |
| 88 | |
| 89 | |
| 90 | Put BMC State |
| 91 | [Documentation] Put BMC in given state. |
| 92 | [Arguments] ${expected_state} |
| 93 | # expected_state - expected BMC state |
| 94 | |
| 95 | ${bmc_state}= Get BMC State |
| 96 | Run Keyword If '${bmc_state}' == '${expected_state}' |
| 97 | ... Log BMC is already in ${expected_state} state |
| 98 | ... ELSE Run Keywords Initiate BMC Reboot AND |
| 99 | ... Wait for BMC state ${expected_state} |
| 100 | |
| 101 | |
| 102 | Initiate BMC Reboot |
| 103 | [Documentation] Initiate BMC reboot. |
| 104 | ${args}= Create Dictionary data=${BMC_REBOOT_TRANS} |
| 105 | Write Attribute |
| 106 | ... ${BMC_STATE_URI} RequestedBMCTransition data=${args} |
| 107 | |
| 108 | ${session_active}= Check If BMC Reboot Is Initiated |
| 109 | Run Keyword If '${session_active}' == '${True}' |
| 110 | ... Fail msg=BMC Reboot didn't occur |
| 111 | |
| 112 | Check If BMC is Up |
| 113 | |
| 114 | Check If BMC Reboot Is Initiated |
| 115 | [Documentation] Checks whether BMC Reboot is initiated by checking |
| 116 | ... BMC connection loss. |
| 117 | # Reboot adds 3 seconds delay before forcing reboot |
| 118 | # To minimize race conditions, we wait for 7 seconds |
| 119 | Sleep 7s |
| 120 | ${alive}= Run Keyword and Return Status |
| 121 | ... Open Connection And Log In |
| 122 | Return From Keyword If '${alive}' == '${False}' ${False} |
| 123 | [Return] ${True} |
| 124 | |
| 125 | Is BMC Ready |
| 126 | [Documentation] Check if BMC state is Ready. |
| 127 | ${bmc_state}= Get BMC State |
| 128 | Should Be Equal ${BMC_READY_STATE} ${bmc_state} |
| 129 | |
| 130 | Is BMC Not Ready |
| 131 | [Documentation] Check if BMC state is Not Ready. |
| 132 | ${bmc_state}= Get BMC State |
| 133 | Should Be Equal ${BMC_NOT_READY_STATE} ${bmc_state} |
| 134 | |
| 135 | Wait for BMC state |
| 136 | [Documentation] Wait until given BMC state is reached. |
| 137 | [Arguments] ${state} |
| 138 | # state - BMC state to wait for |
| 139 | Run Keyword If '${state}' == '${BMC_READY_STATE}' |
| 140 | ... Wait Until Keyword Succeeds |
| 141 | ... 10 min 10 sec Is BMC Ready |
| 142 | ... ELSE IF '${state}' == '${BMC_NOT_READY_STATE}' |
| 143 | ... Wait Until Keyword Succeeds |
| 144 | ... 10 min 10 sec Is BMC Not Ready |
| 145 | ... ELSE Fail msg=Invalid BMC state |
George Keishing | 43a021f | 2017-01-30 11:10:13 -0600 | [diff] [blame] | 146 | |
| 147 | |
| 148 | Set State Interface Version |
| 149 | [Documentation] Set version to indicate which interface to use. |
| 150 | ${resp}= Openbmc Get Request ${CONTROL_URI}chassis0 |
| 151 | ${status}= Run Keyword And Return Status |
| 152 | ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 153 | Run Keyword If '${status}' == '${True}' |
| 154 | ... Set Global Variable ${OBMC_STATES_VERSION} ${1} |
| 155 | ... ELSE |
| 156 | ... Set Global Variable ${OBMC_STATES_VERSION} ${0} |
| 157 | |
| 158 | |
| 159 | Power Off Request |
| 160 | [Documentation] Select appropriate poweroff keyword. |
| 161 | Run Keyword If '${OBMC_STATES_VERSION}' == '${1}' |
| 162 | ... Initiate Power Off |
| 163 | ... ELSE |
| 164 | ... Initiate Host PowerOff |
| 165 | |
| 166 | |
| 167 | Wait For BMC Ready |
| 168 | [Documentation] Check BMC state and wait for BMC Ready. |
| 169 | @{states}= Create List BMC_READY HOST_POWERED_OFF |
| 170 | Run Keyword If '${OBMC_STATES_VERSION}' == '${1}' |
| 171 | ... Wait Until Keyword Succeeds 10 min 10 sec |
| 172 | ... Verify BMC State ${states} |
| 173 | ... ELSE |
| 174 | ... Wait Until Keyword Succeeds 10 min 10 sec |
| 175 | ... Is BMC Ready |
| 176 | |
| 177 | |