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