1*** Settings *** 2Resource ../lib/utils.robot 3Variables ../data/variables.py 4 5*** Variables *** 6 7${BMC_READY_STATE} Ready 8${BMC_NOT_READY_STATE} NotReady 9${QUIET} ${0} 10 11# "0" indicates that the new "xyz" interface should be used. 12${OBMC_STATES_VERSION} ${0} 13 14*** Keywords *** 15 16Initiate 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 26Initiate 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 36Initiate 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 45Is Host Running 46 [Documentation] Check if host state is "Running". 47 ${host_state}= Get Host State 48 Should Be Equal Running ${host_state} 49 50 51Is Host Off 52 [Documentation] Check if host state is "Off". 53 ${host_state}= Get Host State 54 Should Be Equal Off ${host_state} 55 56 57Is 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 65Is 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 71Is 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 76Is Host Quiesced 77 [Documentation] Check if host state is quiesced. 78 ${host_state}= Get Host State 79 Should Be Equal Quiesced ${host_state} 80 ${status}= Run Keyword And Return Status Should Be Equal 81 ... ${host_state} Quiesced 82 [Return] ${status} 83 84 85Get Host State 86 [Documentation] Return the state of the host as a string. 87 [Arguments] ${quiet}=${QUIET} 88 # quiet - Suppress REST output logging to console. 89 ${state}= 90 ... Read Attribute ${HOST_STATE_URI} CurrentHostState 91 ... quiet=${quiet} 92 [Return] ${state.rsplit('.', 1)[1]} 93 94Get Host Trans State 95 [Documentation] Return the transition state of host as a string. 96 ... e.g. On, Off, Reboot 97 [Arguments] ${quiet}=${QUIET} 98 # Description of arguments: 99 # quiet Suppress REST output logging to console. 100 101 ${state}= 102 ... Read Attribute ${HOST_STATE_URI} RequestedHostTransition 103 ... quiet=${quiet} 104 [Return] ${state.rsplit('.', 1)[1]} 105 106Get Chassis Power State 107 [Documentation] Return the power state of the Chassis 108 ... as a string. 109 [Arguments] ${quiet}=${QUIET} 110 # quiet - Suppress REST output logging to console. 111 ${state}= 112 ... Read Attribute ${CHASSIS_STATE_URI} CurrentPowerState 113 ... quiet=${quiet} 114 [Return] ${state.rsplit('.', 1)[1]} 115 116 117Get BMC State 118 [Documentation] Return the state of the BMC. 119 [Arguments] ${quiet}=${QUIET} 120 # quiet - Suppress REST output logging to console. 121 ${state}= 122 ... Read Attribute ${BMC_STATE_URI} CurrentBMCState quiet=${quiet} 123 [Return] ${state.rsplit('.', 1)[1]} 124 125 126Put BMC State 127 [Documentation] Put BMC in given state. 128 [Arguments] ${expected_state} 129 # expected_state - expected BMC state 130 131 ${bmc_state}= Get BMC State 132 Run Keyword If '${bmc_state}' == '${expected_state}' 133 ... Log BMC is already in ${expected_state} state 134 ... ELSE Run Keywords Initiate BMC Reboot AND 135 ... Wait for BMC state ${expected_state} 136 137 138Initiate BMC Reboot 139 [Documentation] Initiate BMC reboot. 140 ${args}= Create Dictionary data=${BMC_REBOOT_TRANS} 141 Write Attribute 142 ... ${BMC_STATE_URI} RequestedBMCTransition data=${args} 143 144 ${session_active}= Check If BMC Reboot Is Initiated 145 Run Keyword If '${session_active}' == '${True}' 146 ... Fail msg=BMC Reboot didn't occur 147 148 Check If BMC is Up 149 150Check If BMC Reboot Is Initiated 151 [Documentation] Checks whether BMC Reboot is initiated by checking 152 ... BMC connection loss. 153 # Reboot adds 3 seconds delay before forcing reboot 154 # To minimize race conditions, we wait for 7 seconds 155 Sleep 7s 156 ${alive}= Run Keyword and Return Status 157 ... Open Connection And Log In 158 Return From Keyword If '${alive}' == '${False}' ${False} 159 [Return] ${True} 160 161Is BMC Ready 162 [Documentation] Check if BMC state is Ready. 163 ${bmc_state}= Get BMC State 164 Should Be Equal ${BMC_READY_STATE} ${bmc_state} 165 166Is BMC Not Ready 167 [Documentation] Check if BMC state is Not Ready. 168 ${bmc_state}= Get BMC State 169 Should Be Equal ${BMC_NOT_READY_STATE} ${bmc_state} 170 171Wait for BMC state 172 [Documentation] Wait until given BMC state is reached. 173 [Arguments] ${state} 174 # state - BMC state to wait for 175 Run Keyword If '${state}' == '${BMC_READY_STATE}' 176 ... Wait Until Keyword Succeeds 177 ... 10 min 10 sec Is BMC Ready 178 ... ELSE IF '${state}' == '${BMC_NOT_READY_STATE}' 179 ... Wait Until Keyword Succeeds 180 ... 10 min 10 sec Is BMC Not Ready 181 ... ELSE Fail msg=Invalid BMC state 182 183 184Set State Interface Version 185 [Documentation] Set version to indicate which interface to use. 186 ${resp}= Openbmc Get Request ${CHASSIS_STATE_URI} 187 ${status}= Run Keyword And Return Status 188 ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} 189 Run Keyword If '${status}' == '${True}' 190 ... Set Global Variable ${OBMC_STATES_VERSION} ${1} 191 ... ELSE 192 ... Set Global Variable ${OBMC_STATES_VERSION} ${0} 193 194 195Power Off Request 196 [Documentation] Select appropriate poweroff keyword. 197 Run Keyword If '${OBMC_STATES_VERSION}' == '${0}' 198 ... Initiate Power Off 199 ... ELSE 200 ... Initiate Host PowerOff 201 202 203Wait For BMC Ready 204 [Documentation] Check BMC state and wait for BMC Ready. 205 @{states}= Create List BMC_READY HOST_POWERED_OFF 206 Run Keyword If '${OBMC_STATES_VERSION}' == '${0}' 207 ... Wait Until Keyword Succeeds 10 min 10 sec 208 ... Verify BMC State ${states} 209 ... ELSE 210 ... Wait Until Keyword Succeeds 10 min 10 sec 211 ... Is BMC Ready 212 213 214