xref: /openbmc/openbmc-test-automation/ipmi/test_ipmi_fru_device.robot (revision 6fb70d98f2f1cb9273ba912deaa2cebe3c23ea86)
1a787bc28SVijay Khemka*** Settings ***
2a787bc28SVijay KhemkaDocumentation  Test IPMI FRU data.
3a787bc28SVijay Khemka
4a787bc28SVijay KhemkaResource               ../lib/ipmi_client.robot
5c288affeSganesanbResource               ../lib/bmc_dbus.robot
6c288affeSganesanbVariables              ../data/ipmi_raw_cmd_table.py
7c288affeSganesanbLibrary                ../lib/ipmi_utils.py
8a787bc28SVijay Khemka
9*6fb70d98SMatt FischerTest Tags             IPMI_FRU_Device
1087dc442cSGeorge Keishing
11a787bc28SVijay Khemka*** Variables ***
1287dc442cSGeorge Keishing
13a787bc28SVijay Khemka${FRU_NAME}       dimm01 dimm02 cpu0 cpu1  motherboard
14c288affeSganesanb${BUSCTL_FRU}                xyz.openbmc_project.FruDevice
15c288affeSganesanb${FRU_DBUS_URL}              /xyz/openbmc_project/FruDevice
16c288affeSganesanb${fru_device_id}             0x00
17c288affeSganesanb${fru_device_id_invalid}     0xff
18c288affeSganesanb${read_write_offset}         0x00 0x00
19c288affeSganesanb&{dbus_dict}
20c288affeSganesanb&{ipmi_dbus_name_mapping}    Chassis Part Number=.CHASSIS_PART_NUMBER
21c288affeSganesanb...  Board Mfg Date=.BOARD_MANUFACTURE_DATE  Board Mfg=.BOARD_MANUFACTURER
22c288affeSganesanb...  Board Product=.BOARD_PRODUCT_NAME  Board Serial=.BOARD_SERIAL_NUMBER
23c288affeSganesanb...  Board Part Number=.BOARD_PART_NUMBER  Product Manufacturer=.PRODUCT_MANUFACTURER
24c288affeSganesanb...  Product Name=.PRODUCT_PRODUCT_NAME  Product Part Number=.PRODUCT_PART_NUMBER
25c288affeSganesanb...  Product Version=.PRODUCT_VERSION  Product Serial=.PRODUCT_SERIAL_NUMBER
26a787bc28SVijay Khemka
27a787bc28SVijay Khemka*** Test Cases ***
28a787bc28SVijay KhemkaTest FRU Device Name
29a787bc28SVijay Khemka    [Documentation]  Search FRU for device name
30a787bc28SVijay Khemka    [Tags]  Test_FRU_Device_Name
31a787bc28SVijay Khemka
32372cd862Sishwaryamathim    ${output}=  Run IPMI Standard Command  fru
33a787bc28SVijay Khemka    Should Contain  ${output}  ${FRU_NAME}  msg=Fail: Given FRU device ${FRU_NAME} not found
34c288affeSganesanb
35c288affeSganesanb
36c288affeSganesanbVerify Fru Device Configuration
37c288affeSganesanb    [Documentation]  Read the FRU device configuration of each device
38c288affeSganesanb    ...  and compare with DBUS data.
39c288affeSganesanb    [Tags]  Verify_Fru_Device_Configuration
40c288affeSganesanb
41c288affeSganesanb    # IPMI FRU print.
42372cd862Sishwaryamathim    ${ipmi_output}=  Run IPMI Standard Command  fru
43c288affeSganesanb
44c288affeSganesanb    # Create dictionary with FRU device serial number as key and details as value from IPMI.
45c288affeSganesanb    ${ipmi_fru}=  Get IPMI FRU Devices Data  ${ipmi_output}
46c288affeSganesanb
47c288affeSganesanb    # Returns all the available FRU dbus uri.
48c288affeSganesanb    ${dbus_fru_uri}=  Get DBUS URI List From BMC  ${BUSCTL_FRU}  ${FRU_DBUS_URL}
49c288affeSganesanb
50c288affeSganesanb    # Returns all the FRU device uri with special characters removed.
51c288affeSganesanb    ${dbus_fru_uri_list}=  Fetch DBUS URI List Without Unicode  ${dbus_fru_uri}
52c288affeSganesanb
53c288affeSganesanb    # Creates dictionary with serial number as key, and corresponding FRU device uri as value from dbus.
54c288affeSganesanb    Get DBUS Dictionary For FRU Devices  ${dbus_fru_uri_list}  ${ipmi_fru}
55c288affeSganesanb
56c288affeSganesanb    # Compare dbus dictionary each field, with IPMI FRU device fields for each FRU device.
57c288affeSganesanb    Compare IPMI FRU with DBUS  ${ipmi_fru}
58c288affeSganesanb
59c288affeSganesanb
60c288affeSganesanbVerify Get FRU Inventory Area Info
61c288affeSganesanb    [Documentation]  Verify IPMI get FRU inventory area info command.
62c288affeSganesanb    [Tags]  Verify_Get_FRU_Inventory_Area_Info
63c288affeSganesanb
64c288affeSganesanb    # IPMI read FRU data command.
65c288affeSganesanb    ${resp}=  Read FRU Data Via IPMI  ${fru_device_id}  ${read_write_offset}
66c288affeSganesanb    ${bytes_read}=  Set Variable  ${resp.split()[0]}
67c288affeSganesanb
68c288affeSganesanb    # IPMI get FRU inventory area info command.
69c288affeSganesanb    ${bytes_inventory}=  Get FRU Inventory Area Info
70c288affeSganesanb
71c288affeSganesanb    # Compare read FRU data Count returned -- count is ‘1’ based, with inventory area count.
72c288affeSganesanb    Should Be Equal  ${bytes_inventory}  ${bytes_read}
73c288affeSganesanb
74c288affeSganesanb
75c288affeSganesanbVerify Get FRU Inventory Area Info For Invalid Device Data
76c288affeSganesanb    [Documentation]  Verify IPMI get FRU inventory area info command for Invalid Device Data.
77c288affeSganesanb    [Tags]  Verify_Get_FRU_Inventory_Area_Info_For_Invalid_Device_Data
78c288affeSganesanb
79c288affeSganesanb    # Verify response for invalid FRU device id.
80c288affeSganesanb    Run Keyword and Expect Error  *${IPMI_RAW_CMD['FRU']['Inventory_Area_Info'][1]}*
81372cd862Sishwaryamathim    ...  Run IPMI Command  ${IPMI_RAW_CMD['FRU']['Inventory_Area_Info'][0]} ${fru_device_id_invalid}
82c288affeSganesanb
83c288affeSganesanb
84c288affeSganesanbVerify Get FRU Inventory Area Info For Invalid Data Request
85c288affeSganesanb    [Documentation]  Verify IPMI get FRU inventory area info command for Invalid Data Request.
86c288affeSganesanb    [Tags]  Verify_Get_FRU_Inventory_Area_Info_For_Invalid_Data_Request
87c288affeSganesanb
88c288affeSganesanb    # Verify response for invalid response data - extra bytes.
89c288affeSganesanb    Run Keyword and Expect Error  *${IPMI_RAW_CMD['FRU']['Inventory_Area_Info'][2]}*
90372cd862Sishwaryamathim    ...  Run IPMI Command  ${IPMI_RAW_CMD['FRU']['Inventory_Area_Info'][0]} ${fru_device_id} 0x00
91c288affeSganesanb
92c288affeSganesanb
93c288affeSganesanbVerify IPMI Write FRU Data
94c288affeSganesanb    [Documentation]  Verify write data in FRU and compare data from read FRU data command via IPMI.
95c288affeSganesanb    [Tags]  Verify_IPMI_Write_FRU_Data
96c288affeSganesanb    [Setup]  Get Default FRU Data
97c288affeSganesanb    [Teardown]  Restore Default FRU Data
98c288affeSganesanb
99c288affeSganesanb    # Generate random data to write in FRU device.
100c288affeSganesanb    ${write_data_prefixed}  ${write_data}=  Generate Random Data For FRU
101c288affeSganesanb
102c288affeSganesanb    # Get the length of the data generated and convert to hex.
103c288affeSganesanb    ${write_data_length}=  Get Length  ${write_data}
104c288affeSganesanb    ${write_data_length}=  Convert To Hex  ${write_data_length}  lowercase=yes
105c288affeSganesanb
106c288affeSganesanb    # Write the data to FRU device.
107c288affeSganesanb    Write FRU Data Via IPMI  ${fru_device_id}  ${read_write_offset}  ${write_data_prefixed}  ${write_data_length}
108c288affeSganesanb
109c288affeSganesanb    # Read the FRU data.
110c288affeSganesanb    ${resp}=  Read FRU Data Via IPMI  ${fru_device_id}  ${read_write_offset}
111c288affeSganesanb    ${resp_data}=  Set Variable  ${resp.split()[1:]}
112c288affeSganesanb
113c288affeSganesanb    # Verify if the data written and read are same.
114c288affeSganesanb    Should Be Equal  ${write_data}  ${resp_data}
115c288affeSganesanb
116c288affeSganesanb
117c288affeSganesanbVerify IPMI Write FRU Data With BMC Reboot
118c288affeSganesanb    [Documentation]  Verify IPMI write data in FRU and compare data from read FRU data command after BMC reboot.
119c288affeSganesanb    [Tags]  Verify_IPMI_Write_FRU_Data_With_BMC_Reboot
120c288affeSganesanb    [Setup]  Get Default FRU Data
121c288affeSganesanb    [Teardown]  Restore Default FRU Data
122c288affeSganesanb
123c288affeSganesanb    # Generate random data to write in FRU device.
124c288affeSganesanb    ${write_data_prefixed}  ${write_data}=  Generate Random Data For FRU
125c288affeSganesanb
126c288affeSganesanb    # Get the length of the data generated and convert to hex.
127c288affeSganesanb    ${write_data_length}=  Get Length  ${write_data}
128c288affeSganesanb    ${write_data_length}=  Convert To Hex  ${write_data_length}  lowercase=yes
129c288affeSganesanb
130c288affeSganesanb    # Write the data to FRU device.
131c288affeSganesanb    Write FRU Data Via IPMI  ${fru_device_id}  ${read_write_offset}  ${write_data_prefixed}  ${write_data_length}
132c288affeSganesanb
133c288affeSganesanb    # Read the FRU data.
134c288affeSganesanb    ${resp}=  Read FRU Data Via IPMI  ${fru_device_id}  ${read_write_offset}
135c288affeSganesanb    ${resp_data}=  Set Variable  ${resp.split()[1:]}
136c288affeSganesanb
137c288affeSganesanb    # Verify if the data written and read are same.
138c288affeSganesanb    Should Be Equal  ${write_data}  ${resp_data}
139c288affeSganesanb
140c288affeSganesanb    # Reboot BMC and verify if the data written and read are same.
141c288affeSganesanb    IPMI MC Reset Cold (run)
142c288affeSganesanb    ${resp}=  Read FRU Data Via IPMI  ${fru_device_id}  ${read_write_offset}
143c288affeSganesanb    Should Not Be Equal  ${resp}  ${initial_fru_data}
144c288affeSganesanb    Should Be Equal  ${resp[1:]}  ${write_data}
145c288affeSganesanb
146c288affeSganesanb
147c288affeSganesanb*** Keywords ***
148c288affeSganesanb
149c288affeSganesanbGet IPMI FRU Devices Data
150c288affeSganesanb    [Documentation]  Get response from IPMI FRU command and format data
151c288affeSganesanb    ...  with Board or Product serial as key and corresponding data as value.
152c288affeSganesanb    [Arguments]  ${ipmi_output}
153c288affeSganesanb
154c288affeSganesanb    # Description of Argument(s):
155c288affeSganesanb    # ipmi_output        All the FRU devices listed in IPMI FRU command.
156c288affeSganesanb
157c288affeSganesanb    # Get the FRU list and return as a dictionary with serial number as key.
158c288affeSganesanb    # Example:
159c288affeSganesanb    # fru_data = {
160c288affeSganesanb    # "123456789012345XYZ":
161c288affeSganesanb    #  {
162c288affeSganesanb    #     FRU Device Description : Builtin FRU Device (ID 0),
163c288affeSganesanb    #     Chassis Type          : Rack Mount Chassis,
164c288affeSganesanb    #     Chassis Part Number   : xxx-xxxxx-xxxx-xxx,
165c288affeSganesanb    #     Board Mfg Date        : Fri Oct 16 06:34:00 2020 UTC,
166c288affeSganesanb    #     Board Mfg             : XXXXX,
167c288affeSganesanb    #     Board Product         : XXXXX,
168c288affeSganesanb    #     Board Serial          : 123456789012345XYZ,
169c288affeSganesanb    #     Board Part Number     : xxx.xxxxx.xxxx
170c288affeSganesanb    #     Board Extra           : 01
171c288affeSganesanb    #     Product Manufacturer  : XXXXX
172c288affeSganesanb    #     Product Name          : XXXXX
173c288affeSganesanb    #     Product Part Number   : xxx-xxxx-xxxx-xxx
174c288affeSganesanb    #     Product Version       : v1.0
175c288affeSganesanb    #     Product Serial        : 1234567890XYZ
176c288affeSganesanb    #  },....}
177c288affeSganesanb
178c288affeSganesanb    # Gets response from FRU data and split each device.
179c288affeSganesanb    ${output}=  Set Variable  ${ipmi_output.strip("\n")}
180c288affeSganesanb    ${output}=  Split String  ${output}  \n\n
181c288affeSganesanb    &{fru}=  Create Dictionary
182c288affeSganesanb    ${num}=  Set Variable  0
183c288affeSganesanb
184c288affeSganesanb    # For each device, identify either Board Serial/Product Serial (whichever is available).
185c288affeSganesanb    FOR  ${devices}  IN  @{output}
186c288affeSganesanb        &{tmp}=  Create Dictionary
187c288affeSganesanb        ${dev}=  Split String  ${devices}  \n
188c288affeSganesanb        FOR  ${device}  IN  @{dev}
189c288affeSganesanb            ${ipmi_fru_board_serial_status}=  Run Keyword And Return Status  Should Contain  ${device}  Board Serial
190c288affeSganesanb            Exit For Loop If  '${ipmi_fru_board_serial_status}' == 'True'
191c288affeSganesanb        END
192c288affeSganesanb        ${frudata}=  Get From List  ${output}  ${num}
193c288affeSganesanb        ${serial_no}=  Run Keyword If  '${ipmi_fru_board_serial_status}' == 'True'
194c288affeSganesanb        ...    Get Lines Containing String  ${frudata}  Board Serial
195c288affeSganesanb        ...  ELSE
196c288affeSganesanb        ...    Get Lines Containing String  ${frudata}  Product Serial
197c288affeSganesanb
198c288affeSganesanb        # Get each device and split field as key and value and append to a dictionary.
199c288affeSganesanb        ${serial_nos}=  Set Variable  ${serial_no.strip()}
200c288affeSganesanb        ${data}=  Split String  ${serial_nos}  :
201c288affeSganesanb        ${serial_number}=  Get From List  ${data}  1
202c288affeSganesanb        ${num}=  Evaluate  int(${num}) + 1
203c288affeSganesanb        FOR  ${entry}  IN  @{dev}
204c288affeSganesanb            ${entry}=  Split String  ${entry}  ${SPACE}:${SPACE}
205c288affeSganesanb            ${entry1}=  Set Variable  ${entry[0].strip()}
206c288affeSganesanb            ${entry2}=  Set Variable  ${entry[1].strip()}
207c288affeSganesanb            Set To Dictionary  ${tmp}  ${entry1}  ${entry2}
208c288affeSganesanb        END
209c288affeSganesanb        ${serial_number}=  Set Variable  ${serial_number.strip()}
210c288affeSganesanb        # Assign serial number as key for main dictionary and a each device detail as value.
211c288affeSganesanb        Set To Dictionary  ${fru}  ${serial_number}  ${tmp}
212c288affeSganesanb    END
213c288affeSganesanb
214409df05dSGeorge Keishing    RETURN  ${fru}
215c288affeSganesanb
216c288affeSganesanb
217c288affeSganesanbGet DBUS Dictionary For FRU Devices
218c288affeSganesanb    [Documentation]  Provides the dictionary of DBUS FRU devices from DBUS FRU.
219c288affeSganesanb    [Arguments]  ${dbus_fru}  ${ipmi_fru}
220c288affeSganesanb
221c288affeSganesanb    # Description of Argument(s):
222c288affeSganesanb    # dbus_fru    FRU dbus uri list.
223c288affeSganesanb    # ipmi_fru    IPMI FRU details.
224c288affeSganesanb
225c288affeSganesanb    # Execute DBUS Introspect Command for each device,
226c288affeSganesanb    # Appends dictionary with serial number as key and FRU dbus uri as value,
227c288affeSganesanb    # if the IPMI FRU key matches the serial number of each device dbus response.
228c288affeSganesanb    # Example :
229c288affeSganesanb    #    ${dbus_output} = { "123456789012345XYZ" : "xyz.openbmc_project.FruDevice/xyz/openbmc_project/FruDevice/Device_0" }
230c288affeSganesanb    FOR  ${fru}  IN  @{dbus_fru}
231c288affeSganesanb        ${cmd}=  Catenate  ${BUSCTL_FRU} ${fru}
232c288affeSganesanb        ${dbus_output}=  Execute DBUS Introspect Command  ${cmd}
233c288affeSganesanb        ${dbus_fru_board_serial_status}=  Run Keyword And Return Status  Should Contain  ${dbus_output}  .BOARD_SERIAL
234c288affeSganesanb        ${dbus_fru_product_serial_status}=  Run Keyword And Return Status  Should Contain  ${dbus_output}  .PRODUCT_SERIAL
235c288affeSganesanb        Run Keyword If  '${dbus_fru_board_serial_status}' == 'True' or '${dbus_fru_product_serial_status}' == 'True'
236c288affeSganesanb        ...    Create Dictionary For DBUS URI  ${dbus_output}  ${ipmi_fru}  ${dbus_fru_board_serial_status}  ${cmd}
237c288affeSganesanb    END
238c288affeSganesanb
239c288affeSganesanb
240c288affeSganesanbCreate Dictionary For DBUS URI
241c288affeSganesanb    [Documentation]  Create Dictionary For DBUS URI
242c288affeSganesanb    [Arguments]  ${dbus_output}  ${ipmi_fru}  ${dbus_fru_board_serial_status}  ${fru_command}
243c288affeSganesanb
244c288affeSganesanb    # Description of Argument(s):
245c288affeSganesanb    # dbus_output                             Dbus response got from BMC console.
246c288affeSganesanb    # ipmi_fru                                IPMI FRU details.
247c288affeSganesanb    # dbus_fru_board_serial_status            FRU devices may have either BOARD_SERIAL or PRODUCT_SERIAL
248c288affeSganesanb    # ...                                     if status was true value of BOARD_SERIAL will be taken for dictionary as an key
249c288affeSganesanb    # ...                                     otherwise value of PRODUCT_SERIAL will be taken as an key for dictionary.
250c288affeSganesanb    # fru_command                             FRU command to map into dictionary as value.
251c288affeSganesanb
252c288affeSganesanb    # Validates the IPMI FRU dictionary key with dbus uri response serial number.
253c288affeSganesanb    # If matches then, sets the serial number as key and FRU uri as value.
254c288affeSganesanb    # ${dbus_dict} defined under variable section.
255c288affeSganesanb    FOR  ${ipmi_fru_serial_no}  IN  @{ipmi_fru.keys()}
256c288affeSganesanb        ${serial_no}=  Run Keyword If  '${dbus_fru_board_serial_status}' == 'True'
257c288affeSganesanb        ...    Get Lines Containing String  ${dbus_output}  .BOARD_SERIAL
258c288affeSganesanb        ...  ELSE
259c288affeSganesanb        ...    Get Lines Containing String  ${dbus_output}  .PRODUCT_SERIAL
260c288affeSganesanb        ${serial_no}=  Split String  ${serial_no}  "
261c288affeSganesanb        ${dbus_serial_no}=  Set Variable  ${serial_no[1].strip()}
262c288affeSganesanb        ${serial_no_status}=  Run Keyword And Return Status  Should Be Equal As Strings  ${ipmi_fru_serial_no}  ${dbus_serial_no}
263c288affeSganesanb        Run Keyword If  '${serial_no_status}' == 'True'
264c288affeSganesanb        ...    Run Keywords  Set To Dictionary  ${dbus_dict}  ${dbus_serial_no}  ${fru_command}  AND
265c288affeSganesanb        ...    Exit For Loop
266c288affeSganesanb    END
267c288affeSganesanb
268c288affeSganesanb
269c288affeSganesanbCompare IPMI FRU with DBUS
270c288affeSganesanb    [Documentation]  Compare the IPMI FRU dictionary values with DBUS dictionary values,
271c288affeSganesanb    ...  if the serial number is present in both FRU and dbus dictionaries.
272c288affeSganesanb    [Arguments]  ${ipmi_fru}
273c288affeSganesanb
274c288affeSganesanb   # Description of Argument(s):
275c288affeSganesanb   # ipmi_fru    IPMI FRU device details.
276c288affeSganesanb
277c288affeSganesanb    # With each IPMI FRU key, get the corresponding valid from dbus dictionary,
278c288affeSganesanb    # Execute the value which is dbus uri and,
279c288affeSganesanb    # validate each dbus field value with IPMI FRU field value.
280c288affeSganesanb    # Values are validated for keys present in the ipmi_dbus_name_mapping dictionary.
281c288affeSganesanb    # Example :
282c288affeSganesanb    #    IPMI FRU field :
283c288affeSganesanb    #             Board Part Number     : 111.22222.0000
284c288affeSganesanb    #    DBUS FRU field :
285c288affeSganesanb    #            .BOARD_PART_NUMBER      property  s     "111.22222.0000"        emits-change
286c288affeSganesanb    FOR  ${key}  ${ipmi_fru_value}  IN  &{ipmi_fru}
287c288affeSganesanb        ${dbus_resp}=  Execute DBUS Introspect Command  ${dbus_dict}[${key}]
288c288affeSganesanb        ${ipmi_fru_subkeys}=  Get Dictionary Keys  ${ipmi_fru_value}
289c288affeSganesanb        FOR  ${subkeys}  IN  @{ipmi_fru_subkeys}
290c288affeSganesanb            ${key_status}=  Run Keyword And Return Status  Dictionary Should Contain Key
291c288affeSganesanb            ...  ${ipmi_dbus_name_mapping}  ${subkeys}
292c288affeSganesanb            Continue For Loop If  '${key_status}' == 'False'
293c288affeSganesanb            ${property_name}=  Get From Dictionary  ${ipmi_dbus_name_mapping}  ${subkeys}
294c288affeSganesanb            ${dbus_data}=  Get Lines Containing String  ${dbus_resp}  ${property_name}
295c288affeSganesanb            ${dbus_value}=  Set Variable  ${dbus_data.split('"')[1].strip()}
296c288affeSganesanb            ${ipmi_response}=  Get From Dictionary  ${ipmi_fru_value}  ${subkeys}
297c288affeSganesanb            ${status}=  Run Keyword And Return Status  Should Contain  ${property_name}  DATE
298c288affeSganesanb            IF  ${status}
299c288affeSganesanb                # If the required IPMI field has date field, the IPMI FRU value is converted to
300c288affeSganesanb                # format = %Y-%m-%d - %H:%M:%S and validated against dbus FRU data.
301c288affeSganesanb                ${ipmi_date}=  Convert Date  ${ipmi_response}  date_format=%a %b %d %H:%M:%S %Y
302c288affeSganesanb                ...  result_format=%Y-%m-%d - %H:%M:%S
303c288affeSganesanb                Run Keyword And Continue On Failure  Should Be Equal As Strings  ${ipmi_date}  ${dbus_value}
304c288affeSganesanb                ...  message=${property_name} Property value mismatch with IPMI and DBUS
305c288affeSganesanb            ELSE
306c288affeSganesanb                Run Keyword And Continue On Failure  Should Be Equal As Strings  ${ipmi_response}  ${dbus_value}
307c288affeSganesanb                ...  message=${property_name} Property value mismatch with IPMI and DBUS
308c288affeSganesanb            END
309c288affeSganesanb        END
310c288affeSganesanb    END
311c288affeSganesanb
312c288affeSganesanb
313c288affeSganesanbGet FRU Inventory Area Info
314c288affeSganesanb    [Documentation]  IPMI Get FRU Inventory Area Info and returns FRU Inventory area size in bytes.
315c288affeSganesanb
316372cd862Sishwaryamathim    ${resp}=  Run IPMI Command  ${IPMI_RAW_CMD['FRU']['Inventory_Area_Info'][0]} ${fru_device_id}
317c288affeSganesanb    ${resp}=  Split String  ${resp}
318c288affeSganesanb
319409df05dSGeorge Keishing    RETURN  ${resp[0]}
320c288affeSganesanb
321c288affeSganesanb
322c288affeSganesanbRead FRU Data Via IPMI
323c288affeSganesanb    [Documentation]  Read FRU data using IPMI raw command.
324c288affeSganesanb    [Arguments]  ${fru_id}  ${offset}
325c288affeSganesanb
326c288affeSganesanb   # Description of Argument(s):
327c288affeSganesanb   # fru_id        FRU id.
328c288affeSganesanb   # offset        Offset byte for read FRU command.
329c288affeSganesanb
330c288affeSganesanb    # IPMI Read FRU Data Command.
331c288affeSganesanb    # 0xff - Count to read --- count is ‘1’ based
332372cd862Sishwaryamathim    ${resp}=  Run IPMI Command
333b9071cd8SKManimozhi123    ...  ${IPMI_RAW_CMD['FRU']['Read'][0]} ${fru_id} ${offset} 0xff
334c288affeSganesanb
335409df05dSGeorge Keishing    RETURN  ${resp}
336c288affeSganesanb
337c288affeSganesanb
338c288affeSganesanbWrite FRU Data Via IPMI
339c288affeSganesanb    [Documentation]  Write FRU data using IPMI raw command.
340c288affeSganesanb    [Arguments]  ${fru_id}  ${offset}  ${data}  ${length}
341c288affeSganesanb
342c288affeSganesanb   # Description of Argument(s):
343c288affeSganesanb   # fru_id        FRU id.
344c288affeSganesanb   # offset        Offset byte for read FRU command.
345c288affeSganesanb   # data          Data to write for write FRU command.
346c288affeSganesanb   # length        Count of bytes that gets written in write FRU command.
347c288affeSganesanb
348c288affeSganesanb    # IPMI Write FRU Data Command.
349372cd862Sishwaryamathim    ${resp}=  Run IPMI Command
350b9071cd8SKManimozhi123    ...  ${IPMI_RAW_CMD['FRU']['Write'][0]} ${fru_id} ${offset} ${data}
351c288affeSganesanb
352c288affeSganesanb    Should Be Equal As Strings  ${resp}  ${length}
353c288affeSganesanb
354c288affeSganesanb
355c288affeSganesanbGenerate Random Data For FRU
356c288affeSganesanb    [Documentation]  Generate random data for write in FRU.
357c288affeSganesanb
358c288affeSganesanb    # Description:
359c288affeSganesanb    #  Generates string of bytes and convert to hexadecimal data.
360c288affeSganesanb    #  Gets the length of initial FRU data read with IPMI read FRU device command.
361c288affeSganesanb
362c288affeSganesanb    # ${frudata_prefixed}    string with bytes prefixed 0x by default
363c288affeSganesanb    # ${fru_data}            string with only hexadecimal bytes without prefix
364c288affeSganesanb
365c288affeSganesanb    ${string}=  Generate Random String  ${initial_fru_length}  [LETTERS]
366c288affeSganesanb    ${frudata_prefixed}  ${fru_data}=  Identify Request Data  ${string}
367c288affeSganesanb
368409df05dSGeorge Keishing    RETURN  ${frudata_prefixed}  ${fru_data}
369c288affeSganesanb
370c288affeSganesanb
371c288affeSganesanbGet Default FRU Data
372c288affeSganesanb    [Documentation]  Get default data via read FRU data IPMI command.
373c288affeSganesanb
374c288affeSganesanb    # Read the default FRU device data.
375c288affeSganesanb    # split the response and identify length of Requested data.
376c288affeSganesanb    ${initial_fru_data}=  Read FRU Data Via IPMI  ${fru_device_id}  ${read_write_offset}
377c288affeSganesanb    ${initial_fru_list}=  Split String  ${initial_fru_data}
378c288affeSganesanb    ${initial_fru_list}=  Set Variable  ${initial_fru_list[1:]}
379c288affeSganesanb    ${initial_fru_length}=  Get Length  ${initial_fru_list}
380c288affeSganesanb    Set Test Variable  ${initial_fru_data}
381c288affeSganesanb    Set Test Variable  ${initial_fru_list}
382c288affeSganesanb    Set Test Variable  ${initial_fru_length}
383c288affeSganesanb
384c288affeSganesanb
385c288affeSganesanbRestore Default FRU Data
386c288affeSganesanb    [Documentation]  Restore default FRU data.
387c288affeSganesanb
388c288affeSganesanb    # Prefix 0x to initial request data.
389c288affeSganesanb    ${fru_list}=  Prefix Bytes  ${initial_fru_list}
390c288affeSganesanb    ${fru_byte}=  Evaluate  " ".join(${fru_list})
391c288affeSganesanb    ${initial_frulength_hex}=  Convert To Hex  ${initial_fru_length}  lowercase=yes
392c288affeSganesanb    # Write the initial FRU data to restore.
393c288affeSganesanb    Write FRU Data Via IPMI  ${fru_device_id}  ${read_write_offset}  ${fru_byte}  ${initial_frulength_hex}
394c288affeSganesanb    # Verify whether initial FRU data is restored.
395c288affeSganesanb    ${fru_data}=  Read FRU Data Via IPMI  ${fru_device_id}  ${read_write_offset}
396c288affeSganesanb    Should Be Equal  ${fru_data}  ${initial_fru_data}
397