Automate testcase to verify BIOS attribute using pldmtool.

        - Verify SetBIOSAttributeCurrentValue
        - Verify GetBIOSAttributeCurrentValueByHandle

Change-Id: Ib9d6cbbcd2f34a9904b08fa72549822b54291be1
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/data/variables.py b/data/variables.py
index 5361228..0658cb6 100755
--- a/data/variables.py
+++ b/data/variables.py
@@ -200,6 +200,9 @@
 EVENT_LOG_URI = SYSTEM_BASE_URI + 'LogServices/EventLog/'
 DUMP_URI = SYSTEM_BASE_URI + 'LogServices/Dump/'
 
+BIOS_ATTR_URI = SYSTEM_BASE_URI + 'Bios'
+BIOS_ATTR_SETTINGS_URI = BIOS_ATTR_URI + '/Settings'
+
 '''
   QEMU HTTPS variable:
 
diff --git a/lib/pldm_utils.py b/lib/pldm_utils.py
index 9008d57..e22af25 100644
--- a/lib/pldm_utils.py
+++ b/lib/pldm_utils.py
@@ -44,3 +44,63 @@
 
     stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string, **bsu_options)
     return json.loads(stdout)
+
+
+def GenerateBIOSAttrHandleValueDict(attr_val_table_data):
+    """
+    From pldmtool bios GetBIOSTable of AttributeValueTable generate dictionary of
+    for BIOS attribute and its value.
+
+    Description of argument(s):
+    attr_val_table_data     pldmtool output from GetBIOSTable table type AttributeValueTable
+                             e.g.
+                            [{
+                                  "AttributeHandle": 20,
+                                  "AttributeNameHandle": "23(pvm-pcie-error-inject)",
+                                  "AttributeType": "BIOSEnumeration",
+                                  "NumberOfPossibleValues": 2,
+                                  "PossibleValueStringHandle[0]": "3(Disabled)",
+                                  "PossibleValueStringHandle[1]": "4(Enabled)",
+                                  "NumberOfDefaultValues": 1,
+                                  "DefaultValueStringHandleIndex[0]": 1,
+                                  "StringHandle": "4(Enabled)"
+                             },
+                             {
+                                  "AttributeHandle": 26,
+                                  "AttributeNameHandle": "28(pvm_fw_boot_side)",
+                                  "AttributeType": "BIOSEnumeration",
+                                  "NumberOfPossibleValues": 2,
+                                  "PossibleValueStringHandle[0]": "11(Perm)",
+                                  "PossibleValueStringHandle[1]": "15(Temp)",
+                                  "NumberOfDefaultValues": 1,
+                                  "DefaultValueStringHandleIndex[0]": 1,
+                                  "StringHandle": "15(Temp)"
+                             }]
+
+    @return                  Dictionary of BIOS attribute and its value.
+                             e.g. {
+                                   'pvm_pcie_error_inject': ['Disabled', 'Enabled'],
+                                   'pvm-fw-boot-side': ['Perm', 'Temp']
+                                  }
+    """
+
+    attr_val_data_dict = {}
+    for item in attr_val_table_data:
+        for attr in item:
+            if (attr == "NumberOfPossibleValues"):
+                value_list = []
+                for i in range(0, int(item[attr])):
+                    attr_values = item["PossibleValueStringHandle[" + str(i) + "]"]
+                    value = re.search(r'\((.*?)\)', attr_values).group(1)
+                    if value:
+                        # Example:
+                        # value = '"Power Off"'
+                        if ' ' in value:
+                            value = '"' + value + '"'
+                        value_list.append(value)
+                    else:
+                        value_list.append('')
+
+                attr_handle = re.findall(r'\(.*?\)', item["AttributeNameHandle"])
+                attr_val_data_dict[attr_handle[0][1:-1]] = value_list
+    return attr_val_data_dict
diff --git a/pldm/test_pldm_bios.robot b/pldm/test_pldm_bios.robot
index a5ef65d..0fc9aca 100644
--- a/pldm/test_pldm_bios.robot
+++ b/pldm/test_pldm_bios.robot
@@ -91,8 +91,7 @@
     FOR  ${key}  IN  @{keys}
         Append To List  ${string_list}  ${pldm_output['${key}']}
     END
-    Log To Console  ${string_list}
-    Valid List  string_list  required_values=${RESPONSE_LIST_GETBIOSTABLE_STRTABLE}
+    Valid List  string_list  required_values=${RESPONSE_LIST_GETBIOSTABLE_ATTRTABLE}
 
 
 Verify GetBIOSTable For AttributeTable
@@ -139,9 +138,57 @@
     END
     Valid List  attr_val_list  required_values=${RESPONSE_LIST_GETBIOSTABLE_ATTRVALTABLE}
 
+
+Verify SetBIOSAttributeCurrentValue
+
+    [Documentation]  Verify SetBIOSAttributeCurrentValue with the
+    ...              various BIOS attribute handle and its values.
+    [Tags]  Verify_SetBIOSAttributeCurrentValue
+
+    # Example output:
+    #
+    # pldmtool bios SetBIOSAttributeCurrentValue -a vmi_hostname -d BMC
+    # {
+    #     "Response": "SUCCESS"
+    # }
+
+    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
+    Log  ${pldm_output}
+    ${attr_val_data}=  GenerateBIOSAttrHandleValueDict  ${pldm_output}
+    Log  ${attr_val_data}
+    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
+    FOR  ${i}  IN  @{attr_handles}
+        @{attr_val_list}=  Set Variable  ${attr_val_data}[${i}]
+        Validate SetBIOSAttributeCurrentValue  ${i}  @{attr_val_list}
+    END
+
+Verify GetBIOSAttributeCurrentValueByHandle
+
+    [Documentation]  Verify GetBIOSAttributeCurrentValueByHandle with the
+    ...              various BIOS attribute handle and its values.
+    [Tags]  Verify_GetBIOSAttributeCurrentValueByHandle
+
+    # Example output:
+    #
+    # pldmtool bios GetBIOSAttributeCurrentValueByHandle -a pvm_fw_boot_side
+    # {
+    #     "CurrentValue": "Temp"
+    # }
+
+    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
+    ${attr_val_data}=  GenerateBIOSAttrHandleValueDict  ${pldm_output}
+    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
+    FOR  ${i}  IN  @{attr_handles}
+        ${cur_attr}=  Pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${i}
+        @{attr_val_list}=  Set Variable  ${attr_val_data}[${i}]
+        Run Keyword If  '${cur_attr['CurrentValue']}' not in @{attr_val_list}
+        ...  Fail  Invalid GetBIOSAttributeCurrentValueByHandle value found.
+    END
+
 *** Keywords ***
 
 PLDM BIOS Suite Cleanup
+
     [Documentation]  Perform pldm BIOS suite cleanup.
 
     ${result}=  Get Current Date  UTC  exclude_millis=True
@@ -149,3 +196,22 @@
     ${cmd_set_date_time}=  Evaluate  $CMD_SETDATETIME % '${current_date_time}'
     ${pldm_output}=  Pldmtool  ${cmd_set_date_time}
     Valid Value  pldm_output['Response']  ['SUCCESS']
+
+Validate SetBIOSAttributeCurrentValue
+
+    [Documentation]  Set BIOS attribute with the available attribute handle
+    ...              values and revert back to original attribute handle value.
+    [Arguments]  ${attr_handle}  @{attr_val_list}
+
+    # Description of argument(s):
+    # attr_handle    BIOS attribute handle (e.g. pvm_system_power_off_policy).
+    # attr_val_list  List of the attribute values for the given attribute handle
+    #                (e.g. ['"Power Off"', '"Stay On"', 'Automatic']).
+
+    ${cur_attr}=  Pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${attr_handle}
+    FOR  ${j}  IN  @{attr_val_list}
+        ${pldm_resp}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${attr_handle} -d ${j}
+        Valid Value  pldm_resp['Response']  ['SUCCESS']
+    END
+    ${pldm_resp}=  pldmtool  bios SetBIOSAttributeCurrentValue -a ${attr_handle} -d ${cur_attr['CurrentValue']}
+    Valid Value  pldm_resp['Response']  ['SUCCESS']