xref: /openbmc/openbmc-test-automation/redfish/managers/test_bmc_dumps.robot (revision 7236716604117174dae91aa09eba3e09f2d33252)
1a401cb86SRahul Maheshwari*** Settings ***
2a401cb86SRahul Maheshwari
3a401cb86SRahul MaheshwariDocumentation       Test BMC dump functionality of OpenBMC.
4a401cb86SRahul Maheshwari
588ec2805SGeorge KeishingResource            ../../lib/bmc_redfish_resource.robot
688ec2805SGeorge KeishingResource            ../../lib/boot_utils.robot
7a401cb86SRahul MaheshwariResource            ../../lib/dump_utils.robot
888ec2805SGeorge KeishingResource            ../../lib/openbmc_ffdc.robot
97e1f2c5cSmanashsarmaVariables           ../../data/pel_variables.py
10a401cb86SRahul Maheshwari
11f514ccb1SGeorge KeishingSuite Setup         Redfish.Login
12a401cb86SRahul MaheshwariTest Setup          Redfish Delete All BMC Dumps
13a401cb86SRahul MaheshwariTest Teardown       Test Teardown Execution
14a401cb86SRahul Maheshwari
156fb70d98SMatt FischerTest Tags          BMC_Dumps
166217ea3aSGeorge Keishing
17de2d1308STim Lee*** Variables ***
18de2d1308STim Lee
19de2d1308STim Lee# Total size of the dump in kilo bytes
20de2d1308STim Lee${BMC_DUMP_TOTAL_SIZE}       ${1024}
21de2d1308STim Lee
22de2d1308STim Lee# Minimum space required for one bmc dump in kilo bytes
23de2d1308STim Lee${BMC_DUMP_MIN_SPACE_REQD}   ${20}
24bd346b30Smanashsarma${MAX_DUMP_COUNT}            ${20}
25395f8804Smanashsarma${BMC_DUMP_COLLECTOR_PATH}   /var/lib/phosphor-debug-collector/dumps
26a401cb86SRahul Maheshwari
27a401cb86SRahul Maheshwari*** Test Cases ***
28a401cb86SRahul Maheshwari
294b5b1fafSmanashsarmaVerify Error Response For Already Deleted Dump Id
304b5b1fafSmanashsarma    [Documentation]  Delete non existing BMC dump and expect an error.
314b5b1fafSmanashsarma    [Tags]  Verify_Error_Response_For_Already_Deleted_Dump_Id
324b5b1fafSmanashsarma
339dcabadbSmanashsarma    Redfish Power Off  stack_mode=skip
344b5b1fafSmanashsarma    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
356cc5bcf6Smanashsarma    Wait Until Keyword Succeeds  15 sec  5 sec  Redfish Delete BMC Dump  ${dump_id}
364b5b1fafSmanashsarma    Run Keyword And Expect Error  ValueError: *  Redfish Delete BMC Dump  ${dump_id}
374b5b1fafSmanashsarma
384b5b1fafSmanashsarma
39a401cb86SRahul MaheshwariVerify User Initiated BMC Dump When Host Powered Off
40a401cb86SRahul Maheshwari    [Documentation]  Create user initiated BMC dump at host off state and
41a401cb86SRahul Maheshwari    ...  verify dump entry for it.
42a401cb86SRahul Maheshwari    [Tags]  Verify_User_Initiated_BMC_Dump_When_Host_Powered_Off
43a401cb86SRahul Maheshwari
44a401cb86SRahul Maheshwari    Redfish Power Off  stack_mode=skip
45bd38aa41SRahul Maheshwari    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
46a401cb86SRahul Maheshwari    ${dump_entries}=  Get BMC Dump Entries
47a401cb86SRahul Maheshwari    Length Should Be  ${dump_entries}  1
48a401cb86SRahul Maheshwari    List Should Contain Value  ${dump_entries}  ${dump_id}
49a401cb86SRahul Maheshwari
50a401cb86SRahul Maheshwari
51e8e9d0c2SRahul MaheshwariVerify User Initiated BMC Dump Size
527831dc27Smanashsarma    [Documentation]  Verify user initiated BMC dump size is under 20 MB.
53e8e9d0c2SRahul Maheshwari    [Tags]  Verify_User_Initiated_BMC_Dump_Size
54e8e9d0c2SRahul Maheshwari
55e52174b5Smanashsarma    Redfish Power Off  stack_mode=skip
56bd38aa41SRahul Maheshwari    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
574d430283Sganesanb    ${resp}=  Redfish.Get Properties  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries/${dump_id}
58e8e9d0c2SRahul Maheshwari
59e8e9d0c2SRahul Maheshwari    # Example of response from above Redfish GET request.
60e8e9d0c2SRahul Maheshwari    # "@odata.type": "#LogEntry.v1_7_0.LogEntry",
61e8e9d0c2SRahul Maheshwari    # "AdditionalDataSizeBytes": 31644,
624d430283Sganesanb    # "AdditionalDataURI": "/redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/attachment/9",
63e8e9d0c2SRahul Maheshwari    # "Created": "2020-10-23T06:32:53+00:00",
64e8e9d0c2SRahul Maheshwari    # "DiagnosticDataType": "Manager",
65e8e9d0c2SRahul Maheshwari    # "EntryType": "Event",
66e8e9d0c2SRahul Maheshwari    # "Id": "9",
67e8e9d0c2SRahul Maheshwari    # "Name": "BMC Dump Entry"
68e8e9d0c2SRahul Maheshwari
697831dc27Smanashsarma    # Max size for dump is 20 MB = 20x1024x1024 Byte.
707831dc27Smanashsarma    Should Be True  0 < ${resp["AdditionalDataSizeBytes"]} < 20971520
71e8e9d0c2SRahul Maheshwari
72e8e9d0c2SRahul Maheshwari
737e1f2c5cSmanashsarmaVerify Internal Failure Initiated BMC Dump Size
747e1f2c5cSmanashsarma    [Documentation]  Verify that the internal failure initiated BMC dump size is under 20 MB.
757e1f2c5cSmanashsarma    [Tags]  Verify_Internal_Failure_Initiated_BMC_Dump_Size
767e1f2c5cSmanashsarma
77a8efe72dSmanashsarma    Redfish Power Off  stack_mode=skip
787e1f2c5cSmanashsarma    Redfish Delete All BMC Dumps
797e1f2c5cSmanashsarma
807e1f2c5cSmanashsarma    # Create an internal failure error log.
817e1f2c5cSmanashsarma    BMC Execute Command  ${CMD_INTERNAL_FAILURE}
827e1f2c5cSmanashsarma
837e1f2c5cSmanashsarma    # Wait for BMC dump to get generated after injecting internal failure.
847e1f2c5cSmanashsarma    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Dump Available
857e1f2c5cSmanashsarma
867e1f2c5cSmanashsarma    # Verify that only one BMC dump is generated after injecting error.
877e1f2c5cSmanashsarma    ${dump_entries}=  Get BMC Dump Entries
887e1f2c5cSmanashsarma    ${length}=  Get length  ${dump_entries}
897e1f2c5cSmanashsarma    Should Be Equal As Integers  ${length}  ${1}
907e1f2c5cSmanashsarma
917e1f2c5cSmanashsarma    # Max size for dump is 20 MB = 20x1024x1024 Byte.
927e1f2c5cSmanashsarma    ${resp}=  Redfish.Get Properties
934d430283Sganesanb    ...  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries/${dump_entries[0]}
947e1f2c5cSmanashsarma    Should Be True  0 < ${resp["AdditionalDataSizeBytes"]} < 20971520
957e1f2c5cSmanashsarma
967e1f2c5cSmanashsarma
97bbc68bc4SmanashsarmaVerify Multiple BMC Dump Creation
98bbc68bc4Smanashsarma    [Documentation]  Verify that multiple BMC dumps can be created one after
99bbc68bc4Smanashsarma    ...  another successfully.
100bbc68bc4Smanashsarma    [Tags]   Verify_Multiple_BMC_Dump_Creation
101bbc68bc4Smanashsarma
102e52174b5Smanashsarma    Redfish Power Off  stack_mode=skip
103bbc68bc4Smanashsarma    ${dump_count}=  Evaluate  random.randint(5, 10)  modules=random
104bbc68bc4Smanashsarma    FOR  ${INDEX}  IN  1  ${dump_count}
105bbc68bc4Smanashsarma      Create User Initiated BMC Dump Via Redfish
106bbc68bc4Smanashsarma    END
107bbc68bc4Smanashsarma
108bbc68bc4Smanashsarma
109395f8804SmanashsarmaVerify BMC Dump Default Location In BMC
110395f8804Smanashsarma     [Documentation]  Verify that BMC dump is created in its default location of BMC.
111224e4c7dSGeorge Keishing     [Tags]  Verify_BMC_Dump_Default_Location_In_BMC
112395f8804Smanashsarma
113e52174b5Smanashsarma     Redfish Power Off  stack_mode=skip
114395f8804Smanashsarma     Redfish Delete All BMC Dumps
115395f8804Smanashsarma     ${dump_id}=  Create User Initiated BMC Dump Via Redfish
116395f8804Smanashsarma     ${dump_file}  ${stderr}  ${rc}=  BMC Execute Command
117395f8804Smanashsarma     ...  ls ${BMC_DUMP_COLLECTOR_PATH}/${dump_id}
118395f8804Smanashsarma     Should Be True  ${rc} == 0
119c30e02a6Smanashsarma     Should Contain Any  ${dump_file}  BMCDUMP  obmcdump
120395f8804Smanashsarma
121395f8804Smanashsarma
1224b5d6acaSmanashsarmaVerify User Initiated BMC Dump At Host Booting
1234b5d6acaSmanashsarma    [Documentation]  Create and verify user initiated BMC dump during Host is powwering on
1244b5d6acaSmanashsarma    ...  or when host booting is in progress.
1254b5d6acaSmanashsarma    [Tags]  Verify_User_Initiated_BMC_Dump_At_Host_Booting
1264b5d6acaSmanashsarma
1279712ac54Smanashsarma    Redfish Power Off  stack_mode=skip
1284b5d6acaSmanashsarma    Redfish Delete All BMC Dumps
1294b5d6acaSmanashsarma
1304b5d6acaSmanashsarma    # Initiate power on.
1314b5d6acaSmanashsarma    Redfish Power Operation  On
1324b5d6acaSmanashsarma    Wait Until Keyword Succeeds  2 min  5 sec  Is Boot Progress Changed
1334b5d6acaSmanashsarma
1344b5d6acaSmanashsarma    # Create user initiated BMC dump and verify only one dump is available.
1354b5d6acaSmanashsarma    Create User Initiated BMC Dump Via Redfish
1364b5d6acaSmanashsarma    ${dump_entries}=  Get BMC Dump Entries
1374b5d6acaSmanashsarma    Length Should Be  ${dump_entries}  1
1384b5d6acaSmanashsarma
1394b5d6acaSmanashsarma
140a401cb86SRahul MaheshwariVerify Dump Persistency On Dump Service Restart
141a401cb86SRahul Maheshwari    [Documentation]  Create user dump, restart dump manager service and verify dump
142a401cb86SRahul Maheshwari    ...  persistency.
143a401cb86SRahul Maheshwari    [Tags]  Verify_Dump_Persistency_On_Dump_Service_Restart
144a401cb86SRahul Maheshwari
145e52174b5Smanashsarma    Redfish Power Off  stack_mode=skip
146bd38aa41SRahul Maheshwari    Create User Initiated BMC Dump Via Redfish
1474d430283Sganesanb    ${dump_entries_before}=  redfish_utils.get_member_list  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries
148a401cb86SRahul Maheshwari
149a401cb86SRahul Maheshwari    # Restart dump service.
150a401cb86SRahul Maheshwari    BMC Execute Command  systemctl restart xyz.openbmc_project.Dump.Manager.service
151a401cb86SRahul Maheshwari    Sleep  10s  reason=Wait for BMC dump service to restart properly
152a401cb86SRahul Maheshwari
1534d430283Sganesanb    ${dump_entries_after}=  redfish_utils.get_member_list  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries
154a401cb86SRahul Maheshwari    Lists Should Be Equal  ${dump_entries_before}  ${dump_entries_after}
155a401cb86SRahul Maheshwari
156a401cb86SRahul Maheshwari
157a401cb86SRahul MaheshwariVerify Dump Persistency On BMC Reset
158a401cb86SRahul Maheshwari    [Documentation]  Create user dump, reset BMC and verify dump persistency.
159a401cb86SRahul Maheshwari    [Tags]  Verify_Dump_Persistency_On_BMC_Reset
160a401cb86SRahul Maheshwari
1618fa9c89eSmanashsarma    # Power off host so that dump is not offloaded to host OS.
1628fa9c89eSmanashsarma    Redfish Power Off  stack_mode=skip
1638fa9c89eSmanashsarma
164bd38aa41SRahul Maheshwari    Create User Initiated BMC Dump Via Redfish
1654d430283Sganesanb    ${dump_entries_before}=  redfish_utils.get_member_list  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries
166a401cb86SRahul Maheshwari
167a401cb86SRahul Maheshwari    # Reset BMC.
16888ec2805SGeorge Keishing    OBMC Reboot (off)  stack_mode=skip
169a401cb86SRahul Maheshwari
1704d430283Sganesanb    ${dump_entries_after}=  redfish_utils.get_member_list  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries
171a401cb86SRahul Maheshwari    Lists Should Be Equal  ${dump_entries_before}  ${dump_entries_after}
172a401cb86SRahul Maheshwari
173a401cb86SRahul Maheshwari
174a401cb86SRahul MaheshwariDelete User Initiated BMC Dump And Verify
175a401cb86SRahul Maheshwari    [Documentation]  Delete user initiated BMC dump and verify.
176a401cb86SRahul Maheshwari    [Tags]  Delete_User_Initiated_BMC_Dump_And_Verify
177a401cb86SRahul Maheshwari
178e52174b5Smanashsarma    Redfish Power Off  stack_mode=skip
179bd38aa41SRahul Maheshwari    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
1806cc5bcf6Smanashsarma    Wait Until Keyword Succeeds  15 sec  5 sec  Redfish Delete BMC Dump  ${dump_id}
181a401cb86SRahul Maheshwari
182a401cb86SRahul Maheshwari    ${dump_entries}=  Get BMC Dump Entries
183a401cb86SRahul Maheshwari    Should Be Empty  ${dump_entries}
184a401cb86SRahul Maheshwari
185a401cb86SRahul Maheshwari
186a401cb86SRahul MaheshwariDelete All User Initiated BMC Dumps And Verify
187a401cb86SRahul Maheshwari    [Documentation]  Delete all user initiated BMC dumps and verify.
188a401cb86SRahul Maheshwari    [Tags]  Delete_All_User_Initiated_BMC_Dumps_And_Verify
189a401cb86SRahul Maheshwari
19070d840eeSmanashsarma    # Power off host so that dump is not offloaded to host OS.
19170d840eeSmanashsarma    Redfish Power Off  stack_mode=skip
19270d840eeSmanashsarma
193a401cb86SRahul Maheshwari    # Create some BMC dump.
194bd38aa41SRahul Maheshwari    Create User Initiated BMC Dump Via Redfish
195bd38aa41SRahul Maheshwari    Create User Initiated BMC Dump Via Redfish
196a401cb86SRahul Maheshwari
197a401cb86SRahul Maheshwari    Redfish Delete All BMC Dumps
198a401cb86SRahul Maheshwari    ${dump_entries}=  Get BMC Dump Entries
199a401cb86SRahul Maheshwari    Should Be Empty  ${dump_entries}
200a401cb86SRahul Maheshwari
201a401cb86SRahul Maheshwari
202a401cb86SRahul MaheshwariCreate Two User Initiated BMC Dumps
203a401cb86SRahul Maheshwari    [Documentation]  Create two user initiated BMC dumps.
204a401cb86SRahul Maheshwari    [Tags]  Create_Two_User_Initiated_BMC_Dumps
205a401cb86SRahul Maheshwari
206e52174b5Smanashsarma    Redfish Power Off  stack_mode=skip
207bd38aa41SRahul Maheshwari    ${dump_id1}=  Create User Initiated BMC Dump Via Redfish
208bd38aa41SRahul Maheshwari    ${dump_id2}=  Create User Initiated BMC Dump Via Redfish
209a401cb86SRahul Maheshwari
210a401cb86SRahul Maheshwari    ${dump_entries}=  Get BMC Dump Entries
211a401cb86SRahul Maheshwari    Length Should Be  ${dump_entries}  2
212a401cb86SRahul Maheshwari    Should Contain  ${dump_entries}  ${dump_id1}
213a401cb86SRahul Maheshwari    Should Contain  ${dump_entries}  ${dump_id2}
214a401cb86SRahul Maheshwari
215a401cb86SRahul Maheshwari
216a401cb86SRahul MaheshwariCreate Two User Initiated BMC Dumps And Delete One
217a401cb86SRahul Maheshwari    [Documentation]  Create two dumps and delete the first.
218a401cb86SRahul Maheshwari    [Tags]  Create_Two_User_Initiated_BMC_Dumps_And_Delete_One
219a401cb86SRahul Maheshwari
220e52174b5Smanashsarma    Redfish Power Off  stack_mode=skip
221bd38aa41SRahul Maheshwari    ${dump_id1}=  Create User Initiated BMC Dump Via Redfish
222bd38aa41SRahul Maheshwari    ${dump_id2}=  Create User Initiated BMC Dump Via Redfish
223a401cb86SRahul Maheshwari
2246cc5bcf6Smanashsarma    Wait Until Keyword Succeeds  15 sec  5 sec  Redfish Delete BMC Dump  ${dump_id1}
225a401cb86SRahul Maheshwari
226a401cb86SRahul Maheshwari    ${dump_entries}=  Get BMC Dump Entries
227a401cb86SRahul Maheshwari    Length Should Be  ${dump_entries}  1
228a401cb86SRahul Maheshwari    List Should Contain Value  ${dump_entries}  ${dump_id2}
229a401cb86SRahul Maheshwari
230a401cb86SRahul Maheshwari
231a401cb86SRahul MaheshwariCreate And Delete User Initiated BMC Dump Multiple Times
232a401cb86SRahul Maheshwari    [Documentation]  Create and delete user initiated BMC dump multiple times.
233a401cb86SRahul Maheshwari    [Tags]  Create_And_Delete_User_Initiated_BMC_Dump_Multiple_Times
234a401cb86SRahul Maheshwari
235e52174b5Smanashsarma    Redfish Power Off  stack_mode=skip
236a401cb86SRahul Maheshwari    FOR  ${INDEX}  IN  1  10
237bd38aa41SRahul Maheshwari      ${dump_id}=  Create User Initiated BMC Dump Via Redfish
2386cc5bcf6Smanashsarma      Wait Until Keyword Succeeds  15 sec  5 sec  Redfish Delete BMC Dump  ${dump_id}
239a401cb86SRahul Maheshwari    END
240a401cb86SRahul Maheshwari
241a401cb86SRahul Maheshwari
242d709c8d9SRahul MaheshwariVerify Maximum BMC Dump Creation
243d709c8d9SRahul Maheshwari    [Documentation]  Create maximum BMC dump and verify error when dump runs out of space.
244d709c8d9SRahul Maheshwari    [Tags]  Verify_Maximum_BMC_Dump_Creation
245d709c8d9SRahul Maheshwari    [Teardown]  Redfish Delete All BMC Dumps
246d709c8d9SRahul Maheshwari
247d709c8d9SRahul Maheshwari    # Maximum allowed space for dump is 1024 KB. BMC typically hold 8-14 dumps
248d709c8d9SRahul Maheshwari    # before running out of this dump space. So trying to create dumps in 20
249d709c8d9SRahul Maheshwari    # iterations to run out of space.
250bd346b30Smanashsarma    # User can key in the Maximum allowed space for bmc dump and how many iteration.
251bd346b30Smanashsarma    FOR  ${n}  IN RANGE  0  ${MAX_DUMP_COUNT}
252bd38aa41SRahul Maheshwari      Create User Initiated BMC Dump Via Redfish
253d709c8d9SRahul Maheshwari      ${dump_space}=  Get Disk Usage For Dumps
254de2d1308STim Lee      Exit For Loop If  ${dump_space} >= (${BMC_DUMP_TOTAL_SIZE} - ${BMC_DUMP_MIN_SPACE_REQD})
255d709c8d9SRahul Maheshwari    END
256d709c8d9SRahul Maheshwari
257d709c8d9SRahul Maheshwari    # Check error while creating dump when dump size is full.
258d709c8d9SRahul Maheshwari    ${payload}=  Create Dictionary  DiagnosticDataType=Manager
2594d430283Sganesanb    Redfish.Post  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Actions/LogService.CollectDiagnosticData
260d709c8d9SRahul Maheshwari    ...  body=${payload}  valid_status_codes=[${HTTP_INTERNAL_SERVER_ERROR}]
261d709c8d9SRahul Maheshwari
262d709c8d9SRahul Maheshwari
263633cac9fSmanashsarmaVerify BMC Core Dump When Host Powered Off
264633cac9fSmanashsarma    [Documentation]  Verify BMC core dump after application crash at host powered off state.
265633cac9fSmanashsarma    [Tags]  Verify_BMC_Core_Dump_When_Host_Powered_Off
266633cac9fSmanashsarma
267633cac9fSmanashsarma    Redfish Power Off  stack_mode=skip
268633cac9fSmanashsarma
269633cac9fSmanashsarma    # Ensure all dumps are cleaned out.
270633cac9fSmanashsarma    Redfish Delete All BMC Dumps
271633cac9fSmanashsarma    Trigger Core Dump
272633cac9fSmanashsarma
273633cac9fSmanashsarma    # Verify that BMC dump is available.
274633cac9fSmanashsarma    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Dump Available
275633cac9fSmanashsarma
276633cac9fSmanashsarma
277849189c9SmanashsarmaVerify Core Dump Size
278849189c9Smanashsarma    [Documentation]  Verify BMC core dump size is under 20 MB.
279849189c9Smanashsarma    [Tags]  Verify_Core_Dump_Size
280849189c9Smanashsarma
281849189c9Smanashsarma    Redfish Power Off  stack_mode=skip
282849189c9Smanashsarma
283849189c9Smanashsarma    # Ensure all dumps are cleaned out.
284849189c9Smanashsarma    Redfish Delete All BMC Dumps
285849189c9Smanashsarma    Trigger Core Dump
286849189c9Smanashsarma
287849189c9Smanashsarma    # Verify that BMC dump is available.
288849189c9Smanashsarma    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Dump Available
289849189c9Smanashsarma    ${dump_entries}=  Get BMC Dump Entries
290849189c9Smanashsarma    ${resp}=  Redfish.Get Properties
2914d430283Sganesanb    ...  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries/${dump_entries[0]}
292849189c9Smanashsarma
293849189c9Smanashsarma    # Max size for dump is 20 MB = 20x1024x1024 Byte.
294849189c9Smanashsarma    Should Be True  0 < ${resp["AdditionalDataSizeBytes"]} < 20971520
295849189c9Smanashsarma
296849189c9Smanashsarma
297fcbfdf60SmanashsarmaVerify Error While Initiating BMC Dump During Dumping State
298fcbfdf60Smanashsarma    [Documentation]  Verify error while initiating BMC dump during dumping state.
299fcbfdf60Smanashsarma    [Tags]  Verify_Error_While_Initiating_BMC_Dump_During_Dumping_State
300fcbfdf60Smanashsarma
301e52174b5Smanashsarma    Redfish Power Off  stack_mode=skip
302af5bc150SNandish-Matti    ${task_id}=  Create User Initiated BMC Dump Via Redfish  ${1}
303fcbfdf60Smanashsarma
304fcbfdf60Smanashsarma    # Check error while initiating BMC dump while dump in progress.
305fcbfdf60Smanashsarma    ${payload}=  Create Dictionary  DiagnosticDataType=Manager
306fcbfdf60Smanashsarma    Redfish.Post
3074d430283Sganesanb    ...  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Actions/LogService.CollectDiagnosticData
308fcbfdf60Smanashsarma    ...  body=${payload}  valid_status_codes=[${HTTP_SERVICE_UNAVAILABLE}]
309fcbfdf60Smanashsarma
310af5bc150SNandish-Matti    # Wait for above initiated dump to complete. Otherwise, on going dump would impact next test.
311af5bc150SNandish-Matti    Wait Until Keyword Succeeds  5 min  15 sec  Check Task Completion  ${task_id}
312af5bc150SNandish-Matti
313fcbfdf60Smanashsarma
314aa845b72SmanashsarmaVerify BMC Dump Create Errors While Another BMC Dump In Progress
315aa845b72Smanashsarma    [Documentation]  Verify BMC dump creation error until older BMC dump completion.
316aa845b72Smanashsarma    [Tags]  Verify_BMC_Dump_Create_Errors_While_Another_BMC_Dump_In_Progress
317aa845b72Smanashsarma
318e52174b5Smanashsarma    Redfish Power Off  stack_mode=skip
319e52174b5Smanashsarma
320aa845b72Smanashsarma    # Initiate a BMC dump that returns without completion.
321aa845b72Smanashsarma    ${task_id}=  Create User Initiated BMC Dump Via Redfish  ${1}
322cf757dacSmanashsarma    ${task_dict}=  Redfish.Get Properties  /redfish/v1/TaskService/Tasks/${task_id}
323aa845b72Smanashsarma    ${payload}=  Create Dictionary  DiagnosticDataType=Manager
324cf757dacSmanashsarma    IF  '${task_dict['TaskState']}' != 'Completed'
325785244cdSmanashsarma        ${resp}=  Redfish.Post
3264d430283Sganesanb        ...  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Actions/LogService.CollectDiagnosticData
327cf757dacSmanashsarma        ...  body=${payload}  valid_status_codes=[${HTTP_SERVICE_UNAVAILABLE}]
328785244cdSmanashsarma    END
329aa845b72Smanashsarma
330aa845b72Smanashsarma    # Wait for above initiated dump to complete. Otherwise, on going dump would impact next test.
331cf757dacSmanashsarma    Wait Until Keyword Succeeds  5 min  15 sec  Check Task Completion  ${task_id}
332aa845b72Smanashsarma
333aa845b72Smanashsarma
334adabd3b3SmanashsarmaVerify Core Dump After Terminating Dump Manager Service
335adabd3b3Smanashsarma    [Documentation]  Verify initiate core dumps and kill Phosphor-dump-manager.
336adabd3b3Smanashsarma    [Tags]  Verify_Core_Dump_After_Terminating_Dump_Manager_Service
337adabd3b3Smanashsarma
338adabd3b3Smanashsarma    Redfish Power Off  stack_mode=skip
339adabd3b3Smanashsarma
340adabd3b3Smanashsarma    # Remove all available dumps in BMC.
341adabd3b3Smanashsarma    Redfish Delete All BMC Dumps
342adabd3b3Smanashsarma
343adabd3b3Smanashsarma    # Find the pid of the phosphor-dump-manage process and kill it.
344adabd3b3Smanashsarma    ${cmd_buf}=  Catenate  kill -s SEGV $(pgrep phosphor-dump-manager)
345adabd3b3Smanashsarma    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd_buf}
346adabd3b3Smanashsarma    Should Be Equal As Integers  ${rc}  ${0}
347adabd3b3Smanashsarma
348adabd3b3Smanashsarma    # Verify that BMC dump is available.
349*72367166Smanashsarma    Wait Until Keyword Succeeds  10 min  10 sec  Is BMC Dump Available
350adabd3b3Smanashsarma
3514611b818SGeorge Keishing    # Verifying that there is only one dump.
352adabd3b3Smanashsarma    ${dump_entries}=  Get BMC Dump Entries
353adabd3b3Smanashsarma    ${length}=  Get length  ${dump_entries}
354adabd3b3Smanashsarma    Should Be Equal As Integers  ${length}  ${1}
355adabd3b3Smanashsarma
356adabd3b3Smanashsarma
3571202ffebSmanashsarmaVerify User Initiated BMC Dump Type
3581202ffebSmanashsarma    [Documentation]  Download user initiate BMC dump and validates its type.
3591202ffebSmanashsarma    [Tags]  Verify_User_Initiated_BMC_Dump_Type
3601202ffebSmanashsarma
361da7fd92cSmanashsarma    Redfish Power Off  stack_mode=skip
3621202ffebSmanashsarma    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
3631202ffebSmanashsarma
3641202ffebSmanashsarma    # Download BMC dump and verify its size.
365c32434a3SYi Hu    ${resp}=  Redfish.Get  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries/${dump_id}
3661202ffebSmanashsarma    ${redfish_dump_creation_timestamp}=  Set Variable  ${resp.dict["Created"]}
367da7fd92cSmanashsarma    # Download BMC dump and verify its size.
368da7fd92cSmanashsarma    ${tarfile}=  Download BMC Dump  ${dump_id}
3691202ffebSmanashsarma
3701202ffebSmanashsarma    # Extract dump and verify type of dump from summary.log content:
3711202ffebSmanashsarma    # Wed Aug 30 17:23:29 UTC 2023 Name:          BMCDUMP.XXXXXXX.0001005.20230830172329
3721202ffebSmanashsarma    # Wed Aug 30 17:23:29 UTC 2023 Epochtime:     1693416209
3731202ffebSmanashsarma    # Wed Aug 30 17:23:29 UTC 2023 ID:            0001005
3741202ffebSmanashsarma    # Wed Aug 30 17:23:29 UTC 2023 Type:          user
3751202ffebSmanashsarma    ${extracted_dump_folder}=  Extract BMC Dump  BMC_dump.tar.gz  ${redfish_dump_creation_timestamp}
3761202ffebSmanashsarma    ${contents}=  OperatingSystem.Get File  ${extracted_dump_folder}/summary.log
3771202ffebSmanashsarma    Should Match Regexp  ${contents}  Type:[ ]*user
3781202ffebSmanashsarma
3791202ffebSmanashsarma    # Clean extracted dump files.
3801202ffebSmanashsarma    Remove Files  output  output.zst
3811202ffebSmanashsarma    Remove Directory  ${extracted_dump_folder}  True
3821202ffebSmanashsarma
3831202ffebSmanashsarma
3847223e6ddSmanashsarmaVerify Retrieve Core Initiated BMC Dump
3857223e6ddSmanashsarma    [Documentation]  Verify retrieval of core initiated BMC dump.
3867223e6ddSmanashsarma    [Tags]  Verify_Retrieve_Core_Initiated_BMC_Dump
3877223e6ddSmanashsarma
3887223e6ddSmanashsarma    Redfish Power Off  stack_mode=skip
3897223e6ddSmanashsarma
3907223e6ddSmanashsarma    # Ensure all dumps are cleaned out.
3917223e6ddSmanashsarma    Redfish Delete All BMC Dumps
3927223e6ddSmanashsarma    Trigger Core Dump
3937223e6ddSmanashsarma
3947223e6ddSmanashsarma    # Verify that BMC dump is available.
3957223e6ddSmanashsarma    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Dump Available
3967223e6ddSmanashsarma
3977223e6ddSmanashsarma    ${dump_entries}=  Get BMC Dump Entries
3987223e6ddSmanashsarma    # Download BMC dump and verify its size.
3997223e6ddSmanashsarma    Download BMC Dump  ${dump_entries[0]}
4007223e6ddSmanashsarma
4017223e6ddSmanashsarma
402fcc14df5SmanashsarmaVerify Retrieve User Initiated BMC Dump
403fcc14df5Smanashsarma    [Documentation]  Verify retrieval of user initiated BMC dump.
404fcc14df5Smanashsarma    [Tags]  Verify_Retrieve_User_Initiated_BMC_Dump
405fcc14df5Smanashsarma
406da7fd92cSmanashsarma    Redfish Power Off  stack_mode=skip
407fcc14df5Smanashsarma    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
408fcc14df5Smanashsarma
409fcc14df5Smanashsarma    # Download BMC dump.
410fcc14df5Smanashsarma    Download BMC Dump  ${dump_id}
411fcc14df5Smanashsarma
412fcc14df5Smanashsarma
413da7fd92cSmanashsarmaVerify Core Initiated BMC Dump Type
414da7fd92cSmanashsarma    [Documentation]  Download core initiate BMC dump and validates its type.
415da7fd92cSmanashsarma    [Tags]  Verify_Core_Initiated_BMC_Dump_Type
416da7fd92cSmanashsarma
417da7fd92cSmanashsarma    Redfish Power Off  stack_mode=skip
418da7fd92cSmanashsarma
419da7fd92cSmanashsarma    # Ensure all dumps are cleaned out.
420da7fd92cSmanashsarma    Redfish Delete All BMC Dumps
421da7fd92cSmanashsarma    Trigger Core Dump
422da7fd92cSmanashsarma
423da7fd92cSmanashsarma    # Verify that BMC dump is available.
424da7fd92cSmanashsarma    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Dump Available
425da7fd92cSmanashsarma
426da7fd92cSmanashsarma    ${dump_entries}=  Get BMC Dump Entries
427da7fd92cSmanashsarma
428da7fd92cSmanashsarma    # Find the timestamp of BMC dump.
429c32434a3SYi Hu    ${resp}=  Redfish.Get  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries/${dump_entries[0]}
430da7fd92cSmanashsarma    ${redfish_dump_creation_timestamp}=  Set Variable  ${resp.dict["Created"]}
431da7fd92cSmanashsarma
432da7fd92cSmanashsarma    # Download BMC dump and verify its size.
433da7fd92cSmanashsarma    ${tarfile}=  Download BMC Dump  ${dump_entries[0]}
434da7fd92cSmanashsarma
435da7fd92cSmanashsarma    # Extract dump and verify type of dump from summary.log content:
436da7fd92cSmanashsarma    # Wed Aug 30 17:23:29 UTC 2023 Name:          BMCDUMP.XXXXXXX.0001005.20230830172329
437da7fd92cSmanashsarma    # Wed Aug 30 17:23:29 UTC 2023 Epochtime:     1693416209
438da7fd92cSmanashsarma    # Wed Aug 30 17:23:29 UTC 2023 ID:            0001005
439da7fd92cSmanashsarma    # Wed Aug 30 17:23:29 UTC 2023 Type:          core
440da7fd92cSmanashsarma
441da7fd92cSmanashsarma    ${extracted_dump_folder}=  Extract BMC Dump  ${tarfile}  ${redfish_dump_creation_timestamp}
442da7fd92cSmanashsarma    ${contents}=  OperatingSystem.Get File  ${extracted_dump_folder}/summary.log
443da7fd92cSmanashsarma    Should Match Regexp  ${contents}  Type:[ ]*core
444da7fd92cSmanashsarma
445da7fd92cSmanashsarma    # Clean extracted dump files.
446da7fd92cSmanashsarma    Remove Files  output  output.zst
447da7fd92cSmanashsarma    Remove Directory  ${extracted_dump_folder}  True
448da7fd92cSmanashsarma
449da7fd92cSmanashsarma
450f0f29953SmanashsarmaVerify Core Watchdog Initiated BMC Dump
451f0f29953Smanashsarma    [Documentation]  Verify core watchdog timeout initiated BMC dump.
452f0f29953Smanashsarma    [Tags]  Verify_Core_Watchdog_Initiated_BMC_Dump
453f0f29953Smanashsarma
454f0f29953Smanashsarma    Redfish Delete All BMC Dumps
455f0f29953Smanashsarma    Redfish Power Off  stack_mode=skip
456f0f29953Smanashsarma
457f0f29953Smanashsarma    # Trigger watchdog timeout.
458f0f29953Smanashsarma    Redfish Initiate Auto Reboot  2000
459f0f29953Smanashsarma
460f0f29953Smanashsarma    # Wait for BMC dump to get generated after injecting watchdog timeout.
461f0f29953Smanashsarma    Wait Until Keyword Succeeds  4 min  20 sec  Is BMC Dump Available
462f0f29953Smanashsarma
463f0f29953Smanashsarma    # Verify that only one BMC dump is available.
464f0f29953Smanashsarma    ${dump_entry_list}=  Get BMC Dump Entries
465f0f29953Smanashsarma    ${length}=  Get length  ${dump_entry_list}
466f0f29953Smanashsarma    Should Be Equal As Integers  ${length}  ${1}
467f0f29953Smanashsarma
468f0f29953Smanashsarma
469a401cb86SRahul Maheshwari*** Keywords ***
470a401cb86SRahul Maheshwari
471da7fd92cSmanashsarmaDownload BMC Dump
472da7fd92cSmanashsarma    [Documentation]  Download BMC dump and verify its size.
473da7fd92cSmanashsarma    [Arguments]  ${dump_id}
474da7fd92cSmanashsarma
475da7fd92cSmanashsarma    # Description of argument(s):
476da7fd92cSmanashsarma    # dump_id                An integer value that identifies a particular dump (e.g. 1, 3).
477da7fd92cSmanashsarma
478c32434a3SYi Hu    ${resp}=  Redfish.Get  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries/${dump_id}
479da7fd92cSmanashsarma    ${redfish_bmc_dump_size}=  Set Variable  ${resp.dict["AdditionalDataSizeBytes"]}
480da7fd92cSmanashsarma
481da7fd92cSmanashsarma    Initialize OpenBMC
482da7fd92cSmanashsarma    ${headers}=  Create Dictionary  Content-Type=application/octet-stream  X-Auth-Token=${XAUTH_TOKEN}
483da7fd92cSmanashsarma
484c32434a3SYi Hu    ${ret}=  GET On Session  openbmc  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries/${dump_id}/attachment  headers=${headers}
485da7fd92cSmanashsarma
486da7fd92cSmanashsarma    Should Be Equal As Numbers  ${ret.status_code}  200
487da7fd92cSmanashsarma
488da7fd92cSmanashsarma    Create Binary File  BMC_dump.tar.gz  ${ret.content}
489da7fd92cSmanashsarma    ${downloaded_dump_size}=  Get File Size  BMC_dump.tar.gz
490da7fd92cSmanashsarma    Should Be Equal  ${downloaded_dump_size}  ${redfish_bmc_dump_size}
491409df05dSGeorge Keishing    RETURN  BMC_dump.tar.gz
492da7fd92cSmanashsarma
493da7fd92cSmanashsarma
4941202ffebSmanashsarmaExtract BMC Dump
4951202ffebSmanashsarma    [Documentation]  Extract BMC dump from the tar file and returns the name of
4961202ffebSmanashsarma    ...  extracted folder like BMCDUMP.XXXXXXX.0000070.20230706063841.
4971202ffebSmanashsarma    [Arguments]  ${filename}   ${bmc_dump_timestamp}
4981202ffebSmanashsarma
4991202ffebSmanashsarma    # Description of argument(s):
5001202ffebSmanashsarma    # filename                name of BMC dump tar file.
5011202ffebSmanashsarma    # bmc_dump_timestamp      timestamp of generated BMC dump.
5021202ffebSmanashsarma
503fcc14df5Smanashsarma    OperatingSystem.File Should Exist  ${filename}
5041202ffebSmanashsarma    ${rc}=  Run And Return RC  dd if=${filename} of=output.zst bs=1 skip=628
5051202ffebSmanashsarma    Should Be True  0 == ${rc}
5061202ffebSmanashsarma
5071202ffebSmanashsarma    ${rc}=  Run And Return RC  zstd -d output.zst
5081202ffebSmanashsarma    Should Be True  0 == ${rc}
5091202ffebSmanashsarma
5101202ffebSmanashsarma    ${rc}=  Run And Return RC  tar -xvf output
5111202ffebSmanashsarma    Should Be True  0 == ${rc}
5121202ffebSmanashsarma
5131202ffebSmanashsarma    # Find the extracted dump folder identified with BMCDUMP as prefix and
5141202ffebSmanashsarma    # timestamp of dump generation where timestamp format is : 2023-09-27T08:30:17.000000+00:00.
5151202ffebSmanashsarma    ${var}=  Fetch From Left  ${bmc_dump_timestamp}  .
5161202ffebSmanashsarma    ${var}=  Remove String  ${var}  -  T  :
5171202ffebSmanashsarma    ${bmc_extraction_folders}=  OperatingSystem.List Directories In Directory  .  BMCDUMP*${var}
5181202ffebSmanashsarma    ${cnt}=  Get length  ${bmc_extraction_folders}
5191202ffebSmanashsarma    should be equal as numbers  ${cnt}  1
5201202ffebSmanashsarma
521409df05dSGeorge Keishing    RETURN  ${bmc_extraction_folders}[0]
5221202ffebSmanashsarma
5231202ffebSmanashsarma
524a401cb86SRahul MaheshwariGet BMC Dump Entries
525a401cb86SRahul Maheshwari    [Documentation]  Return BMC dump ids list.
526a401cb86SRahul Maheshwari
5274d430283Sganesanb    ${dump_uris}=  redfish_utils.get_member_list  /redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Entries
528a401cb86SRahul Maheshwari    ${dump_ids}=  Create List
529a401cb86SRahul Maheshwari
530a401cb86SRahul Maheshwari    FOR  ${dump_uri}  IN  @{dump_uris}
531a401cb86SRahul Maheshwari      ${dump_id}=  Fetch From Right  ${dump_uri}  /
532a401cb86SRahul Maheshwari      Append To List  ${dump_ids}  ${dump_id}
533a401cb86SRahul Maheshwari    END
534a401cb86SRahul Maheshwari
535409df05dSGeorge Keishing    RETURN  ${dump_ids}
536a401cb86SRahul Maheshwari
537a401cb86SRahul Maheshwari
538633cac9fSmanashsarmaIs BMC Dump Available
539633cac9fSmanashsarma    [Documentation]  Verify if BMC dump is available.
540633cac9fSmanashsarma
541633cac9fSmanashsarma    ${dump_entries}=  Get BMC Dump Entries
542633cac9fSmanashsarma
543633cac9fSmanashsarma    # Verifying that BMC dump is available.
544633cac9fSmanashsarma    ${length}=  Get length  ${dump_entries}
545633cac9fSmanashsarma    Should Be True  0 < ${length}
546633cac9fSmanashsarma
547633cac9fSmanashsarma
548d709c8d9SRahul MaheshwariGet Disk Usage For Dumps
549d709c8d9SRahul Maheshwari    [Documentation]  Return disk usage in kilobyte for BMC dumps.
550d709c8d9SRahul Maheshwari
551395f8804Smanashsarma    ${usage_output}  ${stderr}  ${rc}=  BMC Execute Command  du -s ${BMC_DUMP_COLLECTOR_PATH}
552d709c8d9SRahul Maheshwari
553d709c8d9SRahul Maheshwari    # Example of output from above BMC cli command.
554d709c8d9SRahul Maheshwari    # $ du -s /var/lib/phosphor-debug-collector/dumps
555d709c8d9SRahul Maheshwari    # 516    /var/lib/phosphor-debug-collector/dumps
556d709c8d9SRahul Maheshwari
557d709c8d9SRahul Maheshwari    ${usage_output}=  Fetch From Left  ${usage_output}  /
558d709c8d9SRahul Maheshwari    ${usage_output}=  Convert To Integer  ${usage_output}
559d709c8d9SRahul Maheshwari
560409df05dSGeorge Keishing    RETURN  ${usage_output}
561d709c8d9SRahul Maheshwari
562d709c8d9SRahul Maheshwari
563a401cb86SRahul MaheshwariTest Teardown Execution
564a401cb86SRahul Maheshwari    [Documentation]  Do test teardown operation.
565a401cb86SRahul Maheshwari
566a401cb86SRahul Maheshwari    FFDC On Test Case Fail
567a401cb86SRahul Maheshwari    Close All Connections
568