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# "1" indicates that the new "xyz" interface should be used. 12${OBMC_STATES_VERSION} ${1} 13 14*** Keywords *** 15 16Initiate Host Boot 17 [Documentation] Initiate host power on. 18 [Arguments] ${wait}=${1} 19 20 # Description of argument(s): 21 # wait Indicates that this keyword should wait for host running state. 22 23 ${args}= Create Dictionary data=${HOST_POWERON_TRANS} 24 Write Attribute 25 ... ${HOST_STATE_URI} RequestedHostTransition data=${args} 26 27 # Does caller want to wait for status? 28 Run Keyword If '${wait}' == '${0}' Return From Keyword 29 30 Wait Until Keyword Succeeds 31 ... 10 min 10 sec Is Host Running 32 33 34Initiate Host PowerOff 35 [Documentation] Initiate host power off. 36 # 1. Request soft power off 37 # 2. Hard power off, if failed. 38 [Arguments] ${wait}=${1} 39 40 # Description of argument(s): 41 # wait Indicates that this keyword should wait for host off state. 42 43 ${args}= Create Dictionary data=${HOST_POWEROFF_TRANS} 44 Write Attribute 45 ... ${HOST_STATE_URI} RequestedHostTransition data=${args} 46 47 # Does caller want to wait for status? 48 Run Keyword If '${wait}' == '${0}' Return From Keyword 49 50 ${status}= Run Keyword And Return Status Wait For PowerOff 51 52 Run Keyword if '${status}' == '${False}' Hard Power Off 53 54 55Wait For PowerOff 56 [Documentation] Wait for power off state. 57 58 # Revert to 3 minutes once fixed. 59 Wait Until Keyword Succeeds 6 min 10 sec Is Host Off 60 61 62Hard Power Off 63 [Documentation] Do a hard power off. 64 [Arguments] ${wait}=${1} 65 66 # Description of argument(s): 67 # wait Indicates that this keyword should wait for host off state. 68 69 ${args}= Create Dictionary data=${CHASSIS_POWEROFF_TRANS} 70 Write Attribute 71 ... ${CHASSIS_STATE_URI} RequestedPowerTransition data=${args} 72 73 # Does caller want to wait for status? 74 Run Keyword If '${wait}' == '${0}' Return From Keyword 75 76 Wait Until Keyword Succeeds 77 ... 1 min 10 sec Run Keywords Is Chassis Off AND Is Host Off 78 79 80Initiate Host Reboot 81 [Documentation] Initiate host reboot via REST. 82 [Arguments] ${wait}=${1} 83 84 # Description of argument(s): 85 # wait Indicates that this keyword should wait for host reboot state. 86 87 ${args}= Create Dictionary data=${HOST_REBOOT_TRANS} 88 Write Attribute 89 ... ${HOST_STATE_URI} RequestedHostTransition data=${args} 90 91 # Does caller want to wait for host booted status? 92 Run Keyword If '${wait}' == '${0}' Return From Keyword 93 94 Is Host Rebooted 95 96 97Is Host Running 98 [Documentation] Check if host state is "Running". 99 # Chassis state should be "On" before we check the host state. 100 Is Chassis On 101 ${host_state}= Get Host State 102 Should Be Equal Running ${host_state} 103 # Check to verify that the host is really booted. 104 Is OS Booted 105 106 107Get Host State Attribute 108 [Documentation] Return the state of the host as a string. 109 [Arguments] ${host_attribute} ${quiet}=${QUIET} 110 111 # Description of argument(s): 112 # host_attribute Host attribute name. 113 # quiet Suppress REST output logging to console. 114 115 ${HOST_STATE_URI}= Set Variable If '${PLATFORM_ARCH_TYPE}' == 'x86' and '${host_attribute}' == 'OperatingSystemState' 116 ... ${OS_STATE_URI} ${HOST_STATE_URI} 117 118 ${state}= 119 ... Read Attribute ${HOST_STATE_URI} ${host_attribute} quiet=${quiet} 120 RETURN ${state} 121 122 123Is OS Booted 124 [Documentation] Check OS status. 125 126 # Example: 127 # "/xyz/openbmc_project/state/host0": { 128 # "AttemptsLeft": 0, 129 # "BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart", 130 # "CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Running", 131 # "OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.BootComplete", 132 # "RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.On" 133 # } 134 135 ${boot_stage}= Get Host State Attribute BootProgress 136 Should Be Equal ${OS_BOOT_START} ${boot_stage} 137 138 ${os_state}= Get Host State Attribute OperatingSystemState 139 Should Be Equal ${OS_BOOT_COMPLETE} ${os_state} 140 141 142Is Host Off 143 [Documentation] Check if host state is "Off". 144 145 # Chassis state should be "Off" before we check the host state. 146 Is Chassis Off 147 ${host_state}= Get Host State 148 Should Be Equal Off ${host_state} 149 150 151Is Host Rebooted 152 [Documentation] Checks if host rebooted. 153 154 ${host_trans_state}= Get Host Trans State 155 Should Be Equal ${host_trans_state} Reboot 156 Is Host Running 157 158 159Is Chassis On 160 [Documentation] Check if chassis state is "On". 161 ${power_state}= Get Chassis Power State 162 Should Be Equal On ${power_state} 163 164 165Is Chassis Off 166 [Documentation] Check if chassis state is "Off". 167 ${power_state}= Get Chassis Power State 168 Should Be Equal Off ${power_state} 169 170Is Host Quiesced 171 [Documentation] Check if host state is quiesced. 172 ${host_state}= Get Host State 173 ${status}= Run Keyword And Return Status Should Be Equal 174 ... ${host_state} Quiesced 175 RETURN ${status} 176 177 178Recover Quiesced Host 179 [Documentation] Recover host from quisced state. 180 181 ${resp}= Run Keyword And Return Status Is Host Quiesced 182 Run Keyword If '${resp}' == 'True' 183 ... Run Keywords Initiate Host PowerOff AND 184 ... Log HOST is recovered from quiesced state 185 186 187Get Host State 188 [Documentation] Return the state of the host as a string. 189 [Arguments] ${quiet}=${QUIET} 190 # quiet - Suppress REST output logging to console. 191 ${state}= 192 ... Read Attribute ${HOST_STATE_URI} CurrentHostState 193 ... quiet=${quiet} 194 RETURN ${state.rsplit('.', 1)[1]} 195 196Get Host Trans State 197 [Documentation] Return the transition state of host as a string. 198 ... e.g. On, Off, Reboot 199 [Arguments] ${quiet}=${QUIET} 200 # Description of arguments: 201 # quiet Suppress REST output logging to console. 202 203 ${state}= 204 ... Read Attribute ${HOST_STATE_URI} RequestedHostTransition 205 ... quiet=${quiet} 206 RETURN ${state.rsplit('.', 1)[1]} 207 208Get Chassis Power State 209 [Documentation] Return the power state of the Chassis 210 ... as a string. 211 [Arguments] ${quiet}=${QUIET} 212 # quiet - Suppress REST output logging to console. 213 ${state}= 214 ... Read Attribute ${CHASSIS_STATE_URI} CurrentPowerState 215 ... quiet=${quiet} 216 RETURN ${state.rsplit('.', 1)[1]} 217 218 219Get BMC State 220 [Documentation] Return the state of the BMC. 221 [Arguments] ${quiet}=${QUIET} 222 # quiet - Suppress REST output logging to console. 223 ${state}= 224 ... Read Attribute ${BMC_STATE_URI} CurrentBMCState quiet=${quiet} 225 RETURN ${state.rsplit('.', 1)[1]} 226 227 228Put BMC State 229 [Documentation] Put BMC in given state. 230 [Arguments] ${expected_state} 231 # expected_state - expected BMC state 232 233 ${bmc_state}= Get BMC State 234 Run Keyword If '${bmc_state}' == '${expected_state}' 235 ... Log BMC is already in ${expected_state} state 236 ... ELSE 237 ... OBMC Reboot (off) 238 239Initiate BMC Reboot 240 [Documentation] Initiate BMC reboot. 241 [Arguments] ${wait}=${1} 242 243 # Description of argument(s): 244 # wait Indicates that this keyword should wait for ending state.. 245 246 ${args}= Create Dictionary data=${BMC_REBOOT_TRANS} 247 248 Run Keyword And Ignore Error Write Attribute 249 ... ${BMC_STATE_URI} RequestedBMCTransition data=${args} 250 251 # Does caller want to wait for status? 252 Run Keyword If '${wait}' == '${0}' Return From Keyword 253 254 ${session_active}= Check If BMC Reboot Is Initiated 255 Run Keyword If '${session_active}' == '${True}' 256 ... Fail msg=BMC Reboot didn't occur. 257 258 Check If BMC is Up 259 260Check If BMC Reboot Is Initiated 261 [Documentation] Checks whether BMC Reboot is initiated by checking 262 ... BMC connection loss. 263 # Reboot adds 3 seconds delay before forcing reboot 264 # To minimize race conditions, we wait for 7 seconds 265 Sleep 7s 266 ${alive}= Run Keyword and Return Status 267 ... Open Connection And Log In 268 Return From Keyword If '${alive}' == '${False}' ${False} 269 RETURN ${True} 270 271Is BMC Ready 272 [Documentation] Check if BMC state is Ready. 273 ${bmc_state}= Get BMC State 274 Should Be Equal ${BMC_READY_STATE} ${bmc_state} 275 276Is BMC Not Ready 277 [Documentation] Check if BMC state is Not Ready. 278 ${bmc_state}= Get BMC State 279 Should Be Equal ${BMC_NOT_READY_STATE} ${bmc_state} 280 281Wait for BMC state 282 [Documentation] Wait until given BMC state is reached. 283 [Arguments] ${state} 284 # state - BMC state to wait for 285 Run Keyword If '${state}' == '${BMC_READY_STATE}' 286 ... Wait Until Keyword Succeeds 287 ... 10 min 10 sec Is BMC Ready 288 ... ELSE IF '${state}' == '${BMC_NOT_READY_STATE}' 289 ... Wait Until Keyword Succeeds 290 ... 10 min 10 sec Is BMC Not Ready 291 ... ELSE Fail msg=Invalid BMC state 292 293 294Set State Interface Version 295 [Documentation] Set version to indicate which interface to use. 296 ${resp}= Openbmc Get Request ${CHASSIS_STATE_URI} 297 ${status}= Run Keyword And Return Status 298 ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} 299 Run Keyword If '${status}' == '${True}' 300 ... Set Global Variable ${OBMC_STATES_VERSION} ${1} 301 ... ELSE 302 ... Set Global Variable ${OBMC_STATES_VERSION} ${0} 303 304 305Power Off Request 306 [Documentation] Select appropriate poweroff keyword. 307 Run Keyword If '${OBMC_STATES_VERSION}' == '${0}' 308 ... Initiate Power Off 309 ... ELSE 310 ... Initiate Host PowerOff 311 312 313Wait For BMC Ready 314 [Documentation] Check BMC state and wait for BMC Ready. 315 Wait Until Keyword Succeeds 10 min 10 sec Is BMC Ready 316 317 318Get Host State Via Redfish 319 [Documentation] Return the state of the host Via Redfish as a string. 320 321 ${powerstate}= 322 ... Redfish.Get Attribute ${REDFISH_CHASSIS_URI}/${CHASSIS_ID} PowerState 323 324 RETURN ${powerstate} 325