1*** Settings *** 2 3Documentation Utilities for Robot keywords. 4 5Resource ../lib/resource.txt 6Resource ../lib/rest_client.robot 7Resource ../lib/connection_client.robot 8Resource ../lib/boot_utils.robot 9Library String 10Library DateTime 11Library Process 12Library OperatingSystem 13Library gen_print.py 14Library gen_robot_print.py 15Library gen_cmd.py 16Library 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${SYSTEM_SHUTDOWN_TIME} ${5} 26 27${dbuscmdBase} 28... dbus-send --system --print-reply --dest=${OPENBMC_BASE_DBUS}.settings.Host 29${dbuscmdGet} 30... ${SETTINGS_URI}host0 org.freedesktop.DBus.Properties.Get 31${dbuscmdString}= string:"xyz.openbmc_project.settings.Host" string: 32 33# Assign default value to QUIET for programs which may not define it. 34${QUIET} ${0} 35 36${bmc_mem_free_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f4 37${bmc_mem_total_cmd}= free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f2 38${bmc_cpu_usage_cmd}= top -n 1 | grep CPU: | cut -c 7-9 39${HOST_SETTING} ${SETTINGS_URI}host0 40 41# /run/initramfs/ro associate filesystem should be 100% full always 42${bmc_file_system_usage_cmd}= df -h | cut -c 52-54 | grep 100 | wc -l 43${total_pnor_ro_file_system_cmd}= df -h | grep /media/pnor-ro | wc -l 44${total_bmc_ro_file_system_cmd}= df -h | grep /media/rofs | wc -l 45 46${BOOT_TIME} ${0} 47${BOOT_COUNT} ${0} 48${count} ${0} 49${devicetree_base} /sys/firmware/devicetree/base/model 50 51# Initialize default debug value to 0. 52${DEBUG} ${0} 53 54${probe_cpu_tool_path} ${EXECDIR}/tools/ras/probe_cpus.sh 55${scom_addrs_tool_path} ${EXECDIR}/tools/ras/scom_addr_p9.sh 56${target_file_path} /root/ 57 58${default_tarball} ${EXECDIR}/obmc-phosphor-debug-tarball-witherspoon.tar.xz 59 60# These variables are used to straddle between new and old methods of setting 61# values. 62${boot_prog_method} ${EMPTY} 63${power_policy_setup} ${0} 64${bmc_power_policy_method} ${EMPTY} 65@{valid_power_policy_vars} RESTORE_LAST_STATE ALWAYS_POWER_ON 66... ALWAYS_POWER_OFF 67 68 69*** Keywords *** 70 71Check BMC Performance 72 [Documentation] Check BMC basic CPU Mem File system performance. 73 74 Check BMC CPU Performance 75 Check BMC Mem Performance 76 Check BMC File System Performance 77 78 79Verify PNOR Update 80 [Documentation] Verify that the PNOR is not corrupted. 81 # Example: 82 # FFS: Flash header not found. Code: 100 83 # Error 100 opening ffs ! 84 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 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 128 Wait Until Keyword Succeeds ${timeout} ${interval} Ping Host ${host} 129 130 131Ping Host 132 [Documentation] Ping the given host. 133 [Arguments] ${host} 134 135 # Description of argument(s): 136 # host The host name or IP of the host to ping. 137 138 Should Not Be Empty ${host} msg=No host provided 139 ${RC} ${output}= Run and return RC and Output ping -c 4 ${host} 140 Log RC: ${RC}\nOutput:\n${output} 141 Should be equal ${RC} ${0} 142 143 144Get Boot Progress 145 [Documentation] Get the boot progress and return it. 146 [Arguments] ${quiet}=${QUIET} 147 148 # Description of argument(s): 149 # quiet Indicates whether this keyword should run without any output to 150 # the console. 151 152 Set Boot Progress Method 153 ${state}= Run Keyword If '${boot_prog_method}' == 'New' 154 ... New Get Boot Progress quiet=${quiet} 155 ... ELSE 156 ... Old Get Boot Progress quiet=${quiet} 157 158 [Return] ${state} 159 160 161Set Boot Progress Method 162 [Documentation] Set the boot_prog_method to either 'Old' or 'New'. 163 164 # The boot progress data has moved from an 'org' location to an 'xyz' 165 # location. This keyword will determine whether the new method of getting 166 # the boot progress is valid and will set the global boot_prog_method 167 # variable accordingly. If boot_prog_method is already set (either by a 168 # prior call to this function or via a -v parm), this keyword will simply 169 # return. 170 171 # Note: There are interim builds that contain boot_progress in both the 172 # old and the new location values. It is nearly impossible for this 173 # keyword to determine whether the old boot_progress or the new one is 174 # active. When using such builds where the old boot_progress is active, 175 # the only recourse users will have is that they may specify 176 # -v boot_prog_method:Old to force old behavior on such builds. 177 178 Run Keyword If '${boot_prog_method}' != '${EMPTY}' Return From Keyword 179 180 ${new_status} ${new_value}= Run Keyword And Ignore Error 181 ... New Get Boot Progress 182 # If the new style read fails, the method must necessarily be "Old". 183 Run Keyword If '${new_status}' == 'PASS' 184 ... Run Keywords 185 ... Set Global Variable ${boot_prog_method} New AND 186 ... Rqpvars boot_prog_method AND 187 ... Return From Keyword 188 189 # Default method is "Old". 190 Set Global Variable ${boot_prog_method} Old 191 Rqpvars boot_prog_method 192 193 194Old Get Boot Progress 195 [Documentation] Get the boot progress the old way (via org location). 196 [Arguments] ${quiet}=${QUIET} 197 198 # Description of argument(s): 199 # quiet Indicates whether this keyword should run without any output to 200 # the console. 201 202 ${state}= Read Attribute ${OPENBMC_BASE_URI}sensors/host/BootProgress 203 ... value quiet=${quiet} 204 205 [Return] ${state} 206 207 208New Get Boot Progress 209 [Documentation] Get the boot progress the new way (via xyz location). 210 [Arguments] ${quiet}=${QUIET} 211 212 # Description of argument(s): 213 # quiet Indicates whether this keyword should run without any output to 214 # the console. 215 216 ${state}= Read Attribute ${HOST_STATE_URI} BootProgress quiet=${quiet} 217 218 [Return] ${state.rsplit('.', 1)[1]} 219 220 221Is Power On 222 [Documentation] Verify that the BMC chassis state is on. 223 ${state}= Get Power State 224 Should be equal ${state} ${1} 225 226 227Is Power Off 228 [Documentation] Verify that the BMC chassis state is off. 229 ${state}= Get Power State 230 Should be equal ${state} ${0} 231 232 233Initiate Power On 234 [Documentation] Initiates the power on and waits until the Is Power On 235 ... keyword returns that the power state has switched to on. 236 [Arguments] ${wait}=${1} 237 238 # Description of argument(s): 239 # wait Indicates whether to wait for a powered on state after issuing 240 # the power on command. 241 242 @{arglist}= Create List 243 ${args}= Create Dictionary data=@{arglist} 244 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOn 245 ... data=${args} 246 should be equal as strings ${resp.status_code} ${HTTP_OK} 247 248 # Does caller want to wait for power on status? 249 Run Keyword If '${wait}' == '${0}' Return From Keyword 250 Wait Until Keyword Succeeds 3 min 10 sec Is Power On 251 252 253Initiate Power Off 254 [Documentation] Initiates the power off and waits until the Is Power Off 255 ... keyword returns that the power state has switched to off. 256 257 @{arglist}= Create List 258 ${args}= Create Dictionary data=@{arglist} 259 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ powerOff 260 ... data=${args} 261 should be equal as strings ${resp.status_code} ${HTTP_OK} 262 Wait Until Keyword Succeeds 1 min 10 sec Is Power Off 263 264 265Initiate OS Host Power Off 266 [Documentation] Initiate an OS reboot. 267 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 268 ... ${os_password}=${OS_PASSWORD} ${hard}=${0} 269 270 # Description of argument(s): 271 # os_host The DNS name or IP of the OS. 272 # os_username The username to be used to sign in to the OS. 273 # os_password The password to be used to sign in to the OS. 274 # hard Indicates whether to do a hard vs. soft power off. 275 276 ${time_string}= Run Keyword If ${hard} Set Variable ${SPACE}now 277 ... ELSE Set Variable ${EMPTY} 278 279 ${cmd_buf}= Run Keyword If '${os_username}' == 'root' 280 ... Set Variable shutdown${time_string} 281 ... ELSE 282 ... Set Variable echo ${os_password} | sudo -S shutdown${time_string} 283 284 ${output} ${stderr} ${rc}= OS Execute Command 285 ... ${cmd_buf} fork=${1} 286 287 288Initiate OS Host Reboot 289 [Documentation] Initiate an OS reboot. 290 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 291 ... ${os_password}=${OS_PASSWORD} 292 293 # Description of argument(s): 294 # os_host The host name or IP address of the OS. 295 # os_username The username to be used to sign in to the OS. 296 # os_password The password to be used to sign in to the OS. 297 298 ${cmd_buf}= Run Keyword If '${os_username}' == 'root' 299 ... Set Variable reboot 300 ... ELSE 301 ... Set Variable echo ${os_password} | sudo -S reboot 302 303 ${output} ${stderr} ${rc}= OS Execute Command 304 ... ${cmd_buf} fork=${1} 305 306 307Initiate Auto Reboot 308 [Documentation] Initiate an auto reboot. 309 [Arguments] ${milliseconds}=5000 310 311 # Description of argument(s): 312 # milliseconds The number of milliseconds for the watchdog timer. 313 314 # Set the auto reboot policy. 315 Set Auto Reboot ${1} 316 # Set the watchdog timer. 317 Trigger Host Watchdog Error ${milliseconds} 318 319 320Trigger Warm Reset 321 [Documentation] Initiate a warm reset. 322 323 log to console "Triggering warm reset" 324 ${data}= create dictionary data=@{EMPTY} 325 ${resp}= openbmc post request 326 ... ${OPENBMC_BASE_URI}control/bmc0/action/warmReset data=${data} 327 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} 328 ${session_active}= Check If warmReset is Initiated 329 Run Keyword If '${session_active}' == '${True}' 330 ... Fail msg=warm reset didn't occur 331 332 Sleep ${SYSTEM_SHUTDOWN_TIME}min 333 Check If BMC Is Up 334 335 336Check OS 337 [Documentation] Attempts to ping the host OS and then checks that the host 338 ... OS is up by running an SSH command. 339 340 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 341 ... ${os_password}=${OS_PASSWORD} ${quiet}=${QUIET} 342 ... ${print_string}=${EMPTY} 343 [Teardown] SSHLibrary.Close Connection 344 345 # Description of argument(s): 346 # os_host The DNS name/IP of the OS host associated with our BMC. 347 # os_username The username to be used to sign on to the OS host. 348 # os_password The password to be used to sign on to the OS host. 349 # quiet Indicates whether this keyword should write to console. 350 # print_string A string to be printed before checking the OS. 351 352 rprint ${print_string} 353 354 # Attempt to ping the OS. Store the return code to check later. 355 ${ping_rc}= Run Keyword and Return Status Ping Host ${os_host} 356 357 SSHLibrary.Open connection ${os_host} 358 359 ${status} ${msg}= Run Keyword And Ignore Error Login ${os_username} 360 ... ${os_password} 361 ${err_msg1}= Sprint Error ${msg} 362 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1} 363 Run Keyword If '${status}' == 'FAIL' Fail msg=${err_msg} 364 ${output} ${stderr} ${rc}= Execute Command uptime return_stderr=True 365 ... return_rc=True 366 367 ${temp_msg}= Catenate Could not execute a command on the operating 368 ... system.\n 369 ${err_msg1}= Sprint Error ${temp_msg} 370 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1} 371 372 # If the return code returned by "Execute Command" is non-zero, this 373 # keyword will fail. 374 Should Be Equal ${rc} ${0} msg=${err_msg} 375 # We will likewise fail if there is any stderr data. 376 Should Be Empty ${stderr} 377 378 ${temp_msg}= Set Variable Could not ping the operating system.\n 379 ${err_msg1}= Sprint Error ${temp_msg} 380 ${err_msg}= Catenate SEPARATOR= \n ${err_msg1} 381 # We will likewise fail if the OS did not ping, as we could SSH but not 382 # ping 383 Should Be Equal As Strings ${ping_rc} ${TRUE} msg=${err_msg} 384 385 386Wait for OS 387 [Documentation] Waits for the host OS to come up via calls to "Check OS". 388 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 389 ... ${os_password}=${OS_PASSWORD} ${timeout}=${OS_WAIT_TIMEOUT} 390 ... ${quiet}=${0} 391 [Teardown] rprintn 392 393 # Description of argument(s): 394 # os_host The DNS name or IP of the OS host associated with our 395 # BMC. 396 # os_username The username to be used to sign on to the OS host. 397 # os_password The password to be used to sign on to the OS host. 398 # timeout The timeout in seconds indicating how long you're 399 # willing to wait for the OS to respond. 400 # quiet Indicates whether this keyword should write to console. 401 402 # The interval to be used between calls to "Check OS". 403 ${interval}= Set Variable 5 404 405 ${message}= Catenate Checking every ${interval} seconds for up to 406 ... ${timeout} seconds for the operating system to communicate. 407 rqprint_timen ${message} 408 409 Wait Until Keyword Succeeds ${timeout} sec ${interval} Check OS 410 ... ${os_host} ${os_username} ${os_password} 411 ... print_string=\# 412 413 rqprintn 414 415 rqprint_timen The operating system is now communicating. 416 417 418Get Power State 419 [Documentation] Returns the power state as an integer. Either 0 or 1. 420 [Arguments] ${quiet}=${QUIET} 421 422 # Description of argument(s): 423 # quiet Indicates whether this keyword should run without any output to 424 # the console. 425 426 @{arglist}= Create List 427 ${args}= Create Dictionary data=@{arglist} 428 429 ${resp}= Call Method ${OPENBMC_BASE_URI}control/chassis0/ getPowerState 430 ... data=${args} quiet=${quiet} 431 Should be equal as strings ${resp.status_code} ${HTTP_OK} 432 ${content}= to json ${resp.content} 433 434 [Return] ${content["data"]} 435 436 437Clear BMC Gard Record 438 [Documentation] Clear gard records from the system. 439 440 @{arglist}= Create List 441 ${args}= Create Dictionary data=@{arglist} 442 ${resp}= Call Method 443 ... ${OPENPOWER_CONTROL}gard Reset data=${args} 444 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} 445 446 447Copy PNOR to BMC 448 [Documentation] Copy the PNOR image to the BMC. 449 Import Library SCPLibrary WITH NAME scp 450 Open Connection for SCP 451 Log Copying ${PNOR_IMAGE_PATH} to /tmp 452 scp.Put File ${PNOR_IMAGE_PATH} /tmp 453 454 455Flash PNOR 456 [Documentation] Calls flash bios update method to flash PNOR image 457 [Arguments] ${pnor_image} 458 459 # Description of argument(s): 460 # pnor_image The filename and path of the PNOR image 461 # (e.g. "/home/image/zaius.pnor"). 462 463 @{arglist}= Create List ${pnor_image} 464 ${args}= Create Dictionary data=@{arglist} 465 ${resp}= Call Method /org/openbmc/control/flash/bios/ update 466 ... data=${args} 467 should be equal as strings ${resp.status_code} ${HTTP_OK} 468 Wait Until Keyword Succeeds 2 min 10 sec Is PNOR Flashing 469 470 471Get Flash BIOS Status 472 [Documentation] Returns the status of the flash BIOS API as a string. For 473 ... example 'Flashing', 'Flash Done', etc 474 ${data}= Read Properties /org/openbmc/control/flash/bios 475 [Return] ${data['status']} 476 477 478Is PNOR Flashing 479 [Documentation] Get BIOS 'Flashing' status. This indicates that PNOR 480 ... flashing has started. 481 ${status}= Get Flash BIOS Status 482 Should Contain ${status} Flashing 483 484 485Is PNOR Flash Done 486 [Documentation] Get BIOS 'Flash Done' status. This indicates that the 487 ... PNOR flashing has completed. 488 ${status}= Get Flash BIOS Status 489 should be equal as strings ${status} Flash Done 490 491 492Is OS Starting 493 [Documentation] Check if boot progress is OS starting. 494 ${boot_progress}= Get Boot Progress 495 Should Be Equal ${boot_progress} OSStart 496 497 498Is OS Off 499 [Documentation] Check if boot progress is "Off". 500 ${boot_progress}= Get Boot Progress 501 Should Be Equal ${boot_progress} Off 502 503 504Get Boot Progress To OS Starting State 505 [Documentation] Get the system to a boot progress state of 'FW Progress, 506 ... Starting OS'. 507 508 ${boot_progress}= Get Boot Progress 509 Run Keyword If '${boot_progress}' == 'OSStart' 510 ... Log Host is already in OS starting state 511 ... ELSE 512 ... Run Keywords Initiate Host PowerOff AND Initiate Host Boot 513 ... AND Wait Until Keyword Succeeds 10 min 10 sec Is OS Starting 514 515 516Verify Ping and REST Authentication 517 [Documentation] Verify ping and rest authentication. 518 ${l_ping}= Run Keyword And Return Status 519 ... Ping Host ${OPENBMC_HOST} 520 Run Keyword If '${l_ping}' == '${False}' 521 ... Fail msg=Ping Failed 522 523 ${l_rest}= Run Keyword And Return Status 524 ... Initialize OpenBMC 525 Run Keyword If '${l_rest}' == '${False}' 526 ... Fail msg=REST Authentication Failed 527 528 # Just to make sure the SSH is working for SCP 529 Open Connection And Log In 530 ${system} ${stderr}= Execute Command hostname return_stderr=True 531 Should Be Empty ${stderr} 532 533 534Check If BMC is Up 535 [Documentation] Wait for Host to be online. Checks every X seconds 536 ... interval for Y minutes and fails if timed out. 537 ... Default MAX timedout is 10 min, interval 10 seconds. 538 [Arguments] ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min 539 ... ${interval}=10 sec 540 541 # Description of argument(s): 542 # max_timeout Maximum time to wait. 543 # This should be expressed in Robot Framework's time format 544 # (e.g. "10 minutes"). 545 # interfal Interval to wait between status checks. 546 # This should be expressed in Robot Framework's time format 547 # (e.g. "5 seconds"). 548 549 Wait Until Keyword Succeeds 550 ... ${max_timeout} ${interval} Verify Ping and REST Authentication 551 552 553Check If warmReset is Initiated 554 [Documentation] Ping would be still alive, so try SSH to connect 555 ... if fails the ports are down indicating reboot 556 ... is in progress 557 558 # Warm reset adds 3 seconds delay before forcing reboot 559 # To minimize race conditions, we wait for 7 seconds 560 Sleep 7s 561 ${alive}= Run Keyword and Return Status 562 ... Open Connection And Log In 563 Return From Keyword If '${alive}' == '${False}' ${False} 564 [Return] ${True} 565 566 567Flush REST Sessions 568 [Documentation] Removes all the active session objects 569 Delete All Sessions 570 571 572Initialize DBUS cmd 573 [Documentation] Initialize dbus string with property string to extract 574 [Arguments] ${boot_property} 575 576 # Description of argument(s): 577 # boot_property Property string. 578 579 ${cmd}= Catenate ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString} 580 ${cmd}= Catenate ${cmd}${boot_property} 581 Set Global Variable ${dbuscmd} ${cmd} 582 583 584Create OS Console File Path 585 [Documentation] Create OS console file path name and return it. 586 [Arguments] ${log_file_path}=${EMPTY} 587 588 # Description of arguments: 589 # file_path The caller's candidate value. If this value is ${EMPTY}, this 590 # keyword will compose a file path name. Otherwise, this 591 # keyword will use the caller's file_path value. In either 592 # case, the value will be returned. 593 594 ${status}= Run Keyword And Return Status Variable Should Exist ${TEST_NAME} 595 596 ${default_file_path}= Set Variable If ${status} == ${TRUE} 597 ... /tmp/${OPENBMC_HOST}_${TEST_NAME.replace(' ', '')}_os_console.txt 598 ... /tmp/${OPENBMC_HOST}_os_console.txt 599 600 ${log_file_path}= Set Variable If '${log_file_path}' == '${EMPTY}' 601 ... ${default_file_path} ${log_file_path} 602 603 [Return] ${log_file_path} 604 605 606Create OS Console Command String 607 [Documentation] Return a command string to start OS console logging. 608 609 # First make sure that the ssh_pw program is available. 610 ${cmd}= Catenate which ssh_pw 2>/dev/null || find 611 ... ${EXECDIR} -name 'ssh_pw' 612 613 Rdpissuing ${cmd} 614 ${rc} ${output}= Run And Return Rc And Output ${cmd} 615 Rdpvars rc output 616 617 Should Be Equal As Integers 0 ${rc} msg=Could not find ssh_pw. 618 619 ${ssh_pw_file_path}= Set Variable ${output} 620 621 ${cmd}= Catenate ${ssh_pw_file_path} ${OPENBMC_PASSWORD} -p 2200 622 ... -o "StrictHostKeyChecking no" ${OPENBMC_USERNAME}@${OPENBMC_HOST} 623 624 [Return] ${cmd} 625 626 627Get SOL Console Pid 628 [Documentation] Get the pid of the active SOL console job. 629 [Arguments] ${expect_running}=${0} 630 631 # Description of argument(s): 632 # expect_running If set and if no SOL console job is found, print debug 633 # info and fail. 634 635 # Find the pid of the active system console logging session (if any). 636 ${search_string}= Create OS Console Command String 637 # At least in some cases, ps output does not show double quotes so we must 638 # replace them in our search string with the regexes to indicate that they 639 # are optional. 640 ${search_string}= Replace String ${search_string} " ["]? 641 ${ps_cmd}= Catenate ps axwwo user,pid,cmd 642 ${cmd_buf}= Catenate echo $(${ps_cmd} | egrep '${search_string}' | 643 ... egrep -v grep | cut -c10-14) 644 Rdpissuing ${cmd_buf} 645 ${rc} ${os_con_pid}= Run And Return Rc And Output ${cmd_buf} 646 Rdpvars os_con_pid 647 # If rc is not zero it just means that there is no OS Console process 648 # running. 649 650 Return From Keyword If '${os_con_pid}' != '${EMPTY}' ${os_con_pid} 651 Return From Keyword If '${expect_running}' == '${0}' ${os_con_pid} 652 653 Cmd Fnc cat ${log_file_path} ; echo ; ${ps_cmd} quiet=${0} 654 ... print_output=${1} show_err=${1} 655 656 Should Not Be Empty ${os_con_pid} 657 658 659Stop SOL Console Logging 660 [Documentation] Stop system console logging and return log output. 661 [Arguments] ${log_file_path}=${EMPTY} 662 ... ${targ_file_path}=${EXECDIR}${/}logs${/} 663 ... ${return_data}=${1} 664 665 # If there are muliple system console processes, they will all be stopped. 666 # If there is no existing log file this keyword will return an error 667 # message to that effect (and write that message to targ_file_path, if 668 # specified). 669 # NOTE: This keyword will not fail if there is no running system console 670 # process. 671 672 # Description of arguments: 673 # log_file_path The file path that was used to call "Start SOL 674 # Console Logging". See that keyword (above) for details. 675 # targ_file_path If specified, the file path to which the source 676 # file path (i.e. "log_file_path") should be copied. 677 # return_data If this is set to ${1}, this keyword will return the SOL 678 # data to the caller as a unicode string. 679 680 ${log_file_path}= Create OS Console File Path ${log_file_path} 681 682 ${os_con_pid}= Get SOL Console Pid 683 684 ${cmd_buf}= Catenate kill -9 ${os_con_pid} 685 Run Keyword If '${os_con_pid}' != '${EMPTY}' Rdpissuing ${cmd_buf} 686 ${rc} ${output}= Run Keyword If '${os_con_pid}' != '${EMPTY}' 687 ... Run And Return Rc And Output ${cmd_buf} 688 Run Keyword If '${os_con_pid}' != '${EMPTY}' Rdpvars rc output 689 690 Run Keyword If '${targ_file_path}' != '${EMPTY}' 691 ... Run Keyword And Ignore Error 692 ... Copy File ${log_file_path} ${targ_file_path} 693 694 ${output}= Set Variable ${EMPTY} 695 ${loc_quiet}= Evaluate ${debug}^1 696 ${rc} ${output}= Run Keyword If '${return_data}' == '${1}' 697 ... Cmd Fnc cat ${log_file_path} 2>/dev/null quiet=${loc_quiet} 698 ... print_output=${0} show_err=${0} 699 700 [Return] ${output} 701 702 703Start SOL Console Logging 704 [Documentation] Start system console log to file. 705 [Arguments] ${log_file_path}=${EMPTY} ${return_data}=${1} 706 707 # This keyword will first call "Stop SOL Console Logging". Only then will 708 # it start SOL console logging. The data returned by "Stop SOL Console 709 # Logging" will in turn be returned by this keyword. 710 711 # Description of arguments: 712 # log_file_path The file path to which system console log data should be 713 # written. Note that this path is taken to be a location 714 # on the machine where this program is running rather than 715 # on the Open BMC system. 716 # return_data If this is set to ${1}, this keyword will return any SOL 717 # data to the caller as a unicode string. 718 719 ${log_file_path}= Create OS Console File Path ${log_file_path} 720 721 ${log_output}= Stop SOL Console Logging ${log_file_path} 722 ... return_data=${return_data} 723 724 # Validate by making sure we can create the file. Problems creating the 725 # file would not be noticed by the subsequent ssh command because we fork 726 # the command. 727 Create File ${log_file_path} 728 ${sub_cmd_buf}= Create OS Console Command String 729 # Routing stderr to stdout so that any startup error text will go to the 730 # output file. 731 # TODO: Doesn't work with tox so reverting temporarily. 732 # nohup detaches the process completely from our pty. 733 #${cmd_buf}= Catenate nohup ${sub_cmd_buf} &> ${log_file_path} & 734 ${cmd_buf}= Catenate ${sub_cmd_buf} > ${log_file_path} 2>&1 & 735 Rdpissuing ${cmd_buf} 736 ${rc} ${output}= Run And Return Rc And Output ${cmd_buf} 737 # Because we are forking this command, we essentially will never get a 738 # non-zero return code or any output. 739 Should Be Equal ${rc} ${0} 740 741 Wait Until Keyword Succeeds 10 seconds 0 seconds 742 ... Get SOL Console Pid ${1} 743 744 [Return] ${log_output} 745 746 747Get Time Stamp 748 [Documentation] Get the current time stamp data 749 ${cur_time}= Get Current Date result_format=%Y%m%d%H%M%S%f 750 [Return] ${cur_time} 751 752 753Start Journal Log 754 [Documentation] Start capturing journal log to a file in /tmp using 755 ... journalctl command. By default journal log is collected 756 ... at /tmp/journal_log else user input location. 757 ... The File is appended with datetime. 758 [Arguments] ${file_path}=/tmp/journal_log ${filter}=${EMPTY} 759 760 # Description of arguments: 761 # file_path The file path of the journal file. 762 763 ${cur_time}= Get Time Stamp 764 Set Global Variable ${LOG_TIME} ${cur_time} 765 Open Connection And Log In 766 Start Command 767 ... journalctl -f ${filter} > ${file_path}-${LOG_TIME} 768 Log Journal Log Started: ${file_path}-${LOG_TIME} 769 770 771Stop Journal Log 772 [Documentation] Stop journalctl process if its running. 773 ... By default return log from /tmp/journal_log else 774 ... user input location. 775 [Arguments] ${file_path}=/tmp/journal_log 776 777 # Description of arguments: 778 # file_path The file path of the journal file. 779 780 Open Connection And Log In 781 782 ${rc}= 783 ... Execute Command 784 ... ps | grep journalctl | grep -v grep 785 ... return_stdout=False return_rc=True 786 787 Return From Keyword If '${rc}' == '${1}' 788 ... No journal log process running 789 790 ${output} ${stderr}= 791 ... Execute Command killall journalctl 792 ... return_stderr=True 793 Should Be Empty ${stderr} 794 795 ${journal_log} ${stderr}= 796 ... Execute Command 797 ... cat ${file_path}-${LOG_TIME} 798 ... return_stderr=True 799 Should Be Empty ${stderr} 800 801 Log ${journal_log} 802 803 Execute Command rm ${file_path}-${LOG_TIME} 804 805 [Return] ${journal_log} 806 807 808Mac Address To Hex String 809 [Documentation] Converts MAC address into hex format. 810 ... Example 811 ... Given the following MAC: 00:01:6C:80:02:78 812 ... This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78 813 ... Description of arguments: 814 ... i_macaddress MAC address in the following format 815 ... 00:01:6C:80:02:78 816 [Arguments] ${i_macaddress} 817 818 # Description of arguments: 819 # i_macaddress The MAC address. 820 821 ${mac_hex}= Catenate 0x${i_macaddress.replace(':', ' 0x')} 822 [Return] ${mac_hex} 823 824 825IP Address To Hex String 826 [Documentation] Converts IP address into hex format. 827 ... Example: 828 ... Given the following IP: 10.3.164.100 829 ... This keyword will return: 0xa 0x3 0xa4 0xa0 830 [Arguments] ${i_ipaddress} 831 832 # Description of arguments: 833 # i_macaddress The IP address in the format 10.10.10.10. 834 835 @{ip}= Split String ${i_ipaddress} . 836 ${index}= Set Variable ${0} 837 838 :FOR ${item} IN @{ip} 839 \ ${hex}= Convert To Hex ${item} prefix=0x lowercase=yes 840 \ Set List Value ${ip} ${index} ${hex} 841 \ ${index}= Set Variable ${index + 1} 842 ${ip_hex}= Catenate @{ip} 843 844 [Return] ${ip_hex} 845 846 847BMC CPU Performance Check 848 [Documentation] Minimal 10% of proc should be free in this instance 849 850 ${bmc_cpu_usage_output} ${stderr} ${rc}= BMC Execute Command 851 ... ${bmc_cpu_usage_cmd} 852 ${bmc_cpu_usage_output} ${stderr} ${rc}= BMC Execute Command 853 ... ${bmc_cpu_usage_cmd} 854 ${bmc_cpu_percentage}= Fetch From Left ${bmc_cpu_usage_output} % 855 Should be true ${bmc_cpu_percentage} < 90 856 857 858BMC Mem Performance Check 859 [Documentation] Minimal 10% of memory should be free in this instance 860 861 ${bmc_mem_free_output} ${stderr} ${rc}= BMC Execute Command 862 ... ${bmc_mem_free_cmd} 863 864 ${bmc_mem_total_output} ${stderr} ${rc}= BMC Execute Command 865 ... ${bmc_mem_total_cmd} 866 ${bmc_mem_free_output} ${stderr} ${rc}= BMC Execute Command 867 ... ${bmc_mem_free_cmd} 868 869 ${bmc_mem_total_output} ${stderr} ${rc}= BMC Execute Command 870 ... ${bmc_mem_total_cmd} 871 872 ${bmc_mem_percentage}= Evaluate ${bmc_mem_free_output}*100 873 ${bmc_mem_percentage}= Evaluate 874 ... ${bmc_mem_percentage}/${bmc_mem_total_output} 875 Should be true ${bmc_mem_percentage} > 10 876 877 878BMC File System Usage Check 879 [Documentation] Check the file system space. 4 file system should be 880 ... 100% full which is expected 881 # Filesystem Size Used Available Use% Mounted on 882 # /dev/root 14.4M 14.4M 0 100% / 883 # /dev/ubiblock0_0 14.4M 14.4M 0 100% /media/rofs-c9249b0e 884 # /dev/ubiblock8_0 19.6M 19.6M 0 100% /media/pnor-ro-8764baa3 885 # /dev/ubiblock4_0 14.4M 14.4M 0 100% /media/rofs-407816c 886 # /dev/ubiblock8_4 21.1M 21.1M 0 100% /media/pnor-ro-cecc64c4 887 ${bmc_fs_usage_output} ${stderr} ${rc}= BMC Execute Command 888 ... ${bmc_file_system_usage_cmd} 889 ${bmc_pnor_fs_usage_output} ${stderr} ${rc}= BMC Execute Command 890 ... ${total_pnor_ro_file_system_cmd} 891 ${bmc_bmc_fs_usage_output} ${stderr} ${rc}= BMC Execute Command 892 ... ${total_bmc_ro_file_system_cmd} 893 ${total_bmc_pnor_image}= Evaluate 894 ... ${bmc_pnor_fs_usage_output}+${bmc_bmc_fs_usage_output} 895 # Considering /dev/root also in total 100% used file system 896 ${total_full_fs}= Evaluate ${total_bmc_pnor_image}+1 897 Should Be True ${bmc_fs_usage_output}==${total_full_fs} 898 899 900Check BMC CPU Performance 901 [Documentation] Minimal 10% of proc should be free in 3 sample 902 :FOR ${var} IN Range 1 4 903 \ BMC CPU Performance check 904 905 906Check BMC Mem Performance 907 [Documentation] Minimal 10% of memory should be free 908 909 :FOR ${var} IN Range 1 4 910 \ BMC Mem Performance check 911 912 913Check BMC File System Performance 914 [Documentation] Check for file system usage for 4 times 915 916 :FOR ${var} IN Range 1 4 917 \ BMC File System Usage check 918 919 920Get URL List 921 [Documentation] Return list of URLs under given URL. 922 [Arguments] ${openbmc_url} 923 924 # Description of argument(s): 925 # openbmc_url URL for list operation (e.g. 926 # /xyz/openbmc_project/inventory). 927 928 ${url_list}= Read Properties ${openbmc_url}/list quiet=${1} 929 Sort List ${url_list} 930 931 [Return] ${url_list} 932 933 934Get Endpoint Paths 935 [Documentation] Returns all url paths ending with given endpoint 936 ... Example: 937 ... Given the following endpoint: cpu 938 ... This keyword will return: list of all urls ending with 939 ... cpu - 940 ... /org/openbmc/inventory/system/chassis/motherboard/cpu0, 941 ... /org/openbmc/inventory/system/chassis/motherboard/cpu1 942 [Arguments] ${path} ${endpoint} 943 944 # Description of arguments: 945 # path URL path for enumeration. 946 # endpoint Endpoint string (url path ending). 947 948 ${resp}= Read Properties ${path}/enumerate timeout=30 949 Log Dictionary ${resp} 950 951 ${list}= Get Dictionary Keys ${resp} 952 # For a given string, look for prefix and suffix for matching expression. 953 # Start of string followed by zero or more of any character followed by 954 # any digit or lower case character. 955 ${resp}= Get Matches ${list} regexp=^.*[0-9a-z_].${endpoint}[0-9a-z]*$ 956 957 [Return] ${resp} 958 959 960Check Zombie Process 961 [Documentation] Check if any defunct process exist or not on BMC 962 ${count} ${stderr} ${rc}= Execute Command ps -o stat | grep Z | wc -l 963 ... return_stderr=True return_rc=True 964 Should Be True ${count}==0 965 Should Be Empty ${stderr} 966 967 968Prune Journal Log 969 [Documentation] Prune archived journal logs. 970 [Arguments] ${vacuum_size}=1M 971 972 # This keyword can be used to prevent the journal 973 # log from filling up the /run filesystem. 974 # This command will retain only the latest logs 975 # of the user specified size. 976 977 # Description of argument(s): 978 # vacuum_size Size of journal. 979 980 Open Connection And Log In 981 ${output} ${stderr} ${rc}= 982 ... Execute Command 983 ... journalctl --vacuum-size=${vacuum_size} 984 ... return_stderr=True return_rc=True 985 986 Should Be Equal ${rc} ${0} msg=${stderr} 987 988 989Set BMC Power Policy 990 [Documentation] Set the given BMC power policy. 991 [Arguments] ${policy} 992 993 # Note that this function will translate the old style "RESTORE_LAST_STATE" 994 # policy to the new style "xyz.openbmc_project.Control.Power.RestorePolicy. 995 # Policy.Restore" for you. 996 997 # Description of argument(s): 998 # policy Power restore policy (e.g "RESTORE_LAST_STATE", 999 # ${RESTORE_LAST_STATE}). 1000 1001 # Set the bmc_power_policy_method to either 'Old' or 'New'. 1002 Set Power Policy Method 1003 # This translation helps bridge between old and new method for calling. 1004 ${policy}= Translate Power Policy Value ${policy} 1005 # Run the appropriate keyword. 1006 Run Key ${bmc_power_policy_method} Set Power Policy \ ${policy} 1007 ${currentPolicy}= Get System Power Policy 1008 Should Be Equal ${currentPolicy} ${policy} 1009 1010 1011New Set Power Policy 1012 [Documentation] Set the given BMC power policy (new method). 1013 [Arguments] ${policy} 1014 1015 # Description of argument(s): 1016 # policy Power restore policy (e.g. ${ALWAYS_POWER_OFF}). 1017 1018 ${valueDict}= Create Dictionary data=${policy} 1019 Write Attribute 1020 ... ${POWER_RESTORE_URI} PowerRestorePolicy data=${valueDict} 1021 1022 1023Old Set Power Policy 1024 [Documentation] Set the given BMC power policy (old method). 1025 [Arguments] ${policy} 1026 1027 # Description of argument(s): 1028 # policy Power restore policy (e.g. "ALWAYS_POWER_OFF"). 1029 1030 ${valueDict}= create dictionary data=${policy} 1031 Write Attribute ${HOST_SETTING} power_policy data=${valueDict} 1032 1033 1034Get System Power Policy 1035 [Documentation] Returns the BMC power policy. 1036 1037 # Set the bmc_power_policy_method to either 'Old' or 'New'. 1038 Set Power Policy Method 1039 ${cmd_buf}= Create List ${bmc_power_policy_method} Get Power Policy 1040 # Run the appropriate keyword. 1041 ${currentPolicy}= Run Keyword @{cmd_buf} 1042 1043 [Return] ${currentPolicy} 1044 1045 1046New Get Power Policy 1047 [Documentation] Returns the BMC power policy (new method). 1048 ${currentPolicy}= Read Attribute ${POWER_RESTORE_URI} PowerRestorePolicy 1049 1050 [Return] ${currentPolicy} 1051 1052 1053Old Get Power Policy 1054 [Documentation] Returns the BMC power policy (old method). 1055 ${currentPolicy}= Read Attribute ${HOST_SETTING} power_policy 1056 1057 [Return] ${currentPolicy} 1058 1059 1060Get Auto Reboot 1061 [Documentation] Returns auto reboot setting. 1062 ${setting}= Read Attribute ${CONTROL_HOST_URI}/auto_reboot AutoReboot 1063 1064 [Return] ${setting} 1065 1066 1067Set Auto Reboot 1068 [Documentation] Set the given auto reboot setting. 1069 [Arguments] ${setting} 1070 1071 # Description of argument(s): 1072 # setting The reboot setting, 1 for enabling and 0 for disabling. 1073 1074 ${valueDict}= Set Variable ${setting} 1075 ${data}= Create Dictionary data=${valueDict} 1076 Write Attribute ${CONTROL_HOST_URI}/auto_reboot AutoReboot data=${data} 1077 ${current_setting}= Get Auto Reboot 1078 Should Be Equal As Integers ${current_setting} ${setting} 1079 1080 1081Set BMC Reset Reference Time 1082 [Documentation] Set current boot time as a reference and increment 1083 ... boot count. 1084 1085 ${cur_btime}= Get BMC Boot Time 1086 Run Keyword If ${BOOT_TIME} == ${0} and ${BOOT_COUNT} == ${0} 1087 ... Set Global Variable ${BOOT_TIME} ${cur_btime} 1088 ... ELSE IF ${cur_btime} > ${BOOT_TIME} 1089 ... Run Keywords Set Global Variable ${BOOT_TIME} ${cur_btime} 1090 ... AND 1091 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1} 1092 1093 1094Get BMC Boot Time 1095 [Documentation] Returns boot time from /proc/stat. 1096 1097 Open Connection And Log In 1098 ${output} ${stderr}= 1099 ... Execute Command egrep '^btime ' /proc/stat | cut -f 2 -d ' ' 1100 ... return_stderr=True 1101 Should Be Empty ${stderr} 1102 ${btime}= Convert To Integer ${output} 1103 [Return] ${btime} 1104 1105 1106Enable Core Dump On BMC 1107 [Documentation] Enable core dump collection. 1108 ${core_pattern} ${stderr} ${rc}= BMC Execute Command 1109 ... echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern 1110 Should Be Equal As Strings ${core_pattern} /tmp/core_%e.%p 1111 1112 1113Get Number Of BMC Core Dump Files 1114 [Documentation] Returns number of core dump files on BMC. 1115 Open Connection And Log In 1116 ${num_of_core_dump}= Execute Command 1117 ... ls /tmp/core* 2>/dev/null | wc -l 1118 [Return] ${num_of_core_dump} 1119 1120 1121Set Core Dump File Size Unlimited 1122 [Documentation] Set core dump file size to unlimited. 1123 BMC Execute Command ulimit -c unlimited 1124 1125 1126Check For Core Dumps 1127 [Documentation] Check for any core dumps exist. 1128 ${output}= Get Number Of BMC Core Dump Files 1129 Run Keyword If ${output} > 0 1130 ... Log **Warning** BMC core dump files exist level=WARN 1131 1132 1133Trigger Host Watchdog Error 1134 [Documentation] Inject host watchdog timeout error via REST. 1135 [Arguments] ${milliseconds}=1000 ${sleep_time}=5s 1136 1137 # Description of argument(s): 1138 # milliseconds The time watchdog timer value in milliseconds (e.g. 1000 = 1139 # 1 second). 1140 # sleep_time Time delay for host watchdog error to get injected. 1141 # Default is 5 seconds. 1142 1143 ${data}= Create Dictionary 1144 ... data=xyz.openbmc_project.State.Watchdog.Action.PowerCycle 1145 ${status} ${result}= Run Keyword And Ignore Error 1146 ... Read Attribute ${HOST_WATCHDOG_URI} ExpireAction 1147 Run Keyword If '${status}' == 'PASS' 1148 ... Write Attribute ${HOST_WATCHDOG_URI} ExpireAction data=${data} 1149 1150 ${data}= Create Dictionary data=${milliseconds} 1151 Write Attribute ${HOST_WATCHDOG_URI} Interval data=${data} 1152 1153 ${data}= Create Dictionary data=${True} 1154 Write Attribute ${HOST_WATCHDOG_URI} Enabled data=${data} 1155 1156 Sleep ${sleep_time} 1157 1158 1159Login To OS Host 1160 [Documentation] Login to OS Host and return the Login response code. 1161 [Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME} 1162 ... ${os_password}=${OS_PASSWORD} 1163 1164 # Description of arguments: 1165 # ${os_host} IP address of the OS Host. 1166 # ${os_username} OS Host Login user name. 1167 # ${os_password} OS Host Login passwrd. 1168 1169 REST Power On stack_mode=skip quiet=1 1170 1171 SSHLibrary.Open Connection ${os_host} 1172 ${resp}= Login ${os_username} ${os_password} 1173 [Return] ${resp} 1174 1175 1176Configure Initial Settings 1177 [Documentation] Restore old IP and route. 1178 ... This keyword requires initial settings viz IP address, 1179 ... Network Mask, default gatway and serial console IP and port 1180 ... information which should be provided in command line. 1181 1182 [Arguments] ${host}=${OPENBMC_HOST} ${mask}=${NET_MASK} 1183 ... ${gw_ip}=${GW_IP} 1184 1185 # Description of arguments: 1186 # host IP address of the OS Host. 1187 # mask Network mask. 1188 # gu_ip Gateway IP address or hostname. 1189 1190 # Open telnet connection and ignore the error, in case telnet session is 1191 # already opened by the program calling this keyword. 1192 Run Keyword And Ignore Error Open Telnet Connection to BMC Serial Console 1193 Telnet.write ifconfig eth0 ${host} netmask ${mask} 1194 Telnet.write route add default gw ${gw_ip} 1195 1196 1197Install Debug Tarball On BMC 1198 [Documentation] Copy the debug tar file to BMC and install. 1199 [Arguments] ${tarball_file_path}=${default_tarball} 1200 ... ${targ_tarball_dir_path}=/tmp/tarball/ 1201 1202 # Description of arguments: 1203 # tarball_file_path Path of the debug tarball file. 1204 # The tar file is downloaded from the build page 1205 # https://openpower.xyz/job/openbmc-build/ 1206 # obmc-phosphor-debug-tarball-witherspoon.tar.xz 1207 # 1208 # targ_tarball_dir_path The directory path where the tarball is to be 1209 # installed. 1210 1211 OperatingSystem.File Should Exist ${tarball_file_path} 1212 ... msg=${tarball_file_path} doesn't exist. 1213 1214 # Upload the file to BMC. 1215 Import Library SCPLibrary WITH NAME scp 1216 Open Connection for SCP 1217 scp.Put File ${tarball_file_path} /tmp/debug-tarball.tar.xz 1218 1219 # Create tarball directory and install. 1220 BMC Execute Command mkdir -p ${targ_tarball_dir_path} 1221 BMC Execute Command 1222 ... tar -xf /tmp/debug-tarball.tar.xz -C ${targ_tarball_dir_path} 1223 1224 # Remove the tarball file from BMC. 1225 BMC Execute Command rm -f /tmp/debug-tarball.tar.xz 1226 1227 1228Get BMC Boot Count 1229 [Documentation] Returns BMC boot count based on boot time. 1230 ${cur_btime}= Get BMC Boot Time 1231 1232 # Set global variable BOOT_TIME to current boot time if current boot time 1233 # is changed. Also increase value of global variable BOOT_COUNT by 1. 1234 Run Keyword If ${cur_btime} > ${BOOT_TIME} 1235 ... Run Keywords Set Global Variable ${BOOT_TIME} ${cur_btime} 1236 ... AND 1237 ... Set Global Variable ${BOOT_COUNT} ${BOOT_COUNT + 1} 1238 1239 [Return] ${BOOT_COUNT} 1240 1241 1242Set BMC Boot Count 1243 [Documentation] Set BMC boot count to given value. 1244 [Arguments] ${count} 1245 1246 # Description of arguments: 1247 # count boot count value. 1248 ${cur_btime}= Get BMC Boot Time 1249 1250 # Set global variable BOOT_COUNT to given value. 1251 Set Global Variable ${BOOT_COUNT} ${count} 1252 1253 # Set BOOT_TIME variable to current boot time. 1254 Set Global Variable ${BOOT_COUNT} ${count} 1255 1256 1257Get System LED State 1258 [Documentation] Return the state of given system LED. 1259 [Arguments] ${led_name} 1260 1261 # Description of argument(s): 1262 # led_name System LED name (e.g. heartbeat, identify, beep). 1263 1264 ${state}= Read Attribute ${LED_PHYSICAL_URI}${led_name} State 1265 [Return] ${state.rsplit('.', 1)[1]} 1266 1267 1268Set System LED State 1269 [Documentation] Set given system LED via REST. 1270 [Arguments] ${led_name} ${led_state} 1271 # Description of argument(s): 1272 # led_name System LED name (e.g. heartbeat, identify, beep). 1273 # led_state LED state to be set (e.g. On, Off). 1274 1275 ${args}= Create Dictionary 1276 ... data=xyz.openbmc_project.Led.Physical.Action.${led_state} 1277 Write Attribute ${LED_PHYSICAL_URI}${led_name} State data=${args} 1278 1279 Verify LED State ${led_name} ${led_state} 1280 1281 1282Verify LED State 1283 [Documentation] Checks if LED is in given state. 1284 [Arguments] ${led_name} ${led_state} 1285 # Description of argument(s): 1286 # led_name System LED name (e.g. heartbeat, identify, beep). 1287 # led_state LED state to be verified (e.g. On, Off). 1288 1289 ${state}= Get System LED State ${led_name} 1290 Should Be Equal ${state} ${led_state} 1291 1292 1293Get LED State XYZ 1294 [Documentation] Returns state of given LED. 1295 [Arguments] ${led_name} 1296 1297 # Description of argument(s): 1298 # led_name Name of LED. 1299 1300 ${state}= Read Attribute ${LED_GROUPS_URI}${led_name} Asserted 1301 # Returns the state of the LED, either On or Off. 1302 [Return] ${state} 1303 1304 1305Delete Error Logs 1306 [Documentation] Delete error logs. 1307 1308 # Check if error logs entries exist, if not return. 1309 ${resp}= OpenBMC Get Request ${BMC_LOGGING_ENTRY}${/}list quiet=${1} 1310 Return From Keyword If ${resp.status_code} == ${HTTP_NOT_FOUND} 1311 1312 # Get the list of error logs entries and delete them all. 1313 ${elog_entries}= Get URL List ${BMC_LOGGING_ENTRY} 1314 :FOR ${entry} IN @{elog_entries} 1315 \ Delete Error Log Entry ${entry} 1316 1317 1318Delete Error Log Entry 1319 [Documentation] Delete error log entry. 1320 [Arguments] ${entry_path} 1321 1322 # Description of argument(s): 1323 # entry_path Delete an error log entry. 1324 # Ex. /xyz/openbmc_project/logging/entry/1 1325 1326 # Skip delete if entry URI is a callout. 1327 # Example: /xyz/openbmc_project/logging/entry/1/callout 1328 Return From Keyword If '${entry_path.rsplit('/', 1)[1]}' == 'callout' 1329 1330 ${data}= Create Dictionary data=@{EMPTY} 1331 ${resp}= Openbmc Delete Request ${entry_path} data=${data} 1332 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} 1333 1334 1335Delete All Error Logs 1336 [Documentation] Delete all error log entries using "DeleteAll" interface. 1337 1338 ${data}= Create Dictionary data=@{EMPTY} 1339 ${resp}= Openbmc Post Request ${BMC_LOGGING_URI}action/DeleteAll 1340 ... data=${data} 1341 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} 1342 1343 1344Get BMC Version 1345 [Documentation] Returns BMC version from /etc/os-release. 1346 ... e.g. "v1.99.6-141-ge662190" 1347 1348 ${cmd}= Set Variable grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '=' 1349 ${output} ${stderr} ${rc}= BMC Execute Command ${cmd} 1350 [Return] ${output} 1351 1352 1353Get PNOR Version 1354 [Documentation] Returns the PNOR version from the BMC. 1355 1356 ${pnor_attrs}= Get PNOR Attributes 1357 [Return] ${pnor_attrs['version']} 1358 1359 1360Get PNOR Attributes 1361 [Documentation] Return PNOR software attributes as a dictionary. 1362 1363 # This keyword parses /var/lib/phosphor-software-manager/pnor/ro/pnor.toc 1364 # into key/value pairs. 1365 1366 ${outbuf} ${stderr} ${rc}= BMC Execute Command 1367 ... cat /var/lib/phosphor-software-manager/pnor/ro/pnor.toc 1368 ${pnor_attrs}= Key Value Outbuf To Dict ${outbuf} delim== 1369 1370 [Return] ${pnor_attrs} 1371 1372 1373Get Elog URL List 1374 [Documentation] Return error log entry list of URLs. 1375 1376 ${url_list}= Read Properties /xyz/openbmc_project/logging/entry/ 1377 Sort List ${url_list} 1378 [Return] ${url_list} 1379 1380 1381Read Turbo Setting Via REST 1382 [Documentation] Return turbo setting via REST. 1383 # Returns 1 if TurboAllowed, 0 if not. 1384 1385 ${turbo_setting}= Read Attribute 1386 ... ${CONTROL_HOST_URI}turbo_allowed TurboAllowed 1387 [Return] ${turbo_setting} 1388 1389 1390Set Turbo Setting Via REST 1391 [Documentation] Set turbo setting via REST. 1392 [Arguments] ${setting} ${verify}=${False} 1393 1394 # Description of argument(s): 1395 # setting State to set TurboAllowed, 1=allowed, 0=not allowed. 1396 # verify If True, read the TurboAllowed setting to confirm. 1397 1398 ${data}= Create Dictionary data=${${setting}} 1399 Write Attribute ${CONTROL_HOST_URI}turbo_allowed TurboAllowed 1400 ... verify=${verify} data=${data} 1401 1402 1403Set Control Boot Mode 1404 [Documentation] Set given boot mode on the boot object path attribute. 1405 [Arguments] ${boot_path} ${boot_mode} 1406 1407 # Description of argument(s): 1408 # boot_path Boot object path. 1409 # Example: 1410 # /xyz/openbmc_project/control/host0/boot 1411 # /xyz/openbmc_project/control/host0/boot/one_time 1412 # boot_mode Boot mode which need to be set. 1413 # Example: 1414 # "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular" 1415 1416 ${valueDict}= Create Dictionary data=${boot_mode} 1417 Write Attribute ${boot_path} BootMode data=${valueDict} 1418 1419 1420Copy Address Translation Utils To HOST OS 1421 [Documentation] Copy address translation utils to host OS. 1422 1423 OperatingSystem.File Should Exist ${probe_cpu_tool_path} 1424 ... msg=${probe_cpu_tool_path} doesn't exist. 1425 OperatingSystem.File Should Exist ${probe_cpu_tool_path} 1426 ... msg=${probe_cpu_tool_path} doesn't exist. 1427 1428 scp.Open connection ${OS_HOST} username=${OS_USERNAME} 1429 ... password=${OS_PASSWORD} 1430 scp.Put File ${probe_cpu_tool_path} ${target_file_path} 1431 scp.Put File ${scom_addrs_tool_path} ${target_file_path} 1432 1433 1434Verify BMC RTC And UTC Time Drift 1435 [Documentation] Verify that the RTC and UTC time difference is less than 1436 ... the given time_drift_max. 1437 [Arguments] ${time_diff_max}=${10} 1438 1439 # Description of argument(s): 1440 # time_diff_max The max allowable RTC and UTC time difference in seconds. 1441 1442 # Example: 1443 # time_dict: 1444 # [local_time]: Fri 2017-11-03 152756 UTC 1445 # [local_time_seconds]: 1509740876 1446 # [universal_time]: Fri 2017-11-03 152756 UTC 1447 # [universal_time_seconds]: 1509740876 1448 # [rtc_time]: Fri 2016-05-20 163403 1449 # [rtc_time_seconds]: 1463780043 1450 # [time_zone]: n/a (UTC, +0000) 1451 # [network_time_on]: yes 1452 # [ntp_synchronized]: no 1453 # [rtc_in_local_tz]: no 1454 1455 ${time}= Get BMC Date Time 1456 ${time_diff}= Evaluate 1457 ... ${time['universal_time_seconds']} - ${time['rtc_time_seconds']} 1458 Should Be True ${time_diff} < ${time_diff_max} 1459 1460 1461Watchdog Object Should Exist 1462 [Documentation] Check that watchdog object exists. 1463 1464 ${resp}= OpenBMC Get Request ${WATCHDOG_URI}host0 1465 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} 1466 ... msg=Expected watchdog object does not exist. 1467 1468 1469Validate IP On BMC 1470 [Documentation] Validate IP address is present in set of IP addresses. 1471 [Arguments] ${ip_address} ${ip_data} 1472 1473 # Description of argument(s): 1474 # ip_address IP address to check (e.g. xx.xx.xx.xx). 1475 # ip_data Set of the IP addresses present. 1476 1477 Should Contain Match ${ip_data} ${ip_address}/* 1478 ... msg=${ip_address} not found in the list provided. 1479 1480 1481Remove Journald Logs 1482 [Documentation] Remove all journald logs and restart service. 1483 1484 ${cmd}= Catenate systemctl stop systemd-journald.service && 1485 ... rm -rf /var/log/journal && systemctl start systemd-journald.service 1486 1487 BMC Execute Command ${cmd} 1488 1489 1490Verify Identify LED State 1491 [Documentation] Verify the identify LED state 1492 ... matches caller's expectations. 1493 [Arguments] ${expected_state} 1494 1495 # Description of argument(s): 1496 # expected_state The LED state expected by the caller ("Blink" or "Off"). 1497 1498 ${resp}= Read Attribute ${LED_PHYSICAL_URI}/front_id State 1499 Should Be Equal ${resp} 1500 ... xyz.openbmc_project.Led.Physical.Action.${expected_state} 1501 ... msg=Unexpected LED state. 1502 1503 ${resp}= Read Attribute ${LED_PHYSICAL_URI}/rear_id State 1504 Should Be Equal ${resp} 1505 ... xyz.openbmc_project.Led.Physical.Action.${expected_state} 1506 ... msg=Unexpected LED state. 1507 1508 1509Verify The Attribute 1510 [Documentation] Verify the given attribute. 1511 [Arguments] ${uri} ${attribute_name} ${attribute_value} 1512 1513 # Description of argument(s): 1514 # uri URI path 1515 # (e.g. "/xyz/openbmc_project/control/host0/TPMEnable"). 1516 # attribute_name Name of attribute to be verified (e.g. "TPMEnable"). 1517 # attribute_value The expected value of attribute (e.g. "1", "0", etc.) 1518 1519 ${output}= Read Attribute ${uri} ${attribute_name} 1520 Should Be Equal ${attribute_value} ${output} 1521 ... msg=Attribute "${attribute_name} does not have the expected value. 1522 1523 1524Get BMC Flash Chip Boot Side 1525 [Documentation] Return the BMC flash chip boot side. 1526 1527 # Example: 1528 # 0 - indicates chip select is current side. 1529 # 32 - indicates chip select is alternate side. 1530 1531 ${boot_side} ${stderr} ${rc}= BMC Execute Command 1532 ... cat /sys/class/watchdog/watchdog1/bootstatus 1533 1534 [Return] ${boot_side} 1535 1536 1537Check For Regex In Journald 1538 [Documentation] Parse the journal log and check for regex string. 1539 [Arguments] ${regex}=${ERROR_REGEX} ${error_check}=${0} ${boot}=${EMPTY} 1540 1541 # Description of argument(s): 1542 # regex Strings to be filter. 1543 # error_check Check for errors. 1544 # boot Argument to check current or persistent full boot log 1545 # (e.g. "-b"). 1546 1547 ${journal_log} ${stderr} ${rc}= BMC Execute Command 1548 ... journalctl --no-pager ${boot} | egrep '${regex}' ignore_err=1 1549 1550 Run Keyword If ${error_check} == ${0} 1551 ... Should Be Empty ${journal_log} 1552 ... ELSE 1553 ... Should Not Be Empty ${journal_log} 1554 1555 1556Get Service Attribute 1557 [Documentation] Get service attribute policy output. 1558 [Arguments] ${option} ${servicename} 1559 1560 # Description of argument(s): 1561 # option systemctl supported options 1562 # servicename Qualified service name 1563 ${cmd}= Set Variable 1564 ... systemctl -p ${option} show ${servicename} | cut -d = -f2 1565 ${attr} ${stderr} ${rc}= BMC Execute Command ${cmd} 1566 [Return] ${attr} 1567 1568 1569Set REST Logging Policy 1570 [Documentation] Enable or disable REST logging setting. 1571 [Arguments] ${policy_setting}=${True} 1572 1573 # Description of argument(s): 1574 # policy_setting The policy setting value which can be either True or False. 1575 1576 ${log_dict}= Create Dictionary data=${policy_setting} 1577 Write Attribute ${BMC_LOGGING_URI}${/}rest_api_logs Enabled 1578 ... data=${log_dict} verify=${1} expected_value=${policy_setting} 1579 1580 1581Update Root Password 1582 [Documentation] Update system "root" user password. 1583 [Arguments] ${openbmc_password}=${OPENBMC_PASSWORD} 1584 1585 # Description of argument(s): 1586 # openbmc_password The root password for the open BMC system. 1587 1588 @{password} = Create List ${openbmc_password} 1589 ${data} = Create Dictionary data=@{password} 1590 1591 ${headers} = Create Dictionary Content-Type=application/json 1592 ${resp} = Post Request openbmc ${BMC_USER_URI}root/action/SetPassword 1593 ... data=${data} headers=${headers} 1594 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} 1595 ... msg=Updating the new root password failed, RC=${resp.status_code}. 1596