Fix for inventory testcases

Changes:

    - Made the testcases independent of the variable file ${VPD_DEATILS}
      and resolved the key errors from vpd-tool and bus-ctl command responses.
Tested:

    - Ran testcases from the sandbox successfully.

Change-Id: I83d596750308d4320b859114ed2428f9f3e8f71a
Signed-off-by: dnirmala <dhurgam.nirmala1@ibm.com>
diff --git a/openpower/vpd/test_vpd_tool.robot b/openpower/vpd/test_vpd_tool.robot
index 6cb0bd0..e8d8d44 100644
--- a/openpower/vpd/test_vpd_tool.robot
+++ b/openpower/vpd/test_vpd_tool.robot
@@ -14,6 +14,8 @@
 ${DR_WRITE_VALUE}              XYZ Component
 ${PN_WRITE_VALUE}              XYZ1234
 ${SN_WRITE_VALUE}              ABCD12345678
+@{fields}                      PN  SN  LocationCode
+@{vpd_fields}                  PN  SN
 
 *** Test Cases ***
 
@@ -29,10 +31,11 @@
 
 
 Verify VPD Component Read
-    [Documentation]  Verify details of VPD component via vpdtool.
+    [Documentation]  Verify details of all VPD component via vpdtool.
     [Tags]  Verify_VPD_Component_Read
 
-    ${components}=  Get Dictionary Keys  ${VPD_DETAILS}
+    ${vpd_records}=  Vpdtool  -i
+    ${components}=  Get Dictionary Keys  ${vpd_records}
     FOR  ${component}  IN  @{components}
         Verify VPD Component Read Operation  ${component}
     END
@@ -42,9 +45,15 @@
     [Documentation]  Verify reading VPD field value via vpdtool.
     [Tags]  Verify_VPD_Field_Read
 
-    ${components}=  Get Dictionary Keys  ${VPD_DETAILS}
+    ${vpd_records}=  Vpdtool  -i
+    ${components}=  Get Dictionary Keys  ${vpd_records}
     FOR  ${component}  IN  @{components}
-        Verify VPD Field Read Operation  ${component}
+       #  drive component field values response in ascii format due to that skipping here. 
+       IF  'drive' in '${component}'
+           Continue FOR Loop
+       ELSE
+           Verify VPD Field Read Operation  ${component}
+       END
     END
 
 
@@ -63,35 +72,6 @@
 
 *** Keywords ***
 
-Verify VPD Data
-    [Documentation]  Verify VPD data of given component.
-    [Arguments]  ${vpd_records}  ${component}
-    # Description of arguments:
-    # vpd_records     All VPD data Via vpdtool.
-    # component       VPD component (e.g. /system/chassis/motherboard/vdd_vrm1).
-
-    # Verification of "CC" and "FN" will be added later.
-    @{vpd_fields}=  Create List  DR  LocationCode  SN  PN
-    FOR  ${field}  IN  @{vpd_fields}
-      ${busctl_field}=  Set Variable If
-      ...  '${field}' == 'DR'  xyz.openbmc_project.Inventory.Item PrettyName
-      ...  '${field}' == 'LocationCode'  com.ibm.ipzvpd.Location LocationCode
-      ...  '${field}' == 'PN'  xyz.openbmc_project.Inventory.Decorator.Asset PartNumber
-      ...  '${field}' == 'SN'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
-
-      ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY} /xyz/openbmc_project/inventory${component}
-      ...  ${busctl_field}
-      ${cmd_output}=  BMC Execute Command  ${cmd}
-      # Example of cmd_output:
-      #   [0]:                                            s "ABCD.XY1.1234567-P0"
-      #   [1]:
-      #   [2]:                                            0
-
-      Valid Value  vpd_records['${component}']['${field}']  ['${cmd_output[0].split('"')[1].strip('"')}']
-    END
-    Valid Value  vpd_records['${component}']['type']  ['${VPD_DETAILS['${component}']['type']}']
-
-
 Verify VPD Component Read Operation
     [Documentation]  Verify reading VPD details of given component via vpdtool.
     [Arguments]  ${component}
@@ -110,7 +90,34 @@
     #    [SN]:                                         YL2E32010000
     #    [PN]:                                         PN12345
 
-    Verify VPD Data  ${vpd_records}  ${component}
+    ${vpdtool_res}=  Set To Dictionary  ${vpd_records}[${component}]
+    FOR  ${vpd_field}  IN  @{fields}
+        ${match_key_exists}=  Run Keyword And Return Status 
+        ...  Dictionary Should Contain Key  ${vpdtool_res}  ${vpd_field}
+          IF  '${match_key_exists}' == 'True'
+              #  drive components busctl field response in ascii due to that checking only locationcode.
+              IF  'drive' in '${component}'
+                  ${vpd_field}=  Set Variable  LocationCode
+              END
+              # Skip check if VPD field is empty. 
+              Run Keyword If  '${vpd_records['${component}']['${vpd_field}']}' == ''
+              ...  Continue For Loop
+              
+              # Get VPD field values via busctl.
+              ${busctl_field}=  Set Variable If
+              ...  '${vpd_field}' == 'LocationCode'  com.ibm.ipzvpd.Location LocationCode
+              ...  '${vpd_field}' == 'PN'  xyz.openbmc_project.Inventory.Decorator.Asset PartNumber
+              ...  '${vpd_field}' == 'SN'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
+              ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY}
+              ...  /xyz/openbmc_project/inventory${component} ${busctl_field}
+              ${cmd_output}=  BMC Execute Command  ${cmd}
+              # Check whether the vpdtool response and busctl response matching.
+              Valid Value  vpd_records['${component}']['${vpd_field}'] 
+              ...  ['${cmd_output[0].split('"')[1].strip('"')}']
+          ELSE
+             Continue For Loop
+          END
+    END
 
 
 Verify VPD Field Read Operation
@@ -119,11 +126,30 @@
     # Description of arguments:
     # component       VDP component (e.g. /system/chassis/motherboard/vdd_vrm1).
 
-    # Verification of "CC" and "FN" will be added later.
-    @{vpd_fields}=  Create List  DR  SN  PN
+    ${vpd_records}=  Vpdtool  -o -O ${component}
+    ${vpdtool_res}=  Set To Dictionary  ${vpd_records}[${component}]
+    FOR  ${field}  IN  @{vpd_fields}
+         ${match_key_exists}=  Run Keyword And Return Status
+         ...  Dictionary Should Contain Key  ${vpdtool_res}  ${field}
+         IF  '${match_key_exists}' == 'True'
+             ${vpd_records}=  Vpdtool  -r -O ${component} -R VINI -K ${field}
+             # Skip check if field value is empty.
+             Run Keyword If  '${vpd_records['${component}']['${field}']}' == ''
+             ...  Continue For Loop
 
-    FOR  ${fields}  IN   @{vpd_fields}
-        Verify VPD Field Value  ${component}  ${fields}
+             ${busctl_field}=  Set Variable If
+             ...  '${field}' == 'PN'  xyz.openbmc_project.Inventory.Decorator.Asset PartNumber
+             ...  '${field}' == 'SN'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
+             ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY}
+             ...  /xyz/openbmc_project/inventory${component} ${busctl_field}
+             ${cmd_output}=  BMC Execute Command  ${cmd}
+
+             # Check vpdtool response and busctl response for the component field.
+             Valid Value  vpd_records['${component}']['${field}']
+             ...  ['${cmd_output[0].split('"')[1].strip('"')}']
+         ELSE
+            Continue For Loop
+         END
     END