Fix for BIOS attribute sanity test suite

Changes:

Miscellaneous fixes for BIOS attribute sanity test suite.

But, still there are some failure to handle. Will fix it in further commits.

Tested:

Tested on BMC environment.

Change-Id: Ie513ab31b1ae89f88355f9dc3c8966bcca67d9f4
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/lib/bios_attr_utils.robot b/lib/bios_attr_utils.robot
index b16ce7c..3520a1f 100644
--- a/lib/bios_attr_utils.robot
+++ b/lib/bios_attr_utils.robot
@@ -8,6 +8,10 @@
 Library          tftp_update_utils.py
 
 
+*** Variables ***
+${OS_RUNNING_TIMEOUT}            30
+
+
 *** Keywords ***
 
 Set BIOS Attribute Value And Verify
@@ -20,14 +24,30 @@
     # @{attr_val}       Attribute value for the given attribute handle.
     # ${verify}         Verify the new value.
 
+    # Check if the BIOS attribute value type is string.
+    ${type_str}=    Evaluate  isinstance($attr_val, str)
 
-    ${type_int}=    Evaluate  isinstance($attr_val, int)
-    ${value}=  Set Variable If  '${type_int}' == '${True}'  ${attr_val}  '${attr_val}'
+    IF  ${type_str}
+        # Handling the case when the BIOS attribute value is an empty string.
+        ${attr_value_length}=  Evaluate  len($attr_val.replace('"', ''))
+        IF  ${attr_value_length} 
+            ${value}=  Set Variable  "${attr_val}"
+        ELSE
+            ${value}=  Set Variable  ${attr_val}
+        END
+   ELSE
+       ${value}=  Set Variable  ${attr_val}
+   END
 
-    Redfish.Patch  ${BIOS_ATTR_SETTINGS_URI}  body={"Attributes":{"${attr_handle}": ${value}}}
-    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
+    # BIOS attribute with _current are ReadOnly can not be updated.
+    IF  'current' in '${attr_handle}'
+        Log To Console  BIOS attribute with _current are ReadOnly can not be updated !!
+    ELSE
+        Redfish.Patch  ${BIOS_ATTR_SETTINGS_URI}  body={"Attributes":{"${attr_handle}": ${value}}}
+        ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
 
-    Run Keyword If  '${verify}' == '${True}'  Verify BIOS Attribute  ${attr_handle}  ${attr_val}
+        Run Keyword If  '${verify}' == '${True}'  Verify BIOS Attribute  ${attr_handle}  ${attr_val}
+    END
 
 
 Set Optional BIOS Attribute Values And Verify
@@ -57,7 +77,10 @@
     # ${attr_val}       The expected value for the given attribute handle.
 
     ${output}=  Redfish.Get Attribute  ${BIOS_ATTR_URI}  Attributes
-    Should Be Equal  ${output['${attr_handle}']}  ${attr_val}
+    ${cmd_rsp_status}=  Run Keyword And Return Status  Should Not Be Empty  ${output['${attr_handle}']}
+    IF  ${cmd_rsp_status}
+        Should Be Equal  ${output['${attr_handle}']}  ${attr_val}
+    END
 
 
 Switch And Verify BIOS Attribute Firmware Boot Side
diff --git a/lib/pldm_utils.py b/lib/pldm_utils.py
index f2541f9..1d70b36 100755
--- a/lib/pldm_utils.py
+++ b/lib/pldm_utils.py
@@ -45,7 +45,7 @@
     bsu_options = fa.args_to_objects(bsu_options)
 
     stdout, stderr, rc = bsu.bmc_execute_command(
-        "pldmtool " + option_string, **bsu_options
+        "pldmtool " + option_string, **bsu_options, ignore_err=1
     )
     if stderr:
         return stderr
@@ -206,14 +206,22 @@
         attr_handle = re.findall(r"\(.*?\)", item["AttributeNameHandle"])
         attr_name = attr_handle[0][1:-1]
 
-        command = "bios GetBIOSAttributeCurrentValueByHandle -a " + attr_name
-        value = pldmtool(command)
-        attr_val_data_dict[attr_name] = value["CurrentValue"]
-        if not value["CurrentValue"]:
-            if "name" in attr_name:
-                attr_val_data_dict[attr_name] = '""'
-            elif "hb_lid_ids" in attr_name:
-                attr_val_data_dict[attr_name] = '""'
+        # Exclude BIOS attribute which are ReadOnly.
+        if "ReadOnly" not in item["AttributeType"]:
+            command = (
+                "bios GetBIOSAttributeCurrentValueByHandle -a " + attr_name
+            )
+            value = pldmtool(command)
+            if "error" in value:
+                print("Ignore BIOS attribute which throws error...")
+                pass
+            elif not value["CurrentValue"]:
+                if "name" in attr_name:
+                    attr_val_data_dict[attr_name] = '""'
+                elif "hb_lid_ids" in attr_name:
+                    attr_val_data_dict[attr_name] = '""'
+            else:
+                attr_val_data_dict[attr_name] = value["CurrentValue"]
 
     return attr_val_data_dict
 
@@ -304,7 +312,8 @@
             )
             if random_val != existing_data[attr]:
                 break
-        attr_random_data[attr] = random_val.strip('"')
+        if isinstance(random_val, str):
+            attr_random_data[attr] = random_val.strip('"')
     logger.info("Values generated for string type attributes")
 
     for attr in int_attr_data:
diff --git a/pldm/test_redfish_bios_attributes.robot b/pldm/test_redfish_bios_attributes.robot
index 502a732..2e22fa1 100755
--- a/pldm/test_redfish_bios_attributes.robot
+++ b/pldm/test_redfish_bios_attributes.robot
@@ -125,6 +125,7 @@
     ...              and set back to original BIOS attribute values using Redfish.
     [Tags]  Redfish_Verify_Set_BIOS_Enumeration_Attribute_Type
 
+    @{failed_attr_list}=  Create List
 
     # Fetch BIOS attribute optional values from pldmtool getbiostable.
     ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
@@ -136,9 +137,15 @@
     # Update multiple attribute values for corresponding attribute handle.
     FOR  ${i}  IN  @{attr_handles}
         @{attr_val_list}=  Set Variable  ${attr_val_data}[${i}]
-        Set Optional BIOS Attribute Values And Verify  ${i}  @{attr_val_list}
+        ${status}=  Run Keyword And Return Status
+        ...  Set Optional BIOS Attribute Values And Verify  ${i}  @{attr_val_list}
+        Run Keyword If  ${status} == ${False}  Append To List  ${failed_attr_list}  ${i}
     END
 
+    ${fail_count}=  Get Length  ${failed_attr_list}
+    Should Be Equal  ${fail_count}  ${0}
+    ...  msg= BIOS write Failed ${fail_count} list: ${failed_attr_list}
+
 
 Redfish Verify Restore BIOS Attribute Values
     [Documentation]  Restore all BIOS attribute values with its default values and verify
@@ -152,7 +159,6 @@
         Set BIOS Attribute Value And Verify  ${i}  ${bios_default_data['${i}']}
     END
 
-
 *** Keywords ***
 
 Redfish BIOS Suite Setup