xref: /openbmc/openbmc-test-automation/openpower/vpd/test_vpd_tool.robot (revision 49c1b53931191184251a4d1d9ba9ab127ee9f9fb)
1*** Settings ***
2Documentation   This suite tests System Vital Product Data (VPD) using vpdtool.
3
4Library         ../../lib/vpd_utils.py
5Variables       ../../data/vpd_variables.py
6Resource        ../../lib/openbmc_ffdc.robot
7Resource        ../../lib/boot_utils.robot
8
9Test Teardown   FFDC On Test Case Fail
10
11Test Tags      VPD_Tool
12
13*** Variables ***
14
15${CMD_GET_PROPERTY_INVENTORY}  busctl get-property xyz.openbmc_project.Inventory.Manager
16${DR_WRITE_VALUE}              XYZ Component
17${PN_WRITE_VALUE}              XYZ1234
18${SN_WRITE_VALUE}              ABCD12345678
19@{fields}                      PN  SN  LocationCode
20@{vpd_fields}                  PN  SN
21
22*** Test Cases ***
23
24Verify System VPD Data Via Vpdtool
25    [Documentation]  Verify the system VPD details via vpdtool output.
26    [Tags]  Verify_System_VPD_Data_Via_Vpdtool
27    [Template]  Verify VPD Data Via Vpdtool
28
29    # Component     Field
30    System          Model
31    System          SerialNumber
32    System          LocationCode
33
34
35Verify VPD Component Read
36    [Documentation]  Verify details of all VPD component via vpdtool.
37    [Tags]  Verify_VPD_Component_Read
38
39    ${vpd_records}=  Vpdtool  -i
40    ${components}=  Get Dictionary Keys  ${vpd_records}
41    FOR  ${component}  IN  @{components}
42        Verify VPD Component Read Operation  ${component}
43    END
44
45
46Verify VPD Field Read
47    [Documentation]  Verify reading VPD field value via vpdtool.
48    [Tags]  Verify_VPD_Field_Read
49
50    ${vpd_records}=  Vpdtool  -i
51    ${components}=  Get Dictionary Keys  ${vpd_records}
52    FOR  ${component}  IN  @{components}
53       # Drive component field values response in ascii format
54       # due to that skipping here.
55       IF  'drive' in '${component}'
56           CONTINUE
57       ELSE
58           Verify VPD Field Read Operation  ${component}
59       END
60    END
61
62
63Verify VPD Field Write
64    [Documentation]  Verify writing VPD field value via vpdtool.
65    [Tags]  Verify_VPD_Field_Write
66
67    # Put system to power off state before VPD write operation.
68    Redfish Power Off  stack_mode=skip
69
70    ${components}=  Get Dictionary Keys  ${VPD_DETAILS}
71    FOR  ${component}  IN  @{components}
72        # VPD fields "DR", "CC" and "FN" will be added later.
73        @{vpd_fields}=  Create List  SN  PN
74        ${field}=  Evaluate  random.choice($vpd_fields)  random
75        Verify VPD Field Write Operation  ${component}  ${field}
76    END
77
78
79*** Keywords ***
80
81Verify VPD Component Read Operation
82    [Documentation]  Verify reading VPD details of given component via vpdtool.
83    [Arguments]  ${component}
84    # Description of arguments:
85    # component       VDP component (e.g. /system/chassis/motherboard/vdd_vrm1).
86
87    ${vpd_records}=  Vpdtool  -o -O ${component}
88
89    # Example output from 'Vpdtool  -o -O /system/chassis/motherboard/vdd_vrm1':
90    #  [/system/chassis/motherboard/vdd_vrm1]:
91    #    [DR]:                                         CPU POWER CARD
92    #    [type]:                                       xyz.openbmc_project.Inventory.Item.Vrm
93    #    [CC]:                                         E123
94    #    [FN]:                                         F123456
95    #    [LocationCode]:                               ABCD.XY1.1234567-P0
96    #    [SN]:                                         YL2E32010000
97    #    [PN]:                                         PN12345
98
99    ${vpdtool_res}=  Set To Dictionary  ${vpd_records}[${component}]
100    FOR  ${vpd_field}  IN  @{fields}
101        ${match_key_exists}=  Run Keyword And Return Status
102        ...  Dictionary Should Contain Key  ${vpdtool_res}  ${vpd_field}
103          IF  '${match_key_exists}' == 'True'
104              #  drive components busctl field response in ascii due to that checking only locationcode.
105              IF  'drive' in '${component}'
106                  ${vpd_field}=  Set Variable  LocationCode
107              END
108              # Skip check if VPD field is empty.
109              IF  '${vpd_records['${component}']['${vpd_field}']}' == ''  CONTINUE
110
111              # Get VPD field values via busctl.
112              ${busctl_field}=  Set Variable If
113              ...  '${vpd_field}' == 'LocationCode'  com.ibm.ipzvpd.Location LocationCode
114              ...  '${vpd_field}' == 'PN'  xyz.openbmc_project.Inventory.Decorator.Asset PartNumber
115              ...  '${vpd_field}' == 'SN'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
116              ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY}
117              ...  /xyz/openbmc_project/inventory${component} ${busctl_field}
118              ${cmd_output}=  BMC Execute Command  ${cmd}
119              # Check whether the vpdtool response and busctl response matching.
120              Valid Value  vpd_records['${component}']['${vpd_field}']
121              ...  ['${cmd_output[0].split('"')[1].strip('"')}']
122          ELSE
123             CONTINUE
124          END
125    END
126
127
128Verify VPD Field Read Operation
129    [Documentation]  Verify reading all VPD fields for given component via vpdtool.
130    [Arguments]  ${component}
131    # Description of arguments:
132    # component       VDP component (e.g. /system/chassis/motherboard/vdd_vrm1).
133
134    ${vpd_records}=  Vpdtool  -o -O ${component}
135    ${vpdtool_res}=  Set To Dictionary  ${vpd_records}[${component}]
136    FOR  ${field}  IN  @{vpd_fields}
137         ${match_key_exists}=  Run Keyword And Return Status
138         ...  Dictionary Should Contain Key  ${vpdtool_res}  ${field}
139         IF  '${match_key_exists}' == 'True'
140             ${vpd_records}=  Vpdtool  -r -O ${component} -R VINI -K ${field}
141             # Skip check if field value is empty.
142             IF  '${vpd_records['${component}']['${field}']}' == ''  CONTINUE
143
144             ${busctl_field}=  Set Variable If
145             ...  '${field}' == 'PN'  xyz.openbmc_project.Inventory.Decorator.Asset PartNumber
146             ...  '${field}' == 'SN'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
147             ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY}
148             ...  /xyz/openbmc_project/inventory${component} ${busctl_field}
149             ${cmd_output}=  BMC Execute Command  ${cmd}
150
151             # Check vpdtool response and busctl response for the component field.
152             Valid Value  vpd_records['${component}']['${field}']
153             ...  ['${cmd_output[0].split('"')[1].strip('"')}']
154         ELSE
155            CONTINUE
156         END
157    END
158
159
160Verify VPD Field Write Operation
161    [Documentation]  Verify writing VPD fields for given component via vpdtool.
162    [Arguments]  ${component}  ${field}
163    [Teardown]  Restore VPD Value  ${component}  ${field}  ${old_field_value}
164
165    # Description of arguments:
166    # component       VPD component (e.g. /system/chassis/motherboard/vdd_vrm1).
167    # field           VPD component field (e.g. PN, SN)
168
169    ${vpd_records}=  Vpdtool  -r -O ${component} -R VINI -K ${field}
170    Set Test Variable  ${old_field_value}  ${vpd_records['${component}']['${field}']}
171
172    ${write_value}=  Set Variable If
173    ...  '${field}' == 'DR'  ${DR_WRITE_VALUE}
174    ...  '${field}' == 'PN'  ${PN_WRITE_VALUE}
175    ...  '${field}' == 'SN'  ${SN_WRITE_VALUE}
176
177    Vpdtool  -w -O ${component} -R VINI -K ${field} --value ${write_value}
178
179    Verify VPD Field Value  ${component}  ${field}
180
181
182Restore VPD Value
183    [Documentation]  Restore VPD's field value of given component.
184    [Arguments]  ${component}  ${field}  ${value}
185    # Description of arguments:
186    # component       VPD component (e.g. /system/chassis/motherboard/vdd_vrm1).
187    # field           VPD component field (e.g. PN, SN)
188    # value           VPD value to be restore.
189
190    Vpdtool  -w -O ${component} -R VINI -K ${field} --value ${value}
191
192
193Verify VPD Field Value
194    [Documentation]  Verify VPD field value via vpdtool.
195    [Arguments]  ${component}  ${field}
196    # Description of arguments:
197    # component       VDP component (e.g. /system/chassis/motherboard/vdd_vrm1).
198    # field           VPD field (e.g. DR, SN, PN)
199
200    Redfish OBMC Reboot (off)  stack_mode=normal
201    ${vpd_records}=  Vpdtool  -r -O ${component} -R VINI -K ${field}
202
203    ${busctl_field}=  Set Variable If
204    ...  '${field}' == 'DR'  xyz.openbmc_project.Inventory.Item PrettyName
205    ...  '${field}' == 'PN'  xyz.openbmc_project.Inventory.Decorator.Asset PartNumber
206    ...  '${field}' == 'SN'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
207
208    ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY} /xyz/openbmc_project/inventory${component}
209    ...  ${busctl_field}
210    ${cmd_output}=  BMC Execute Command  ${cmd}
211
212    Valid Value  vpd_records['${component}']['${field}']  ['${cmd_output[0].split('"')[1].strip('"')}']
213
214
215Verify VPD Data Via Vpdtool
216    [Documentation]  Get VPD details of given component via vpdtool and verify it
217    ...              using busctl command.
218    [Arguments]  ${component}  ${field}
219    # Description of arguments:
220    # component       VPD component (e.g. System,Chassis etc).
221    # field           VPD field (e.g. Serialnumber,LocationCode etc).
222
223    ${component_url}=  Set Variable If
224    ...  '${component}' == 'System'  /system
225
226    # Get VPD details of given component via vpd-tool.
227    ${vpd_records}=  Vpdtool  -o -O ${component_url}
228
229    # Get VPD details of given component via busctl command.
230    ${busctl_field}=  Set Variable If
231    ...  '${field}' == 'LocationCode'  com.ibm.ipzvpd.Location LocationCode
232    ...  '${field}' == 'Model'  xyz.openbmc_project.Inventory.Decorator.Asset Model
233    ...  '${field}' == 'SerialNumber'  xyz.openbmc_project.Inventory.Decorator.Asset SerialNumber
234
235    ${cmd}=  Catenate  ${CMD_GET_PROPERTY_INVENTORY} /xyz/openbmc_project/inventory/system
236    ...  ${busctl_field}
237    ${cmd_output}=  BMC Execute Command  ${cmd}
238    # Example of cmd_output:
239    #   [0]:                                            s "ABCD.XY1.1234567-P0"
240    #   [1]:
241    #   [2]:                                            0
242
243    # Cross check vpdtool output with busctl response.
244    Should Be Equal As Strings  ${vpd_records["/system"]["${field}"]}
245    ...  ${cmd_output[0].split('"')[1].strip('"')}
246