blob: 76195c38812d2a2eb4839844f80a874a73eca1a2 [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
Michael Walsha6723f22016-11-22 11:12:01 -06008Library gen_print.py
9Library gen_robot_print.py
Chris Austenb29d2e82016-06-07 12:25:35 -050010
11*** Variables ***
12${SYSTEM_SHUTDOWN_TIME} ${5}
Michael Walsha6723f22016-11-22 11:12:01 -060013${dbuscmdBase}
14... dbus-send --system --print-reply --dest=org.openbmc.settings.Host
15${dbuscmdGet}
16... /org/openbmc/settings/host0 org.freedesktop.DBus.Properties.Get
17${dbuscmdString}= string:"org.openbmc.settings.Host" string:
18
19# Assign default value to QUIET for programs which may not define it.
20${QUIET} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050021
22*** Keywords ***
Chris Austenb29d2e82016-06-07 12:25:35 -050023Wait For Host To Ping
root442f0ef2016-08-04 20:23:05 +000024 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
25 ... ${interval}=5 sec
26
27 # host The DNS name or IP of the host to ping.
28 # timeout The amount of time after which attempts to ping cease.
29 # interval The amount of time in between attempts to ping.
30
31 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050032
33Ping Host
34 [Arguments] ${host}
George Keishing8a84f952016-08-25 04:54:53 -050035 Should Not Be Empty ${host} msg=No host provided
Michael Walsha6723f22016-11-22 11:12:01 -060036 ${RC} ${output}= Run and return RC and Output ping -c 4 ${host}
Chris Austenb29d2e82016-06-07 12:25:35 -050037 Log RC: ${RC}\nOutput:\n${output}
38 Should be equal ${RC} ${0}
39
40Get Boot Progress
Michael Walsha6723f22016-11-22 11:12:01 -060041 [Arguments] ${quiet}=${QUIET}
42
43 ${state}= Read Attribute /org/openbmc/sensors/host/BootProgress
44 ... value quiet=${quiet}
Chris Austenb29d2e82016-06-07 12:25:35 -050045 [return] ${state}
46
47Is Power On
root442f0ef2016-08-04 20:23:05 +000048 ${state}= Get Power State
49 Should be equal ${state} ${1}
Chris Austenb29d2e82016-06-07 12:25:35 -050050
51Is Power Off
root442f0ef2016-08-04 20:23:05 +000052 ${state}= Get Power State
53 Should be equal ${state} ${0}
Chris Austenb29d2e82016-06-07 12:25:35 -050054
root442f0ef2016-08-04 20:23:05 +000055Initiate Power On
56 [Documentation] Initiates the power on and waits until the Is Power On
57 ... keyword returns that the power state has switched to on.
Michael Walsha6723f22016-11-22 11:12:01 -060058 [Arguments] ${wait}=${1}
59
Chris Austenb29d2e82016-06-07 12:25:35 -050060 @{arglist}= Create List
61 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -060062 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOn
63 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -050064 should be equal as strings ${resp.status_code} ${HTTP_OK}
Chris Austenb29d2e82016-06-07 12:25:35 -050065
Michael Walsha6723f22016-11-22 11:12:01 -060066 # Does caller want to wait for power on status?
67 Run Keyword If '${wait}' == '${0}' Return From Keyword
68 Wait Until Keyword Succeeds 3 min 10 sec Is Power On
Rahul Maheshwarif684ba72016-10-25 07:24:41 -050069
root442f0ef2016-08-04 20:23:05 +000070Initiate Power Off
71 [Documentation] Initiates the power off and waits until the Is Power Off
72 ... keyword returns that the power state has switched to off.
Chris Austenb29d2e82016-06-07 12:25:35 -050073 @{arglist}= Create List
74 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -060075 ${resp}= Call Method /org/openbmc/control/chassis0/ powerOff
76 ... data=${args}
Chris Austenb29d2e82016-06-07 12:25:35 -050077 should be equal as strings ${resp.status_code} ${HTTP_OK}
Michael Walsha6723f22016-11-22 11:12:01 -060078 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off
Chris Austenb29d2e82016-06-07 12:25:35 -050079
80Trigger Warm Reset
81 log to console "Triggering warm reset"
Michael Walsha6723f22016-11-22 11:12:01 -060082 ${data}= create dictionary data=@{EMPTY}
83 ${resp}= openbmc post request /org/openbmc/control/bmc0/action/warmReset
84 ... data=${data}
Chris Austenb29d2e82016-06-07 12:25:35 -050085 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingb3700812016-08-31 03:03:30 -050086 ${session_active}= Check If warmReset is Initiated
87 Run Keyword If '${session_active}' == '${True}'
88 ... Fail msg=warm reset didn't occur
89
Chris Austenb29d2e82016-06-07 12:25:35 -050090 Sleep ${SYSTEM_SHUTDOWN_TIME}min
91 Wait For Host To Ping ${OPENBMC_HOST}
Michael Walsh49ab0f42016-07-20 11:44:33 -050092
93Check OS
root442f0ef2016-08-04 20:23:05 +000094 [Documentation] Attempts to ping the host OS and then checks that the host
95 ... OS is up by running an SSH command.
Michael Walsh49ab0f42016-07-20 11:44:33 -050096
97 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
Michael Walsha6723f22016-11-22 11:12:01 -060098 ... ${os_password}=${OS_PASSWORD} ${quiet}=${QUIET}
99 ... ${print_string}=${EMPTY}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500100 [Teardown] Close Connection
101
102 # os_host The DNS name/IP of the OS host associated with our BMC.
103 # os_username The username to be used to sign on to the OS host.
104 # os_password The password to be used to sign on to the OS host.
Michael Walsha6723f22016-11-22 11:12:01 -0600105 # quiet Indicates whether this keyword should write to console.
106 # print_string A string to be printed before checking the OS.
107
108 rprint ${print_string}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500109
root442f0ef2016-08-04 20:23:05 +0000110 # Attempt to ping the OS. Store the return code to check later.
111 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
112
Michael Walsh49ab0f42016-07-20 11:44:33 -0500113 Open connection ${os_host}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500114
Michael Walsha6723f22016-11-22 11:12:01 -0600115 ${status} ${msg}= Run Keyword And Ignore Error Login ${os_username}
116 ... ${os_password}
117 ${err_msg1}= Sprint Error ${msg}
118 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
119 Run Keyword If '${status}' == 'FAIL' Fail msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500120 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
121 ... return_rc=True
122
Michael Walsha6723f22016-11-22 11:12:01 -0600123 ${temp_msg}= Catenate Could not execute a command on the operating
124 ... system.\n
125 ${err_msg1}= Sprint Error ${temp_msg}
126 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
127
128 # If the return code returned by "Execute Command" is non-zero, this
129 # keyword will fail.
130 Should Be Equal ${rc} ${0} msg=${err_msg}
Michael Walsh49ab0f42016-07-20 11:44:33 -0500131 # We will likewise fail if there is any stderr data.
132 Should Be Empty ${stderr}
133
Michael Walsha6723f22016-11-22 11:12:01 -0600134 ${temp_msg}= Set Variable Could not ping the operating system.\n
135 ${err_msg1}= Sprint Error ${temp_msg}
136 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
137 # We will likewise fail if the OS did not ping, as we could SSH but not
138 # ping
139 Should Be Equal As Strings ${ping_rc} ${TRUE} msg=${err_msg}
root442f0ef2016-08-04 20:23:05 +0000140
Michael Walsh49ab0f42016-07-20 11:44:33 -0500141Wait for OS
142 [Documentation] Waits for the host OS to come up via calls to "Check OS".
143 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
144 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
Michael Walsha6723f22016-11-22 11:12:01 -0600145 ... ${quiet}=${0}
146 [Teardown] rprintn
Michael Walsh49ab0f42016-07-20 11:44:33 -0500147
148 # os_host The DNS name or IP of the OS host associated with our
149 # BMC.
150 # os_username The username to be used to sign on to the OS host.
151 # os_password The password to be used to sign on to the OS host.
152 # timeout The timeout in seconds indicating how long you're
153 # willing to wait for the OS to respond.
Michael Walsha6723f22016-11-22 11:12:01 -0600154 # quiet Indicates whether this keyword should write to console.
Michael Walsh49ab0f42016-07-20 11:44:33 -0500155
156 # The interval to be used between calls to "Check OS".
157 ${interval}= Set Variable 5
158
Michael Walsha6723f22016-11-22 11:12:01 -0600159 ${message}= Catenate Checking every ${interval} seconds for up to
160 ... ${timeout} seconds for the operating system to communicate.
161 rqprint_timen ${message}
162
Michael Walsh49ab0f42016-07-20 11:44:33 -0500163 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
164 ... ${os_host} ${os_username} ${os_password}
Michael Walsha6723f22016-11-22 11:12:01 -0600165 ... print_string=\#
166
167 rqprintn
168
169 rqprint_timen The operating system is now communicating.
root442f0ef2016-08-04 20:23:05 +0000170
171Get BMC State
172 [Documentation] Returns the state of the BMC as a string. (i.e: BMC_READY)
Michael Walsha6723f22016-11-22 11:12:01 -0600173 [Arguments] ${quiet}=${QUIET}
174
root442f0ef2016-08-04 20:23:05 +0000175 @{arglist}= Create List
176 ${args}= Create Dictionary data=@{arglist}
177 ${resp}= Call Method /org/openbmc/managers/System/ getSystemState
Michael Walsha6723f22016-11-22 11:12:01 -0600178 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000179 Should be equal as strings ${resp.status_code} ${HTTP_OK}
180 ${content}= to json ${resp.content}
181 [return] ${content["data"]}
182
183Get Power State
184 [Documentation] Returns the power state as an integer. Either 0 or 1.
Michael Walsha6723f22016-11-22 11:12:01 -0600185 [Arguments] ${quiet}=${QUIET}
186
root442f0ef2016-08-04 20:23:05 +0000187 @{arglist}= Create List
188 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -0600189
root442f0ef2016-08-04 20:23:05 +0000190 ${resp}= Call Method /org/openbmc/control/chassis0/ getPowerState
Michael Walsha6723f22016-11-22 11:12:01 -0600191 ... data=${args} quiet=${quiet}
root442f0ef2016-08-04 20:23:05 +0000192 Should be equal as strings ${resp.status_code} ${HTTP_OK}
193 ${content}= to json ${resp.content}
194 [return] ${content["data"]}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500195
196Clear BMC Record Log
197 [Documentation] Clears all the event logs on the BMC. This would be
198 ... equivalent to ipmitool sel clear.
199 @{arglist}= Create List
200 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -0600201 ${resp}= Call Method /org/openbmc/records/events/ clear data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500202 should be equal as strings ${resp.status_code} ${HTTP_OK}
203
204Copy PNOR to BMC
205 Import Library SCPLibrary WITH NAME scp
206 Open Connection for SCP
207 Log Copying ${PNOR_IMAGE_PATH} to /tmp
208 scp.Put File ${PNOR_IMAGE_PATH} /tmp
209
210Flash PNOR
211 [Documentation] Calls flash bios update method to flash PNOR image
212 [arguments] ${pnor_image}
213 @{arglist}= Create List ${pnor_image}
214 ${args}= Create Dictionary data=@{arglist}
Michael Walsha6723f22016-11-22 11:12:01 -0600215 ${resp}= Call Method /org/openbmc/control/flash/bios/ update
216 ... data=${args}
Jay Azurine4c52eb2016-08-16 20:51:10 -0500217 should be equal as strings ${resp.status_code} ${HTTP_OK}
218 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing
219
220Get Flash BIOS Status
221 [Documentation] Returns the status of the flash BIOS API as a string. For
222 ... example 'Flashing', 'Flash Done', etc
223 ${data}= Read Properties /org/openbmc/control/flash/bios
224 [return] ${data['status']}
225
226Is PNOR Flashing
227 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR
228 ... flashing has started.
229 ${status}= Get Flash BIOS Status
230 should be equal as strings ${status} Flashing
231
232Is PNOR Flash Done
233 [Documentation] Get BIOS 'Flash Done' status. This indicates that the
234 ... PNOR flashing has completed.
Leah McNutt9ba32272016-11-17 15:48:39 +0000235 ${status}= Get Flash BIOS Status
Jay Azurine4c52eb2016-08-16 20:51:10 -0500236 should be equal as strings ${status} Flash Done
237
238Is System State Host Booted
239 [Documentation] Checks whether system state is HOST_BOOTED.
240 ${state}= Get BMC State
241 should be equal as strings ${state} HOST_BOOTED
George Keishing5e870cd2016-08-24 10:05:47 -0500242
243Verify Ping and REST Authentication
Michael Walsha6723f22016-11-22 11:12:01 -0600244 ${l_ping}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500245 ... Ping Host ${OPENBMC_HOST}
George Keishingc4d3dc02016-09-19 03:45:55 -0500246 Run Keyword If '${l_ping}' == '${False}'
247 ... Fail msg=Ping Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500248
Michael Walsha6723f22016-11-22 11:12:01 -0600249 ${l_rest}= Run Keyword And Return Status
George Keishing5e870cd2016-08-24 10:05:47 -0500250 ... Initialize OpenBMC
George Keishingc4d3dc02016-09-19 03:45:55 -0500251 Run Keyword If '${l_rest}' == '${False}'
252 ... Fail msg=REST Authentication Failed
George Keishing5e870cd2016-08-24 10:05:47 -0500253
254 # Just to make sure the SSH is working for SCP
255 Open Connection And Log In
256 ${system} ${stderr}= Execute Command hostname return_stderr=True
257 Should Be Empty ${stderr}
258
George Keishingc4d3dc02016-09-19 03:45:55 -0500259Check If BMC is Up
260 [Documentation] Wait for Host to be online. Checks every X seconds
261 ... interval for Y minutes and fails if timed out.
262 ... Default MAX timedout is 10 min, interval 10 seconds.
Leah McNuttf9689502016-11-03 15:38:08 +0000263 [arguments] ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
George Keishingc4d3dc02016-09-19 03:45:55 -0500264 ... ${interval}=10 sec
265
266 Wait Until Keyword Succeeds
267 ... ${max_timeout} ${interval} Verify Ping and REST Authentication
268
George Keishingb3700812016-08-31 03:03:30 -0500269
270Check If warmReset is Initiated
271 [Documentation] Ping would be still alive, so try SSH to connect
272 ... if fails the ports are down indicating reboot
273 ... is in progress
274 ${alive}= Run Keyword and Return Status
275 ... Open Connection And Log In
276 Return From Keyword If '${alive}' == '${False}' ${False}
277 [return] ${True}
278
George Keishing06ae4aa2016-08-30 01:41:28 -0500279Flush REST Sessions
280 [Documentation] Removes all the active session objects
281 Delete All Sessions
George Keishingb3700812016-08-31 03:03:30 -0500282
Sivas SRRe1143ae2016-08-26 22:31:02 -0500283Initialize DBUS cmd
284 [Documentation] Initialize dbus string with property string to extract
285 [arguments] ${boot_property}
Michael Walsha6723f22016-11-22 11:12:01 -0600286 ${cmd}= Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
287 ${cmd}= Catenate ${cmd}${boot_property}
Sivas SRRe1143ae2016-08-26 22:31:02 -0500288 Set Global Variable ${dbuscmd} ${cmd}
289
George Keishing30c12ff2016-09-02 10:25:29 -0500290
291Start SOL Console Logging
292 [Documentation] Start logging to a file in /tmp so that it can
293 ... be read by any other test cases. Stop existing
294 ... running client processes if there is any.
295 ... By default logging at /tmp/obmc-console.log else
296 ... user input location.
297 ... The File is appended with datetime and pid of
298 ... process which created this log file.
299 [Arguments] ${file_path}=/tmp/obmc-console.log
300
301 Open Connection And Log In
302
303 ${cur_time}= Get Time Stamp
304 Set Global Variable ${LOG_TIME} ${cur_time}
305 Start Command
306 ... obmc-console-client > ${file_path}-${LOG_TIME}_$$
307
308
309Stop SOL Console Logging
310 [Documentation] Login to BMC and Stop the obmc-console-client process.
311 ... Find the pids from the log to filter the one started by
312 ... specific test datetime and stop that process only.
313 ... Ignore if there is no process running and return message
314 ... "No obmc-console-client process running"
315 ... By default retrieving log from /tmp/obmc-console.log else
316 ... user input location.
317 [Arguments] ${file_path}=/tmp/obmc-console.log
318
319 Open Connection And Log In
320
Michael Walsha6723f22016-11-22 11:12:01 -0600321 ${pid} ${stderr}=
George Keishing30c12ff2016-09-02 10:25:29 -0500322 ... Execute Command
323 ... ls ${file_path}-${LOG_TIME}_* | cut -d'_' -f 2
324 ... return_stderr=True
George Keishing30c12ff2016-09-02 10:25:29 -0500325 Should Be Empty ${stderr}
326
George Keishingd4678952016-10-12 04:29:28 -0500327 ${rc}=
328 ... Execute Command
329 ... ps ax | grep ${pid} | grep -v grep
330 ... return_stdout=False return_rc=True
331
332 Return From Keyword If '${rc}' == '${1}'
333 ... No obmc-console-client process running
334
George Keishing30c12ff2016-09-02 10:25:29 -0500335 ${console} ${stderr}=
336 ... Execute Command kill -s KILL ${pid}
337 ... return_stderr=True
338 Should Be Empty ${stderr}
George Keishingd4678952016-10-12 04:29:28 -0500339 Log Current Client PID:${pid}
George Keishing30c12ff2016-09-02 10:25:29 -0500340
341 ${console} ${stderr}=
342 ... Execute Command
343 ... cat ${file_path}-${LOG_TIME}_${pid}
344 ... return_stderr=True
345 Should Be Empty ${stderr}
346
347 [Return] ${console}
348
349
350Get Time Stamp
351 [Documentation] Get the current time stamp data
352 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
353 [return] ${cur_time}
354
George Keishing1b150202016-09-29 08:51:58 -0500355
356Verify BMC State
357 [Documentation] Get the BMC state and verify if the current
358 ... BMC state is as expected.
359 [Arguments] ${expected}
360
361 ${current}= Get BMC State
George Keishing8db0e1b2016-10-20 13:46:54 -0500362 Should Contain ${expected} ${current}
George Keishing1b150202016-09-29 08:51:58 -0500363
Rahul Maheshwarif684ba72016-10-25 07:24:41 -0500364Start Journal Log
365 [Documentation] Start capturing journal log to a file in /tmp using
366 ... journalctl command. By default journal log is collected
367 ... at /tmp/journal_log else user input location.
368 ... The File is appended with datetime.
369 [Arguments] ${file_path}=/tmp/journal_log
370
371 Open Connection And Log In
372
373 ${cur_time}= Get Time Stamp
374 Set Global Variable ${LOG_TIME} ${cur_time}
375 Start Command
376 ... journalctl -f > ${file_path}-${LOG_TIME}
377 Log Journal Log Started: ${file_path}-${LOG_TIME}
378
379Stop Journal Log
380 [Documentation] Stop journalctl process if its running.
381 ... By default return log from /tmp/journal_log else
382 ... user input location.
383 [Arguments] ${file_path}=/tmp/journal_log
384
385 Open Connection And Log In
386
387 ${rc}=
388 ... Execute Command
389 ... ps ax | grep journalctl | grep -v grep
390 ... return_stdout=False return_rc=True
391
392 Return From Keyword If '${rc}' == '${1}'
393 ... No journal log process running
394
395 ${output} ${stderr}=
396 ... Execute Command killall journalctl
397 ... return_stderr=True
398 Should Be Empty ${stderr}
399
400 ${journal_log} ${stderr}=
401 ... Execute Command
402 ... cat ${file_path}-${LOG_TIME}
403 ... return_stderr=True
404 Should Be Empty ${stderr}
405
406 Log ${journal_log}
407
408 Execute Command rm ${file_path}-${LOG_TIME}
409
410 [Return] ${journal_log}
Rahul Maheshwari757d80c2016-10-17 01:09:55 -0500411
412Mac Address To Hex String
413 [Documentation] Converts MAC address into hex format.
414 ... Example
415 ... Given the following MAC: 00:01:6C:80:02:78
416 ... This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78
417 ... Description of arguments:
418 ... i_macaddress MAC address in the following format 00:01:6C:80:02:78
419 [Arguments] ${i_macaddress}
420
421 ${mac_hex}= Catenate 0x${i_macaddress.replace(':', ' 0x')}
422 [return] ${mac_hex}
423
424IP Address To Hex String
425 [Documentation] Converts IP address into hex format.
426 ... Example:
427 ... Given the following IP: 10.3.164.100
428 ... This keyword will return: 0xa 0x3 0xa4 0xa0
429 ... Description of arguments:
430 ... i_ipaddress IP address in the following format 10.10.10.10
431 [Arguments] ${i_ipaddress}
432
433 @{ip}= Split String ${i_ipaddress} .
434 ${index}= Set Variable ${0}
435
436 :FOR ${item} IN @{ip}
437 \ ${hex}= Convert To Hex ${item} prefix=0x lowercase=yes
438 \ Set List Value ${ip} ${index} ${hex}
439 \ ${index}= Set Variable ${index + 1}
440 ${ip_hex}= Catenate @{ip}
441 [return] ${ip_hex}