blob: 5590e9be0a3b02e45511f1e2befcecb2004d0d99 [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
George Keishing30c12ff2016-09-02 10:25:29 -05005Library DateTime
6Library Process
Chris Austenb29d2e82016-06-07 12:25:35 -05007Library OperatingSystem
8
9*** Variables ***
10${SYSTEM_SHUTDOWN_TIME} ${5}
Sivas SRRe1143ae2016-08-26 22:31:02 -050011${dbuscmdBase} = dbus-send --system --print-reply --dest=org.openbmc.settings.Host
12${dbuscmdGet} = /org/openbmc/settings/host0 org.freedesktop.DBus.Properties.Get
13${dbuscmdString} = string:"org.openbmc.settings.Host" string:
Chris Austenb29d2e82016-06-07 12:25:35 -050014
15*** Keywords ***
Chris Austenb29d2e82016-06-07 12:25:35 -050016Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000017 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
18 ... ${interval}=5 sec
19
20 # host The DNS name or IP of the host to ping.
21 # timeout The amount of time after which attempts to ping cease.
22 # interval The amount of time in between attempts to ping.
23
24 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050025
26Ping Host
27 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050028 Should Not Be Empty ${host} msg=No host provided
Chris Austenb29d2e82016-06-07 12:25:35 -050029 ${RC} ${output} = Run and return RC and Output ping -c 4 ${host}
30 Log RC: ${RC}\nOutput:\n${output}
31 Should be equal ${RC} ${0}
32
33Get Boot Progress
34 ${state} = Read Attribute /org/openbmc/sensors/host/BootProgress value
35 [return] ${state}
36
37Is Power On
root442f0ef2016-08-04 20:23:05 +000038 ${state}= Get Power State
39 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -050040
41Is Power Off
root442f0ef2016-08-04 20:23:05 +000042 ${state}= Get Power State
43 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050044
root442f0ef2016-08-04 20:23:05 +000045Initiate Power On
46 [Documentation] Initiates the power on and waits until the Is Power On
47 ... keyword returns that the power state has switched to on.
Chris Austenb29d2e82016-06-07 12:25:35 -050048 @{arglist}= Create List
49 ${args}= Create Dictionary data=@{arglist}
50 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOn data=${args}
51 should be equal as strings ${resp.status_code} ${HTTP_OK}
Gunnar Millsbb398ac2016-11-14 11:50:22 -060052 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
Chris Austenb29d2e82016-06-07 12:25:35 -050053
Rahul Maheshwarif684ba72016-10-25 07:24:41 -050054
root442f0ef2016-08-04 20:23:05 +000055Initiate Power Off
56 [Documentation] Initiates the power off and waits until the Is Power Off
57 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -050058 @{arglist}= Create List
59 ${args}= Create Dictionary data=@{arglist}
60 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOff data=${args}
61 should be equal as strings ${resp.status_code} ${HTTP_OK}
Gunnar Millsbb398ac2016-11-14 11:50:22 -060062 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
Chris Austenb29d2e82016-06-07 12:25:35 -050063
64Trigger Warm Reset
65 log to console "Triggering warm reset"
66 ${data} = create dictionary data=@{EMPTY}
67 ${resp} = openbmc post request /org/openbmc/control/bmc0/action/warmReset data=${data}
68 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingb3700812016-08-31 03:03:30 -050069 ${session_active}= Check If warmReset is Initiated
70 Run Keyword If '${session_active}' == '${True}'
71 ... Fail msg=warm reset didn't occur
72
Chris Austenb29d2e82016-06-07 12:25:35 -050073 Sleep ${SYSTEM_SHUTDOWN_TIME}min
74 Wait For Host To Ping ${OPENBMC_HOST}
Michael Walsh49ab0f42016-07-20 11:44:33 -050075
76Check OS
root442f0ef2016-08-04 20:23:05 +000077 [Documentation] Attempts to ping the host OS and then checks that the host
78 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -050079
80 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
81 ... ${os_password}=${OS_PASSWORD}
82 [Teardown] Close Connection
83
84 # os_host The DNS name/IP of the OS host associated with our BMC.
85 # os_username The username to be used to sign on to the OS host.
86 # os_password The password to be used to sign on to the OS host.
87
root442f0ef2016-08-04 20:23:05 +000088 # Attempt to ping the OS. Store the return code to check later.
89 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
90
Michael Walsh49ab0f42016-07-20 11:44:33 -050091 Open connection ${os_host}
92 Login ${os_username} ${os_password}
93
94 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
95 ... return_rc=True
96
97 # If the return code returned by "Execute Command" is non-zero, this keyword
98 # will fail.
99 Should Be Equal ${rc} ${0}
100 # We will likewise fail if there is any stderr data.
101 Should Be Empty ${stderr}
102
root442f0ef2016-08-04 20:23:05 +0000103 # We will likewise fail if the OS did not ping, as we could SSH but not ping
104 Should Be Equal As Strings ${ping_rc} ${TRUE}
105
Michael Walsh49ab0f42016-07-20 11:44:33 -0500106Wait for OS
107 [Documentation] Waits for the host OS to come up via calls to "Check OS".
108 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
109 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
110
111 # os_host The DNS name or IP of the OS host associated with our
112 # BMC.
113 # os_username The username to be used to sign on to the OS host.
114 # os_password The password to be used to sign on to the OS host.
115 # timeout The timeout in seconds indicating how long you're
116 # willing to wait for the OS to respond.
117
118 # The interval to be used between calls to "Check OS".
119 ${interval}= Set Variable 5
120
121 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
122 ... ${os_host} ${os_username} ${os_password}
root442f0ef2016-08-04 20:23:05 +0000123
124Get BMC State
125 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
126 @{arglist}= Create List
127 ${args}= Create Dictionary data=@{arglist}
128 ${resp}= Call Method /org/openbmc/managers/System/ getSystemState
129 ... data=${args}
130 Should be equal as strings ${resp.status_code} ${HTTP_OK}
131 ${content}= to json ${resp.content}
132 [return] ${content["data"]}
133
134Get Power State
135 [Documentation] Returns the power state as an integer. Either 0 or 1.
136 @{arglist}= Create List
137 ${args}= Create Dictionary data=@{arglist}
138 ${resp}= Call Method /org/openbmc/control/chassis0/ getPowerState
139 ... data=${args}
140 Should be equal as strings ${resp.status_code} ${HTTP_OK}
141 ${content}= to json ${resp.content}
142 [return] ${content["data"]}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500143
144Clear BMC Record Log
145 [Documentation] Clears all the event logs on the BMC. This would be
146 ... equivalent to ipmitool sel clear.
147 @{arglist}= Create List
148 ${args}= Create Dictionary data=@{arglist}
149 ${resp}= Call Method /org/openbmc/records/events/ clear data=${args}
150 should be equal as strings ${resp.status_code} ${HTTP_OK}
151
152Copy PNOR to BMC
153 Import Library SCPLibrary WITH NAME scp
154 Open Connection for SCP
155 Log Copying ${PNOR_IMAGE_PATH} to /tmp
156 scp.Put File ${PNOR_IMAGE_PATH} /tmp
157
158Flash PNOR
159 [Documentation] Calls flash bios update method to flash PNOR image
160 [arguments] ${pnor_image}
161 @{arglist}= Create List ${pnor_image}
162 ${args}= Create Dictionary data=@{arglist}
163 ${resp}= Call Method /org/openbmc/control/flash/bios/ update data=${args}
164 should be equal as strings ${resp.status_code} ${HTTP_OK}
165 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing
166
167Get Flash BIOS Status
168 [Documentation] Returns the status of the flash BIOS API as a string. For
169 ... example 'Flashing', 'Flash Done', etc
170 ${data}= Read Properties /org/openbmc/control/flash/bios
171 [return] ${data['status']}
172
173Is PNOR Flashing
174 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR
175 ... flashing has started.
176 ${status}= Get Flash BIOS Status
177 should be equal as strings ${status} Flashing
178
179Is PNOR Flash Done
180 [Documentation] Get BIOS 'Flash Done' status. This indicates that the
181 ... PNOR flashing has completed.
Leah McNutt9ba32272016-11-17 15:48:39 +0000182 ${status}= Get Flash BIOS Status
Jay Azurine4c52eb2016-08-16 20:51:10 -0500183 should be equal as strings ${status} Flash Done
184
185Is System State Host Booted
186 [Documentation] Checks whether system state is HOST_BOOTED.
187 ${state}= Get BMC State
188 should be equal as strings ${state} HOST_BOOTED
George Keishing5e870cd2016-08-24 10:05:47 -0500189
190Verify Ping and REST Authentication
191 ${l_ping} = Run Keyword And Return Status
192 ... Ping Host ${OPENBMC_HOST}
George Keishingc4d3dc02016-09-19 03:45:55 -0500193 Run Keyword If '${l_ping}' == '${False}'
194 ... Fail msg=Ping Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500195
196 ${l_rest} = Run Keyword And Return Status
197 ... Initialize OpenBMC
George Keishingc4d3dc02016-09-19 03:45:55 -0500198 Run Keyword If '${l_rest}' == '${False}'
199 ... Fail msg=REST Authentication Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500200
201 # Just to make sure the SSH is working for SCP
202 Open Connection And Log In
203 ${system} ${stderr}= Execute Command hostname return_stderr=True
204 Should Be Empty ${stderr}
205
George Keishingc4d3dc02016-09-19 03:45:55 -0500206
207Check If BMC is Up
208 [Documentation] Wait for Host to be online. Checks every X seconds
209 ... interval for Y minutes and fails if timed out.
210 ... Default MAX timedout is 10 min, interval 10 seconds.
Leah McNuttf9689502016-11-03 15:38:08 +0000211 [arguments] ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
George Keishingc4d3dc02016-09-19 03:45:55 -0500212 ... ${interval}=10 sec
213
214 Wait Until Keyword Succeeds
215 ... ${max_timeout} ${interval} Verify Ping and REST Authentication
216
George Keishingb3700812016-08-31 03:03:30 -0500217
218Check If warmReset is Initiated
219 [Documentation] Ping would be still alive, so try SSH to connect
220 ... if fails the ports are down indicating reboot
221 ... is in progress
222 ${alive}= Run Keyword and Return Status
223 ... Open Connection And Log In
224 Return From Keyword If '${alive}' == '${False}' ${False}
225 [return] ${True}
226
George Keishing06ae4aa2016-08-30 01:41:28 -0500227Flush REST Sessions
228 [Documentation] Removes all the active session objects
229 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500230
Sivas SRRe1143ae2016-08-26 22:31:02 -0500231Initialize DBUS cmd
232 [Documentation] Initialize dbus string with property string to extract
233 [arguments] ${boot_property}
234 ${cmd} = Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
235 ${cmd} = Catenate ${cmd}${boot_property}
236 Set Global Variable ${dbuscmd} ${cmd}
237
George Keishing30c12ff2016-09-02 10:25:29 -0500238
239Start SOL Console Logging
240 [Documentation] Start logging to a file in /tmp so that it can
241 ... be read by any other test cases. Stop existing
242 ... running client processes if there is any.
243 ... By default logging at /tmp/obmc-console.log else
244 ... user input location.
245 ... The File is appended with datetime and pid of
246 ... process which created this log file.
247 [Arguments] ${file_path}=/tmp/obmc-console.log
248
249 Open Connection And Log In
250
251 ${cur_time}= Get Time Stamp
252 Set Global Variable ${LOG_TIME} ${cur_time}
253 Start Command
254 ... obmc-console-client > ${file_path}-${LOG_TIME}_$$
255
256
257Stop SOL Console Logging
258 [Documentation] Login to BMC and Stop the obmc-console-client process.
259 ... Find the pids from the log to filter the one started by
260 ... specific test datetime and stop that process only.
261 ... Ignore if there is no process running and return message
262 ... "No obmc-console-client process running"
263 ... By default retrieving log from /tmp/obmc-console.log else
264 ... user input location.
265 [Arguments] ${file_path}=/tmp/obmc-console.log
266
267 Open Connection And Log In
268
269 ${pid} ${stderr} =
270 ... Execute Command
271 ... ls ${file_path}-${LOG_TIME}_* | cut -d'_' -f 2
272 ... return_stderr=True
George Keishing30c12ff2016-09-02 10:25:29 -0500273 Should Be Empty ${stderr}
274
George Keishingd4678952016-10-12 04:29:28 -0500275 ${rc}=
276 ... Execute Command
277 ... ps ax | grep ${pid} | grep -v grep
278 ... return_stdout=False return_rc=True
279
280 Return From Keyword If '${rc}' == '${1}'
281 ... No obmc-console-client process running
282
George Keishing30c12ff2016-09-02 10:25:29 -0500283 ${console} ${stderr}=
284 ... Execute Command kill -s KILL ${pid}
285 ... return_stderr=True
286 Should Be Empty ${stderr}
George Keishingd4678952016-10-12 04:29:28 -0500287 Log Current Client PID:${pid}
George Keishing30c12ff2016-09-02 10:25:29 -0500288
289 ${console} ${stderr}=
290 ... Execute Command
291 ... cat ${file_path}-${LOG_TIME}_${pid}
292 ... return_stderr=True
293 Should Be Empty ${stderr}
294
295 [Return] ${console}
296
297
298Get Time Stamp
299 [Documentation] Get the current time stamp data
300 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
301 [return] ${cur_time}
302
George Keishing1b150202016-09-29 08:51:58 -0500303
304Verify BMC State
305 [Documentation] Get the BMC state and verify if the current
306 ... BMC state is as expected.
307 [Arguments] ${expected}
308
309 ${current}= Get BMC State
George Keishing8db0e1b2016-10-20 13:46:54 -0500310 Should Contain ${expected} ${current}
George Keishing1b150202016-09-29 08:51:58 -0500311
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500312Start Journal Log
313 [Documentation] Start capturing journal log to a file in /tmp using
314 ... journalctl command. By default journal log is collected
315 ... at /tmp/journal_log else user input location.
316 ... The File is appended with datetime.
317 [Arguments] ${file_path}=/tmp/journal_log
318
319 Open Connection And Log In
320
321 ${cur_time}= Get Time Stamp
322 Set Global Variable ${LOG_TIME} ${cur_time}
323 Start Command
324 ... journalctl -f > ${file_path}-${LOG_TIME}
325 Log Journal Log Started: ${file_path}-${LOG_TIME}
326
327Stop Journal Log
328 [Documentation] Stop journalctl process if its running.
329 ... By default return log from /tmp/journal_log else
330 ... user input location.
331 [Arguments] ${file_path}=/tmp/journal_log
332
333 Open Connection And Log In
334
335 ${rc}=
336 ... Execute Command
337 ... ps ax | grep journalctl | grep -v grep
338 ... return_stdout=False return_rc=True
339
340 Return From Keyword If '${rc}' == '${1}'
341 ... No journal log process running
342
343 ${output} ${stderr}=
344 ... Execute Command killall journalctl
345 ... return_stderr=True
346 Should Be Empty ${stderr}
347
348 ${journal_log} ${stderr}=
349 ... Execute Command
350 ... cat ${file_path}-${LOG_TIME}
351 ... return_stderr=True
352 Should Be Empty ${stderr}
353
354 Log ${journal_log}
355
356 Execute Command rm ${file_path}-${LOG_TIME}
357
358 [Return] ${journal_log}
359