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