Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Resource ../lib/resource.txt |
| 3 | Resource ../lib/rest_client.robot |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 4 | Resource ../lib/connection_client.robot |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 5 | |
| 6 | Library OperatingSystem |
| 7 | |
| 8 | *** Variables *** |
| 9 | ${SYSTEM_SHUTDOWN_TIME} ${5} |
| 10 | |
| 11 | *** Keywords *** |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 12 | Wait For Host To Ping |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 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} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 21 | |
| 22 | Ping Host |
| 23 | [Arguments] ${host} |
George Keishing | 8a84f95 | 2016-08-25 04:54:53 -0500 | [diff] [blame] | 24 | Should Not Be Empty ${host} msg=No host provided |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 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 | |
| 29 | Get Boot Progress |
| 30 | ${state} = Read Attribute /org/openbmc/sensors/host/BootProgress value |
| 31 | [return] ${state} |
| 32 | |
| 33 | Is Power On |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 34 | ${state}= Get Power State |
| 35 | Should be equal ${state} ${1} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 36 | |
| 37 | Is Power Off |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 38 | ${state}= Get Power State |
| 39 | Should be equal ${state} ${0} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 40 | |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 41 | Initiate 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. |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 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 | |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 50 | Initiate 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. |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 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 | |
| 59 | Trigger 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} |
George Keishing | b370081 | 2016-08-31 03:03:30 -0500 | [diff] [blame] | 64 | ${session_active}= Check If warmReset is Initiated |
| 65 | Run Keyword If '${session_active}' == '${True}' |
| 66 | ... Fail msg=warm reset didn't occur |
| 67 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 68 | Sleep ${SYSTEM_SHUTDOWN_TIME}min |
| 69 | Wait For Host To Ping ${OPENBMC_HOST} |
Michael Walsh | 49ab0f4 | 2016-07-20 11:44:33 -0500 | [diff] [blame] | 70 | |
| 71 | Check OS |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 72 | [Documentation] Attempts to ping the host OS and then checks that the host |
| 73 | ... OS is up by running an SSH command. |
Michael Walsh | 49ab0f4 | 2016-07-20 11:44:33 -0500 | [diff] [blame] | 74 | |
| 75 | [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} |
| 76 | ... ${os_password}=${OS_PASSWORD} |
| 77 | [Teardown] Close Connection |
| 78 | |
| 79 | # os_host The DNS name/IP of the OS host associated with our BMC. |
| 80 | # os_username The username to be used to sign on to the OS host. |
| 81 | # os_password The password to be used to sign on to the OS host. |
| 82 | |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 83 | # Attempt to ping the OS. Store the return code to check later. |
| 84 | ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host} |
| 85 | |
Michael Walsh | 49ab0f4 | 2016-07-20 11:44:33 -0500 | [diff] [blame] | 86 | Open connection ${os_host} |
| 87 | Login ${os_username} ${os_password} |
| 88 | |
| 89 | ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True |
| 90 | ... return_rc=True |
| 91 | |
| 92 | # If the return code returned by "Execute Command" is non-zero, this keyword |
| 93 | # will fail. |
| 94 | Should Be Equal ${rc} ${0} |
| 95 | # We will likewise fail if there is any stderr data. |
| 96 | Should Be Empty ${stderr} |
| 97 | |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 98 | # We will likewise fail if the OS did not ping, as we could SSH but not ping |
| 99 | Should Be Equal As Strings ${ping_rc} ${TRUE} |
| 100 | |
Michael Walsh | 49ab0f4 | 2016-07-20 11:44:33 -0500 | [diff] [blame] | 101 | Wait for OS |
| 102 | [Documentation] Waits for the host OS to come up via calls to "Check OS". |
| 103 | [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} |
| 104 | ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT} |
| 105 | |
| 106 | # os_host The DNS name or IP of the OS host associated with our |
| 107 | # BMC. |
| 108 | # os_username The username to be used to sign on to the OS host. |
| 109 | # os_password The password to be used to sign on to the OS host. |
| 110 | # timeout The timeout in seconds indicating how long you're |
| 111 | # willing to wait for the OS to respond. |
| 112 | |
| 113 | # The interval to be used between calls to "Check OS". |
| 114 | ${interval}= Set Variable 5 |
| 115 | |
| 116 | Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS |
| 117 | ... ${os_host} ${os_username} ${os_password} |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 118 | |
| 119 | Get BMC State |
| 120 | [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY) |
| 121 | @{arglist}= Create List |
| 122 | ${args}= Create Dictionary data=@{arglist} |
| 123 | ${resp}= Call Method /org/openbmc/managers/System/ getSystemState |
| 124 | ... data=${args} |
| 125 | Should be equal as strings ${resp.status_code} ${HTTP_OK} |
| 126 | ${content}= to json ${resp.content} |
| 127 | [return] ${content["data"]} |
| 128 | |
| 129 | Get Power State |
| 130 | [Documentation] Returns the power state as an integer. Either 0 or 1. |
| 131 | @{arglist}= Create List |
| 132 | ${args}= Create Dictionary data=@{arglist} |
| 133 | ${resp}= Call Method /org/openbmc/control/chassis0/ getPowerState |
| 134 | ... data=${args} |
| 135 | Should be equal as strings ${resp.status_code} ${HTTP_OK} |
| 136 | ${content}= to json ${resp.content} |
| 137 | [return] ${content["data"]} |
Jay Azurin | e4c52eb | 2016-08-16 20:51:10 -0500 | [diff] [blame] | 138 | |
| 139 | Clear BMC Record Log |
| 140 | [Documentation] Clears all the event logs on the BMC. This would be |
| 141 | ... equivalent to ipmitool sel clear. |
| 142 | @{arglist}= Create List |
| 143 | ${args}= Create Dictionary data=@{arglist} |
| 144 | ${resp}= Call Method /org/openbmc/records/events/ clear data=${args} |
| 145 | should be equal as strings ${resp.status_code} ${HTTP_OK} |
| 146 | |
| 147 | Copy PNOR to BMC |
| 148 | Import Library SCPLibrary WITH NAME scp |
| 149 | Open Connection for SCP |
| 150 | Log Copying ${PNOR_IMAGE_PATH} to /tmp |
| 151 | scp.Put File ${PNOR_IMAGE_PATH} /tmp |
| 152 | |
| 153 | Flash PNOR |
| 154 | [Documentation] Calls flash bios update method to flash PNOR image |
| 155 | [arguments] ${pnor_image} |
| 156 | @{arglist}= Create List ${pnor_image} |
| 157 | ${args}= Create Dictionary data=@{arglist} |
| 158 | ${resp}= Call Method /org/openbmc/control/flash/bios/ update data=${args} |
| 159 | should be equal as strings ${resp.status_code} ${HTTP_OK} |
| 160 | Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing |
| 161 | |
| 162 | Get Flash BIOS Status |
| 163 | [Documentation] Returns the status of the flash BIOS API as a string. For |
| 164 | ... example 'Flashing', 'Flash Done', etc |
| 165 | ${data}= Read Properties /org/openbmc/control/flash/bios |
| 166 | [return] ${data['status']} |
| 167 | |
| 168 | Is PNOR Flashing |
| 169 | [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR |
| 170 | ... flashing has started. |
| 171 | ${status}= Get Flash BIOS Status |
| 172 | should be equal as strings ${status} Flashing |
| 173 | |
| 174 | Is PNOR Flash Done |
| 175 | [Documentation] Get BIOS 'Flash Done' status. This indicates that the |
| 176 | ... PNOR flashing has completed. |
| 177 | ${status}= Get Flash BIOS Status |
| 178 | should be equal as strings ${status} Flash Done |
| 179 | |
| 180 | Is System State Host Booted |
| 181 | [Documentation] Checks whether system state is HOST_BOOTED. |
| 182 | ${state}= Get BMC State |
| 183 | should be equal as strings ${state} HOST_BOOTED |
George Keishing | 5e870cd | 2016-08-24 10:05:47 -0500 | [diff] [blame] | 184 | |
| 185 | Verify Ping and REST Authentication |
| 186 | ${l_ping} = Run Keyword And Return Status |
| 187 | ... Ping Host ${OPENBMC_HOST} |
| 188 | Return From Keyword If '${l_ping}' == '${False}' ${False} |
| 189 | |
| 190 | ${l_rest} = Run Keyword And Return Status |
| 191 | ... Initialize OpenBMC |
| 192 | Return From Keyword If '${l_rest}' == '${False}' ${False} |
| 193 | |
| 194 | # Just to make sure the SSH is working for SCP |
| 195 | Open Connection And Log In |
| 196 | ${system} ${stderr}= Execute Command hostname return_stderr=True |
| 197 | Should Be Empty ${stderr} |
| 198 | |
| 199 | [return] ${True} |
George Keishing | b370081 | 2016-08-31 03:03:30 -0500 | [diff] [blame] | 200 | |
| 201 | Check If warmReset is Initiated |
| 202 | [Documentation] Ping would be still alive, so try SSH to connect |
| 203 | ... if fails the ports are down indicating reboot |
| 204 | ... is in progress |
| 205 | ${alive}= Run Keyword and Return Status |
| 206 | ... Open Connection And Log In |
| 207 | Return From Keyword If '${alive}' == '${False}' ${False} |
| 208 | [return] ${True} |
| 209 | |
George Keishing | 06ae4aa | 2016-08-30 01:41:28 -0500 | [diff] [blame^] | 210 | Flush REST Sessions |
| 211 | [Documentation] Removes all the active session objects |
| 212 | Delete All Sessions |
George Keishing | b370081 | 2016-08-31 03:03:30 -0500 | [diff] [blame] | 213 | |