blob: eadae80d75b2741b7234f54c297e27c58cb98a83 [file] [log] [blame]
Rahul Maheshwariad676bf2017-06-22 15:06:05 -05001*** Settings ***
2Documentation This module provides general keywords for dump.
3
Rahul Maheshwari1612ac92017-08-30 14:42:32 -05004Library bmc_ssh_utils.py
Rahul Maheshwariad676bf2017-06-22 15:06:05 -05005
6*** Variables ***
7
8*** Keywords ***
9
10Create User Initiated Dump
11 [Documentation] Generate user initiated dump and return
Steven Sombara011c022019-01-16 18:13:52 -060012 ... the dump id number (e.g., "5"). Optionally return EMPTY
13 ... if out of dump space.
14 [Arguments] ${check_out_of_space}=${False}
15
16 # Description of Argument(s):
17 # check_out_of_space If ${False}, a dump will be created and
18 # its dump_id will be returned.
19 # If ${True}, either the dump_id will be
20 # returned, or the value ${EMPTY} will be
21 # returned if out of dump space was
22 # detected when creating the dump.
Rahul Maheshwariad676bf2017-06-22 15:06:05 -050023
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -050024 ${resp}= OpenBMC Get Request ${DUMP_URI}
25 Run Keyword If '${resp.status_code}' == '${HTTP_NOT_FOUND}'
George Keishing73d8f242021-03-19 08:51:56 -050026 ... Set Global Variable ${DUMP_URI} /xyz/openbmc_project/dump/
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -050027
Rahul Maheshwariad676bf2017-06-22 15:06:05 -050028 ${data}= Create Dictionary data=@{EMPTY}
29 ${resp}= OpenBMC Post Request
Steven Sombara011c022019-01-16 18:13:52 -060030 ... ${DUMP_URI}action/CreateDump data=${data} quiet=${1}
31
32 Run Keyword If '${check_out_of_space}' == '${False}'
George Keishing656eb4a2019-09-03 03:48:01 -050033 ... Run Keyword And Return Get The Dump Id ${resp}
34 ... ELSE
35 ... Run Keyword And Return Check For Too Many Dumps ${resp}
Steven Sombara011c022019-01-16 18:13:52 -060036
37
38Get The Dump Id
39 [Documentation] Wait for the dump to be created. Return the
40 ... dump id number (e.g., "5").
41 [Arguments] ${resp}
42
43 # Description of Argument(s):
44 # resp Response object from action/Create Dump attempt.
45 # Example object:
46 # {
47 # "data": 5,
48 # "message": "200 OK",
49 # "status": "ok"
50 # },
51 # The "data" field conveys the id number of the created dump.
Rahul Maheshwariad676bf2017-06-22 15:06:05 -050052
53 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
54 ${json}= To JSON ${resp.content}
George Keishing73c4ebf2017-11-13 07:10:28 -060055
George Keishing73c4ebf2017-11-13 07:10:28 -060056 Run Keyword If ${json["data"]} == ${None}
57 ... Fail Dump id returned null.
58
Rahul Maheshwariad676bf2017-06-22 15:06:05 -050059 ${dump_id}= Set Variable ${json["data"]}
60
Rahul Maheshwarie2cd17f2017-09-26 21:26:50 -050061 Wait Until Keyword Succeeds 3 min 15 sec Check Dump Existence
Rahul Maheshwariad676bf2017-06-22 15:06:05 -050062 ... ${dump_id}
63
64 [Return] ${dump_id}
65
66
Steven Sombara011c022019-01-16 18:13:52 -060067Check For Too Many Dumps
68 [Documentation] Return the dump_id number, or return ${EMPTY} if dump
69 ... creation failed due to too many dumps.
70 [Arguments] ${resp}
71
72 # Description of Argument(s):
73 # resp Response object from action/Create Dump attempt.
74 # Example object if there are too many dumps:
George Keishing506756e2019-08-06 01:07:55 -050075 # {
Steven Sombara011c022019-01-16 18:13:52 -060076 # "data": {
George Keishing506756e2019-08-06 01:07:55 -050077 # "description": "xyz.openbmc_project.Dump.Create.Error.QuotaExceeded"
78 # },
79 # "message": "Dump not captured due to a cap.",
Steven Sombara011c022019-01-16 18:13:52 -060080 # "status": "error"
George Keishing506756e2019-08-06 01:07:55 -050081 # }
Steven Sombara011c022019-01-16 18:13:52 -060082
83 # If dump was created normally, return the dump_id number.
84 Run Keyword If '${resp.status_code}' == '${HTTP_OK}'
85 ... Run Keyword And Return Get The Dump Id ${resp}
86
George Keishing506756e2019-08-06 01:07:55 -050087 ${json}= To JSON ${resp.content}
88 ${exception}= Set Variable ${json["message"]}
Steven Sombara011c022019-01-16 18:13:52 -060089 ${at_capacity}= Set Variable Dump not captured due to a cap
90 ${too_many_dumps}= Evaluate $at_capacity in $exception
Michael Walshc108e422019-03-28 12:27:18 -050091 Printn
Steven Sombara011c022019-01-16 18:13:52 -060092 Rprint Vars exception too_many_dumps
93 # If there are too many dumps, return ${EMPTY}, otherwise Fail.
94 ${status}= Run Keyword If ${too_many_dumps} Set Variable ${EMPTY}
95 ... ELSE Fail msg=${exception}.
96
97 [Return] ${status}
98
99
Rahul Maheshwari953038b2017-10-17 05:08:59 -0500100Verify No Dump In Progress
101 [Documentation] Verify no dump in progress.
102
Rahul Maheshwari4cfdc392017-10-25 09:44:47 -0500103 ${dump_progress} ${stderr} ${rc}= BMC Execute Command ls /tmp
104 Should Not Contain ${dump_progress} obmcdump
Rahul Maheshwari953038b2017-10-17 05:08:59 -0500105
106
Rahul Maheshwariad676bf2017-06-22 15:06:05 -0500107Check Dump Existence
108 [Documentation] Verify if given dump exist.
109 [Arguments] ${dump_id}
110
111 # Description of Argument(s):
112 # dump_id An integer value that identifies a particular dump
113 # object(e.g. 1, 3, 5).
114
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500115 ${resp}= OpenBMC Get Request ${DUMP_URI}
116 Run Keyword If '${resp.status_code}' == '${HTTP_NOT_FOUND}'
George Keishing73d8f242021-03-19 08:51:56 -0500117 ... Set Global Variable ${DUMP_ENTRY_URI} /xyz/openbmc_project/dump/entry/
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500118
George Keishing8d693382018-12-18 12:15:04 -0600119 ${resp}= OpenBMC Get Request ${DUMP_ENTRY_URI}${dump_id}
Rahul Maheshwariad676bf2017-06-22 15:06:05 -0500120 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
121
122
123Delete BMC Dump
124 [Documentation] Deletes a given bmc dump.
125 [Arguments] ${dump_id}
126
127 # Description of Argument(s):
Gunnar Mills28e403b2017-10-25 16:16:38 -0500128 # dump_id An integer value that identifies a particular dump (e.g. 1, 3).
Rahul Maheshwariad676bf2017-06-22 15:06:05 -0500129
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500130 ${resp}= OpenBMC Get Request ${DUMP_URI}
131 Run Keyword If '${resp.status_code}' == '${HTTP_NOT_FOUND}'
George Keishing73d8f242021-03-19 08:51:56 -0500132 ... Set Global Variable ${DUMP_ENTRY_URI} /xyz/openbmc_project/dump/entry/
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500133
Rahul Maheshwariad676bf2017-06-22 15:06:05 -0500134 ${data}= Create Dictionary data=@{EMPTY}
135 ${resp}= OpenBMC Post Request
George Keishing8d693382018-12-18 12:15:04 -0600136 ... ${DUMP_ENTRY_URI}${dump_id}/action/Delete data=${data}
Rahul Maheshwariad676bf2017-06-22 15:06:05 -0500137
138 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
139
140Delete All Dumps
141 [Documentation] Delete all dumps.
142
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500143 ${resp}= OpenBMC Get Request ${DUMP_URI}
144 Run Keyword If '${resp.status_code}' == '${HTTP_NOT_FOUND}'
George Keishing73d8f242021-03-19 08:51:56 -0500145 ... Set Global Variable ${DUMP_ENTRY_URI} /xyz/openbmc_project/dump/entry/
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500146
Rahul Maheshwariad676bf2017-06-22 15:06:05 -0500147 # Check if dump entries exist, if not return.
George Keishing6a6e76d2017-09-14 08:19:17 -0500148 ${resp}= OpenBMC Get Request ${DUMP_ENTRY_URI}list quiet=${1}
Rahul Maheshwariad676bf2017-06-22 15:06:05 -0500149 Return From Keyword If ${resp.status_code} == ${HTTP_NOT_FOUND}
150
151 # Get the list of dump entries and delete them all.
152 ${dump_entries}= Get URL List ${DUMP_ENTRY_URI}
Marissa Garza20ccfc72020-06-19 12:51:10 -0500153 FOR ${entry} IN @{dump_entries}
154 ${dump_id}= Fetch From Right ${entry} /
155 Delete BMC Dump ${dump_id}
156 END
George Keishingc9fcd092017-09-20 09:24:37 -0500157
Rahul Maheshwaride5d6f12020-10-14 02:08:00 -0500158
Rahul Maheshwari95cbceb2020-10-21 23:25:08 -0500159Redfish Delete BMC Dump
160 [Documentation] Deletes a given BMC dump via Redfish..
161 [Arguments] ${dump_id}
162
163 # Description of Argument(s):
164 # dump_id An integer value that identifies a particular dump (e.g. 1, 3).
165
166 Redfish.Delete /redfish/v1/Managers/bmc/LogServices/Dump/Entries/${dump_id}
167
168
Rahul Maheshwaride5d6f12020-10-14 02:08:00 -0500169Redfish Delete All BMC Dumps
170 [Documentation] Delete all BMC dumps via Redfish.
171
172 # Check if dump entries exist, if not return.
173 ${resp}= Redfish.Get /redfish/v1/Managers/bmc/LogServices/Dump/Entries
174 Return From Keyword If ${resp.dict["Members@odata.count"]} == ${0}
175
176 Redfish.Post /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog
177
178
George Keishing2ef6a7d2021-05-19 09:05:32 -0500179Redfish Delete All System Dumps
180 [Documentation] Delete all system dumps via Redfish.
181
182 Redfish.Post /redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog
183
184
George Keishingc9fcd092017-09-20 09:24:37 -0500185Delete All BMC Dump
186 [Documentation] Delete all BMC dump entries using "DeleteAll" interface.
187
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500188 ${resp}= OpenBMC Get Request ${DUMP_URI}
189 Run Keyword If '${resp.status_code}' == '${HTTP_NOT_FOUND}'
George Keishing73d8f242021-03-19 08:51:56 -0500190 ... Set Global Variable ${DUMP_URI} /xyz/openbmc_project/dump/
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500191
George Keishingc9fcd092017-09-20 09:24:37 -0500192 ${data}= Create Dictionary data=@{EMPTY}
193 ${resp}= Openbmc Post Request ${DUMP_URI}action/DeleteAll data=${data}
194 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
George Keishingdc428762017-11-11 12:37:12 -0600195
George Keishingdc428762017-11-11 12:37:12 -0600196Dump Should Not Exist
197 [Documentation] Verify that BMC dumps do not exist.
198
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500199 ${resp}= OpenBMC Get Request ${DUMP_URI}
200 Run Keyword If '${resp.status_code}' == '${HTTP_NOT_FOUND}'
George Keishing73d8f242021-03-19 08:51:56 -0500201 ... Set Global Variable ${DUMP_ENTRY_URI} /xyz/openbmc_project/dump/entry/
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500202
George Keishing8d693382018-12-18 12:15:04 -0600203 ${resp}= OpenBMC Get Request ${DUMP_ENTRY_URI}list quiet=${1}
George Keishingdc428762017-11-11 12:37:12 -0600204 Should Be Equal As Strings ${resp.status_code} ${HTTP_NOT_FOUND}
205
Steven Sombar336fa972019-11-07 13:12:58 -0600206Check Existence Of BMC Dump File
Sivas SRR7aabd792017-10-18 21:28:23 -0500207 [Documentation] Verify existence of BMC dump file.
208 [Arguments] ${dump_id}
209
210 # Description of argument(s):
211 # dump_id BMC dump identifier
212
213 ${dump_check_cmd}= Set Variable
214 ... ls /var/lib/phosphor-debug-collector/dumps
215
216 # Output of sample BMC Execute command with '2' as dump id is as follows
217 # ls /var/lib/phosphor-debug-collector/dumps/2
218 # obmcdump_2_XXXXXXXXXX.tar.xz
219 ${file_there} ${stderr} ${rc}= BMC Execute Command
220 ... ${dump_check_cmd}/${dump_id}
221 Should End With ${file_there} tar.xz msg=BMC dump file not found.
Rahul Maheshwari1612ac92017-08-30 14:42:32 -0500222
223Get Dump Entries
224 [Documentation] Return dump entries list.
225
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500226 ${resp}= OpenBMC Get Request ${DUMP_URI}
227 Run Keyword If '${resp.status_code}' == '${HTTP_NOT_FOUND}'
George Keishing73d8f242021-03-19 08:51:56 -0500228 ... Set Global Variable ${DUMP_ENTRY_URI} /xyz/openbmc_project/dump/entry/
Rahul Maheshwaria89ff9e2020-09-25 05:04:33 -0500229
Rahul Maheshwari1612ac92017-08-30 14:42:32 -0500230 ${dump_entries}= Get URL List ${DUMP_ENTRY_URI}
231 [Return] ${dump_entries}
232
Rahul Maheshwari1612ac92017-08-30 14:42:32 -0500233Trigger Core Dump
234 [Documentation] Trigger core dump.
235
236 # Find the pid of the active ipmid and kill it.
George Keishingbfd5c8f2018-07-11 10:27:28 -0500237 ${cmd_buf}= Catenate kill -s SEGV $(ps | egrep ' ipmid$' |
Rahul Maheshwari1612ac92017-08-30 14:42:32 -0500238 ... egrep -v grep | \ cut -c1-6)
239
240 ${cmd_output} ${stderr} ${rc}= BMC Execute Command ${cmd_buf}
241 Should Be Empty ${stderr} msg=BMC execute command error.
242 Should Be Equal As Integers ${rc} ${0}
243 ... msg=BMC execute command return code is not zero.
Anusha Dathatrifd350222021-04-08 06:07:49 -0500244
245Create User Initiated BMC Dump Using Redfish
246 [Documentation] Trigger user initiated BMC dump via Redfish and return task id.
247
248 ${payload}= Create Dictionary DiagnosticDataType=Manager
249 ${resp}= Redfish.Post
250 ... /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData
251 ... body=${payload} valid_status_codes=[${HTTP_ACCEPTED}, ${HTTP_OK}]
252
253 # Example of response from above Redfish POST request.
254 # "@odata.id": "/redfish/v1/TaskService/Tasks/0",
255 # "@odata.type": "#Task.v1_4_3.Task",
256 # "Id": "0",
257 # "TaskState": "Running",
258 # "TaskStatus": "OK"
259
260 ${task_id}= Set Variable ${resp.dict['Id']}
261 [Return] ${task_id}
262
263Auto Generate BMC Dump
264 [Documentation] Auto generate BMC dump.
265
Anusha Dathatri21961472021-06-10 03:16:35 -0500266 ${cmd}= Catenate busctl --verbose call xyz.openbmc_project.Dump.Manager
George Keishing6ecc04b2021-06-04 04:15:06 -0500267 ... /xyz/openbmc_project/dump/bmc xyz.openbmc_project.Dump.Create CreateDump a{ss} 0
Anusha Dathatri21961472021-06-10 03:16:35 -0500268 ${stdout} ${stderr} ${rc}=
269 ... BMC Execute Command ${cmd}
Anusha Dathatrifd350222021-04-08 06:07:49 -0500270 [Return] ${stdout} ${stderr} ${rc}
271
272Get Dump Size
273 [Documentation] Get dump size.
Anusha Dathatrieed0e592021-04-21 03:17:12 -0500274 [Arguments] ${dump_uri}
Anusha Dathatrifd350222021-04-08 06:07:49 -0500275
276 # Description of argument(s):
Anusha Dathatrieed0e592021-04-21 03:17:12 -0500277 # dump_uri Dump URI
278 # (Eg. /xyz/openbmc_project/dump/bmc/entry/1).
Anusha Dathatrifd350222021-04-08 06:07:49 -0500279
Anusha Dathatrieed0e592021-04-21 03:17:12 -0500280 # Example of Dump entry.
281 # "data": {
282 # "CompletedTime": 1616760931,
283 # "Elapsed": 1616760931,
284 # "OffloadUri": "",
285 # "Offloaded": false,
286 # "Password": "",
287 # "Size": 3056,
288 # "SourceDumpId": 117440513,
289 # "StartTime": 1616760931,
290 # "Status": "xyz.openbmc_project.Common.Progress.OperationStatus.Completed",
291 # "VSPString": ""
292 # },
Anusha Dathatrifd350222021-04-08 06:07:49 -0500293
Anusha Dathatrieed0e592021-04-21 03:17:12 -0500294 Log ${dump_uri}
295 ${dump_data}= Redfish.Get Properties ${dump_uri}
296 [Return] ${dump_data["data"]["Size"]}
Anusha Dathatrifd350222021-04-08 06:07:49 -0500297
298Get Dump ID
Anusha Dathatrieed0e592021-04-21 03:17:12 -0500299 [Documentation] Return dump ID.
Anusha Dathatrifd350222021-04-08 06:07:49 -0500300 [Arguments] ${task_id}
301
302 # Description of argument(s):
303 # task_id Task ID.
304
305 # Example of HttpHeaders field of task details.
306 # "Payload": {
307 # "HttpHeaders": [
308 # "Host: <BMC_IP>",
309 # "Accept-Encoding: identity",
310 # "Connection: Keep-Alive",
311 # "Accept: */*",
312 # "Content-Length: 33",
313 # "Location: /redfish/v1/Managers/bmc/LogServices/Dump/Entries/2"]
314 # ],
315 # "HttpOperation": "POST",
316 # "JsonBody": "{\"DiagnosticDataType\":\"Manager\"}",
317 # "TargetUri":
318 # "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData"
319 # }
320
321 ${task_dict}= Redfish.Get Properties /redfish/v1/TaskService/Tasks/${task_id}
322 ${key} ${value}= Set Variable ${task_dict["Payload"]["HttpHeaders"][-1].split(":")}
323 Run Keyword If '${key}' != 'Location' Fail
324 [Return] ${value.split('/')[-1]}
325
326Get Task Status
327 [Documentation] Return task status.
328 [Arguments] ${task_id}
329
330 # Description of argument(s):
331 # task_id Task ID.
332
333 ${resp}= Redfish.Get Properties /redfish/v1/TaskService/Tasks/${task_id}
334 [Return] ${resp['TaskState']}
335
Anusha Dathatrieed0e592021-04-21 03:17:12 -0500336Check Task Completion
337 [Documentation] Check if the task is complete.
338 [Arguments] ${task_id}
339
340 # Description of argument(s):
341 # task_id Task ID.
342
343 ${status}= Get Task Status ${task_id}
344 Run Keyword Unless '${status}' == 'Cancelled' or '${status}' == 'Completed'
345 ... Fail Task is still running.
346 [Return] ${status}
347
Anusha Dathatrifd350222021-04-08 06:07:49 -0500348Get Dump ID And Status
349 [Documentation] Return dump ID and status.
350 [Arguments] ${task_id}
351
352 # Description of argument(s):
353 # task_id Task ID.
354
Anusha Dathatrieed0e592021-04-21 03:17:12 -0500355 ${task_status}= Wait Until Keyword Succeeds 10 min 15 sec Check Task Completion ${task_id}
356 ${dump_id}= Run Keyword If '${task_status}' == 'Completed' Get Dump ID ${task_id}
357 ... ELSE Set Variable None
358 [Return] ${dump_id} ${task_status}