xref: /openbmc/openbmc-test-automation/lib/vpd_tool_resource.robot (revision 87cfb9ea02a746bd8d6aa8396195d2b261e482e4)
1*** Settings ***
2Documentation   Utility file for system Vital Product Data (VPD) using vpdtool.
3
4Library         ../../lib/vpd_utils.py
5Variables       ../../data/vpd_variables.py
6Resource        ../../lib/boot_utils.robot
7
8
9*** Variables ***
10
11${DR_WRITE_VALUE}              XYZ Component
12${PN_WRITE_VALUE}              XYZ1234
13${SN_WRITE_VALUE}              ABCD12345678
14@{fields}                      PN  SN  LocationCode
15@{vpd_fields}                  PN  SN
16
17
18*** Keywords ***
19
20Verify VPD Component Read Operation
21    [Documentation]  Verify reading VPD details of given component via vpdtool.
22    [Arguments]  ${component}
23    # Description of arguments:
24    # component       VDP component (e.g. /system/chassis/motherboard/vdd_vrm1).
25
26    ${vpd_records}=  Vpdtool  -o -O ${component}
27
28    # Example output from 'Vpdtool  -o -O /system/chassis/motherboard/vdd_vrm1':
29    #  [/system/chassis/motherboard/vdd_vrm1]:
30    #    [DR]:                                         CPU POWER CARD
31    #    [type]:                                       xyz.openbmc_project.Inventory.Item.Vrm
32    #    [CC]:                                         E123
33    #    [FN]:                                         F123456
34    #    [LocationCode]:                               ABCD.XY1.1234567-P0
35    #    [SN]:                                         YL2E32010000
36    #    [PN]:                                         PN12345
37
38    ${vpdtool_res}=  Set To Dictionary  ${vpd_records}[${component}]
39    FOR  ${vpd_field}  IN  @{fields}
40        ${match_key_exists}=  Run Keyword And Return Status
41        ...  Dictionary Should Contain Key  ${vpdtool_res}  ${vpd_field}
42          IF  '${match_key_exists}' == 'True'
43              #  drive components busctl field response in ascii due to that checking only locationcode.
44              IF  'drive' in '${component}'
45                  ${vpd_field}=  Set Variable  LocationCode
46              END
47              # Skip check if VPD field is empty.
48              IF  '${vpd_records['${component}']['${vpd_field}']}' == ''  CONTINUE
49
50              # Get VPD field values via busctl.
51              ${busctl_field}=  Set Variable If
52              ...  '${vpd_field}' == 'LocationCode'  com.ibm.ipzvpd.Location LocationCode
53              ...  '${vpd_field}' == 'PN'  xyz.openbmc_project.Inventory.Decorator.Asset PartNumber
54              ...  '${vpd_field}' == 'SN'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
55              ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY}
56              ...  /xyz/openbmc_project/inventory${component} ${busctl_field}
57              ${cmd_output}=  BMC Execute Command  ${cmd}
58              # Check whether the vpdtool response and busctl response matching.
59              Valid Value  vpd_records['${component}']['${vpd_field}']
60              ...  ['${cmd_output[0].split('"')[1].strip('"')}']
61          ELSE
62             CONTINUE
63          END
64    END
65
66
67Verify VPD Field Read Operation
68    [Documentation]  Verify reading all VPD fields for given component via vpdtool.
69    [Arguments]  ${component}
70    # Description of arguments:
71    # component       VDP component (e.g. /system/chassis/motherboard/vdd_vrm1).
72
73    ${vpd_records}=  Vpdtool  -o -O ${component}
74    ${vpdtool_res}=  Set To Dictionary  ${vpd_records}[${component}]
75    FOR  ${field}  IN  @{vpd_fields}
76         ${match_key_exists}=  Run Keyword And Return Status
77         ...  Dictionary Should Contain Key  ${vpdtool_res}  ${field}
78         IF  '${match_key_exists}' == 'True'
79             ${vpd_records}=  Vpdtool  -r -O ${component} -R VINI -K ${field}
80             # Skip check if field value is empty.
81             IF  '${vpd_records['${component}']['${field}']}' == ''  CONTINUE
82
83             ${busctl_field}=  Set Variable If
84             ...  '${field}' == 'PN'  xyz.openbmc_project.Inventory.Decorator.Asset PartNumber
85             ...  '${field}' == 'SN'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
86             ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY}
87             ...  /xyz/openbmc_project/inventory${component} ${busctl_field}
88             ${cmd_output}=  BMC Execute Command  ${cmd}
89
90             # Check vpdtool response and busctl response for the component field.
91             Valid Value  vpd_records['${component}']['${field}']
92             ...  ['${cmd_output[0].split('"')[1].strip('"')}']
93         ELSE
94            CONTINUE
95         END
96    END
97
98
99Verify VPD Field Write Operation
100    [Documentation]  Verify writing VPD fields for given component via vpdtool.
101    [Arguments]  ${component}  ${field}
102    [Teardown]  Restore VPD Value  ${component}  ${field}  ${old_field_value}
103
104    # Description of arguments:
105    # component       VPD component (e.g. /system/chassis/motherboard/vdd_vrm1).
106    # field           VPD component field (e.g. PN, SN)
107
108    ${vpd_records}=  Vpdtool  -r -O ${component} -R VINI -K ${field}
109    Set Test Variable  ${old_field_value}  ${vpd_records['${component}']['${field}']}
110
111    ${write_value}=  Set Variable If
112    ...  '${field}' == 'DR'  ${DR_WRITE_VALUE}
113    ...  '${field}' == 'PN'  ${PN_WRITE_VALUE}
114    ...  '${field}' == 'SN'  ${SN_WRITE_VALUE}
115
116    Vpdtool  -w -O ${component} -R VINI -K ${field} --value ${write_value}
117
118    Verify VPD Field Value  ${component}  ${field}
119
120
121Restore VPD Value
122    [Documentation]  Restore VPD's field value of given component.
123    [Arguments]  ${component}  ${field}  ${value}
124    # Description of arguments:
125    # component       VPD component (e.g. /system/chassis/motherboard/vdd_vrm1).
126    # field           VPD component field (e.g. PN, SN)
127    # value           VPD value to be restore.
128
129    Vpdtool  -w -O ${component} -R VINI -K ${field} --value ${value}
130
131
132Verify VPD Field Value
133    [Documentation]  Verify VPD field value via vpdtool.
134    [Arguments]  ${component}  ${field}
135    # Description of arguments:
136    # component       VDP component (e.g. /system/chassis/motherboard/vdd_vrm1).
137    # field           VPD field (e.g. DR, SN, PN)
138
139    Redfish OBMC Reboot (off)  stack_mode=normal
140    ${vpd_records}=  Vpdtool  -r -O ${component} -R VINI -K ${field}
141
142    ${busctl_field}=  Set Variable If
143    ...  '${field}' == 'DR'  xyz.openbmc_project.Inventory.Item PrettyName
144    ...  '${field}' == 'PN'  xyz.openbmc_project.Inventory.Decorator.Asset PartNumber
145    ...  '${field}' == 'SN'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
146
147    ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY} /xyz/openbmc_project/inventory${component}
148    ...  ${busctl_field}
149    ${cmd_output}=  BMC Execute Command  ${cmd}
150
151    Valid Value  vpd_records['${component}']['${field}']  ['${cmd_output[0].split('"')[1].strip('"')}']
152
153
154Verify VPD Data Via Vpdtool
155    [Documentation]  Get VPD details of given component via vpdtool and verify it
156    ...              using busctl command.
157    [Arguments]  ${component}  ${field}
158    # Description of arguments:
159    # component       VPD component (e.g. System,Chassis etc).
160    # field           VPD field (e.g. Serialnumber,LocationCode etc).
161
162    ${component_url}=  Set Variable If
163    ...  '${component}' == 'System'  /system
164
165    # Get VPD details of given component via vpd-tool.
166    ${vpd_records}=  Vpdtool  -o -O ${component_url}
167
168    # Get VPD details of given component via busctl command.
169    ${busctl_field}=  Set Variable If
170    ...  '${field}' == 'LocationCode'  com.ibm.ipzvpd.Location LocationCode
171    ...  '${field}' == 'Model'  xyz.openbmc_project.Inventory.Decorator.Asset Model
172    ...  '${field}' == 'SerialNumber'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
173
174    ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY} /xyz/openbmc_project/inventory/system
175    ...  ${busctl_field}
176    ${cmd_output}=  BMC Execute Command  ${cmd}
177    # Example of cmd_output:
178    #   [0]:                                            s "ABCD.XY1.1234567-P0"
179    #   [1]:
180    #   [2]:                                            0
181
182    # Cross check vpdtool output with busctl response.
183    Should Be Equal As Strings  ${vpd_records["/system"]["${field}"]}
184    ...  ${cmd_output[0].split('"')[1].strip('"')}
185