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 |
| 4 | |
| 5 | Library OperatingSystem |
| 6 | |
| 7 | *** Variables *** |
| 8 | ${SYSTEM_SHUTDOWN_TIME} ${5} |
| 9 | |
| 10 | *** Keywords *** |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 11 | Wait For Host To Ping |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 12 | [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min |
| 13 | ... ${interval}=5 sec |
| 14 | |
| 15 | # host The DNS name or IP of the host to ping. |
| 16 | # timeout The amount of time after which attempts to ping cease. |
| 17 | # interval The amount of time in between attempts to ping. |
| 18 | |
| 19 | Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 20 | |
| 21 | Ping Host |
| 22 | [Arguments] ${host} |
| 23 | ${RC} ${output} = Run and return RC and Output ping -c 4 ${host} |
| 24 | Log RC: ${RC}\nOutput:\n${output} |
| 25 | Should be equal ${RC} ${0} |
| 26 | |
| 27 | Get Boot Progress |
| 28 | ${state} = Read Attribute /org/openbmc/sensors/host/BootProgress value |
| 29 | [return] ${state} |
| 30 | |
| 31 | Is Power On |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 32 | ${state}= Get Power State |
| 33 | Should be equal ${state} ${1} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 34 | |
| 35 | Is Power Off |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 36 | ${state}= Get Power State |
| 37 | Should be equal ${state} ${0} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 38 | |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 39 | Initiate Power On |
| 40 | [Documentation] Initiates the power on and waits until the Is Power On |
| 41 | ... keyword returns that the power state has switched to on. |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 42 | @{arglist}= Create List |
| 43 | ${args}= Create Dictionary data=@{arglist} |
| 44 | ${resp}= Call Method /org/openbmc/control/chassis0/ powerOn data=${args} |
| 45 | should be equal as strings ${resp.status_code} ${HTTP_OK} |
| 46 | Wait Until Keyword Succeeds 3 min 10 sec Is Power On |
| 47 | |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 48 | Initiate Power Off |
| 49 | [Documentation] Initiates the power off and waits until the Is Power Off |
| 50 | ... keyword returns that the power state has switched to off. |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 51 | @{arglist}= Create List |
| 52 | ${args}= Create Dictionary data=@{arglist} |
| 53 | ${resp}= Call Method /org/openbmc/control/chassis0/ powerOff data=${args} |
| 54 | should be equal as strings ${resp.status_code} ${HTTP_OK} |
| 55 | Wait Until Keyword Succeeds 1 min 10 sec Is Power Off |
| 56 | |
| 57 | Trigger Warm Reset |
| 58 | log to console "Triggering warm reset" |
| 59 | ${data} = create dictionary data=@{EMPTY} |
| 60 | ${resp} = openbmc post request /org/openbmc/control/bmc0/action/warmReset data=${data} |
| 61 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 62 | Sleep ${SYSTEM_SHUTDOWN_TIME}min |
| 63 | Wait For Host To Ping ${OPENBMC_HOST} |
Michael Walsh | 49ab0f4 | 2016-07-20 11:44:33 -0500 | [diff] [blame] | 64 | |
| 65 | Check OS |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 66 | [Documentation] Attempts to ping the host OS and then checks that the host |
| 67 | ... OS is up by running an SSH command. |
Michael Walsh | 49ab0f4 | 2016-07-20 11:44:33 -0500 | [diff] [blame] | 68 | |
| 69 | [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} |
| 70 | ... ${os_password}=${OS_PASSWORD} |
| 71 | [Teardown] Close Connection |
| 72 | |
| 73 | # os_host The DNS name/IP of the OS host associated with our BMC. |
| 74 | # os_username The username to be used to sign on to the OS host. |
| 75 | # os_password The password to be used to sign on to the OS host. |
| 76 | |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 77 | # Attempt to ping the OS. Store the return code to check later. |
| 78 | ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host} |
| 79 | |
Michael Walsh | 49ab0f4 | 2016-07-20 11:44:33 -0500 | [diff] [blame] | 80 | Open connection ${os_host} |
| 81 | Login ${os_username} ${os_password} |
| 82 | |
| 83 | ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True |
| 84 | ... return_rc=True |
| 85 | |
| 86 | # If the return code returned by "Execute Command" is non-zero, this keyword |
| 87 | # will fail. |
| 88 | Should Be Equal ${rc} ${0} |
| 89 | # We will likewise fail if there is any stderr data. |
| 90 | Should Be Empty ${stderr} |
| 91 | |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 92 | # We will likewise fail if the OS did not ping, as we could SSH but not ping |
| 93 | Should Be Equal As Strings ${ping_rc} ${TRUE} |
| 94 | |
Michael Walsh | 49ab0f4 | 2016-07-20 11:44:33 -0500 | [diff] [blame] | 95 | Wait for OS |
| 96 | [Documentation] Waits for the host OS to come up via calls to "Check OS". |
| 97 | [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} |
| 98 | ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT} |
| 99 | |
| 100 | # os_host The DNS name or IP of the OS host associated with our |
| 101 | # BMC. |
| 102 | # os_username The username to be used to sign on to the OS host. |
| 103 | # os_password The password to be used to sign on to the OS host. |
| 104 | # timeout The timeout in seconds indicating how long you're |
| 105 | # willing to wait for the OS to respond. |
| 106 | |
| 107 | # The interval to be used between calls to "Check OS". |
| 108 | ${interval}= Set Variable 5 |
| 109 | |
| 110 | Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS |
| 111 | ... ${os_host} ${os_username} ${os_password} |
root | 442f0ef | 2016-08-04 20:23:05 +0000 | [diff] [blame] | 112 | |
| 113 | Get BMC State |
| 114 | [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY) |
| 115 | @{arglist}= Create List |
| 116 | ${args}= Create Dictionary data=@{arglist} |
| 117 | ${resp}= Call Method /org/openbmc/managers/System/ getSystemState |
| 118 | ... data=${args} |
| 119 | Should be equal as strings ${resp.status_code} ${HTTP_OK} |
| 120 | ${content}= to json ${resp.content} |
| 121 | [return] ${content["data"]} |
| 122 | |
| 123 | Get Power State |
| 124 | [Documentation] Returns the power state as an integer. Either 0 or 1. |
| 125 | @{arglist}= Create List |
| 126 | ${args}= Create Dictionary data=@{arglist} |
| 127 | ${resp}= Call Method /org/openbmc/control/chassis0/ getPowerState |
| 128 | ... data=${args} |
| 129 | Should be equal as strings ${resp.status_code} ${HTTP_OK} |
| 130 | ${content}= to json ${resp.content} |
| 131 | [return] ${content["data"]} |