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