blob: 08878a402ad153a881ec83827fe937a9be6578a9 [file] [log] [blame]
Steven Sombarf60cbcf2018-12-07 08:12:18 -06001*** Settings ***
2
3Documentation Utilities for Robot keywords that do not use REST.
4
Sandhya Somashekar839a0c22019-01-31 05:05:43 -06005Resource ../lib/resource.robot
Steven Sombarf60cbcf2018-12-07 08:12:18 -06006Resource ../lib/connection_client.robot
7Resource ../lib/boot_utils.robot
8Library String
9Library DateTime
10Library Process
11Library OperatingSystem
12Library gen_print.py
13Library gen_robot_print.py
14Library gen_cmd.py
Michael Walsh07ed7942019-11-08 14:41:30 -060015Library gen_robot_valid.py
Steven Sombarf60cbcf2018-12-07 08:12:18 -060016Library gen_robot_keyword.py
17Library bmc_ssh_utils.py
18Library utils.py
19Library var_funcs.py
20Library SCPLibrary WITH NAME scp
21
22*** Variables ***
23
24${pflash_cmd} /usr/sbin/pflash -r /dev/stdout -P VERSION
25
26${dbuscmdBase}
27... dbus-send --system --print-reply --dest=${OPENBMC_BASE_DBUS}.settings.Host
28${dbuscmdGet}
29... ${SETTINGS_URI}host0 org.freedesktop.DBus.Properties.Get
30${dbuscmdString}= string:"xyz.openbmc_project.settings.Host" string:
31
32# Assign default value to QUIET for programs which may not define it.
33${QUIET} ${0}
34
35${bmc_mem_free_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f4
36${bmc_mem_total_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f2
37${bmc_cpu_usage_cmd}= top -n 1 | grep CPU: | cut -c 7-9
38${HOST_SETTING} ${SETTINGS_URI}host0
39
40# /run/initramfs/ro associate filesystem should be 100% full always
41${bmc_file_system_usage_cmd}= df -h | cut -c 52-54 | grep 100 | wc -l
42${total_pnor_ro_file_system_cmd}= df -h | grep /media/pnor-ro | wc -l
43${total_bmc_ro_file_system_cmd}= df -h | grep /media/rofs | wc -l
44
45${BOOT_TIME} ${0}
46${BOOT_COUNT} ${0}
47${count} ${0}
48${devicetree_base} /sys/firmware/devicetree/base/model
49
50# Initialize default debug value to 0.
51${DEBUG} ${0}
52
53${probe_cpu_tool_path} ${EXECDIR}/tools/ras/probe_cpus.sh
54${scom_addrs_tool_path} ${EXECDIR}/tools/ras/scom_addr_p9.sh
55${target_file_path} /root/
56
57${default_tarball} ${EXECDIR}/obmc-phosphor-debug-tarball-witherspoon.tar.xz
58
59# These variables are used to straddle between new and old methods of setting
60# values.
61${bmc_power_policy_method} ${EMPTY}
62@{valid_power_policy_vars} RESTORE_LAST_STATE ALWAYS_POWER_ON
63... ALWAYS_POWER_OFF
64
George Keishingb9f3f772020-01-15 23:23:08 -060065${check_performance} ${1}
66
Steven Sombarf60cbcf2018-12-07 08:12:18 -060067
68*** Keywords ***
69
70Check BMC Performance
71 [Documentation] Check BMC basic CPU Mem File system performance.
72
George Keishingb9f3f772020-01-15 23:23:08 -060073 Return From Keyword If not ${check_performance}
74
Steven Sombarf60cbcf2018-12-07 08:12:18 -060075 Check BMC CPU Performance
76 Check BMC Mem Performance
77 Check BMC File System Performance
78
79
80Verify PNOR Update
81 [Documentation] Verify that the PNOR is not corrupted.
82 # Example:
83 # FFS: Flash header not found. Code: 100
84 # Error 100 opening ffs !
85
86 ${stdout} ${stderr} ${rc}=
87 ... BMC Execute Command /usr/sbin/pflash -h | egrep -q skip
88 ... ignore_err=${1}
89 ${pflash_cmd}= Set Variable If ${rc} == ${0} ${pflash_cmd} --skip=4096
90 ... ${pflash_cmd}
91 ${pnor_info}= BMC Execute Command ${pflash_cmd}
92 Should Not Contain Any ${pnor_info} Flash header not found Error
93
94
95Get BMC System Model
96 [Documentation] Get the BMC model from the device tree and return it.
97
98 ${bmc_model} ${stderr} ${rc}= BMC Execute Command
99 ... cat ${devicetree_base} | cut -d " " -f 1 return_stderr=True
100 ... test_mode=0
101 Should Be Empty ${stderr}
102 Should Not Be Empty ${bmc_model} msg=BMC model is empty.
103 [Return] ${bmc_model}
104
105
106Verify BMC System Model
107 [Documentation] Verify the BMC model with ${OPENBMC_MODEL}.
108 [Arguments] ${bmc_model}
109
110 # Description of argument(s):
111 # bmc_model System model (e.g. "witherspoon").
112
113 ${tmp_bmc_model}= Fetch From Right ${OPENBMC_MODEL} /
114 ${tmp_bmc_model}= Fetch From Left ${tmp_bmc_model} .
115 ${ret}= Run Keyword And Return Status Should Contain ${bmc_model}
116 ... ${tmp_bmc_model} ignore_case=True
117 [Return] ${ret}
118
119
120Wait For Host To Ping
121 [Documentation] Wait for the given host to ping.
122 [Arguments] ${host} ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
123 ... ${interval}=5 sec
124
125 # Description of argument(s):
126 # host The host name or IP of the host to ping.
127 # timeout The amount of time after which ping attempts cease.
128 # This should be expressed in Robot Framework's time format
129 # (e.g. "10 seconds").
130 # interval The amount of time in between attempts to ping.
131 # This should be expressed in Robot Framework's time format
132 # (e.g. "5 seconds").
133
134 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host}
135
136
137Ping Host
138 [Documentation] Ping the given host.
139 [Arguments] ${host}
140
141 # Description of argument(s):
142 # host The host name or IP of the host to ping.
143
144 Should Not Be Empty ${host} msg=No host provided
145 ${RC} ${output}= Run and return RC and Output ping -c 4 ${host}
146 Log RC: ${RC}\nOutput:\n${output}
147 Should be equal ${RC} ${0}
148
149
150Check OS
151 [Documentation] Attempts to ping the host OS and then checks that the host
152 ... OS is up by running an SSH command.
153
154 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
155 ... ${os_password}=${OS_PASSWORD} ${quiet}=${QUIET}
156 ... ${print_string}=${EMPTY}
157 [Teardown] SSHLibrary.Close Connection
158
159 # Description of argument(s):
160 # os_host The DNS name/IP of the OS host associated with our BMC.
161 # os_username The username to be used to sign on to the OS host.
162 # os_password The password to be used to sign on to the OS host.
163 # quiet Indicates whether this keyword should write to console.
164 # print_string A string to be printed before checking the OS.
165
Michael Walshc108e422019-03-28 12:27:18 -0500166 Log To Console ${print_string} no_newline=True
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600167
168 # Attempt to ping the OS. Store the return code to check later.
169 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host}
170
171 SSHLibrary.Open connection ${os_host}
172
George Keishing30751662019-03-05 06:35:55 -0600173 ${status} ${msg}= Run Keyword And Ignore Error SSHLibrary.Login ${os_username}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600174 ... ${os_password}
175 ${err_msg1}= Sprint Error ${msg}
176 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
177 Run Keyword If '${status}' == 'FAIL' Fail msg=${err_msg}
178 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True
179 ... return_rc=True
180
181 ${temp_msg}= Catenate Could not execute a command on the operating
182 ... system.\n
183 ${err_msg1}= Sprint Error ${temp_msg}
184 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
185
186 # If the return code returned by "Execute Command" is non-zero, this
187 # keyword will fail.
188 Should Be Equal ${rc} ${0} msg=${err_msg}
189 # We will likewise fail if there is any stderr data.
190 Should Be Empty ${stderr}
191
192 ${temp_msg}= Set Variable Could not ping the operating system.\n
193 ${err_msg1}= Sprint Error ${temp_msg}
194 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1}
195 # We will likewise fail if the OS did not ping, as we could SSH but not
196 # ping
197 Should Be Equal As Strings ${ping_rc} ${TRUE} msg=${err_msg}
198
199
200Wait for OS
201 [Documentation] Waits for the host OS to come up via calls to "Check OS".
202 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
203 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT}
204 ... ${quiet}=${0}
Michael Walshc108e422019-03-28 12:27:18 -0500205 [Teardown] Printn
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600206
207 # Description of argument(s):
208 # os_host The DNS name or IP of the OS host associated with our
209 # BMC.
210 # os_username The username to be used to sign on to the OS host.
211 # os_password The password to be used to sign on to the OS host.
212 # timeout The timeout in seconds indicating how long you're
213 # willing to wait for the OS to respond.
214 # quiet Indicates whether this keyword should write to console.
215
216 # The interval to be used between calls to "Check OS".
217 ${interval}= Set Variable 5
218
219 ${message}= Catenate Checking every ${interval} seconds for up to
220 ... ${timeout} seconds for the operating system to communicate.
Michael Walshc108e422019-03-28 12:27:18 -0500221 Qprint Timen ${message}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600222
223 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS
224 ... ${os_host} ${os_username} ${os_password}
225 ... print_string=\#
226
Michael Walshc108e422019-03-28 12:27:18 -0500227 Qprintn
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600228
Michael Walshc108e422019-03-28 12:27:18 -0500229 Qprint Timen The operating system is now communicating.
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600230
231
232Copy PNOR to BMC
233 [Documentation] Copy the PNOR image to the BMC.
234 Import Library SCPLibrary WITH NAME scp
235 Open Connection for SCP
236 Log Copying ${PNOR_IMAGE_PATH} to /tmp
237 scp.Put File ${PNOR_IMAGE_PATH} /tmp
238
239
240Is OS Starting
241 [Documentation] Check if boot progress is OS starting.
242 ${boot_progress}= Get Boot Progress
243 Should Be Equal ${boot_progress} OSStart
244
245
246Is OS Off
247 [Documentation] Check if boot progress is "Off".
248 ${boot_progress}= Get Boot Progress
249 Should Be Equal ${boot_progress} Off
250
251
252Get Boot Progress To OS Starting State
253 [Documentation] Get the system to a boot progress state of 'FW Progress,
254 ... Starting OS'.
255
256 ${boot_progress}= Get Boot Progress
257 Run Keyword If '${boot_progress}' == 'OSStart'
258 ... Log Host is already in OS starting state
259 ... ELSE
260 ... Run Keywords Initiate Host PowerOff AND Initiate Host Boot
261 ... AND Wait Until Keyword Succeeds 10 min 10 sec Is OS Starting
262
263
264Check If warmReset is Initiated
265 [Documentation] Ping would be still alive, so try SSH to connect
266 ... if fails the ports are down indicating reboot
267 ... is in progress
268
269 # Warm reset adds 3 seconds delay before forcing reboot
270 # To minimize race conditions, we wait for 7 seconds
271 Sleep 7s
272 ${alive}= Run Keyword and Return Status
273 ... Open Connection And Log In
274 Return From Keyword If '${alive}' == '${False}' ${False}
275 [Return] ${True}
276
277
278Initialize DBUS cmd
279 [Documentation] Initialize dbus string with property string to extract
280 [Arguments] ${boot_property}
281
282 # Description of argument(s):
283 # boot_property Property string.
284
285 ${cmd}= Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
286 ${cmd}= Catenate ${cmd}${boot_property}
287 Set Global Variable ${dbuscmd} ${cmd}
288
289
290Create OS Console Command String
291 [Documentation] Return a command string to start OS console logging.
292
293 # First make sure that the ssh_pw program is available.
294 ${cmd}= Catenate which ssh_pw 2>/dev/null || find
295 ... ${EXECDIR} -name 'ssh_pw'
296
Michael Walshc108e422019-03-28 12:27:18 -0500297 Dprint Issuing ${cmd}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600298 ${rc} ${output}= Run And Return Rc And Output ${cmd}
299 Rdpvars rc output
300
301 Should Be Equal As Integers 0 ${rc} msg=Could not find ssh_pw.
302
303 ${ssh_pw_file_path}= Set Variable ${output}
304
George Keishing088166c2019-12-13 08:11:28 -0600305 ${cmd}= Catenate ${ssh_pw_file_path} ${OPENBMC_PASSWORD} -p ${HOST_SOL_PORT}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600306 ... -o "StrictHostKeyChecking no" ${OPENBMC_USERNAME}@${OPENBMC_HOST}
307
308 [Return] ${cmd}
309
310
311Get SOL Console Pid
312 [Documentation] Get the pid of the active SOL console job.
Michael Walsh07ed7942019-11-08 14:41:30 -0600313 [Arguments] ${expect_running}=${0} ${log_file_path}=${EMPTY}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600314
315 # Description of argument(s):
Michael Walsh07ed7942019-11-08 14:41:30 -0600316 # expect_running If set and if no SOL console job is found, print debug info and fail.
317 # log_file_path Needed to print debug info if expect_running is set and no pid is found.
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600318
319 # Find the pid of the active system console logging session (if any).
320 ${search_string}= Create OS Console Command String
321 # At least in some cases, ps output does not show double quotes so we must
322 # replace them in our search string with the regexes to indicate that they
323 # are optional.
324 ${search_string}= Replace String ${search_string} " ["]?
325 ${ps_cmd}= Catenate ps axwwo user,pid,cmd
326 ${cmd_buf}= Catenate echo $(${ps_cmd} | egrep '${search_string}' |
327 ... egrep -v grep | cut -c10-14)
Michael Walshc108e422019-03-28 12:27:18 -0500328 Dprint Issuing ${cmd_buf}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600329 ${rc} ${os_con_pid}= Run And Return Rc And Output ${cmd_buf}
330 Rdpvars os_con_pid
331 # If rc is not zero it just means that there is no OS Console process
332 # running.
333
334 Return From Keyword If '${os_con_pid}' != '${EMPTY}' ${os_con_pid}
335 Return From Keyword If '${expect_running}' == '${0}' ${os_con_pid}
336
337 Cmd Fnc cat ${log_file_path} ; echo ; ${ps_cmd} quiet=${0}
338 ... print_output=${1} show_err=${1}
Michael Walsh07ed7942019-11-08 14:41:30 -0600339 Valid Value os_con_pid
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600340
341
342Stop SOL Console Logging
343 [Documentation] Stop system console logging and return log output.
344 [Arguments] ${log_file_path}=${EMPTY}
345 ... ${targ_file_path}=${EXECDIR}${/}logs${/}
346 ... ${return_data}=${1}
347
348 # If there are muliple system console processes, they will all be stopped.
349 # If there is no existing log file this keyword will return an error
350 # message to that effect (and write that message to targ_file_path, if
351 # specified).
352 # NOTE: This keyword will not fail if there is no running system console
353 # process.
354
355 # Description of arguments:
356 # log_file_path The file path that was used to call "Start SOL
357 # Console Logging". See that keyword (above) for details.
358 # targ_file_path If specified, the file path to which the source
359 # file path (i.e. "log_file_path") should be copied.
360 # return_data If this is set to ${1}, this keyword will return the SOL
361 # data to the caller as a unicode string.
362
363 ${log_file_path}= Create OS Console File Path ${log_file_path}
364
365 ${os_con_pid}= Get SOL Console Pid
366
367 ${cmd_buf}= Catenate kill -9 ${os_con_pid}
Michael Walshc108e422019-03-28 12:27:18 -0500368 Run Keyword If '${os_con_pid}' != '${EMPTY}' Dprint Issuing ${cmd_buf}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600369 ${rc} ${output}= Run Keyword If '${os_con_pid}' != '${EMPTY}'
370 ... Run And Return Rc And Output ${cmd_buf}
371 Run Keyword If '${os_con_pid}' != '${EMPTY}' Rdpvars rc output
372
373 Run Keyword If '${targ_file_path}' != '${EMPTY}'
374 ... Run Keyword And Ignore Error
375 ... Copy File ${log_file_path} ${targ_file_path}
376
377 ${output}= Set Variable ${EMPTY}
378 ${loc_quiet}= Evaluate ${debug}^1
379 ${rc} ${output}= Run Keyword If '${return_data}' == '${1}'
380 ... Cmd Fnc cat ${log_file_path} 2>/dev/null quiet=${loc_quiet}
381 ... print_output=${0} show_err=${0}
382
383 [Return] ${output}
384
385
386Start SOL Console Logging
387 [Documentation] Start system console log to file.
388 [Arguments] ${log_file_path}=${EMPTY} ${return_data}=${1}
389
390 # This keyword will first call "Stop SOL Console Logging". Only then will
391 # it start SOL console logging. The data returned by "Stop SOL Console
392 # Logging" will in turn be returned by this keyword.
393
394 # Description of arguments:
395 # log_file_path The file path to which system console log data should be
396 # written. Note that this path is taken to be a location
397 # on the machine where this program is running rather than
398 # on the Open BMC system.
399 # return_data If this is set to ${1}, this keyword will return any SOL
400 # data to the caller as a unicode string.
401
402 ${log_file_path}= Create OS Console File Path ${log_file_path}
403
404 ${log_output}= Stop SOL Console Logging ${log_file_path}
405 ... return_data=${return_data}
406
407 # Validate by making sure we can create the file. Problems creating the
408 # file would not be noticed by the subsequent ssh command because we fork
409 # the command.
410 Create File ${log_file_path}
411 ${sub_cmd_buf}= Create OS Console Command String
412 # Routing stderr to stdout so that any startup error text will go to the
413 # output file.
414 # TODO: Doesn't work with tox so reverting temporarily.
415 # nohup detaches the process completely from our pty.
416 #${cmd_buf}= Catenate nohup ${sub_cmd_buf} &> ${log_file_path} &
417 ${cmd_buf}= Catenate ${sub_cmd_buf} > ${log_file_path} 2>&1 &
Michael Walshc108e422019-03-28 12:27:18 -0500418 Dprint Issuing ${cmd_buf}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600419 ${rc} ${output}= Run And Return Rc And Output ${cmd_buf}
420 # Because we are forking this command, we essentially will never get a
421 # non-zero return code or any output.
422 Should Be Equal ${rc} ${0}
423
424 Wait Until Keyword Succeeds 10 seconds 0 seconds
Michael Walsh07ed7942019-11-08 14:41:30 -0600425 ... Get SOL Console Pid ${1} ${log_file_path}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600426
427 [Return] ${log_output}
428
429
430Get Time Stamp
431 [Documentation] Get the current time stamp data
432 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f
433 [Return] ${cur_time}
434
435
436Start Journal Log
437 [Documentation] Start capturing journal log to a file in /tmp using
438 ... journalctl command. By default journal log is collected
439 ... at /tmp/journal_log else user input location.
440 ... The File is appended with datetime.
441 [Arguments] ${file_path}=/tmp/journal_log ${filter}=${EMPTY}
442
443 # Description of arguments:
444 # file_path The file path of the journal file.
445
446 ${cur_time}= Get Time Stamp
447 Set Global Variable ${LOG_TIME} ${cur_time}
448 Open Connection And Log In
449 Start Command
450 ... journalctl -f ${filter} > ${file_path}-${LOG_TIME}
451 Log Journal Log Started: ${file_path}-${LOG_TIME}
452
453
454Stop Journal Log
455 [Documentation] Stop journalctl process if its running.
456 ... By default return log from /tmp/journal_log else
457 ... user input location.
458 [Arguments] ${file_path}=/tmp/journal_log
459
460 # Description of arguments:
461 # file_path The file path of the journal file.
462
463 Open Connection And Log In
464
465 ${rc}=
466 ... Execute Command
467 ... ps | grep journalctl | grep -v grep
468 ... return_stdout=False return_rc=True
469
470 Return From Keyword If '${rc}' == '${1}'
471 ... No journal log process running
472
473 ${output} ${stderr}=
474 ... Execute Command killall journalctl
475 ... return_stderr=True
476 Should Be Empty ${stderr}
477
478 ${journal_log} ${stderr}=
479 ... Execute Command
480 ... cat ${file_path}-${LOG_TIME}
481 ... return_stderr=True
482 Should Be Empty ${stderr}
483
484 Log ${journal_log}
485
486 Execute Command rm ${file_path}-${LOG_TIME}
487
488 [Return] ${journal_log}
489
490
491Mac Address To Hex String
492 [Documentation] Converts MAC address into hex format.
493 ... Example
494 ... Given the following MAC: 00:01:6C:80:02:78
495 ... This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78
496 ... Description of arguments:
497 ... i_macaddress MAC address in the following format
498 ... 00:01:6C:80:02:78
499 [Arguments] ${i_macaddress}
500
501 # Description of arguments:
502 # i_macaddress The MAC address.
503
504 ${mac_hex}= Catenate 0x${i_macaddress.replace(':', ' 0x')}
505 [Return] ${mac_hex}
506
507
508IP Address To Hex String
509 [Documentation] Converts IP address into hex format.
510 ... Example:
511 ... Given the following IP: 10.3.164.100
512 ... This keyword will return: 0xa 0x3 0xa4 0xa0
513 [Arguments] ${i_ipaddress}
514
515 # Description of arguments:
516 # i_macaddress The IP address in the format 10.10.10.10.
517
518 @{ip}= Split String ${i_ipaddress} .
519 ${index}= Set Variable ${0}
520
Marissa Garza20ccfc72020-06-19 12:51:10 -0500521 FOR ${item} IN @{ip}
522 ${hex}= Convert To Hex ${item} prefix=0x lowercase=yes
523 Set List Value ${ip} ${index} ${hex}
524 ${index}= Set Variable ${index + 1}
525 END
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600526 ${ip_hex}= Catenate @{ip}
527
528 [Return] ${ip_hex}
529
530
531BMC CPU Performance Check
532 [Documentation] Minimal 10% of proc should be free in this instance
533
534 ${bmc_cpu_usage_output} ${stderr} ${rc}= BMC Execute Command
535 ... ${bmc_cpu_usage_cmd}
536 ${bmc_cpu_usage_output} ${stderr} ${rc}= BMC Execute Command
537 ... ${bmc_cpu_usage_cmd}
538 ${bmc_cpu_percentage}= Fetch From Left ${bmc_cpu_usage_output} %
Sivas SRR14426bc2019-04-10 10:14:46 -0500539 Rprint Vars bmc_cpu_percentage
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600540 Should be true ${bmc_cpu_percentage} < 90
541
542
543BMC Mem Performance Check
544 [Documentation] Minimal 10% of memory should be free in this instance
545
546 ${bmc_mem_free_output} ${stderr} ${rc}= BMC Execute Command
547 ... ${bmc_mem_free_cmd}
548
549 ${bmc_mem_total_output} ${stderr} ${rc}= BMC Execute Command
550 ... ${bmc_mem_total_cmd}
551 ${bmc_mem_free_output} ${stderr} ${rc}= BMC Execute Command
552 ... ${bmc_mem_free_cmd}
553
554 ${bmc_mem_total_output} ${stderr} ${rc}= BMC Execute Command
555 ... ${bmc_mem_total_cmd}
556
557 ${bmc_mem_percentage}= Evaluate ${bmc_mem_free_output}*100
558 ${bmc_mem_percentage}= Evaluate
559 ... ${bmc_mem_percentage}/${bmc_mem_total_output}
Sivas SRR14426bc2019-04-10 10:14:46 -0500560 Rprint Vars bmc_mem_percentage
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600561 Should be true ${bmc_mem_percentage} > 10
562
563
564BMC File System Usage Check
565 [Documentation] Check the file system space. 4 file system should be
566 ... 100% full which is expected
567 # Filesystem Size Used Available Use% Mounted on
568 # /dev/root 14.4M 14.4M 0 100% /
569 # /dev/ubiblock0_0 14.4M 14.4M 0 100% /media/rofs-c9249b0e
570 # /dev/ubiblock8_0 19.6M 19.6M 0 100% /media/pnor-ro-8764baa3
571 # /dev/ubiblock4_0 14.4M 14.4M 0 100% /media/rofs-407816c
572 # /dev/ubiblock8_4 21.1M 21.1M 0 100% /media/pnor-ro-cecc64c4
573 ${bmc_fs_usage_output} ${stderr} ${rc}= BMC Execute Command
574 ... ${bmc_file_system_usage_cmd}
575 ${bmc_pnor_fs_usage_output} ${stderr} ${rc}= BMC Execute Command
576 ... ${total_pnor_ro_file_system_cmd}
577 ${bmc_bmc_fs_usage_output} ${stderr} ${rc}= BMC Execute Command
578 ... ${total_bmc_ro_file_system_cmd}
579 ${total_bmc_pnor_image}= Evaluate
580 ... ${bmc_pnor_fs_usage_output}+${bmc_bmc_fs_usage_output}
581 # Considering /dev/root also in total 100% used file system
582 ${total_full_fs}= Evaluate ${total_bmc_pnor_image}+1
Sivas SRR14426bc2019-04-10 10:14:46 -0500583 Rprint Vars bmc_fs_usage_output bmc_pnor_fs_usage_output bmc_bmc_fs_usage_output
584 ... total_full_fs
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600585 Should Be True ${bmc_fs_usage_output}==${total_full_fs}
586
587
588Check BMC CPU Performance
589 [Documentation] Minimal 10% of proc should be free in 3 sample
Marissa Garza20ccfc72020-06-19 12:51:10 -0500590 FOR ${var} IN RANGE 1 4
591 BMC CPU Performance Check
592 END
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600593
594Check BMC Mem Performance
595 [Documentation] Minimal 10% of memory should be free
596
Marissa Garza20ccfc72020-06-19 12:51:10 -0500597 FOR ${var} IN RANGE 1 4
598 BMC Mem Performance Check
599 END
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600600
601Check BMC File System Performance
602 [Documentation] Check for file system usage for 4 times
603
Marissa Garza20ccfc72020-06-19 12:51:10 -0500604 FOR ${var} IN RANGE 1 4
605 BMC File System Usage check
606 END
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600607
608Get URL List
609 [Documentation] Return list of URLs under given URL.
610 [Arguments] ${openbmc_url}
611
612 # Description of argument(s):
613 # openbmc_url URL for list operation (e.g.
614 # /xyz/openbmc_project/inventory).
615
Steven Sombaraaaab222018-12-19 13:16:23 -0600616 ${url_list}= Read Properties ${openbmc_url}list quiet=${1}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600617 Sort List ${url_list}
618
619 [Return] ${url_list}
620
621
622Check Zombie Process
623 [Documentation] Check if any defunct process exist or not on BMC
624 ${count} ${stderr} ${rc}= Execute Command ps -o stat | grep Z | wc -l
625 ... return_stderr=True return_rc=True
626 Should Be True ${count}==0
627 Should Be Empty ${stderr}
628
629
630Prune Journal Log
631 [Documentation] Prune archived journal logs.
632 [Arguments] ${vacuum_size}=1M
633
634 # This keyword can be used to prevent the journal
635 # log from filling up the /run filesystem.
636 # This command will retain only the latest logs
637 # of the user specified size.
638
639 # Description of argument(s):
640 # vacuum_size Size of journal.
641
642 Open Connection And Log In
643 ${output} ${stderr} ${rc}=
644 ... Execute Command
645 ... journalctl --vacuum-size=${vacuum_size}
646 ... return_stderr=True return_rc=True
647
648 Should Be Equal ${rc} ${0} msg=${stderr}
649
650
651Get System Power Policy
652 [Documentation] Returns the BMC power policy.
653
654 # Set the bmc_power_policy_method to either 'Old' or 'New'.
655 Set Power Policy Method
656 ${cmd_buf}= Create List ${bmc_power_policy_method} Get Power Policy
657 # Run the appropriate keyword.
658 ${currentPolicy}= Run Keyword @{cmd_buf}
659
660 [Return] ${currentPolicy}
661
662
663Set BMC Reset Reference Time
664 [Documentation] Set current boot time as a reference and increment
665 ... boot count.
666
667 ${cur_btime}= Get BMC Boot Time
668 Run Keyword If ${BOOT_TIME} == ${0} and ${BOOT_COUNT} == ${0}
669 ... Set Global Variable ${BOOT_TIME} ${cur_btime}
670 ... ELSE IF ${cur_btime} > ${BOOT_TIME}
671 ... Run Keywords Set Global Variable ${BOOT_TIME} ${cur_btime}
672 ... AND
673 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1}
674
675
676Get BMC Boot Time
677 [Documentation] Returns boot time from /proc/stat.
678
679 Open Connection And Log In
680 ${output} ${stderr}=
681 ... Execute Command egrep '^btime ' /proc/stat | cut -f 2 -d ' '
682 ... return_stderr=True
683 Should Be Empty ${stderr}
684 ${btime}= Convert To Integer ${output}
685 [Return] ${btime}
686
687
688Enable Core Dump On BMC
689 [Documentation] Enable core dump collection.
690 ${core_pattern} ${stderr} ${rc}= BMC Execute Command
691 ... echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern
692 Should Be Equal As Strings ${core_pattern} /tmp/core_%e.%p
693
694
695Get Number Of BMC Core Dump Files
696 [Documentation] Returns number of core dump files on BMC.
697 Open Connection And Log In
698 ${num_of_core_dump}= Execute Command
699 ... ls /tmp/core* 2>/dev/null | wc -l
700 [Return] ${num_of_core_dump}
701
702
703Set Core Dump File Size Unlimited
704 [Documentation] Set core dump file size to unlimited.
705 BMC Execute Command ulimit -c unlimited
706
707
708Check For Core Dumps
709 [Documentation] Check for any core dumps exist.
710 ${output}= Get Number Of BMC Core Dump Files
711 Run Keyword If ${output} > 0
712 ... Log **Warning** BMC core dump files exist level=WARN
713
714
715Configure Initial Settings
716 [Documentation] Restore old IP and route.
717 ... This keyword requires initial settings viz IP address,
718 ... Network Mask, default gatway and serial console IP and port
719 ... information which should be provided in command line.
720
721 [Arguments] ${host}=${OPENBMC_HOST} ${mask}=${NET_MASK}
722 ... ${gw_ip}=${GW_IP}
723
724 # Description of arguments:
725 # host IP address of the OS Host.
726 # mask Network mask.
727 # gu_ip Gateway IP address or hostname.
728
729 # Open telnet connection and ignore the error, in case telnet session is
730 # already opened by the program calling this keyword.
731 Run Keyword And Ignore Error Open Telnet Connection to BMC Serial Console
732 Telnet.write ifconfig eth0 ${host} netmask ${mask}
733 Telnet.write route add default gw ${gw_ip}
734
735
736Install Debug Tarball On BMC
737 [Documentation] Copy the debug tar file to BMC and install.
738 [Arguments] ${tarball_file_path}=${default_tarball}
739 ... ${targ_tarball_dir_path}=/tmp/tarball/
740
741 # Description of arguments:
742 # tarball_file_path Path of the debug tarball file.
743 # The tar file is downloaded from the build page
744 # https://openpower.xyz/job/openbmc-build/
745 # obmc-phosphor-debug-tarball-witherspoon.tar.xz
746 #
747 # targ_tarball_dir_path The directory path where the tarball is to be
748 # installed.
749
750 OperatingSystem.File Should Exist ${tarball_file_path}
751 ... msg=${tarball_file_path} doesn't exist.
752
753 # Upload the file to BMC.
754 Import Library SCPLibrary WITH NAME scp
755 Open Connection for SCP
756 scp.Put File ${tarball_file_path} /tmp/debug-tarball.tar.xz
757
758 # Create tarball directory and install.
759 BMC Execute Command mkdir -p ${targ_tarball_dir_path}
760 BMC Execute Command
761 ... tar -xf /tmp/debug-tarball.tar.xz -C ${targ_tarball_dir_path}
762
763 # Remove the tarball file from BMC.
764 BMC Execute Command rm -f /tmp/debug-tarball.tar.xz
765
766
767Get BMC Boot Count
768 [Documentation] Returns BMC boot count based on boot time.
769 ${cur_btime}= Get BMC Boot Time
770
771 # Set global variable BOOT_TIME to current boot time if current boot time
772 # is changed. Also increase value of global variable BOOT_COUNT by 1.
773 Run Keyword If ${cur_btime} > ${BOOT_TIME}
774 ... Run Keywords Set Global Variable ${BOOT_TIME} ${cur_btime}
775 ... AND
776 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1}
777
778 [Return] ${BOOT_COUNT}
779
780
781Set BMC Boot Count
782 [Documentation] Set BMC boot count to given value.
783 [Arguments] ${count}
784
785 # Description of arguments:
786 # count boot count value.
787 ${cur_btime}= Get BMC Boot Time
788
789 # Set global variable BOOT_COUNT to given value.
790 Set Global Variable ${BOOT_COUNT} ${count}
791
792 # Set BOOT_TIME variable to current boot time.
Tony Lee073fbc02020-05-12 15:12:16 +0800793 Set Global Variable ${BOOT_TIME} ${cur_btime}
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600794
795
796Delete Error Log Entry
797 [Documentation] Delete error log entry.
798 [Arguments] ${entry_path}
799
800 # Description of argument(s):
801 # entry_path Delete an error log entry.
802 # Ex. /xyz/openbmc_project/logging/entry/1
803
804 # Skip delete if entry URI is a callout.
805 # Examples:
806 # /xyz/openbmc_project/logging/entry/1/callout
807 # /xyz/openbmc_project/logging/entry/1/callouts/0
808 ${callout_entry}= Run Keyword And Return Status
809 ... Should Match Regexp ${entry_path} /callout[s]?(/|$)
810 Return From Keyword If ${callout_entry}
811
812 ${data}= Create Dictionary data=@{EMPTY}
813 ${resp}= Openbmc Delete Request ${entry_path} data=${data}
814 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
815
816
817Get BMC Version
818 [Documentation] Returns BMC version from /etc/os-release.
819 ... e.g. "v1.99.6-141-ge662190"
820
821 ${cmd}= Set Variable grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
822 ${output} ${stderr} ${rc}= BMC Execute Command ${cmd}
823 [Return] ${output}
824
825
826Get PNOR Version
827 [Documentation] Returns the PNOR version from the BMC.
828
829 ${pnor_attrs}= Get PNOR Attributes
830 [Return] ${pnor_attrs['version']}
831
832
833Get PNOR Attributes
834 [Documentation] Return PNOR software attributes as a dictionary.
835
836 # This keyword parses /var/lib/phosphor-software-manager/pnor/ro/pnor.toc
837 # into key/value pairs.
838
839 ${outbuf} ${stderr} ${rc}= BMC Execute Command
840 ... cat /var/lib/phosphor-software-manager/pnor/ro/pnor.toc
841 ${pnor_attrs}= Key Value Outbuf To Dict ${outbuf} delim==
842
843 [Return] ${pnor_attrs}
844
845
Sivas SRR17dae1a2019-03-24 23:52:02 -0500846GET BMC PNOR Version
847 [Documentation] Return BMC & PNOR version from openbmc shell.
848
849 ${bmc_version}= GET BMC Version
850 ${pnor_version}= GET PNOR Version
851 Log ${bmc_version}
852 Rprint Vars bmc_version
853 Log ${pnor_version}
854 Rprint Vars pnor_version
855
856 [Return] ${bmc_version} ${pnor_version}
857
858
Sushil Singh5ea86d02019-07-11 02:05:16 -0500859Redfish Get BMC Version
860 [Documentation] Get BMC version via Redfish.
861
862 ${output}= Redfish.Get Attribute ${REDFISH_BASE_URI}Managers/bmc FirmwareVersion
863 [Return] ${output}
864
865Redfish Get Host Version
866 [Documentation] Get host version via Redfish.
867
868 ${output}= Redfish.Get Attribute ${REDFISH_BASE_URI}Systems/system BiosVersion
869 [Return] ${output}
870
871
Steven Sombarf60cbcf2018-12-07 08:12:18 -0600872Copy Address Translation Utils To HOST OS
873 [Documentation] Copy address translation utils to host OS.
874
875 OperatingSystem.File Should Exist ${probe_cpu_tool_path}
876 ... msg=${probe_cpu_tool_path} doesn't exist.
877 OperatingSystem.File Should Exist ${probe_cpu_tool_path}
878 ... msg=${probe_cpu_tool_path} doesn't exist.
879
880 scp.Open connection ${OS_HOST} username=${OS_USERNAME}
881 ... password=${OS_PASSWORD}
882 scp.Put File ${probe_cpu_tool_path} ${target_file_path}
883 scp.Put File ${scom_addrs_tool_path} ${target_file_path}
884
885
886Verify BMC RTC And UTC Time Drift
887 [Documentation] Verify that the RTC and UTC time difference is less than
888 ... the given time_drift_max.
889 [Arguments] ${time_diff_max}=${10}
890
891 # Description of argument(s):
892 # time_diff_max The max allowable RTC and UTC time difference in seconds.
893
894 # Example:
895 # time_dict:
896 # [local_time]: Fri 2017-11-03 152756 UTC
897 # [local_time_seconds]: 1509740876
898 # [universal_time]: Fri 2017-11-03 152756 UTC
899 # [universal_time_seconds]: 1509740876
900 # [rtc_time]: Fri 2016-05-20 163403
901 # [rtc_time_seconds]: 1463780043
902 # [time_zone]: n/a (UTC, +0000)
903 # [network_time_on]: yes
904 # [ntp_synchronized]: no
905 # [rtc_in_local_tz]: no
906
907 ${time}= Get BMC Date Time
908 ${time_diff}= Evaluate
909 ... ${time['universal_time_seconds']} - ${time['rtc_time_seconds']}
910 Should Be True ${time_diff} < ${time_diff_max}
911
912
913Validate IP On BMC
914 [Documentation] Validate IP address is present in set of IP addresses.
915 [Arguments] ${ip_address} ${ip_data}
916
917 # Description of argument(s):
918 # ip_address IP address to check (e.g. xx.xx.xx.xx).
919 # ip_data Set of the IP addresses present.
920
921 Should Contain Match ${ip_data} ${ip_address}/*
922 ... msg=${ip_address} not found in the list provided.
923
924
925Remove Journald Logs
926 [Documentation] Remove all journald logs and restart service.
927
928 ${cmd}= Catenate systemctl stop systemd-journald.service &&
929 ... rm -rf /var/log/journal && systemctl start systemd-journald.service
930
931 BMC Execute Command ${cmd}
932
933
934Check For Regex In Journald
935 [Documentation] Parse the journal log and check for regex string.
936 [Arguments] ${regex}=${ERROR_REGEX} ${error_check}=${0} ${boot}=${EMPTY}
937
938 # Description of argument(s):
939 # regex Strings to be filter.
940 # error_check Check for errors.
941 # boot Argument to check current or persistent full boot log
942 # (e.g. "-b").
943
944 ${journal_log} ${stderr} ${rc}= BMC Execute Command
945 ... journalctl --no-pager ${boot} | egrep '${regex}' ignore_err=1
946
947 Run Keyword If ${error_check} == ${0}
948 ... Should Be Empty ${journal_log}
949 ... ELSE
950 ... Should Not Be Empty ${journal_log}
951
952
953Get Service Attribute
954 [Documentation] Get service attribute policy output.
955 [Arguments] ${option} ${servicename}
956
957 # Description of argument(s):
958 # option systemctl supported options
959 # servicename Qualified service name
960 ${cmd}= Set Variable
961 ... systemctl -p ${option} show ${servicename} | cut -d = -f2
962 ${attr} ${stderr} ${rc}= BMC Execute Command ${cmd}
963 [Return] ${attr}
Anusha Dathatrieda09492019-02-26 08:30:13 -0600964
965
966Verify Watchdog Enabled
967 [Documentation] Check that watchdog settings are enabled.
968
969 ${properties}= Read Properties /xyz/openbmc_project/watchdog/host0
970 Should Be Equal As Strings ${properties["Enabled"]} ${True}
971 Should Not Be Equal As Strings ${properties["TimeRemaining"]} 0