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
10Library                 String
11Library                 DateTime
12Library                 Process
13Library                 OperatingSystem
14Library                 gen_print.py
15Library                 gen_misc.py
16Library                 gen_robot_print.py
17Library                 gen_cmd.py
18Library                 gen_robot_keyword.py
19Library                 bmc_ssh_utils.py
20Library                 utils.py
21Library                 var_funcs.py
22Library                 SCPLibrary  WITH NAME  scp
23Library                 gen_robot_valid.py
24
25
26*** Variables ***
27
28${SYSTEM_SHUTDOWN_TIME}   ${5}
29
30# Assign default value to QUIET for programs which may not define it.
31${QUIET}  ${0}
32
33${HOST_SETTING}    ${SETTINGS_URI}host0
34
35${boot_prog_method}               ${EMPTY}
36${power_policy_setup}             ${0}
37${bmc_power_policy_method}        ${EMPTY}
38
39
40*** Keywords ***
41
42
43Verify Ping and REST Authentication
44    [Documentation]  Verify ping and rest authentication.
45    ${l_ping}=   Run Keyword And Return Status
46    ...    Ping Host  ${OPENBMC_HOST}
47    Run Keyword If  '${l_ping}' == '${False}'
48    ...    Fail   msg=Ping Failed
49
50    ${l_rest}=   Run Keyword And Return Status
51    ...    Initialize OpenBMC
52    Run Keyword If  '${l_rest}' == '${False}'
53    ...    Fail   msg=REST Authentication Failed
54
55    # Just to make sure the SSH is working for SCP
56    Open Connection And Log In
57    ${system}   ${stderr}=    Execute Command   hostname   return_stderr=True
58    Should Be Empty     ${stderr}
59
60
61Check If BMC is Up
62    [Documentation]  Wait for Host to be online. Checks every X seconds
63    ...              interval for Y minutes and fails if timed out.
64    ...              Default MAX timedout is 10 min, interval 10 seconds.
65    [Arguments]      ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
66    ...              ${interval}=10 sec
67
68    # Description of argument(s):
69    # max_timeout   Maximum time to wait.
70    #               This should be expressed in Robot Framework's time format
71    #               (e.g. "10 minutes").
72    # interfal      Interval to wait between status checks.
73    #               This should be expressed in Robot Framework's time format
74    #               (e.g. "5 seconds").
75
76    Wait Until Keyword Succeeds
77    ...   ${max_timeout}  ${interval}   Verify Ping and REST Authentication
78
79
80Flush REST Sessions
81    [Documentation]   Removes all the active session objects
82    Delete All Sessions
83
84
85Trigger Host Watchdog Error
86    [Documentation]  Inject host watchdog timeout error via REST.
87    [Arguments]  ${milliseconds}=1000  ${sleep_time}=5s
88
89    # Description of argument(s):
90    # milliseconds  The time watchdog timer value in milliseconds (e.g. 1000 =
91    #               1 second).
92    # sleep_time    Time delay for host watchdog error to get injected.
93    #               Default is 5 seconds.
94
95    ${data}=  Create Dictionary
96    ...  data=xyz.openbmc_project.State.Watchdog.Action.PowerCycle
97    ${status}  ${result}=  Run Keyword And Ignore Error
98    ...  Read Attribute  ${HOST_WATCHDOG_URI}  ExpireAction
99    Run Keyword If  '${status}' == 'PASS'
100    ...  Write Attribute  ${HOST_WATCHDOG_URI}  ExpireAction  data=${data}
101
102    ${int_milliseconds}=  Convert To Integer  ${milliseconds}
103    ${data}=  Create Dictionary  data=${int_milliseconds}
104    Write Attribute  ${HOST_WATCHDOG_URI}  Interval  data=${data}
105
106    ${data}=  Create Dictionary  data=${True}
107    Write Attribute  ${HOST_WATCHDOG_URI}  Enabled  data=${data}
108
109    Sleep  ${sleep_time}
110
111
112Login To OS Host
113    [Documentation]  Login to OS Host and return the Login response code.
114    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
115    ...          ${os_password}=${OS_PASSWORD}
116
117    # Description of arguments:
118    # ${os_host} IP address of the OS Host.
119    # ${os_username}  OS Host Login user name.
120    # ${os_password}  OS Host Login passwrd.
121
122    REST Power On  stack_mode=skip  quiet=1
123
124    SSHLibrary.Open Connection  ${os_host}
125    ${resp}=  SSHLibrary.Login  ${os_username}  ${os_password}
126    [Return]  ${resp}
127
128
129Initiate Auto Reboot
130    [Documentation]  Initiate an auto reboot.
131    [Arguments]  ${milliseconds}=5000
132
133    # Description of argument(s):
134    # milliseconds  The number of milliseconds for the watchdog timer.
135
136    # Set the auto reboot policy.
137    Set Auto Reboot  ${1}
138    # Set the watchdog timer.
139    Trigger Host Watchdog Error  ${milliseconds}
140
141
142Initiate OS Host Reboot
143    [Documentation]  Initiate an OS reboot.
144    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
145    ...          ${os_password}=${OS_PASSWORD}
146
147    # Description of argument(s):
148    # os_host      The host name or IP address of the OS.
149    # os_username  The username to be used to sign in to the OS.
150    # os_password  The password to be used to sign in to the OS.
151
152    ${cmd_buf}=  Run Keyword If  '${os_username}' == 'root'
153    ...      Set Variable  reboot
154    ...  ELSE
155    ...      Set Variable  echo ${os_password} | sudo -S reboot
156
157    ${output}  ${stderr}  ${rc}=  OS Execute Command
158    ...  ${cmd_buf}  fork=${1}
159
160
161Initiate OS Host Power Off
162    [Documentation]  Initiate an OS reboot.
163    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
164    ...          ${os_password}=${OS_PASSWORD}  ${hard}=${0}
165
166    # Description of argument(s):
167    # os_host      The DNS name or IP of the OS.
168    # os_username  The username to be used to sign in to the OS.
169    # os_password  The password to be used to sign in to the OS.
170    # hard         Indicates whether to do a hard vs. soft power off.
171
172    ${time_string}=  Run Keyword If  ${hard}  Set Variable  ${SPACE}now
173    ...  ELSE  Set Variable  ${EMPTY}
174
175    ${cmd_buf}=  Run Keyword If  '${os_username}' == 'root'
176    ...      Set Variable  shutdown${time_string}
177    ...  ELSE
178    ...      Set Variable  echo ${os_password} | sudo -S shutdown${time_string}
179
180    ${output}  ${stderr}  ${rc}=  OS Execute Command
181    ...  ${cmd_buf}  fork=${1}
182
183
184Set System LED State
185    [Documentation]  Set given system LED via REST.
186    [Arguments]  ${led_name}  ${led_state}
187    # Description of argument(s):
188    # led_name     System LED name (e.g. heartbeat, identify, beep).
189    # led_state    LED state to be set (e.g. On, Off).
190
191    ${args}=  Create Dictionary
192    ...  data=xyz.openbmc_project.Led.Physical.Action.${led_state}
193    Write Attribute  ${LED_PHYSICAL_URI}${led_name}  State  data=${args}
194
195    Verify LED State  ${led_name}  ${led_state}
196
197
198Read Turbo Setting Via REST
199    [Documentation]  Return turbo setting via REST.
200    # Returns 1 if TurboAllowed, 0 if not.
201
202    ${turbo_setting}=  Read Attribute
203    ...  ${CONTROL_HOST_URI}turbo_allowed  TurboAllowed
204    [Return]  ${turbo_setting}
205
206
207Set Turbo Setting Via REST
208    [Documentation]  Set turbo setting via REST.
209    [Arguments]  ${setting}  ${verify}=${False}
210
211    # Description of argument(s):
212    # setting  State to set TurboAllowed, 1=allowed, 0=not allowed.
213    # verify   If True, read the TurboAllowed setting to confirm.
214
215    ${data}=  Create Dictionary  data=${${setting}}
216    Write Attribute  ${CONTROL_HOST_URI}turbo_allowed  TurboAllowed
217    ...  verify=${verify}  data=${data}
218
219
220Set REST Logging Policy
221    [Documentation]  Enable or disable REST logging setting.
222    [Arguments]  ${policy_setting}=${True}
223
224    # Description of argument(s):
225    # policy_setting    The policy setting value which can be either
226    #                   True or False.
227
228    ${log_dict}=  Create Dictionary  data=${policy_setting}
229    Write Attribute  ${BMC_LOGGING_URI}rest_api_logs  Enabled
230    ...  data=${log_dict}  verify=${1}  expected_value=${policy_setting}
231
232
233Old Get Boot Progress
234    [Documentation]  Get the boot progress the old way (via org location).
235    [Arguments]  ${quiet}=${QUIET}
236
237    # Description of argument(s):
238    # quiet   Indicates whether this keyword should run without any output to
239    #         the console.
240
241    ${state}=  Read Attribute  ${OPENBMC_BASE_URI}sensors/host/BootProgress
242    ...  value  quiet=${quiet}
243
244    [Return]  ${state}
245
246
247Set Boot Progress Method
248    [Documentation]  Set the boot_prog_method to either 'Old' or 'New'.
249
250    # The boot progress data has moved from an 'org' location to an 'xyz'
251    # location.  This keyword will determine whether the new method of getting
252    # the boot progress is valid and will set the global boot_prog_method
253    # variable accordingly.  If boot_prog_method is already set (either by a
254    # prior call to this function or via a -v parm), this keyword will simply
255    # return.
256
257    # Note:  There are interim builds that contain boot_progress in both the
258    # old and the new location values.  It is nearly impossible for this
259    # keyword to determine whether the old boot_progress or the new one is
260    # active.  When using such builds where the old boot_progress is active,
261    # the only recourse users will have is that they may specify
262    # -v boot_prog_method:Old to force old behavior on such builds.
263
264    Run Keyword If  '${boot_prog_method}' != '${EMPTY}'  Return From Keyword
265
266    ${new_status}  ${new_value}=  Run Keyword And Ignore Error
267    ...  New Get Boot Progress
268    # If the new style read fails, the method must necessarily be "Old".
269    Run Keyword If  '${new_status}' == 'PASS'
270    ...  Run Keywords
271    ...  Set Global Variable  ${boot_prog_method}  New  AND
272    ...  Rqpvars  boot_prog_method  AND
273    ...  Return From Keyword
274
275    # Default method is "Old".
276    Set Global Variable  ${boot_prog_method}  Old
277    Rqpvars  boot_prog_method
278
279
280Initiate Power On
281    [Documentation]  Initiates the power on and waits until the Is Power On
282    ...  keyword returns that the power state has switched to on.
283    [Arguments]  ${wait}=${1}
284
285    # Description of argument(s):
286    # wait   Indicates whether to wait for a powered on state after issuing
287    #        the power on command.
288
289    @{arglist}=   Create List
290    ${args}=     Create Dictionary    data=@{arglist}
291    ${resp}=  Call Method  ${OPENBMC_BASE_URI}control/chassis0/  powerOn
292    ...  data=${args}
293    should be equal as strings      ${resp.status_code}     ${HTTP_OK}
294
295    # Does caller want to wait for power on status?
296    Run Keyword If  '${wait}' == '${0}'  Return From Keyword
297    Wait Until Keyword Succeeds  3 min  10 sec  Is Power On
298
299
300Initiate Power Off
301    [Documentation]  Initiates the power off and waits until the Is Power Off
302    ...  keyword returns that the power state has switched to off.
303
304    @{arglist}=   Create List
305    ${args}=     Create Dictionary    data=@{arglist}
306    ${resp}=  Call Method  ${OPENBMC_BASE_URI}control/chassis0/  powerOff
307    ...  data=${args}
308    should be equal as strings      ${resp.status_code}     ${HTTP_OK}
309    Wait Until Keyword Succeeds  1 min  10 sec  Is Power Off
310
311
312Get Boot Progress
313    [Documentation]  Get the boot progress and return it.
314    [Arguments]  ${quiet}=${QUIET}
315
316    # Description of argument(s):
317    # quiet   Indicates whether this keyword should run without any output to
318    #         the console.
319
320    Set Boot Progress Method
321    ${state}=  Run Keyword If  '${boot_prog_method}' == 'New'
322    ...      New Get Boot Progress  quiet=${quiet}
323    ...  ELSE
324    ...      Old Get Boot Progress  quiet=${quiet}
325
326    [Return]  ${state}
327
328
329New Get Boot Progress
330    [Documentation]  Get the boot progress the new way (via xyz location).
331    [Arguments]  ${quiet}=${QUIET}
332
333    # Description of argument(s):
334    # quiet   Indicates whether this keyword should run without any output to
335    #         the console.
336
337    ${state}=  Read Attribute  ${HOST_STATE_URI}  BootProgress  quiet=${quiet}
338
339    [Return]  ${state.rsplit('.', 1)[1]}
340
341
342New Get Power Policy
343    [Documentation]  Returns the BMC power policy (new method).
344    ${currentPolicy}=  Read Attribute  ${POWER_RESTORE_URI}  PowerRestorePolicy
345
346    [Return]  ${currentPolicy}
347
348
349Old Get Power Policy
350    [Documentation]  Returns the BMC power policy (old method).
351    ${currentPolicy}=  Read Attribute  ${HOST_SETTING}  power_policy
352
353    [Return]  ${currentPolicy}
354
355
356Redfish Get Power Restore Policy
357    [Documentation]  Returns the BMC power restore policy.
358
359    ${power_restore_policy}=  Redfish.Get Attribute  /redfish/v1/Systems/system  PowerRestorePolicy
360    [Return]  ${power_restore_policy}
361
362
363Get Auto Reboot
364    [Documentation]  Returns auto reboot setting.
365    ${setting}=  Read Attribute  ${CONTROL_HOST_URI}/auto_reboot  AutoReboot
366
367    [Return]  ${setting}
368
369
370Redfish Get Auto Reboot
371    [Documentation]  Returns auto reboot setting.
372
373    ${resp}=  Redfish.Get Attribute  /redfish/v1/Systems/system  Boot
374    [Return]  ${resp["AutomaticRetryConfig"]}
375
376
377Trigger Warm Reset
378    [Documentation]  Initiate a warm reset.
379
380    log to console    "Triggering warm reset"
381    ${data}=   create dictionary   data=@{EMPTY}
382    ${resp}=  openbmc post request
383    ...  ${OPENBMC_BASE_URI}control/bmc0/action/warmReset  data=${data}
384    Should Be Equal As Strings      ${resp.status_code}     ${HTTP_OK}
385    ${session_active}=   Check If warmReset is Initiated
386    Run Keyword If   '${session_active}' == '${True}'
387    ...    Fail   msg=warm reset didn't occur
388
389    Sleep   ${SYSTEM_SHUTDOWN_TIME}min
390    Check If BMC Is Up
391
392
393Get Power State
394    [Documentation]  Returns the power state as an integer. Either 0 or 1.
395    [Arguments]  ${quiet}=${QUIET}
396
397    # Description of argument(s):
398    # quiet   Indicates whether this keyword should run without any output to
399    #         the console.
400
401    @{arglist}=  Create List
402    ${args}=  Create Dictionary  data=@{arglist}
403
404    ${resp}=  Call Method  ${OPENBMC_BASE_URI}control/chassis0/  getPowerState
405    ...        data=${args}  quiet=${quiet}
406    Should be equal as strings  ${resp.status_code}  ${HTTP_OK}
407    ${content}=  to json  ${resp.content}
408
409    [Return]  ${content["data"]}
410
411
412Clear BMC Gard Record
413    [Documentation]  Clear gard records from the system.
414
415    @{arglist}=  Create List
416    ${args}=  Create Dictionary  data=@{arglist}
417    ${resp}=  Call Method
418    ...  ${OPENPOWER_CONTROL}gard  Reset  data=${args}
419    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
420
421
422Flash PNOR
423    [Documentation]    Calls flash bios update method to flash PNOR image
424    [Arguments]    ${pnor_image}
425
426    # Description of argument(s):
427    # pnor_image  The filename and path of the PNOR image
428    #             (e.g. "/home/image/zaius.pnor").
429
430    @{arglist}=   Create List    ${pnor_image}
431    ${args}=     Create Dictionary    data=@{arglist}
432    ${resp}=  Call Method  /org/openbmc/control/flash/bios/  update
433    ...  data=${args}
434    should be equal as strings      ${resp.status_code}     ${HTTP_OK}
435    Wait Until Keyword Succeeds    2 min   10 sec    Is PNOR Flashing
436
437
438Get Flash BIOS Status
439    [Documentation]  Returns the status of the flash BIOS API as a string. For
440    ...              example 'Flashing', 'Flash Done', etc
441    ${data}=  Read Properties  /org/openbmc/control/flash/bios
442    [Return]    ${data['status']}
443
444
445Is PNOR Flashing
446    [Documentation]  Get BIOS 'Flashing' status. This indicates that PNOR
447    ...              flashing has started.
448    ${status}=    Get Flash BIOS Status
449    Should Contain  ${status}  Flashing
450
451
452Is PNOR Flash Done
453    [Documentation]  Get BIOS 'Flash Done' status.  This indicates that the
454    ...              PNOR flashing has completed.
455    ${status}=    Get Flash BIOS Status
456    should be equal as strings     ${status}     Flash Done
457
458
459Create OS Console File Path
460    [Documentation]  Create OS console file path name and return it.
461    [Arguments]  ${log_file_path}=${EMPTY}
462
463    # Description of arguments:
464    # file_path  The caller's candidate value.  If this value is ${EMPTY}, this
465    #            keyword will compose a file path name.  Otherwise, this
466    #            keyword will use the caller's file_path value.  In either
467    #            case, the value will be returned.
468
469    ${status}=  Run Keyword And Return Status  Variable Should Exist
470    ...  ${TEST_NAME}
471
472    ${default_file_path}=  Set Variable If  ${status} == ${TRUE}
473    ...  /tmp/${OPENBMC_HOST}_${TEST_NAME.replace(' ', '')}_os_console.txt
474    ...  /tmp/${OPENBMC_HOST}_os_console.txt
475
476    ${log_file_path}=  Set Variable If  '${log_file_path}' == '${EMPTY}'
477    ...  ${default_file_path}  ${log_file_path}
478
479    [Return]  ${log_file_path}
480
481
482Get Endpoint Paths
483    [Documentation]   Returns all url paths ending with given endpoint
484    ...               Example:
485    ...               Given the following endpoint: cpu
486    ...               This keyword will return: list of all urls ending with
487    ...               cpu -
488    ...               /org/openbmc/inventory/system/chassis/motherboard/cpu0,
489    ...               /org/openbmc/inventory/system/chassis/motherboard/cpu1
490    [Arguments]   ${path}   ${endpoint}
491
492    # Description of arguments:
493    # path       URL path for enumeration.
494    # endpoint   Endpoint string (url path ending).
495
496    # Make sure path ends with slash.
497    ${path}=  Add Trailing Slash  ${path}
498
499    ${resp}=  Read Properties  ${path}enumerate  timeout=30
500    Log Dictionary  ${resp}
501
502    ${list}=  Get Dictionary Keys  ${resp}
503    # For a given string, look for prefix and suffix for matching expression.
504    # Start of string followed by zero or more of any character followed by
505    # any digit or lower case character.
506    ${resp}=  Get Matches  ${list}  regexp=^.*[0-9a-z_].${endpoint}\[_0-9a-z]*$  case_insensitive=${True}
507
508    [Return]  ${resp}
509
510
511Set BMC Power Policy
512    [Documentation]   Set the given BMC power policy.
513    [Arguments]   ${policy}
514
515    # Note that this function will translate the old style "RESTORE_LAST_STATE"
516    # policy to the new style "xyz.openbmc_project.Control.Power.RestorePolicy.
517    # Policy.Restore" for you.
518
519    # Description of argument(s):
520    # policy    Power restore policy (e.g "RESTORE_LAST_STATE",
521    #           ${RESTORE_LAST_STATE}).
522
523    # Set the bmc_power_policy_method to either 'Old' or 'New'.
524    Set Power Policy Method
525    # This translation helps bridge between old and new method for calling.
526    ${policy}=  Translate Power Policy Value  ${policy}
527    # Run the appropriate keyword.
528    Run Key  ${bmc_power_policy_method} Set Power Policy \ ${policy}
529    ${currentPolicy}=  Get System Power Policy
530    Should Be Equal    ${currentPolicy}   ${policy}
531
532
533Delete Error Logs
534    [Documentation]  Delete error logs.
535    [Arguments]  ${quiet}=${0}
536    # Description of argument(s):
537    # quiet    If enabled, turns off logging to console.
538
539    # Check if error logs entries exist, if not return.
540    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}list  quiet=${1}
541    Return From Keyword If  ${resp.status_code} == ${HTTP_NOT_FOUND}
542
543    # Get the list of error logs entries and delete them all.
544    ${elog_entries}=  Get URL List  ${BMC_LOGGING_ENTRY}
545    FOR  ${entry}  IN  @{elog_entries}
546        Delete Error Log Entry  ${entry}  quiet=${quiet}
547    END
548
549
550Delete All Error Logs
551    [Documentation]  Delete all error log entries using "DeleteAll" interface.
552
553    ${data}=  Create Dictionary  data=@{EMPTY}
554    ${resp}=  Openbmc Post Request  ${BMC_LOGGING_URI}action/DeleteAll
555    ...  data=${data}
556    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
557
558
559Get Elog URL List
560    [Documentation]  Return error log entry list of URLs.
561
562    ${url_list}=  Read Properties  /xyz/openbmc_project/logging/entry/
563    Sort List  ${url_list}
564    [Return]  ${url_list}
565
566
567Get BMC Flash Chip Boot Side
568    [Documentation]  Return the BMC flash chip boot side.
569
570    # Example:
571    # 0  - indicates chip select is current side.
572    # 32 - indicates chip select is alternate side.
573
574    ${boot_side}  ${stderr}  ${rc}=  BMC Execute Command
575    ...  cat /sys/class/watchdog/watchdog1/bootstatus
576
577    [Return]  ${boot_side}
578
579
580Watchdog Object Should Exist
581    [Documentation]  Check that watchdog object exists.
582
583    ${resp}=  OpenBMC Get Request  ${WATCHDOG_URI}host0
584    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
585    ...  msg=Expected watchdog object does not exist.
586
587
588Get System LED State
589    [Documentation]  Return the state of given system LED.
590    [Arguments]  ${led_name}
591
592    # Description of argument(s):
593    # led_name     System LED name (e.g. heartbeat, identify, beep).
594
595    ${state}=  Read Attribute  ${LED_PHYSICAL_URI}${led_name}  State
596    [Return]  ${state.rsplit('.', 1)[1]}
597
598
599Verify LED State
600    [Documentation]  Checks if LED is in given state.
601    [Arguments]  ${led_name}  ${led_state}
602    # Description of argument(s):
603    # led_name     System LED name (e.g. heartbeat, identify, beep).
604    # led_state    LED state to be verified (e.g. On, Off).
605
606    ${state}=  Get System LED State  ${led_name}
607    Should Be Equal  ${state}  ${led_state}
608
609
610Get LED State XYZ
611    [Documentation]  Returns state of given LED.
612    [Arguments]  ${led_name}
613
614    # Description of argument(s):
615    # led_name  Name of LED.
616
617    ${state}=  Read Attribute  ${LED_GROUPS_URI}${led_name}  Asserted
618    # Returns the state of the LED, either On or Off.
619    [Return]  ${state}
620
621
622Verify Identify LED State
623    [Documentation]  Verify that the identify state of the LED group matches caller's expectations.
624    [Arguments]  ${expected_state}
625
626    # Description of argument(s):
627    # expected_state  The expected LED asserted state (1 = asserted, 0 = not asserted).
628
629    ${led_state}=  Get LED State XYZ  enclosure_identify
630    Should Be Equal  ${led_state}  ${expected_state}  msg=Unexpected LED state.
631
632Verify The Attribute
633    [Documentation]  Verify the given attribute.
634    [Arguments]  ${uri}  ${attribute_name}  ${attribute_value}
635
636    # Description of argument(s):
637    # uri              URI path
638    #                  (e.g. "/xyz/openbmc_project/control/host0/TPMEnable").
639    # attribute_name   Name of attribute to be verified (e.g. "TPMEnable").
640    # attribute_value  The expected value of attribute (e.g. "1", "0", etc.)
641
642    ${output}=  Read Attribute  ${uri}  ${attribute_name}
643    Should Be Equal  ${attribute_value}  ${output}
644    ...  msg=Attribute "${attribute_name} does not have the expected value.
645
646
647New Set Power Policy
648    [Documentation]   Set the given BMC power policy (new method).
649    [Arguments]   ${policy}
650
651    # Description of argument(s):
652    # policy    Power restore policy (e.g. ${ALWAYS_POWER_OFF}).
653
654    ${valueDict}=  Create Dictionary  data=${policy}
655    Write Attribute
656    ...  ${POWER_RESTORE_URI}  PowerRestorePolicy  data=${valueDict}
657
658
659Old Set Power Policy
660    [Documentation]   Set the given BMC power policy (old method).
661    [Arguments]   ${policy}
662
663    # Description of argument(s):
664    # policy    Power restore policy (e.g. "ALWAYS_POWER_OFF").
665
666    ${valueDict}=     create dictionary  data=${policy}
667    Write Attribute    ${HOST_SETTING}    power_policy   data=${valueDict}
668
669
670Redfish Set Power Restore Policy
671    [Documentation]   Set the BMC power restore policy.
672    [Arguments]   ${power_restore_policy}
673
674    # Description of argument(s):
675    # power_restore_policy    Power restore policy (e.g. "AlwaysOff", "AlwaysOn", "LastState").
676
677    Redfish.Patch  /redfish/v1/Systems/system  body={"PowerRestorePolicy": "${power_restore_policy}"}
678    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
679
680
681Set Auto Reboot Setting
682    [Documentation]  Set the given auto reboot setting (REST or Redfish).
683    [Arguments]  ${value}
684
685    # Description of argument(s):
686    # value    The reboot setting, 1 for enabling and 0 for disabling.
687
688    # This is to cater to boot call points and plugin script which will always
689    # send using value 0 or 1. This dictionary maps to redfish string values.
690    ${rest_redfish_dict}=  Create Dictionary
691    ...                    1=RetryAttempts
692    ...                    0=Disabled
693
694    Run Keyword If  ${REDFISH_REST_SUPPORTED} == ${TRUE}
695    ...    Set Auto Reboot  ${value}
696    ...  ELSE
697    ...    Redfish Set Auto Reboot  ${rest_redfish_dict["${value}"]}
698
699
700Set Auto Reboot
701    [Documentation]  Set the given auto reboot setting.
702    [Arguments]  ${setting}
703
704    # Description of argument(s):
705    # setting    The reboot setting, 1 for enabling and 0 for disabling.
706
707    ${valueDict}=  Convert To Integer  ${setting}
708    ${data}=  Create Dictionary  data=${valueDict}
709    Write Attribute  ${CONTROL_HOST_URI}/auto_reboot  AutoReboot   data=${data}
710    ${current_setting}=  Get Auto Reboot
711    Should Be Equal As Integers  ${current_setting}  ${setting}
712
713
714Redfish Set Auto Reboot
715    [Documentation]  Set the given auto reboot setting.
716    [Arguments]  ${setting}
717
718    # Description of argument(s):
719    # setting    The reboot setting, "RetryAttempts" and "Disabled".
720
721    Redfish.Patch  /redfish/v1/Systems/system  body={"Boot": {"AutomaticRetryConfig": "${setting}"}}
722    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
723
724    ${current_setting}=  Redfish Get Auto Reboot
725    Should Be Equal As Strings  ${current_setting}  ${setting}
726
727
728Set Control Boot Mode
729    [Documentation]  Set given boot mode on the boot object path attribute.
730    [Arguments]  ${boot_path}  ${boot_mode}
731
732    # Description of argument(s):
733    # boot_path  Boot object path.
734    #            Example:
735    #            /xyz/openbmc_project/control/host0/boot
736    #            /xyz/openbmc_project/control/host0/boot/one_time
737    # boot_mode  Boot mode which need to be set.
738    #            Example:
739    #            "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"
740
741    ${valueDict}=  Create Dictionary  data=${boot_mode}
742    Write Attribute  ${boot_path}  BootMode  data=${valueDict}
743
744
745Is Power On
746    [Documentation]  Verify that the BMC chassis state is on.
747    ${state}=  Get Power State
748    Should be equal  ${state}  ${1}
749
750
751Is Power Off
752    [Documentation]  Verify that the BMC chassis state is off.
753    ${state}=  Get Power State
754    Should be equal  ${state}  ${0}
755
756
757CLI Get BMC DateTime
758    [Documentation]  Returns BMC date time from date command.
759
760    ${bmc_time_via_date}  ${stderr}  ${rc}=  BMC Execute Command  date +"%Y-%m-%d %H:%M:%S"  print_err=1
761    [Return]  ${bmc_time_via_date}
762
763
764Update Root Password
765    [Documentation]  Update system "root" user password.
766    [Arguments]  ${openbmc_password}=${OPENBMC_PASSWORD}
767
768    # Description of argument(s):
769    # openbmc_password   The root password for the open BMC system.
770
771    @{password}=  Create List  ${openbmc_password}
772    ${data}=  Create Dictionary  data=@{password}
773
774    ${headers}=  Create Dictionary  Content-Type=application/json  X-Auth-Token=${XAUTH_TOKEN}
775    ${resp}=  Post Request  openbmc  ${BMC_USER_URI}root/action/SetPassword
776    ...  data=${data}  headers=${headers}
777    Valid Value  resp.status_code  [${HTTP_OK}]
778
779
780Get Post Boot Action
781    [Documentation]  Get post boot action.
782
783    # Post code update action dictionary.
784    #
785    # {
786    #    BMC image: {
787    #        OnReset: Redfish OBMC Reboot (off),
788    #        Immediate: Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
789    #    },
790    #    Host image: {
791    #        OnReset: RF SYS GracefulRestart,
792    #        Immediate: Wait State  os_running_match_state  10 mins
793    #    }
794    # }
795
796    ${code_base_dir_path}=  Get Code Base Dir Path
797    ${post_code_update_actions}=  Evaluate
798    ...  json.load(open('${code_base_dir_path}data/applytime_table.json'))  modules=json
799    Rprint Vars  post_code_update_actions
800
801    [Return]  ${post_code_update_actions}
802
803
804Redfish Set Boot Default
805    [Documentation]  Set and Verify BootSource and BootType.
806    [Arguments]      ${override_enabled}  ${override_target}
807
808    # Description of argument(s):
809    # override_enabled    Boot source enable type.
810    #                     ('Once', 'Continuous', 'Disabled').
811    # override_target     Boot target type.
812    #                     ('Pxe', 'Cd', 'Hdd', 'Diags', 'BiosSetup', 'None').
813
814    ${data}=  Create Dictionary  BootSourceOverrideEnabled=${override_enabled}
815    ...  BootSourceOverrideTarget=${override_target}
816    ${payload}=  Create Dictionary  Boot=${data}
817
818    Redfish.Patch  /redfish/v1/Systems/system  body=&{payload}
819    ...  valid_status_codes=[${HTTP_OK},${HTTP_NO_CONTENT}]
820
821    ${resp}=  Redfish.Get Attribute  /redfish/v1/Systems/system  Boot
822    Should Be Equal As Strings  ${resp["BootSourceOverrideEnabled"]}  ${override_enabled}
823    Should Be Equal As Strings  ${resp["BootSourceOverrideTarget"]}  ${override_target}
824