xref: /openbmc/openbmc-test-automation/lib/utils.robot (revision 3128a73d84f7a095d3ea80ffd8a405147fd9aa9f)
1*** Settings ***
2
3Documentation  Utilities for Robot keywords that use REST.
4
5Resource                ../lib/resource.robot
6Resource                ../lib/rest_client.robot
7Resource                ../lib/connection_client.robot
8Resource                ../lib/boot_utils.robot
9Resource                ../lib/common_utils.robot
10Resource                ../lib/bmc_redfish_utils.robot
11Library                 String
12Library                 DateTime
13Library                 Process
14Library                 OperatingSystem
15Library                 gen_print.py
16Library                 gen_misc.py
17Library                 gen_robot_print.py
18Library                 gen_cmd.py
19Library                 gen_robot_keyword.py
20Library                 bmc_ssh_utils.py
21Library                 utils.py
22Library                 var_funcs.py
23Library                 SCPLibrary  AS  scp
24Library                 gen_robot_valid.py
25Library                 pldm_utils.py
26
27
28*** Variables ***
29
30${SYSTEM_SHUTDOWN_TIME}   ${5}
31
32# Assign default value to QUIET for programs which may not define it.
33${QUIET}  ${0}
34
35${HOST_SETTING}    ${SETTINGS_URI}host0
36
37${boot_prog_method}               ${EMPTY}
38${power_policy_setup}             ${0}
39${bmc_power_policy_method}        ${EMPTY}
40@{BOOT_PROGRESS_STATES}           SystemHardwareInitializationComplete  OSBootStarted  OSRunning
41
42${REDFISH_SYS_STATE_WAIT_TIMEOUT}    120 Seconds
43
44*** Keywords ***
45
46
47Verify Ping and REST Authentication
48    [Documentation]  Verify ping and rest authentication.
49    ${l_ping}=   Run Keyword And Return Status
50    ...    Ping Host  ${OPENBMC_HOST}
51    IF  '${l_ping}' == '${False}'  Fail   msg=Ping Failed
52
53    ${l_rest}=   Run Keyword And Return Status
54    ...    Initialize OpenBMC
55    IF  '${l_rest}' == '${False}'  Fail   msg=REST Authentication Failed
56
57    # Just to make sure the SSH is working for SCP
58    Open Connection And Log In
59    ${system}   ${stderr}=    Execute Command   hostname   return_stderr=True
60    Should Be Empty     ${stderr}
61
62
63Verify Ping SSH And Redfish Authentication
64    [Documentation]  Verify ping, SSH and redfish authentication.
65
66    ${l_ping}=   Run Keyword And Return Status  Ping Host  ${OPENBMC_HOST}
67    IF  '${l_ping}' == '${False}'  Fail   msg=Ping Failed
68
69    ${l_rest}=   Run Keyword And Return Status   Redfish.Login
70    IF  '${l_rest}' == '${False}'  Fail   msg=REST Authentication Failed
71
72    # Just to make sure the SSH is working.
73    Open Connection And Log In
74    ${system}   ${stderr}=    Execute Command   hostname   return_stderr=True
75    Should Be Empty     ${stderr}
76
77
78Check If BMC is Up
79    [Documentation]  Wait for Host to be online. Checks every X seconds
80    ...              interval for Y minutes and fails if timed out.
81    ...              Default MAX timedout is 10 min, interval 10 seconds.
82    [Arguments]      ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
83    ...              ${interval}=10 sec
84
85    # Description of argument(s):
86    # max_timeout   Maximum time to wait.
87    #               This should be expressed in Robot Framework's time format
88    #               (e.g. "10 minutes").
89    # interval      Interval to wait between status checks.
90    #               This should be expressed in Robot Framework's time format
91    #               (e.g. "5 seconds").
92
93    Wait Until Keyword Succeeds
94    ...   ${max_timeout}  ${interval}   Verify Ping and REST Authentication
95
96
97Flush REST Sessions
98    [Documentation]   Removes all the active session objects
99    Delete All Sessions
100
101
102Trigger Host Watchdog Error
103    [Documentation]  Inject host watchdog timeout error via REST.
104    [Arguments]  ${milliseconds}=1000  ${sleep_time}=5s
105
106    # Description of argument(s):
107    # milliseconds  The time watchdog timer value in milliseconds (e.g. 1000 =
108    #               1 second).
109    # sleep_time    Time delay for host watchdog error to get injected.
110    #               Default is 5 seconds.
111
112    ${data}=  Create Dictionary
113    ...  data=xyz.openbmc_project.State.Watchdog.Action.PowerCycle
114    ${status}  ${result}=  Run Keyword And Ignore Error
115    ...  Read Attribute  ${HOST_WATCHDOG_URI}  ExpireAction
116    IF  '${status}' == 'PASS'
117        Write Attribute  ${HOST_WATCHDOG_URI}  ExpireAction  data=${data}
118    END
119
120    ${int_milliseconds}=  Convert To Integer  ${milliseconds}
121    ${data}=  Create Dictionary  data=${int_milliseconds}
122    Write Attribute  ${HOST_WATCHDOG_URI}  Interval  data=${data}
123
124    ${data}=  Create Dictionary  data=${True}
125    Write Attribute  ${HOST_WATCHDOG_URI}  Enabled  data=${data}
126
127    Sleep  ${sleep_time}
128
129
130Login To OS Host
131    [Documentation]  Login to OS Host and return the Login response code.
132    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
133    ...          ${os_password}=${OS_PASSWORD}
134
135    # Description of arguments:
136    # ${os_host} IP address of the OS Host.
137    # ${os_username}  OS Host Login user name.
138    # ${os_password}  OS Host Login passwrd.
139
140    Redfish Power On  stack_mode=skip  quiet=1
141
142    SSHLibrary.Open Connection  ${os_host}
143    ${resp}=  SSHLibrary.Login  ${os_username}  ${os_password}
144    RETURN  ${resp}
145
146
147Initiate Auto Reboot
148    [Documentation]  Initiate an auto reboot.
149    [Arguments]  ${milliseconds}=5000
150
151    # Description of argument(s):
152    # milliseconds  The number of milliseconds for the watchdog timer.
153
154    # Set the auto reboot policy.
155    Set Auto Reboot  ${1}
156    # Set the watchdog timer.
157    Trigger Host Watchdog Error  ${milliseconds}
158
159
160Initiate OS Host Reboot
161    [Documentation]  Initiate an OS reboot.
162    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
163    ...          ${os_password}=${OS_PASSWORD}
164
165    # Description of argument(s):
166    # os_host      The host name or IP address of the OS.
167    # os_username  The username to be used to sign in to the OS.
168    # os_password  The password to be used to sign in to the OS.
169
170    ${cmd_buf}=    Set Variable If    '${os_username}' == 'root'    reboot
171    ...    echo ${os_password} | sudo -S reboot
172
173    ${output}  ${stderr}  ${rc}=  OS Execute Command
174    ...  ${cmd_buf}  fork=${1}
175
176
177Initiate OS Host Power Off
178    [Documentation]  Initiate an OS reboot.
179    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
180    ...          ${os_password}=${OS_PASSWORD}  ${hard}=${0}
181
182    # Description of argument(s):
183    # os_host      The DNS name or IP of the OS.
184    # os_username  The username to be used to sign in to the OS.
185    # os_password  The password to be used to sign in to the OS.
186    # hard         Indicates whether to do a hard vs. soft power off.
187
188    ${time_string}=    Set Variable If    ${hard}    ${SPACE}now
189    ...    ${EMPTY}
190
191    ${cmd_buf}=    Set Variable If    '${os_username}' == 'root'    shutdown${time_string}
192    ...    echo ${os_password} | sudo -S shutdown${time_string}
193
194    ${output}  ${stderr}  ${rc}=  OS Execute Command
195    ...  ${cmd_buf}  fork=${1}
196
197
198Set System LED State
199    [Documentation]  Set given system LED via REST.
200    [Arguments]  ${led_name}  ${led_state}
201    # Description of argument(s):
202    # led_name     System LED name (e.g. heartbeat, identify, beep).
203    # led_state    LED state to be set (e.g. On, Off).
204
205    ${args}=  Create Dictionary
206    ...  data=xyz.openbmc_project.Led.Physical.Action.${led_state}
207    Write Attribute  ${LED_PHYSICAL_URI}${led_name}  State  data=${args}
208
209    Verify LED State  ${led_name}  ${led_state}
210
211
212Old Get Boot Progress
213    [Documentation]  Get the boot progress the old way (via org location).
214    [Arguments]  ${quiet}=${QUIET}
215
216    # Description of argument(s):
217    # quiet   Indicates whether this keyword should run without any output to
218    #         the console.
219
220    ${state}=  Read Attribute  ${OPENBMC_BASE_URI}sensors/host/BootProgress
221    ...  value  quiet=${quiet}
222
223    RETURN  ${state}
224
225
226Set Boot Progress Method
227    [Documentation]  Set the boot_prog_method to either 'Old' or 'New'.
228
229    # The boot progress data has moved from an 'org' location to an 'xyz'
230    # location.  This keyword will determine whether the new method of getting
231    # the boot progress is valid and will set the global boot_prog_method
232    # variable accordingly.  If boot_prog_method is already set (either by a
233    # prior call to this function or via a -v parm), this keyword will simply
234    # return.
235
236    # Note:  There are interim builds that contain boot_progress in both the
237    # old and the new location values.  It is nearly impossible for this
238    # keyword to determine whether the old boot_progress or the new one is
239    # active.  When using such builds where the old boot_progress is active,
240    # the only recourse users will have is that they may specify
241    # -v boot_prog_method:Old to force old behavior on such builds.
242
243    IF  '${boot_prog_method}' != '${EMPTY}'  Return From Keyword
244
245    ${new_status}  ${new_value}=  Run Keyword And Ignore Error
246    ...  New Get Boot Progress
247    # If the new style read fails, the method must necessarily be "Old".
248    IF  '${new_status}' == 'PASS'
249        Set Global Variable  ${boot_prog_method}  New
250        Rqpvars  boot_prog_method
251        Return From Keyword
252    END
253
254    # Default method is "Old".
255    Set Global Variable  ${boot_prog_method}  Old
256    Rqpvars  boot_prog_method
257
258
259Initiate Power On
260    [Documentation]  Initiates the power on and waits until the Is Power On
261    ...  keyword returns that the power state has switched to on.
262    [Arguments]  ${wait}=${1}
263
264    # Description of argument(s):
265    # wait   Indicates whether to wait for a powered on state after issuing
266    #        the power on command.
267
268    @{arglist}=   Create List
269    ${args}=     Create Dictionary    data=@{arglist}
270    ${resp}=  Call Method  ${OPENBMC_BASE_URI}control/chassis0/  powerOn
271    ...  data=${args}
272    should be equal as strings      ${resp.status_code}     ${HTTP_OK}
273
274    # Does caller want to wait for power on status?
275    IF  '${wait}' == '${0}'  Return From Keyword
276    Wait Until Keyword Succeeds  3 min  10 sec  Is Power On
277
278
279Initiate Power Off
280    [Documentation]  Initiates the power off and waits until the Is Power Off
281    ...  keyword returns that the power state has switched to off.
282
283    @{arglist}=   Create List
284    ${args}=     Create Dictionary    data=@{arglist}
285    ${resp}=  Call Method  ${OPENBMC_BASE_URI}control/chassis0/  powerOff
286    ...  data=${args}
287    should be equal as strings      ${resp.status_code}     ${HTTP_OK}
288    Wait Until Keyword Succeeds  1 min  10 sec  Is Power Off
289
290
291Get Boot Progress
292    [Documentation]  Get the boot progress and return it.
293    [Arguments]  ${quiet}=${QUIET}
294
295    # Description of argument(s):
296    # quiet   Indicates whether this keyword should run without any output to
297    #         the console.
298
299    Set Boot Progress Method
300    IF  '${boot_prog_method}' == 'New'
301        ${state}=  New Get Boot Progress  quiet=${quiet}
302    ELSE
303        ${state}=  Old Get Boot Progress  quiet=${quiet}
304    END
305
306    RETURN  ${state}
307
308
309New Get Boot Progress
310    [Documentation]  Get the boot progress the new way (via xyz location).
311    [Arguments]  ${quiet}=${QUIET}
312
313    # Description of argument(s):
314    # quiet   Indicates whether this keyword should run without any output to
315    #         the console.
316
317    ${state}=  Read Attribute  ${HOST_STATE_URI}  BootProgress  quiet=${quiet}
318
319    RETURN  ${state.rsplit('.', 1)[1]}
320
321
322New Get Power Policy
323    [Documentation]  Returns the BMC power policy (new method).
324    ${currentPolicy}=  Read Attribute  ${POWER_RESTORE_URI}  PowerRestorePolicy
325
326    RETURN  ${currentPolicy}
327
328
329Old Get Power Policy
330    [Documentation]  Returns the BMC power policy (old method).
331    ${currentPolicy}=  Read Attribute  ${HOST_SETTING}  power_policy
332
333    RETURN  ${currentPolicy}
334
335
336Redfish Get Power Restore Policy
337    [Documentation]  Returns the BMC power restore policy.
338
339    ${power_restore_policy}=  Redfish.Get Attribute  /redfish/v1/Systems/${SYSTEM_ID}  PowerRestorePolicy
340    RETURN  ${power_restore_policy}
341
342
343Get Auto Reboot
344    [Documentation]  Returns auto reboot setting.
345    ${setting}=  Read Attribute  ${CONTROL_HOST_URI}/auto_reboot  AutoReboot
346
347    RETURN  ${setting}
348
349
350Redfish Get Auto Reboot
351    [Documentation]  Returns auto reboot setting.
352
353    ${resp}=  Wait Until Keyword Succeeds  1 min  20 sec
354    ...  Redfish.Get Attribute  /redfish/v1/Systems/${SYSTEM_ID}  Boot
355    RETURN  ${resp["AutomaticRetryConfig"]}
356
357
358Trigger Warm Reset
359    [Documentation]  Initiate a warm reset.
360
361    log to console    "Triggering warm reset"
362    ${data}=   create dictionary   data=@{EMPTY}
363    ${resp}=  Openbmc Post Request
364    ...  ${OPENBMC_BASE_URI}control/bmc0/action/warmReset  data=${data}
365    Should Be Equal As Strings      ${resp.status_code}     ${HTTP_OK}
366    ${session_active}=   Check If warmReset is Initiated
367    IF  '${session_active}' == '${True}'  Fail   msg=warm reset didn't occur
368
369    Sleep   ${SYSTEM_SHUTDOWN_TIME}min
370    Check If BMC Is Up
371
372
373Get Power State
374    [Documentation]  Returns the power state as an integer. Either 0 or 1.
375    [Arguments]  ${quiet}=${QUIET}
376
377    # Description of argument(s):
378    # quiet   Indicates whether this keyword should run without any output to
379    #         the console.
380
381    @{arglist}=  Create List
382    ${args}=  Create Dictionary  data=@{arglist}
383
384    ${resp}=  Call Method  ${OPENBMC_BASE_URI}control/chassis0/  getPowerState
385    ...        data=${args}  quiet=${quiet}
386    Should be equal as strings  ${resp.status_code}  ${HTTP_OK}
387
388    RETURN  ${resp.json()["data"]}
389
390
391Clear BMC Gard Record
392    [Documentation]  Clear gard records from the system.
393
394    @{arglist}=  Create List
395    ${args}=  Create Dictionary  data=@{arglist}
396    ${resp}=  Call Method
397    ...  ${OPENPOWER_CONTROL}gard  Reset  data=${args}
398    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
399
400
401Flash PNOR
402    [Documentation]    Calls flash bios update method to flash PNOR image
403    [Arguments]    ${pnor_image}
404
405    # Description of argument(s):
406    # pnor_image  The filename and path of the PNOR image
407    #             (e.g. "/home/image/zaius.pnor").
408
409    @{arglist}=   Create List    ${pnor_image}
410    ${args}=     Create Dictionary    data=@{arglist}
411    ${resp}=  Call Method  /org/openbmc/control/flash/bios/  update
412    ...  data=${args}
413    should be equal as strings      ${resp.status_code}     ${HTTP_OK}
414    Wait Until Keyword Succeeds    2 min   10 sec    Is PNOR Flashing
415
416
417Get Flash BIOS Status
418    [Documentation]  Returns the status of the flash BIOS API as a string. For
419    ...              example 'Flashing', 'Flash Done', etc
420    ${data}=  Read Properties  /org/openbmc/control/flash/bios
421    RETURN    ${data['status']}
422
423
424Is PNOR Flashing
425    [Documentation]  Get BIOS 'Flashing' status. This indicates that PNOR
426    ...              flashing has started.
427    ${status}=    Get Flash BIOS Status
428    Should Contain  ${status}  Flashing
429
430
431Is PNOR Flash Done
432    [Documentation]  Get BIOS 'Flash Done' status.  This indicates that the
433    ...              PNOR flashing has completed.
434    ${status}=    Get Flash BIOS Status
435    should be equal as strings     ${status}     Flash Done
436
437
438Create OS Console File Path
439    [Documentation]  Create OS console file path name and return it.
440    [Arguments]  ${log_file_path}=${EMPTY}
441
442    # Description of arguments:
443    # file_path  The caller's candidate value.  If this value is ${EMPTY}, this
444    #            keyword will compose a file path name.  Otherwise, this
445    #            keyword will use the caller's file_path value.  In either
446    #            case, the value will be returned.
447
448    ${status}=  Run Keyword And Return Status  Variable Should Exist
449    ...  ${TEST_NAME}
450
451    ${default_file_path}=  Set Variable If  ${status} == ${TRUE}
452    ...  ${EXECDIR}${/}tmp${/}${OPENBMC_HOST}_${TEST_NAME.replace(' ', '')}_os_console.txt
453    ...  ${EXECDIR}${/}tmp${/}${OPENBMC_HOST}_os_console.txt
454
455    ${log_file_path}=  Set Variable If  '${log_file_path}' == '${EMPTY}'
456    ...  ${default_file_path}  ${log_file_path}
457
458    RETURN  ${log_file_path}
459
460
461Get Endpoint Paths
462    [Documentation]   Returns all url paths ending with given endpoint
463    ...               Example:
464    ...               Given the following endpoint: cpu
465    ...               This keyword will return: list of all urls ending with
466    ...               cpu -
467    ...               /org/openbmc/inventory/system/chassis/motherboard/cpu0,
468    ...               /org/openbmc/inventory/system/chassis/motherboard/cpu1
469    [Arguments]   ${path}   ${endpoint}
470
471    # Description of arguments:
472    # path       URL path for enumeration.
473    # endpoint   Endpoint string (url path ending).
474
475    # Make sure path ends with slash.
476    ${path}=  Add Trailing Slash  ${path}
477
478    ${resp}=  Read Properties  ${path}enumerate  timeout=30
479    Log Dictionary  ${resp}
480
481    ${list}=  Get Dictionary Keys  ${resp}
482    # For a given string, look for prefix and suffix for matching expression.
483    # Start of string followed by zero or more of any character followed by
484    # any digit or lower case character.
485    ${resp}=  Get Matches  ${list}  regexp=^.*[0-9a-z_].${endpoint}\[_0-9a-z]*$  case_insensitive=${True}
486
487    RETURN  ${resp}
488
489
490Set BMC Power Policy
491    [Documentation]   Set the given BMC power policy.
492    [Arguments]   ${policy}
493
494    # Note that this function will translate the old style "RESTORE_LAST_STATE"
495    # policy to the new style "xyz.openbmc_project.Control.Power.RestorePolicy.
496    # Policy.Restore" for you.
497
498    # Description of argument(s):
499    # policy    Power restore policy (e.g "RESTORE_LAST_STATE",
500    #           ${RESTORE_LAST_STATE}).
501
502    # Set the bmc_power_policy_method to either 'Old' or 'New'.
503    Set Power Policy Method
504    # This translation helps bridge between old and new method for calling.
505    ${policy}=  Translate Power Policy Value  ${policy}
506    # Run the appropriate keyword.
507    Run Key  ${bmc_power_policy_method} Set Power Policy \ ${policy}
508    ${currentPolicy}=  Get System Power Policy
509    Should Be Equal    ${currentPolicy}   ${policy}
510
511
512Delete Error Logs
513    [Documentation]  Delete error logs.
514    [Arguments]  ${quiet}=${0}
515    # Description of argument(s):
516    # quiet    If enabled, turns off logging to console.
517
518    # Check if error logs entries exist, if not return.
519    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}list  quiet=${1}
520    Return From Keyword If  ${resp.status_code} == ${HTTP_NOT_FOUND}
521
522    # Get the list of error logs entries and delete them all.
523    ${elog_entries}=  Get URL List  ${BMC_LOGGING_ENTRY}
524    FOR  ${entry}  IN  @{elog_entries}
525        Delete Error Log Entry  ${entry}  quiet=${quiet}
526    END
527
528
529Delete All Error Logs
530    [Documentation]  Delete all error log entries using "DeleteAll" interface.
531
532    ${args}=  Set Variable   {"data": []}
533    ${resp}=  Openbmc Post Request  ${BMC_LOGGING_URI}action/DeleteAll
534    ...  data=${args}
535    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
536
537
538Get Elog URL List
539    [Documentation]  Return error log entry list of URLs.
540
541    ${url_list}=  Read Properties  /xyz/openbmc_project/logging/entry/
542    Sort List  ${url_list}
543    RETURN  ${url_list}
544
545
546Get BMC Flash Chip Boot Side
547    [Documentation]  Return the BMC flash chip boot side.
548
549    # Example:
550    # 0  - indicates chip select is current side.
551    # 32 - indicates chip select is alternate side.
552
553    ${boot_side}  ${stderr}  ${rc}=  BMC Execute Command
554    ...  cat /sys/class/watchdog/watchdog1/bootstatus
555
556    RETURN  ${boot_side}
557
558
559Watchdog Object Should Exist
560    [Documentation]  Check that watchdog object exists.
561
562    ${resp}=  OpenBMC Get Request  ${WATCHDOG_URI}host0
563    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
564    ...  msg=Expected watchdog object does not exist.
565
566
567Get System LED State
568    [Documentation]  Return the state of given system LED.
569    [Arguments]  ${led_name}
570
571    # Description of argument(s):
572    # led_name     System LED name (e.g. heartbeat, identify, beep).
573
574    ${state}=  Read Attribute  ${LED_PHYSICAL_URI}${led_name}  State
575    RETURN  ${state.rsplit('.', 1)[1]}
576
577
578Verify LED State
579    [Documentation]  Checks if LED is in given state.
580    [Arguments]  ${led_name}  ${led_state}
581    # Description of argument(s):
582    # led_name     System LED name (e.g. heartbeat, identify, beep).
583    # led_state    LED state to be verified (e.g. On, Off).
584
585    ${state}=  Get System LED State  ${led_name}
586    Should Be Equal  ${state}  ${led_state}
587
588
589Get LED State XYZ
590    [Documentation]  Returns state of given LED.
591    [Arguments]  ${led_name}
592
593    # Description of argument(s):
594    # led_name  Name of LED.
595
596    ${state}=  Read Attribute  ${LED_GROUPS_URI}${led_name}  Asserted
597    # Returns the state of the LED, either On or Off.
598    RETURN  ${state}
599
600
601Verify Identify LED State
602    [Documentation]  Verify that the identify state of the LED group matches caller's expectations.
603    [Arguments]  ${expected_state}
604
605    # Description of argument(s):
606    # expected_state  The expected LED asserted state (1 = asserted, 0 = not asserted).
607
608    ${led_state}=  Get LED State XYZ  enclosure_identify
609    Should Be Equal  ${led_state}  ${expected_state}  msg=Unexpected LED state.
610
611Verify The Attribute
612    [Documentation]  Verify the given attribute.
613    [Arguments]  ${uri}  ${attribute_name}  ${attribute_value}
614
615    # Description of argument(s):
616    # uri              URI path
617    #                  (e.g. "/xyz/openbmc_project/control/host0/TPMEnable").
618    # attribute_name   Name of attribute to be verified (e.g. "TPMEnable").
619    # attribute_value  The expected value of attribute (e.g. "1", "0", etc.)
620
621    ${output}=  Read Attribute  ${uri}  ${attribute_name}
622    Should Be Equal  ${attribute_value}  ${output}
623    ...  msg=Attribute "${attribute_name} does not have the expected value.
624
625
626New Set Power Policy
627    [Documentation]   Set the given BMC power policy (new method).
628    [Arguments]   ${policy}
629
630    # Description of argument(s):
631    # policy    Power restore policy (e.g. ${ALWAYS_POWER_OFF}).
632
633    ${valueDict}=  Create Dictionary  data=${policy}
634    Write Attribute
635    ...  ${POWER_RESTORE_URI}  PowerRestorePolicy  data=${valueDict}
636
637
638Old Set Power Policy
639    [Documentation]   Set the given BMC power policy (old method).
640    [Arguments]   ${policy}
641
642    # Description of argument(s):
643    # policy    Power restore policy (e.g. "ALWAYS_POWER_OFF").
644
645    ${valueDict}=     create dictionary  data=${policy}
646    Write Attribute    ${HOST_SETTING}    power_policy   data=${valueDict}
647
648
649Redfish Set Power Restore Policy
650    [Documentation]   Set the BMC power restore policy.
651    [Arguments]   ${power_restore_policy}
652
653    # Description of argument(s):
654    # power_restore_policy    Power restore policy (e.g. "AlwaysOff", "AlwaysOn", "LastState").
655
656    Redfish.Patch  /redfish/v1/Systems/${SYSTEM_ID}  body={"PowerRestorePolicy": "${power_restore_policy}"}
657    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
658
659
660IPMI Set Power Restore Policy
661    [Documentation]   Set the BMC power restore policy using IPMI.
662    [Arguments]   ${power_restore_policy}=always-off
663
664    # Description of argument(s):
665    # power_restore_policy    Power restore policies
666    #                         always-on   : turn on when power is restored
667    #                         previous    : return to previous state when power is restored
668    #                         always-off  : stay off after power is restored
669
670    ${resp}=  Run IPMI Standard Command  chassis policy ${power_restore_policy}
671    # Example:  Set chassis power restore policy to always-off
672    Should Contain  ${resp}  ${power_restore_policy}
673
674
675Set Auto Reboot Setting
676    [Documentation]  Set the given auto reboot setting (REST or Redfish).
677    [Arguments]  ${value}
678
679    # Description of argument(s):
680    # value    The reboot setting, 1 for enabling and 0 for disabling.
681
682    # This is to cater to boot call points and plugin script which will always
683    # send using value 0 or 1. This dictionary maps to redfish string values.
684    ${rest_redfish_dict}=  Create Dictionary
685    ...                    1=RetryAttempts
686    ...                    0=Disabled
687
688    IF  ${REDFISH_SUPPORT_TRANS_STATE} == ${1}
689        Redfish Set Auto Reboot  ${rest_redfish_dict["${value}"]}
690    ELSE
691        Set Auto Reboot  ${value}
692    END
693
694Set Auto Reboot
695    [Documentation]  Set the given auto reboot setting.
696    [Arguments]  ${setting}
697
698    # Description of argument(s):
699    # setting    The reboot setting, 1 for enabling and 0 for disabling.
700
701    ${valueDict}=  Convert To Integer  ${setting}
702    ${data}=  Create Dictionary  data=${valueDict}
703    Write Attribute  ${CONTROL_HOST_URI}/auto_reboot  AutoReboot   data=${data}
704    ${current_setting}=  Get Auto Reboot
705    Should Be Equal As Integers  ${current_setting}  ${setting}
706
707
708Redfish Set Auto Reboot
709    [Documentation]  Set the given auto reboot setting.
710    [Arguments]  ${setting}
711
712    # Description of argument(s):
713    # setting    The reboot setting, "RetryAttempts" and "Disabled".
714
715    Redfish.Patch  /redfish/v1/Systems/${SYSTEM_ID}  body={"Boot": {"AutomaticRetryConfig": "${setting}"}}
716    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
717
718    ${current_setting}=  Redfish Get Auto Reboot
719    Should Be Equal As Strings  ${current_setting}  ${setting}
720
721
722Set Control Boot Mode
723    [Documentation]  Set given boot mode on the boot object path attribute.
724    [Arguments]  ${boot_path}  ${boot_mode}
725
726    # Description of argument(s):
727    # boot_path  Boot object path.
728    #            Example:
729    #            /xyz/openbmc_project/control/host0/boot
730    #            /xyz/openbmc_project/control/host0/boot/one_time
731    # boot_mode  Boot mode which need to be set.
732    #            Example:
733    #            "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"
734
735    ${valueDict}=  Create Dictionary  data=${boot_mode}
736    Write Attribute  ${boot_path}  BootMode  data=${valueDict}
737
738
739Is Power On
740    [Documentation]  Verify that the BMC chassis state is on.
741    ${state}=  Get Power State
742    Should be equal  ${state}  ${1}
743
744
745Is Power Off
746    [Documentation]  Verify that the BMC chassis state is off.
747    ${state}=  Get Power State
748    Should be equal  ${state}  ${0}
749
750
751CLI Get BMC DateTime
752    [Documentation]  Returns BMC date time from date command.
753
754    ${bmc_time_via_date}  ${stderr}  ${rc}=  BMC Execute Command  date +"%Y-%m-%dT%H:%M:%S"  print_err=1
755    RETURN  ${bmc_time_via_date}
756
757
758Update Root Password
759    [Documentation]  Update system "root" user password.
760    [Arguments]  ${openbmc_password}=${OPENBMC_PASSWORD}
761
762    # Description of argument(s):
763    # openbmc_password   The root password for the open BMC system.
764
765    @{password}=  Create List  ${openbmc_password}
766    ${data}=  Create Dictionary  data=@{password}
767
768    ${headers}=  Create Dictionary  Content-Type=application/json  X-Auth-Token=${XAUTH_TOKEN}
769    ${resp}=  POST On Session  openbmc  ${BMC_USER_URI}root/action/SetPassword
770    ...  data=${data}  headers=${headers}
771    Valid Value  resp.status_code  [${HTTP_OK}]
772
773
774Get Post Boot Action
775    [Documentation]  Get post boot action.
776
777    # Post code update action dictionary.
778    #
779    # {
780    #    BMC image: {
781    #        OnReset: Redfish OBMC Reboot (off),
782    #        Immediate: Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
783    #    },
784    #    Host image: {
785    #        OnReset: RF SYS GracefulRestart,
786    #        Immediate: Wait State  os_running_match_state  10 mins
787    #    }
788    # }
789
790    ${code_base_dir_path}=  Get Code Base Dir Path
791    ${post_code_update_actions}=  Evaluate
792    ...  json.load(open('${code_base_dir_path}data/applytime_table.json'))  modules=json
793    Rprint Vars  post_code_update_actions
794
795    RETURN  ${post_code_update_actions}
796
797
798Get Task State From File
799    [Documentation]  Get task states from pre-define data/task_state.json file.
800
801    # Example:  Task state JSON format.
802    #
803    # {
804    #   "TaskRunning": {
805    #           "TaskState": "Running",
806    #           "TaskStatus": "OK"
807    #   },
808    #   "TaskCompleted": {
809    #           "TaskState": "Completed",
810    #           "TaskStatus": "OK"
811    #   },
812    #   "TaskException": {
813    #           "TaskState": "Exception",
814    #           "TaskStatus": "Warning"
815    #   }
816    # }
817
818    # Python module: get_code_base_dir_path()
819    ${code_base_dir_path}=  Get Code Base Dir Path
820    ${task_state}=  Evaluate
821    ...  json.load(open('${code_base_dir_path}data/task_state.json'))  modules=json
822    Rprint Vars  task_state
823
824    RETURN  ${task_state}
825
826
827Redfish Set Boot Default
828    [Documentation]  Set and Verify Boot source override
829    [Arguments]      ${override_enabled}  ${override_target}  ${override_mode}=UEFI
830
831    # Description of argument(s):
832    # override_enabled    Boot source override enable type.
833    #                     ('Once', 'Continuous', 'Disabled').
834    # override_target     Boot source override target.
835    #                     ('Pxe', 'Cd', 'Hdd', 'Diags', 'BiosSetup', 'None').
836    # override_mode       Boot source override mode (relevant only for x86 arch).
837    #                     ('Legacy', 'UEFI').
838
839    ${data}=  Create Dictionary  BootSourceOverrideEnabled=${override_enabled}
840    ...  BootSourceOverrideTarget=${override_target}
841
842    IF  '${PLATFORM_ARCH_TYPE}' == 'x86'
843        Set To Dictionary  ${data}  BootSourceOverrideMode  ${override_mode}
844    END
845
846    ${payload}=  Create Dictionary  Boot=${data}
847
848    Redfish.Patch  /redfish/v1/Systems/${SYSTEM_ID}  body=&{payload}
849    ...  valid_status_codes=[${HTTP_OK},${HTTP_NO_CONTENT}]
850
851    ${resp}=  Redfish.Get Attribute  /redfish/v1/Systems/${SYSTEM_ID}  Boot
852    Should Be Equal As Strings  ${resp["BootSourceOverrideEnabled"]}  ${override_enabled}
853    Should Be Equal As Strings  ${resp["BootSourceOverrideTarget"]}  ${override_target}
854    IF  '${PLATFORM_ARCH_TYPE}' == 'x86'
855        Should Be Equal As Strings  ${resp["BootSourceOverrideMode"]}  ${override_mode}
856    END
857
858
859# Redfish state keywords.
860
861Redfish Get BMC State
862    [Documentation]  Return BMC health state.
863
864    # "Enabled" ->  BMC Ready, "Starting" -> BMC NotReady
865
866    # Example:
867    # "Status": {
868    #    "Health": "OK",
869    #    "HealthRollup": "OK",
870    #    "State": "Enabled"
871    # },
872
873    ${status}=  Wait Until Keyword Succeeds  1 min  20 sec
874    ...  Redfish.Get Attribute  /redfish/v1/Managers/${MANAGER_ID}  Status
875    RETURN  ${status["State"]}
876
877
878Redfish Verify BMC State
879    [Documentation]  Verify BMC state is enabled.
880    [Arguments]  ${match_state}=Enabled
881
882    # Description of argument(s):
883    # match_state    Expected match state (e.g. Enabled, Starting, Error)
884
885    ${Status}=  Wait Until Keyword Succeeds  1 min  20 sec
886    ...  Redfish.Get Attribute  /redfish/v1/Managers/${MANAGER_ID}  Status
887
888    Should Be Equal As Strings  ${match_state}  ${Status['State']}
889
890
891Redfish Get Host State
892    [Documentation]  Return host power and health state.
893
894    # Refer: http://redfish.dmtf.org/schemas/v1/Resource.json#/definitions/Status
895
896    # Example:
897    # "PowerState": "Off",
898    # "Status": {
899    #    "Health": "OK",
900    #    "HealthRollup": "OK",
901    #    "State": "StandbyOffline"
902    # },
903
904    ${chassis}=  Wait Until Keyword Succeeds  1 min  20 sec
905    ...  Redfish.Get Properties  /redfish/v1/Chassis/${CHASSIS_ID}
906    RETURN  ${chassis["PowerState"]}  ${chassis["Status"]["State"]}
907
908
909Redfish Get Boot Progress
910    [Documentation]  Return boot progress state.
911
912    # Example: /redfish/v1/Systems/system/
913    # "BootProgress": {
914    #    "LastState": "OSRunning"
915    # },
916
917    ${boot_progress}=  Wait Until Keyword Succeeds  1 min  20 sec
918    ...  Redfish.Get Properties  /redfish/v1/Systems/${SYSTEM_ID}/
919
920    Return From Keyword If  "${PLATFORM_ARCH_TYPE}" == "x86"
921    ...  NA  ${boot_progress["Status"]["State"]}
922
923    RETURN  ${boot_progress["BootProgress"]["LastState"]}  ${boot_progress["Status"]["State"]}
924
925
926Redfish Get States
927    [Documentation]  Return all the BMC and host states in dictionary.
928    [Timeout]  ${REDFISH_SYS_STATE_WAIT_TIMEOUT}
929
930    # Refer: openbmc/docs/designs/boot-progress.md
931
932    Redfish.Login
933
934    ${bmc_state}=  Redfish Get BMC State
935    ${chassis_state}  ${chassis_status}=  Redfish Get Host State
936    ${boot_progress}  ${host_state}=  Redfish Get Boot Progress
937
938    ${states}=  Create Dictionary
939    ...  bmc=${bmc_state}
940    ...  chassis=${chassis_state}
941    ...  host=${host_state}
942    ...  boot_progress=${boot_progress}
943
944    # Disable loggoing state to prevent huge log.html record when boot
945    # test is run in loops.
946    #Log  ${states}
947
948    RETURN  ${states}
949
950
951Is BMC Not Quiesced
952    [Documentation]  Verify BMC state is not quiesced.
953
954    ${bmc_state}=   Redfish Get States
955
956    Log To Console  BMC State : ${bmc_state}
957
958    Should Not Be Equal As Strings  Quiesced  ${bmc_state['bmc']}
959
960
961Is BMC Standby
962    [Documentation]  Check if BMC is ready and host at standby.
963
964    ${standby_states}=  Create Dictionary
965    ...  bmc=Enabled
966    ...  chassis=Off
967    ...  host=Disabled
968    ...  boot_progress=None
969
970    IF  '${PLATFORM_ARCH_TYPE}' == 'x86'
971        Set To Dictionary  ${standby_states}  boot_progress=NA
972    END
973
974    Wait Until Keyword Succeeds  3 min  10 sec  Redfish Get States
975
976    Wait Until Keyword Succeeds  5 min  10 sec  Match State  ${standby_states}
977
978
979Match State
980    [Documentation]  Check if the expected and current states are matched.
981    [Arguments]  ${match_state}
982
983    # Description of argument(s):
984    # match_state      Expected states in dictionary.
985
986    ${current_state}=  Redfish Get States
987    Dictionaries Should Be Equal  ${match_state}  ${current_state}
988
989
990Wait For Host Boot Progress To Reach Required State
991    [Documentation]  Wait till host boot progress reaches required state.
992    [Arguments]      ${expected_boot_state}=OSRunning
993
994    # Description of argument(s):
995    # expected_boot_state    Expected boot state. E.g. OSRunning, SystemInitComplete etc.
996
997    Wait Until Keyword Succeeds  ${power_on_timeout}  20 sec
998    ...  Is Boot Progress At Required State  ${expected_boot_state}
999
1000
1001Redfish Initiate Auto Reboot
1002    [Documentation]  Initiate an auto reboot.
1003    [Arguments]  ${interval}=2000
1004
1005    # Description of argument(s):
1006    # interval  Value in milliseconds to set Watchdog interval
1007
1008    # Set auto reboot policy
1009    Redfish Set Auto Reboot  RetryAttempts
1010
1011    Redfish Power Operation  On
1012
1013    Wait Until Keyword Succeeds  2 min  5 sec  Is Boot Progress Changed
1014
1015    # Set watchdog timer
1016    Set Watchdog Interval Using Busctl  ${interval}
1017
1018
1019Is Boot Progress Changed
1020    [Documentation]  Get BootProgress state and expect boot state mismatch.
1021    [Arguments]  ${boot_state}=None
1022
1023    # Description of argument(s):
1024    # boot_state   Value of the BootProgress state to match against.
1025
1026    ${boot_progress}  ${host_state}=  Redfish Get Boot Progress
1027
1028    Should Not Be Equal  ${boot_progress}   ${boot_state}
1029
1030
1031Is Boot Progress At Required State
1032    [Documentation]  Get BootProgress state and expect boot state to match.
1033    [Arguments]  ${boot_state}=None
1034
1035    # Description of argument(s):
1036    # boot_state   Value of the BootProgress state to match.
1037
1038    ${boot_progress}  ${host_state}=  Redfish Get Boot Progress
1039
1040    Should Be Equal  ${boot_progress}   ${boot_state}
1041
1042
1043Is Boot Progress At Any State
1044    [Documentation]  Get BootProgress state and expect boot state to match
1045    ...              with any of the states mentioned in the list.
1046    [Arguments]  ${boot_states}=@{BOOT_PROGRESS_STATES}
1047
1048    # Description of argument(s):
1049    # boot_states   List of the BootProgress states to match.
1050
1051    ${boot_progress}  ${host_state}=  Redfish Get Boot Progress
1052    Should Contain Any  ${boot_progress}  @{boot_states}
1053
1054
1055Is Host At State
1056    [Documentation]  Get Host state and check if it matches
1057    ...   user input expected state.
1058    [Arguments]  ${expected_host_state}
1059
1060    # Description of argument(s):
1061    # expected_host_state  Expected Host State to check.(e.g. Quiesced).
1062
1063    ${boot_progress}  ${host_state}=  Redfish Get Boot Progress
1064
1065    Should Be Equal  ${host_state}  ${expected_host_state}
1066
1067
1068Set Watchdog Interval Using Busctl
1069    [Documentation]  Set Watchdog time interval.
1070    [Arguments]  ${milliseconds}=1000
1071
1072    # Description of argument(s):
1073    # milliseconds     Time interval for watchdog timer
1074
1075    ${cmd}=  Catenate  busctl set-property xyz.openbmc_project.Watchdog
1076    ...                /xyz/openbmc_project/watchdog/host0
1077    ...                xyz.openbmc_project.State.Watchdog Interval t ${milliseconds}
1078    BMC Execute Command  ${cmd}
1079
1080
1081Stop PLDM Service And Wait
1082    [Documentation]  Stop PLDM service and wait for Host to initiate reset.
1083
1084    BMC Execute Command  systemctl stop pldmd.service
1085
1086
1087Get BIOS Attribute
1088    [Documentation]  Get the BIOS attribute for /redfish/v1/Systems/system/Bios.
1089
1090    # Python module:  get_member_list(resource_path)
1091    ${systems}=  Redfish_Utils.Get Member List  /redfish/v1/Systems
1092    ${bios_attr_dict}=  Redfish.Get Attribute  ${systems[0]}/Bios  Attributes
1093
1094    RETURN  ${bios_attr_dict}
1095
1096
1097Set BIOS Attribute
1098    [Documentation]  PATCH the BIOS attribute for /redfish/v1/Systems/system/Bios.
1099    [Arguments]  ${attribute_name}  ${attribute_value}
1100
1101    # Description of argument(s):
1102    # attribute_name     Any valid BIOS attribute.
1103    # attribute_value    Valid allowed attribute values.
1104
1105    # Python module:  get_member_list(resource_path)
1106    ${systems}=  Redfish_Utils.Get Member List  /redfish/v1/Systems
1107    Redfish.Patch  ${systems[0]}/Bios/Settings  body={"Attributes":{"${attribute_name}":"${attribute_value}"}}
1108
1109
1110Is BMC Operational
1111    [Documentation]  Check if BMC is enabled.
1112    [Teardown]  Redfish.Logout
1113
1114    Wait Until Keyword Succeeds  5 min  5 sec  Ping Host  ${OPENBMC_HOST}
1115    # In some of bmc stack, network services will gets loaded before redfish/ipmi services gets loaded.
1116    # Hence, 3mins sleep time is added to allow other service gets loaded.
1117    Sleep  180s
1118    Redfish.login
1119    ${bmc_status}=  Redfish Get BMC State
1120    Should Be Equal  ${bmc_status}  Enabled
1121
1122
1123PLDM Set BIOS Attribute
1124    [Documentation]  Set the BIOS attribute via pldmtool and verify the attribute is set.
1125    ...              Defaulted for fw_boot_side for boot test usage caller.
1126    [Arguments]  ${attribute_name}=fw_boot_side  ${attribute_value}=Temp
1127
1128    # Description of argument(s):
1129    # attribute_name      Valid BIOS attribute name e.g ("fw_boot_side")
1130    # attribute_value     Valid BIOS attribute value for fw_boot_side.
1131
1132    # PLDM response output example:
1133    # {
1134    #    "Response": "SUCCESS"
1135    # }
1136
1137    ${resp}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${attribute_name} -d ${attribute_value}
1138    Should Be Equal As Strings  ${resp["Response"]}  SUCCESS
1139
1140    # PLDM GET output example:
1141    # {
1142    #    "CurrentValue": "Temp"
1143    # }
1144
1145    ${pldm_output}=  PLDM Get BIOS Attribute  ${attribute_name}
1146    Should Be Equal As Strings  ${pldm_output["CurrentValue"]}  ${attribute_value}
1147    ...  msg=Expecting ${attribute_value} but got ${pldm_output["CurrentValue"]}
1148
1149
1150PLDM Get BIOS Attribute
1151    [Documentation]  Get the BIOS attribute via pldmtool for a given attribute and return value.
1152    [Arguments]  ${attribute_name}
1153
1154    # Description of argument(s):
1155    # attribute_name     Valid BIOS attribute name e.g ("fw_boot_side")
1156
1157    ${pldm_output}=  pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${attribute_name}
1158    RETURN  ${pldm_output}
1159
1160
1161Verify Host Power State
1162    [Documentation]  Get the Host Power state and compare it with the expected state.
1163    [Arguments]  ${expected_power_state}
1164
1165    # Description of argument(s):
1166    # expected_power_state   State of Host e.g. Off or On.
1167
1168    ${power_state}  ${health_status}=  Redfish Get Host State
1169    Should Be Equal  ${power_state}  ${expected_power_state}
1170
1171
1172Verify Host Is Up
1173    [Documentation]  Verify Host is Up.
1174
1175    Wait Until Keyword Succeeds  3 min  30 sec  Verify Host Power State  On
1176    # Python module:  os_execute(cmd)
1177    Wait Until Keyword Succeeds  10 min  30 sec  OS Execute Command  uptime
1178