1*** Settings *** 2Resource ../lib/resource.txt 3Resource ../lib/rest_client.robot 4Resource ../lib/connection_client.robot 5 6Library OperatingSystem 7 8*** Variables *** 9${SYSTEM_SHUTDOWN_TIME} ${5} 10 11*** Keywords *** 12Wait For Host To Ping 13 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min 14 ... ${interval}=5 sec 15 16 # host The DNS name or IP of the host to ping. 17 # timeout The amount of time after which attempts to ping cease. 18 # interval The amount of time in between attempts to ping. 19 20 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host} 21 22Ping Host 23 [Arguments] ${host} 24 Should Not Be Empty ${host} msg=No host provided 25 ${RC} ${output} = Run and return RC and Output ping -c 4 ${host} 26 Log RC: ${RC}\nOutput:\n${output} 27 Should be equal ${RC} ${0} 28 29Get Boot Progress 30 ${state} = Read Attribute /org/openbmc/sensors/host/BootProgress value 31 [return] ${state} 32 33Is Power On 34 ${state}= Get Power State 35 Should be equal ${state} ${1} 36 37Is Power Off 38 ${state}= Get Power State 39 Should be equal ${state} ${0} 40 41Initiate Power On 42 [Documentation] Initiates the power on and waits until the Is Power On 43 ... keyword returns that the power state has switched to on. 44 @{arglist}= Create List 45 ${args}= Create Dictionary data=@{arglist} 46 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOn data=${args} 47 should be equal as strings ${resp.status_code} ${HTTP_OK} 48 Wait Until Keyword Succeeds 3 min 10 sec Is Power On 49 50Initiate Power Off 51 [Documentation] Initiates the power off and waits until the Is Power Off 52 ... keyword returns that the power state has switched to off. 53 @{arglist}= Create List 54 ${args}= Create Dictionary data=@{arglist} 55 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOff data=${args} 56 should be equal as strings ${resp.status_code} ${HTTP_OK} 57 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off 58 59Trigger Warm Reset 60 log to console "Triggering warm reset" 61 ${data} = create dictionary data=@{EMPTY} 62 ${resp} = openbmc post request /org/openbmc/control/bmc0/action/warmReset data=${data} 63 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} 64 Sleep ${SYSTEM_SHUTDOWN_TIME}min 65 Wait For Host To Ping ${OPENBMC_HOST} 66 67Check OS 68 [Documentation] Attempts to ping the host OS and then checks that the host 69 ... OS is up by running an SSH command. 70 71 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 72 ... ${os_password}=${OS_PASSWORD} 73 [Teardown] Close Connection 74 75 # os_host The DNS name/IP of the OS host associated with our BMC. 76 # os_username The username to be used to sign on to the OS host. 77 # os_password The password to be used to sign on to the OS host. 78 79 # Attempt to ping the OS. Store the return code to check later. 80 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host} 81 82 Open connection ${os_host} 83 Login ${os_username} ${os_password} 84 85 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True 86 ... return_rc=True 87 88 # If the return code returned by "Execute Command" is non-zero, this keyword 89 # will fail. 90 Should Be Equal ${rc} ${0} 91 # We will likewise fail if there is any stderr data. 92 Should Be Empty ${stderr} 93 94 # We will likewise fail if the OS did not ping, as we could SSH but not ping 95 Should Be Equal As Strings ${ping_rc} ${TRUE} 96 97Wait for OS 98 [Documentation] Waits for the host OS to come up via calls to "Check OS". 99 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 100 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT} 101 102 # os_host The DNS name or IP of the OS host associated with our 103 # BMC. 104 # os_username The username to be used to sign on to the OS host. 105 # os_password The password to be used to sign on to the OS host. 106 # timeout The timeout in seconds indicating how long you're 107 # willing to wait for the OS to respond. 108 109 # The interval to be used between calls to "Check OS". 110 ${interval}= Set Variable 5 111 112 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS 113 ... ${os_host} ${os_username} ${os_password} 114 115Get BMC State 116 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY) 117 @{arglist}= Create List 118 ${args}= Create Dictionary data=@{arglist} 119 ${resp}= Call Method /org/openbmc/managers/System/ getSystemState 120 ... data=${args} 121 Should be equal as strings ${resp.status_code} ${HTTP_OK} 122 ${content}= to json ${resp.content} 123 [return] ${content["data"]} 124 125Get Power State 126 [Documentation] Returns the power state as an integer. Either 0 or 1. 127 @{arglist}= Create List 128 ${args}= Create Dictionary data=@{arglist} 129 ${resp}= Call Method /org/openbmc/control/chassis0/ getPowerState 130 ... data=${args} 131 Should be equal as strings ${resp.status_code} ${HTTP_OK} 132 ${content}= to json ${resp.content} 133 [return] ${content["data"]} 134 135Clear BMC Record Log 136 [Documentation] Clears all the event logs on the BMC. This would be 137 ... equivalent to ipmitool sel clear. 138 @{arglist}= Create List 139 ${args}= Create Dictionary data=@{arglist} 140 ${resp}= Call Method /org/openbmc/records/events/ clear data=${args} 141 should be equal as strings ${resp.status_code} ${HTTP_OK} 142 143Copy PNOR to BMC 144 Import Library SCPLibrary WITH NAME scp 145 Open Connection for SCP 146 Log Copying ${PNOR_IMAGE_PATH} to /tmp 147 scp.Put File ${PNOR_IMAGE_PATH} /tmp 148 149Flash PNOR 150 [Documentation] Calls flash bios update method to flash PNOR image 151 [arguments] ${pnor_image} 152 @{arglist}= Create List ${pnor_image} 153 ${args}= Create Dictionary data=@{arglist} 154 ${resp}= Call Method /org/openbmc/control/flash/bios/ update data=${args} 155 should be equal as strings ${resp.status_code} ${HTTP_OK} 156 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing 157 158Get Flash BIOS Status 159 [Documentation] Returns the status of the flash BIOS API as a string. For 160 ... example 'Flashing', 'Flash Done', etc 161 ${data}= Read Properties /org/openbmc/control/flash/bios 162 [return] ${data['status']} 163 164Is PNOR Flashing 165 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR 166 ... flashing has started. 167 ${status}= Get Flash BIOS Status 168 should be equal as strings ${status} Flashing 169 170Is PNOR Flash Done 171 [Documentation] Get BIOS 'Flash Done' status. This indicates that the 172 ... PNOR flashing has completed. 173 ${status}= Get Flash BIOS Status 174 should be equal as strings ${status} Flash Done 175 176Is System State Host Booted 177 [Documentation] Checks whether system state is HOST_BOOTED. 178 ${state}= Get BMC State 179 should be equal as strings ${state} HOST_BOOTED 180 181Verify Ping and REST Authentication 182 ${l_ping} = Run Keyword And Return Status 183 ... Ping Host ${OPENBMC_HOST} 184 Return From Keyword If '${l_ping}' == '${False}' ${False} 185 186 ${l_rest} = Run Keyword And Return Status 187 ... Initialize OpenBMC 188 Return From Keyword If '${l_rest}' == '${False}' ${False} 189 190 # Just to make sure the SSH is working for SCP 191 Open Connection And Log In 192 ${system} ${stderr}= Execute Command hostname return_stderr=True 193 Should Be Empty ${stderr} 194 195 [return] ${True} 196