blob: 2a4a01fd0d4e9bface43e91c427b1d27045fb8ea [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
2Resource ../lib/resource.txt
3Resource ../lib/rest_client.robot
George Keishing5e870cd2016-08-24 10:05:47 -05004Resource ../lib/connection_client.robot
Chris Austenb29d2e82016-06-07 12:25:35 -05005
6Library OperatingSystem
7
8*** Variables ***
9${SYSTEM_SHUTDOWN_TIME} ${5}
10
11*** Keywords ***
Chris Austenb29d2e82016-06-07 12:25:35 -050012Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000013 [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 Austenb29d2e82016-06-07 12:25:35 -050021
22Ping Host
23 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050024 Should Not Be Empty ${host} msg=No host provided
Chris Austenb29d2e82016-06-07 12:25:35 -050025 ${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
root442f0ef2016-08-04 20:23:05 +000034 ${state}= Get Power State
35 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -050036
37Is Power Off
root442f0ef2016-08-04 20:23:05 +000038 ${state}= Get Power State
39 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050040
root442f0ef2016-08-04 20:23:05 +000041Initiate 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 Austenb29d2e82016-06-07 12:25:35 -050044 @{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
root442f0ef2016-08-04 20:23:05 +000050Initiate 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 Austenb29d2e82016-06-07 12:25:35 -050053 @{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}
George Keishingb3700812016-08-31 03:03:30 -050064 ${session_active}= Check If warmReset is Initiated
65 Run Keyword If '${session_active}' == '${True}'
66 ... Fail msg=warm reset didn't occur
67
Chris Austenb29d2e82016-06-07 12:25:35 -050068 Sleep ${SYSTEM_SHUTDOWN_TIME}min
69 Wait For Host To Ping ${OPENBMC_HOST}
Michael Walsh49ab0f42016-07-20 11:44:33 -050070
71Check OS
root442f0ef2016-08-04 20:23:05 +000072 [Documentation] Attempts to ping the host OS and then checks that the host
73 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -050074
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
root442f0ef2016-08-04 20:23:05 +000083 # 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 Walsh49ab0f42016-07-20 11:44:33 -050086 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
root442f0ef2016-08-04 20:23:05 +000098 # 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 Walsh49ab0f42016-07-20 11:44:33 -0500101Wait 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}
root442f0ef2016-08-04 20:23:05 +0000118
119Get 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
129Get 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 Azurine4c52eb2016-08-16 20:51:10 -0500138
139Clear 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
147Copy 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
153Flash 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
162Get 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
168Is 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
174Is 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
180Is 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 Keishing5e870cd2016-08-24 10:05:47 -0500184
185Verify 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 Keishingb3700812016-08-31 03:03:30 -0500200
201Check 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
210