1*** Settings ***
2Documentation    Utilities for redfish BIOS attribute operations.
3
4Resource         resource.robot
5Resource         bmc_redfish_resource.robot
6Resource         common_utils.robot
7Resource         utils.robot
8Library          tftp_update_utils.py
9
10
11*** Variables ***
12${OS_RUNNING_TIMEOUT}            30
13
14
15*** Keywords ***
16
17Set BIOS Attribute Value And Verify
18
19    [Documentation]  Set BIOS attribute handle with attribute value and verify.
20    [Arguments]      ${attr_handle}  ${attr_val}  ${verify}=${True}
21
22    # Description of argument(s):
23    # ${attr_handle}    BIOS Attribute handle (e.g. 'vmi_if0_ipv4_method').
24    # @{attr_val}       Attribute value for the given attribute handle.
25    # ${verify}         Verify the new value.
26
27    # Check if the BIOS attribute value type is string.
28    ${type_str}=    Evaluate  isinstance($attr_val, str)
29
30    IF  ${type_str}
31        # Handling the case when the BIOS attribute value is an empty string.
32        ${attr_value_length}=  Evaluate  len($attr_val.replace('"', ''))
33        IF  ${attr_value_length}
34            ${value}=  Set Variable  "${attr_val}"
35        ELSE
36            ${value}=  Set Variable  ${attr_val}
37        END
38   ELSE
39       ${value}=  Set Variable  ${attr_val}
40   END
41
42    # BIOS attribute with _current are ReadOnly can not be updated.
43    IF  'current' in '${attr_handle}'
44        Log To Console  BIOS attribute with _current are ReadOnly can not be updated !!
45    ELSE
46        Redfish.Patch  ${BIOS_ATTR_SETTINGS_URI}  body={"Attributes":{"${attr_handle}": ${value}}}
47        ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
48
49        Run Keyword If  '${verify}' == '${True}'  Verify BIOS Attribute  ${attr_handle}  ${attr_val}
50    END
51
52
53Set Optional BIOS Attribute Values And Verify
54
55    [Documentation]  For the given BIOS attribute handle update with optional
56    ...              attribute values and verify.
57    [Arguments]  ${attr_handle}  @{attr_val_list}
58
59    # Description of argument(s):
60    # ${attr_handle}    BIOS Attribute handle (e.g. 'vmi_if0_ipv4_method').
61    # @{attr_val_list}  List of the attribute values for the given attribute handle.
62    #                   (e.g. ['IPv4Static', 'IPv4DHCP']).
63
64    FOR  ${attr}  IN  @{attr_val_list}
65        ${new_attr}=  Evaluate  $attr.replace('"', '')
66        Set BIOS Attribute Value And Verify  ${attr_handle}  ${new_attr}
67    END
68
69
70Verify BIOS Attribute
71
72    [Documentation]  Verify BIOS attribute value.
73    [Arguments]  ${attr_handle}  ${attr_val}
74
75    # Description of argument(s):
76    # ${attr_handle}    BIOS Attribute handle (e.g. 'vmi_if0_ipv4_method').
77    # ${attr_val}       The expected value for the given attribute handle.
78
79    ${output}=  Redfish.Get Attribute  ${BIOS_ATTR_URI}  Attributes
80    ${cmd_rsp_status}=  Run Keyword And Return Status  Should Not Be Empty  ${output['${attr_handle}']}
81    IF  ${cmd_rsp_status}
82        Should Be Equal  ${output['${attr_handle}']}  ${attr_val}
83    END
84
85
86Switch And Verify BIOS Attribute Firmware Boot Side
87    [Documentation]  Switch BIOS attribute firmware boot side value to Perm/Temp
88    ...              at host power off state and verify firmware boot side
89    ...              value after BMC reboot.
90    [Arguments]      ${set_fw_boot_side}
91
92    # Description of argument(s):
93    # set_fw_boot_side    Firmware boot side optional value Perm/Temp.
94
95    # Do host power off.
96    Redfish Power Off  stack_mode=skip  quiet=1
97
98    # Get pre reboot state.
99    ${pre_reboot_state}=  Get Pre Reboot State
100
101    # Get fw_boot_side value.
102    # fw_boot_side values are not same.
103
104    ${cur_boot_side}=  Redfish.Get Attribute  ${BIOS_ATTR_URI}  Attributes
105
106    Log To Console  Current firmware boot side :: ${cur_boot_side["fw_boot_side"]}
107    Log To Console  Given firmware boot side :: ${set_fw_boot_side}
108
109    Return From Keyword If  "${cur_boot_side["fw_boot_side_current"]}" == "${set_fw_boot_side}"
110    ...  ${True}
111
112    # Set the given firmware boot side value.
113    Set BIOS Attribute Value And Verify  fw_boot_side  ${set_fw_boot_side}  False
114
115    # Power on BMC and wait for BMC to take reboot.
116    Log To Console  Perform power on operation & expect BMC to take reboot...
117    Redfish Power Operation  On
118
119    Log To Console  Wait for the BMC to take reboot and come back online...
120    Wait For Reboot  start_boot_seconds=${pre_reboot_state['epoch_seconds']}
121    ...  wait_state_check=0
122
123    # Post BMC reboot, host should auto power on back to runtime.
124    Log To Console  BMC rebooted, wait for host to boot...
125    Wait Until Keyword Succeeds  ${OS_RUNNING_TIMEOUT} min  20 sec
126    ...  Is Boot Progress At Any State
127
128    # Verify firmware boot side values after BMC reboot.
129    Verify BIOS Attribute  fw_boot_side  ${set_fw_boot_side}
130    Verify BIOS Attribute  fw_boot_side_current  ${set_fw_boot_side}
131