1*** Settings ***
2
3Documentation       Test BMC dump functionality of OpenBMC.
4
5Resource            ../../lib/bmc_redfish_resource.robot
6Resource            ../../lib/boot_utils.robot
7Resource            ../../lib/dump_utils.robot
8Resource            ../../lib/openbmc_ffdc.robot
9
10Suite Setup         Redfish.Login
11Test Setup          Redfish Delete All BMC Dumps
12Test Teardown       Test Teardown Execution
13
14*** Variables ***
15
16# Total size of the dump in kilo bytes
17${BMC_DUMP_TOTAL_SIZE}       ${1024}
18
19# Minimum space required for one bmc dump in kilo bytes
20${BMC_DUMP_MIN_SPACE_REQD}   ${20}
21${MAX_DUMP_COUNT}            ${20}
22${BMC_DUMP_COLLECTOR_PATH}   /var/lib/phosphor-debug-collector/dumps
23
24*** Test Cases ***
25
26Verify Error Response For Already Deleted Dump Id
27    [Documentation]  Delete non existing BMC dump and expect an error.
28    [Tags]  Verify_Error_Response_For_Already_Deleted_Dump_Id
29
30    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
31    Redfish Delete BMC Dump  ${dump_id}
32    Run Keyword And Expect Error  ValueError: *  Redfish Delete BMC Dump  ${dump_id}
33
34
35Verify User Initiated BMC Dump When Host Powered Off
36    [Documentation]  Create user initiated BMC dump at host off state and
37    ...  verify dump entry for it.
38    [Tags]  Verify_User_Initiated_BMC_Dump_When_Host_Powered_Off
39
40    Redfish Power Off  stack_mode=skip
41    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
42    ${dump_entries}=  Get BMC Dump Entries
43    Length Should Be  ${dump_entries}  1
44    List Should Contain Value  ${dump_entries}  ${dump_id}
45
46
47Verify User Initiated BMC Dump Size
48    [Documentation]  Verify user initiated BMC dump size is under 20 MB.
49    [Tags]  Verify_User_Initiated_BMC_Dump_Size
50
51    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
52    ${resp}=  Redfish.Get Properties  /redfish/v1/Managers/bmc/LogServices/Dump/Entries/${dump_id}
53
54    # Example of response from above Redfish GET request.
55    # "@odata.type": "#LogEntry.v1_7_0.LogEntry",
56    # "AdditionalDataSizeBytes": 31644,
57    # "AdditionalDataURI": "/redfish/v1/Managers/bmc/LogServices/Dump/attachment/9",
58    # "Created": "2020-10-23T06:32:53+00:00",
59    # "DiagnosticDataType": "Manager",
60    # "EntryType": "Event",
61    # "Id": "9",
62    # "Name": "BMC Dump Entry"
63
64    # Max size for dump is 20 MB = 20x1024x1024 Byte.
65    Should Be True  0 < ${resp["AdditionalDataSizeBytes"]} < 20971520
66
67
68Verify Multiple BMC Dump Creation
69    [Documentation]  Verify that multiple BMC dumps can be created one after
70    ...  another successfully.
71    [Tags]   Verify_Multiple_BMC_Dump_Creation
72
73    ${dump_count}=  Evaluate  random.randint(5, 10)  modules=random
74    FOR  ${INDEX}  IN  1  ${dump_count}
75      Create User Initiated BMC Dump Via Redfish
76    END
77
78
79Verify BMC Dump Default Location In BMC
80     [Documentation]  Verify that BMC dump is created in its default location of BMC.
81     [Tags]  Verify_BMC_Dump_Default_Location_In_BMC
82
83     Redfish Delete All BMC Dumps
84     ${dump_id}=  Create User Initiated BMC Dump Via Redfish
85     ${dump_file}  ${stderr}  ${rc}=  BMC Execute Command
86     ...  ls ${BMC_DUMP_COLLECTOR_PATH}/${dump_id}
87     Should Be True  ${rc} == 0
88     Should Start With  ${dump_file}  BMCDUMP
89
90
91Verify User Initiated BMC Dump When Host Booted
92    [Documentation]  Create user initiated BMC dump at host booted state and
93    ...  verify dump entry for it.
94    [Tags]  Verify_User_Initiated_BMC_Dump_When_Host_Booted
95
96    Redfish Power On  stack_mode=skip
97    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
98    ${dump_entries}=  Get BMC Dump Entries
99    Length Should Be  ${dump_entries}  1
100    List Should Contain Value  ${dump_entries}  ${dump_id}
101
102
103Verify Dump Persistency On Dump Service Restart
104    [Documentation]  Create user dump, restart dump manager service and verify dump
105    ...  persistency.
106    [Tags]  Verify_Dump_Persistency_On_Dump_Service_Restart
107
108    Create User Initiated BMC Dump Via Redfish
109    ${dump_entries_before}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
110
111    # Restart dump service.
112    BMC Execute Command  systemctl restart xyz.openbmc_project.Dump.Manager.service
113    Sleep  10s  reason=Wait for BMC dump service to restart properly
114
115    ${dump_entries_after}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
116    Lists Should Be Equal  ${dump_entries_before}  ${dump_entries_after}
117
118
119Verify Dump Persistency On BMC Reset
120    [Documentation]  Create user dump, reset BMC and verify dump persistency.
121    [Tags]  Verify_Dump_Persistency_On_BMC_Reset
122
123    # Power off host so that dump is not offloaded to host OS.
124    Redfish Power Off  stack_mode=skip
125
126    Create User Initiated BMC Dump Via Redfish
127    ${dump_entries_before}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
128
129    # Reset BMC.
130    OBMC Reboot (off)  stack_mode=skip
131
132    ${dump_entries_after}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
133    Lists Should Be Equal  ${dump_entries_before}  ${dump_entries_after}
134
135
136Delete User Initiated BMC Dump And Verify
137    [Documentation]  Delete user initiated BMC dump and verify.
138    [Tags]  Delete_User_Initiated_BMC_Dump_And_Verify
139
140    ${dump_id}=  Create User Initiated BMC Dump Via Redfish
141    Redfish Delete BMC Dump  ${dump_id}
142
143    ${dump_entries}=  Get BMC Dump Entries
144    Should Be Empty  ${dump_entries}
145
146
147Delete All User Initiated BMC Dumps And Verify
148    [Documentation]  Delete all user initiated BMC dumps and verify.
149    [Tags]  Delete_All_User_Initiated_BMC_Dumps_And_Verify
150
151    # Power off host so that dump is not offloaded to host OS.
152    Redfish Power Off  stack_mode=skip
153
154    # Create some BMC dump.
155    Create User Initiated BMC Dump Via Redfish
156    Create User Initiated BMC Dump Via Redfish
157
158    Redfish Delete All BMC Dumps
159    ${dump_entries}=  Get BMC Dump Entries
160    Should Be Empty  ${dump_entries}
161
162
163Create Two User Initiated BMC Dumps
164    [Documentation]  Create two user initiated BMC dumps.
165    [Tags]  Create_Two_User_Initiated_BMC_Dumps
166
167    ${dump_id1}=  Create User Initiated BMC Dump Via Redfish
168    ${dump_id2}=  Create User Initiated BMC Dump Via Redfish
169
170    ${dump_entries}=  Get BMC Dump Entries
171    Length Should Be  ${dump_entries}  2
172    Should Contain  ${dump_entries}  ${dump_id1}
173    Should Contain  ${dump_entries}  ${dump_id2}
174
175
176Create Two User Initiated BMC Dumps And Delete One
177    [Documentation]  Create two dumps and delete the first.
178    [Tags]  Create_Two_User_Initiated_BMC_Dumps_And_Delete_One
179
180    ${dump_id1}=  Create User Initiated BMC Dump Via Redfish
181    ${dump_id2}=  Create User Initiated BMC Dump Via Redfish
182
183    Redfish Delete BMC Dump  ${dump_id1}
184
185    ${dump_entries}=  Get BMC Dump Entries
186    Length Should Be  ${dump_entries}  1
187    List Should Contain Value  ${dump_entries}  ${dump_id2}
188
189
190Create And Delete User Initiated BMC Dump Multiple Times
191    [Documentation]  Create and delete user initiated BMC dump multiple times.
192    [Tags]  Create_And_Delete_User_Initiated_BMC_Dump_Multiple_Times
193
194    FOR  ${INDEX}  IN  1  10
195      ${dump_id}=  Create User Initiated BMC Dump Via Redfish
196      Redfish Delete BMC Dump  ${dump_id}
197    END
198
199
200Verify Maximum BMC Dump Creation
201    [Documentation]  Create maximum BMC dump and verify error when dump runs out of space.
202    [Tags]  Verify_Maximum_BMC_Dump_Creation
203    [Teardown]  Redfish Delete All BMC Dumps
204
205    # Maximum allowed space for dump is 1024 KB. BMC typically hold 8-14 dumps
206    # before running out of this dump space. So trying to create dumps in 20
207    # iterations to run out of space.
208    # User can key in the Maximum allowed space for bmc dump and how many iteration.
209    FOR  ${n}  IN RANGE  0  ${MAX_DUMP_COUNT}
210      Create User Initiated BMC Dump Via Redfish
211      ${dump_space}=  Get Disk Usage For Dumps
212      Exit For Loop If  ${dump_space} >= (${BMC_DUMP_TOTAL_SIZE} - ${BMC_DUMP_MIN_SPACE_REQD})
213    END
214
215    # Check error while creating dump when dump size is full.
216    ${payload}=  Create Dictionary  DiagnosticDataType=Manager
217    Redfish.Post  /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData
218    ...  body=${payload}  valid_status_codes=[${HTTP_INTERNAL_SERVER_ERROR}]
219
220
221Verify BMC Core Dump When Host Powered Off
222    [Documentation]  Verify BMC core dump after application crash at host powered off state.
223    [Tags]  Verify_BMC_Core_Dump_When_Host_Powered_Off
224
225    Redfish Power Off  stack_mode=skip
226
227    # Ensure all dumps are cleaned out.
228    Redfish Delete All BMC Dumps
229    Trigger Core Dump
230
231    # Verify that BMC dump is available.
232    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Dump Available
233
234
235Verify Core Dump Size
236    [Documentation]  Verify BMC core dump size is under 20 MB.
237    [Tags]  Verify_Core_Dump_Size
238
239    Redfish Power Off  stack_mode=skip
240
241    # Ensure all dumps are cleaned out.
242    Redfish Delete All BMC Dumps
243    Trigger Core Dump
244
245    # Verify that BMC dump is available.
246    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Dump Available
247    ${dump_entries}=  Get BMC Dump Entries
248    ${resp}=  Redfish.Get Properties
249    ...  /redfish/v1/Managers/bmc/LogServices/Dump/Entries/${dump_entries[0]}
250
251    # Max size for dump is 20 MB = 20x1024x1024 Byte.
252    Should Be True  0 < ${resp["AdditionalDataSizeBytes"]} < 20971520
253
254
255Verify Error While Initiating BMC Dump During Dumping State
256    [Documentation]  Verify error while initiating BMC dump during dumping state.
257    [Tags]  Verify_Error_While_Initiating_BMC_Dump_During_Dumping_State
258
259    ${task_id}=  Create User Initiated BMC Dump Via Redfish  ${1}
260
261    # Check error while initiating BMC dump while dump in progress.
262    ${payload}=  Create Dictionary  DiagnosticDataType=Manager
263    Redfish.Post
264    ...  /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData
265    ...  body=${payload}  valid_status_codes=[${HTTP_SERVICE_UNAVAILABLE}]
266
267    # Wait for above initiated dump to complete. Otherwise, on going dump would impact next test.
268    Wait Until Keyword Succeeds  5 min  15 sec  Check Task Completion  ${task_id}
269
270
271Verify BMC Dump Create Errors While Another BMC Dump In Progress
272    [Documentation]  Verify BMC dump creation error until older BMC dump completion.
273    [Tags]  Verify_BMC_Dump_Create_Errors_While_Another_BMC_Dump_In_Progress
274
275    # Initiate a BMC dump that returns without completion.
276    ${task_id}=  Create User Initiated BMC Dump Via Redfish  ${1}
277
278    # Now continue to initiate multiple dump request which is not expected to be accepted
279    # till earlier BMC dump task is completed. A limit is set to avoid risk of infinite loop.
280    ${payload}=  Create Dictionary  DiagnosticDataType=Manager
281    WHILE  True  limit=1000
282        ${task_dict}=  Redfish.Get Properties  /redfish/v1/TaskService/Tasks/${task_id}
283        IF  '${task_dict['TaskState']}' == 'Completed'  BREAK
284        Redfish.Post
285        ...  /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData
286        ...  body=${payload}  valid_status_codes=[${HTTP_SERVICE_UNAVAILABLE}]
287    END
288
289    # The next BMC dump initiation request should be accepted as earlier dump is completed.
290    ${resp}=  Redfish.Post
291    ...  /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData
292    ...  body=${payload}  valid_status_codes=[${HTTP_ACCEPTED}]
293
294    # Wait for above initiated dump to complete. Otherwise, on going dump would impact next test.
295    Wait Until Keyword Succeeds  5 min  15 sec  Check Task Completion  ${resp.dict['Id']}
296
297
298*** Keywords ***
299
300Get BMC Dump Entries
301    [Documentation]  Return BMC dump ids list.
302
303    ${dump_uris}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
304    ${dump_ids}=  Create List
305
306    FOR  ${dump_uri}  IN  @{dump_uris}
307      ${dump_id}=  Fetch From Right  ${dump_uri}  /
308      Append To List  ${dump_ids}  ${dump_id}
309    END
310
311    [Return]  ${dump_ids}
312
313
314Is BMC Dump Available
315    [Documentation]  Verify if BMC dump is available.
316
317    ${dump_entries}=  Get BMC Dump Entries
318
319    # Verifying that BMC dump is available.
320    ${length}=  Get length  ${dump_entries}
321    Should Be True  0 < ${length}
322
323
324Get Disk Usage For Dumps
325    [Documentation]  Return disk usage in kilobyte for BMC dumps.
326
327    ${usage_output}  ${stderr}  ${rc}=  BMC Execute Command  du -s ${BMC_DUMP_COLLECTOR_PATH}
328
329    # Example of output from above BMC cli command.
330    # $ du -s /var/lib/phosphor-debug-collector/dumps
331    # 516    /var/lib/phosphor-debug-collector/dumps
332
333    ${usage_output}=  Fetch From Left  ${usage_output}  /
334    ${usage_output}=  Convert To Integer  ${usage_output}
335
336    [return]  ${usage_output}
337
338
339Test Teardown Execution
340    [Documentation]  Do test teardown operation.
341
342    FFDC On Test Case Fail
343    Close All Connections
344