1*** Settings ***
2Documentation    This suite test various BIOS attributes operations using Redfish.
3
4Resource         ../lib/resource.robot
5Resource         ../lib/bmc_redfish_resource.robot
6Resource         ../lib/common_utils.robot
7Resource         ../lib/openbmc_ffdc.robot
8Resource         ../lib/bios_attr_utils.robot
9Library          ../lib/pldm_utils.py
10Variables        ../data/pldm_variables.py
11
12Test Teardown    FFDC On Test Case Fail
13
14Suite Setup      Redfish BIOS Suite Setup
15Suite Teardown   Run Keyword And Ignore Error  Redfish BIOS Suite Cleanup
16
17*** Variables ***
18
19${bios_original_data}       ${EMPTY}
20${attr_table_data}          ${EMPTY}
21
22
23*** Test Cases ***
24
25Redfish Verify Set BIOS Attribute With Invalid Attribute Name
26    [Documentation]  Verify set BIOS attribute with invalid attribute name using
27    ...              Redfish.
28    [Tags]  Redfish_Verify_Set_BIOS_Attribute_With_Invalid_Attribute_Name
29
30    ${random_str}=  Generate Random String  8  [LETTERS][NUMBERS]
31    Redfish.Patch  ${BIOS_ATTR_SETTINGS_URI}  body={"Attributes":{"${random_str}": '${random_str}'}}
32    ...  valid_status_codes=[${HTTP_BAD_REQUEST}]
33
34
35Redfish Verify Set Invalid Optional Value For BIOS Enumeration Attribute Type
36    [Documentation]  Verify set invalid optional value for BIOS enumeration attribute type
37    ...              using Redfish.
38    [Tags]  Redfish_Verify_Set_Invalid_Optional_Value_For_BIOS_Enumeration_Attribute_Type
39
40    ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
41    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
42    ${enum_attr}=  Evaluate  random.choice(${attr_handles})  modules=random
43
44    Redfish.Patch  ${BIOS_ATTR_SETTINGS_URI}  body={"Attributes":{"${enum_attr}": '0'}}
45    ...  valid_status_codes=[${HTTP_INTERNAL_SERVER_ERROR},${HTTP_FORBIDDEN}]
46
47
48Redfish Verify Set Out Of Range Integer Value For BIOS Integer Attribute Type
49    [Documentation]  Verify set out of range integer value for BIOS integer attribute type
50    ...              using Redfish.
51    [Tags]  Redfish_Verify_Set_Out_Of_Range_Integer_Value_For_BIOS_Integer_Attribute_Type
52
53    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSInteger  ${attr_table_data}
54    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
55    ${int_attr}=  Evaluate  random.choice(${attr_handles})  modules=random
56    ${count}=  Evaluate  ${attr_val_data['${int_attr}']["UpperBound"]} + 5
57
58    Redfish.Patch  ${BIOS_ATTR_SETTINGS_URI}  body={"Attributes":{"${int_attr}": ${count}}}
59    ...  valid_status_codes=[${HTTP_INTERNAL_SERVER_ERROR},${HTTP_BAD_REQUEST}]
60
61
62Redfish Verify Set Out Of Range String Value For BIOS String Attribute Type
63
64    [Documentation]  Verify set out of range string value for BIOS string attribute type
65    ...              using Redfish.
66    [Tags]  Redfish_Verify_Set_Out_Of_Range_String_Value_For_BIOS_String_Attribute_Type
67
68    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSString  ${attr_table_data}
69    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
70    ${str_attr}=  Evaluate  random.choice(${attr_handles})  modules=random
71    ${count}=  Evaluate  ${attr_val_data['${str_attr}']["MaximumStringLength"]} + 5
72    ${random_value}=  Generate Random String  ${count}  [LETTERS][NUMBERS]
73
74    Redfish.Patch  ${BIOS_ATTR_SETTINGS_URI}  body={"Attributes":{"${str_attr}": '${random_value}'}}
75    ...  valid_status_codes=[${HTTP_INTERNAL_SERVER_ERROR},${HTTP_BAD_REQUEST}]
76
77
78Redfish Verify Set BIOS String Attribute Type
79    [Documentation]  Verify set BIOS string attribute type for various BIOS
80    ...              attribute handle with random values with in the range using Redfish.
81    [Tags]  Redfish_Verify_Set_BIOS_String_Attribute_Type
82
83    @{failed_attr_list}=  Create List
84
85    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSString  ${attr_table_data}
86    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
87    FOR  ${i}  IN  @{attr_handles}
88        ${random_value}=  GetRandomBIOSIntAndStrValues  ${i}  ${attr_val_data['${i}']["MaximumStringLength"]}
89        ${status}=  Run Keyword And Return Status
90        ...  Set BIOS Attribute Value And Verify  ${i}  ${random_value}
91        Run Keyword If  ${status} == ${False}  Append To List  ${failed_attr_list}  ${i}
92    END
93
94    ${fail_count}=  Get Length  ${failed_attr_list}
95    Should Be Equal  ${fail_count}  ${0}
96    ...  msg= BIOS write Failed ${fail_count} list: ${failed_attr_list}
97
98
99
100Redfish Verify Set BIOS Integer Attribute Type
101    [Documentation]  Verify set BIOS integer attribute type for various BIOS
102    ...              attribute handle with random values with in the range using Redfish.
103    [Tags]  Redfish_Verify_Set_BIOS_Integer_Attribute_Type
104
105    @{failed_attr_list}=  Create List
106
107    ${attr_val_data}=  GetBIOSStrAndIntAttributeHandles  BIOSInteger  ${attr_table_data}
108    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
109    FOR  ${i}  IN  @{attr_handles}
110        ${random_value}=  GetRandomBIOSIntAndStrValues  ${i}  ${attr_val_data['${i}']["UpperBound"]}
111        ${status}=  Run Keyword And Return Status
112        ...  Set BIOS Attribute Value And Verify  ${i}  ${random_value}
113        Run Keyword If  ${status} == ${False}  Append To List  ${failed_attr_list}  ${i}
114    END
115
116    ${fail_count}=  Get Length  ${failed_attr_list}
117    Should Be Equal  ${fail_count}  ${0}
118    ...  msg= BIOS write Failed ${fail_count} list: ${failed_attr_list}
119
120
121Redfish Verify Set BIOS Enumeration Attribute Type
122    [Documentation]  Validate get and update BIOS attribute optional values
123    ...              and set back to original BIOS attribute values using Redfish.
124    [Tags]  Redfish_Verify_Set_BIOS_Enumeration_Attribute_Type
125
126
127    # Fetch BIOS attribute optional values from pldmtool getbiostable.
128    ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
129    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
130
131    # Example:
132    # {'vmi_if0_ipv4_method': ['IPv4Static', 'IPv4DHCP']}
133
134    # Update multiple attribute values for corresponding attribute handle.
135    FOR  ${i}  IN  @{attr_handles}
136        @{attr_val_list}=  Set Variable  ${attr_val_data}[${i}]
137        Set Optional BIOS Attribute Values And Verify  ${i}  @{attr_val_list}
138    END
139
140
141Redfish Verify Restore BIOS Attribute Values
142    [Documentation]  Restore all BIOS attribute values with its default values and verify
143    ...              using Redfish.
144    [Tags]  Redfish_Verify_Restore_BIOS_Attribute_Values
145
146    ${bios_default_data}=  GetBIOSAttrDefaultValues  ${attr_table_data}
147    @{attr_handles}=  Get Dictionary Keys  ${bios_default_data}
148
149    FOR  ${i}  IN  @{attr_handles}
150        Set BIOS Attribute Value And Verify  ${i}  ${bios_default_data['${i}']}
151    END
152
153
154*** Keywords ***
155
156Redfish BIOS Suite Setup
157    [Documentation]  Perform Redfish BIOS suite setup.
158
159    Redfish.Login
160    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
161    Set Global Variable  ${attr_table_data}  ${pldm_output}
162
163    ${data}=  GetBIOSAttrOriginalValues  ${pldm_output}
164    Set Global Variable  ${bios_original_data}  ${data}
165
166
167Redfish BIOS Suite Cleanup
168    [Documentation]  Perform Redfish BIOS suite cleanup.
169
170    @{attr_handles}=  Get Dictionary Keys  ${bios_original_data}
171    FOR  ${i}  IN  @{attr_handles}
172        Set BIOS Attribute Value And Verify  ${i}  ${bios_original_data['${i}']}
173    END
174    Redfish.Logout
175