Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation This module provides general keywords for dump. |
| 3 | |
Rahul Maheshwari | 1612ac9 | 2017-08-30 14:42:32 -0500 | [diff] [blame] | 4 | Library bmc_ssh_utils.py |
Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 5 | |
| 6 | *** Variables *** |
| 7 | |
| 8 | *** Keywords *** |
| 9 | |
| 10 | Create User Initiated Dump |
| 11 | [Documentation] Generate user initiated dump and return |
Steven Sombar | a011c02 | 2019-01-16 18:13:52 -0600 | [diff] [blame] | 12 | ... 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 Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 23 | |
| 24 | ${data}= Create Dictionary data=@{EMPTY} |
| 25 | ${resp}= OpenBMC Post Request |
Steven Sombar | a011c02 | 2019-01-16 18:13:52 -0600 | [diff] [blame] | 26 | ... ${DUMP_URI}action/CreateDump data=${data} quiet=${1} |
| 27 | |
| 28 | Run Keyword If '${check_out_of_space}' == '${False}' |
George Keishing | 656eb4a | 2019-09-03 03:48:01 -0500 | [diff] [blame] | 29 | ... Run Keyword And Return Get The Dump Id ${resp} |
| 30 | ... ELSE |
| 31 | ... Run Keyword And Return Check For Too Many Dumps ${resp} |
Steven Sombar | a011c02 | 2019-01-16 18:13:52 -0600 | [diff] [blame] | 32 | |
| 33 | |
| 34 | Get The Dump Id |
| 35 | [Documentation] Wait for the dump to be created. Return the |
| 36 | ... dump id number (e.g., "5"). |
| 37 | [Arguments] ${resp} |
| 38 | |
| 39 | # Description of Argument(s): |
| 40 | # resp Response object from action/Create Dump attempt. |
| 41 | # Example object: |
| 42 | # { |
| 43 | # "data": 5, |
| 44 | # "message": "200 OK", |
| 45 | # "status": "ok" |
| 46 | # }, |
| 47 | # The "data" field conveys the id number of the created dump. |
Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 48 | |
| 49 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 50 | ${json}= To JSON ${resp.content} |
George Keishing | 73c4ebf | 2017-11-13 07:10:28 -0600 | [diff] [blame] | 51 | |
George Keishing | 73c4ebf | 2017-11-13 07:10:28 -0600 | [diff] [blame] | 52 | Run Keyword If ${json["data"]} == ${None} |
| 53 | ... Fail Dump id returned null. |
| 54 | |
Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 55 | ${dump_id}= Set Variable ${json["data"]} |
| 56 | |
Rahul Maheshwari | e2cd17f | 2017-09-26 21:26:50 -0500 | [diff] [blame] | 57 | Wait Until Keyword Succeeds 3 min 15 sec Check Dump Existence |
Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 58 | ... ${dump_id} |
| 59 | |
| 60 | [Return] ${dump_id} |
| 61 | |
| 62 | |
Steven Sombar | a011c02 | 2019-01-16 18:13:52 -0600 | [diff] [blame] | 63 | Check For Too Many Dumps |
| 64 | [Documentation] Return the dump_id number, or return ${EMPTY} if dump |
| 65 | ... creation failed due to too many dumps. |
| 66 | [Arguments] ${resp} |
| 67 | |
| 68 | # Description of Argument(s): |
| 69 | # resp Response object from action/Create Dump attempt. |
| 70 | # Example object if there are too many dumps: |
George Keishing | 506756e | 2019-08-06 01:07:55 -0500 | [diff] [blame] | 71 | # { |
Steven Sombar | a011c02 | 2019-01-16 18:13:52 -0600 | [diff] [blame] | 72 | # "data": { |
George Keishing | 506756e | 2019-08-06 01:07:55 -0500 | [diff] [blame] | 73 | # "description": "xyz.openbmc_project.Dump.Create.Error.QuotaExceeded" |
| 74 | # }, |
| 75 | # "message": "Dump not captured due to a cap.", |
Steven Sombar | a011c02 | 2019-01-16 18:13:52 -0600 | [diff] [blame] | 76 | # "status": "error" |
George Keishing | 506756e | 2019-08-06 01:07:55 -0500 | [diff] [blame] | 77 | # } |
Steven Sombar | a011c02 | 2019-01-16 18:13:52 -0600 | [diff] [blame] | 78 | |
| 79 | # If dump was created normally, return the dump_id number. |
| 80 | Run Keyword If '${resp.status_code}' == '${HTTP_OK}' |
| 81 | ... Run Keyword And Return Get The Dump Id ${resp} |
| 82 | |
George Keishing | 506756e | 2019-08-06 01:07:55 -0500 | [diff] [blame] | 83 | ${json}= To JSON ${resp.content} |
| 84 | ${exception}= Set Variable ${json["message"]} |
Steven Sombar | a011c02 | 2019-01-16 18:13:52 -0600 | [diff] [blame] | 85 | ${at_capacity}= Set Variable Dump not captured due to a cap |
| 86 | ${too_many_dumps}= Evaluate $at_capacity in $exception |
Michael Walsh | c108e42 | 2019-03-28 12:27:18 -0500 | [diff] [blame] | 87 | Printn |
Steven Sombar | a011c02 | 2019-01-16 18:13:52 -0600 | [diff] [blame] | 88 | Rprint Vars exception too_many_dumps |
| 89 | # If there are too many dumps, return ${EMPTY}, otherwise Fail. |
| 90 | ${status}= Run Keyword If ${too_many_dumps} Set Variable ${EMPTY} |
| 91 | ... ELSE Fail msg=${exception}. |
| 92 | |
| 93 | [Return] ${status} |
| 94 | |
| 95 | |
Rahul Maheshwari | 953038b | 2017-10-17 05:08:59 -0500 | [diff] [blame] | 96 | Verify No Dump In Progress |
| 97 | [Documentation] Verify no dump in progress. |
| 98 | |
Rahul Maheshwari | 4cfdc39 | 2017-10-25 09:44:47 -0500 | [diff] [blame] | 99 | ${dump_progress} ${stderr} ${rc}= BMC Execute Command ls /tmp |
| 100 | Should Not Contain ${dump_progress} obmcdump |
Rahul Maheshwari | 953038b | 2017-10-17 05:08:59 -0500 | [diff] [blame] | 101 | |
| 102 | |
Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 103 | Check Dump Existence |
| 104 | [Documentation] Verify if given dump exist. |
| 105 | [Arguments] ${dump_id} |
| 106 | |
| 107 | # Description of Argument(s): |
| 108 | # dump_id An integer value that identifies a particular dump |
| 109 | # object(e.g. 1, 3, 5). |
| 110 | |
George Keishing | 8d69338 | 2018-12-18 12:15:04 -0600 | [diff] [blame] | 111 | ${resp}= OpenBMC Get Request ${DUMP_ENTRY_URI}${dump_id} |
Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 112 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 113 | |
| 114 | |
| 115 | Delete BMC Dump |
| 116 | [Documentation] Deletes a given bmc dump. |
| 117 | [Arguments] ${dump_id} |
| 118 | |
| 119 | # Description of Argument(s): |
Gunnar Mills | 28e403b | 2017-10-25 16:16:38 -0500 | [diff] [blame] | 120 | # dump_id An integer value that identifies a particular dump (e.g. 1, 3). |
Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 121 | |
| 122 | ${data}= Create Dictionary data=@{EMPTY} |
| 123 | ${resp}= OpenBMC Post Request |
George Keishing | 8d69338 | 2018-12-18 12:15:04 -0600 | [diff] [blame] | 124 | ... ${DUMP_ENTRY_URI}${dump_id}/action/Delete data=${data} |
Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 125 | |
| 126 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 127 | |
| 128 | Delete All Dumps |
| 129 | [Documentation] Delete all dumps. |
| 130 | |
| 131 | # Check if dump entries exist, if not return. |
George Keishing | 6a6e76d | 2017-09-14 08:19:17 -0500 | [diff] [blame] | 132 | ${resp}= OpenBMC Get Request ${DUMP_ENTRY_URI}list quiet=${1} |
Rahul Maheshwari | ad676bf | 2017-06-22 15:06:05 -0500 | [diff] [blame] | 133 | Return From Keyword If ${resp.status_code} == ${HTTP_NOT_FOUND} |
| 134 | |
| 135 | # Get the list of dump entries and delete them all. |
| 136 | ${dump_entries}= Get URL List ${DUMP_ENTRY_URI} |
Marissa Garza | 20ccfc7 | 2020-06-19 12:51:10 -0500 | [diff] [blame] | 137 | FOR ${entry} IN @{dump_entries} |
| 138 | ${dump_id}= Fetch From Right ${entry} / |
| 139 | Delete BMC Dump ${dump_id} |
| 140 | END |
George Keishing | c9fcd09 | 2017-09-20 09:24:37 -0500 | [diff] [blame] | 141 | |
Rahul Maheshwari | de5d6f1 | 2020-10-14 02:08:00 -0500 | [diff] [blame] | 142 | |
Rahul Maheshwari | 95cbceb | 2020-10-21 23:25:08 -0500 | [diff] [blame] | 143 | Redfish Delete BMC Dump |
| 144 | [Documentation] Deletes a given BMC dump via Redfish.. |
| 145 | [Arguments] ${dump_id} |
| 146 | |
| 147 | # Description of Argument(s): |
| 148 | # dump_id An integer value that identifies a particular dump (e.g. 1, 3). |
| 149 | |
| 150 | Redfish.Delete /redfish/v1/Managers/bmc/LogServices/Dump/Entries/${dump_id} |
| 151 | |
| 152 | |
Rahul Maheshwari | de5d6f1 | 2020-10-14 02:08:00 -0500 | [diff] [blame] | 153 | Redfish Delete All BMC Dumps |
| 154 | [Documentation] Delete all BMC dumps via Redfish. |
| 155 | |
| 156 | # Check if dump entries exist, if not return. |
| 157 | ${resp}= Redfish.Get /redfish/v1/Managers/bmc/LogServices/Dump/Entries |
| 158 | Return From Keyword If ${resp.dict["Members@odata.count"]} == ${0} |
| 159 | |
| 160 | Redfish.Post /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog |
| 161 | |
| 162 | |
George Keishing | c9fcd09 | 2017-09-20 09:24:37 -0500 | [diff] [blame] | 163 | Delete All BMC Dump |
| 164 | [Documentation] Delete all BMC dump entries using "DeleteAll" interface. |
| 165 | |
| 166 | ${data}= Create Dictionary data=@{EMPTY} |
| 167 | ${resp}= Openbmc Post Request ${DUMP_URI}action/DeleteAll data=${data} |
| 168 | Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
George Keishing | dc42876 | 2017-11-11 12:37:12 -0600 | [diff] [blame] | 169 | |
George Keishing | dc42876 | 2017-11-11 12:37:12 -0600 | [diff] [blame] | 170 | Dump Should Not Exist |
| 171 | [Documentation] Verify that BMC dumps do not exist. |
| 172 | |
George Keishing | 8d69338 | 2018-12-18 12:15:04 -0600 | [diff] [blame] | 173 | ${resp}= OpenBMC Get Request ${DUMP_ENTRY_URI}list quiet=${1} |
George Keishing | dc42876 | 2017-11-11 12:37:12 -0600 | [diff] [blame] | 174 | Should Be Equal As Strings ${resp.status_code} ${HTTP_NOT_FOUND} |
| 175 | |
Steven Sombar | 336fa97 | 2019-11-07 13:12:58 -0600 | [diff] [blame] | 176 | Check Existence Of BMC Dump File |
Sivas SRR | 7aabd79 | 2017-10-18 21:28:23 -0500 | [diff] [blame] | 177 | [Documentation] Verify existence of BMC dump file. |
| 178 | [Arguments] ${dump_id} |
| 179 | |
| 180 | # Description of argument(s): |
| 181 | # dump_id BMC dump identifier |
| 182 | |
| 183 | ${dump_check_cmd}= Set Variable |
| 184 | ... ls /var/lib/phosphor-debug-collector/dumps |
| 185 | |
| 186 | # Output of sample BMC Execute command with '2' as dump id is as follows |
| 187 | # ls /var/lib/phosphor-debug-collector/dumps/2 |
| 188 | # obmcdump_2_XXXXXXXXXX.tar.xz |
| 189 | ${file_there} ${stderr} ${rc}= BMC Execute Command |
| 190 | ... ${dump_check_cmd}/${dump_id} |
| 191 | Should End With ${file_there} tar.xz msg=BMC dump file not found. |
Rahul Maheshwari | 1612ac9 | 2017-08-30 14:42:32 -0500 | [diff] [blame] | 192 | |
| 193 | Get Dump Entries |
| 194 | [Documentation] Return dump entries list. |
| 195 | |
| 196 | ${dump_entries}= Get URL List ${DUMP_ENTRY_URI} |
| 197 | [Return] ${dump_entries} |
| 198 | |
| 199 | |
| 200 | Trigger Core Dump |
| 201 | [Documentation] Trigger core dump. |
| 202 | |
| 203 | # Find the pid of the active ipmid and kill it. |
George Keishing | bfd5c8f | 2018-07-11 10:27:28 -0500 | [diff] [blame] | 204 | ${cmd_buf}= Catenate kill -s SEGV $(ps | egrep ' ipmid$' | |
Rahul Maheshwari | 1612ac9 | 2017-08-30 14:42:32 -0500 | [diff] [blame] | 205 | ... egrep -v grep | \ cut -c1-6) |
| 206 | |
| 207 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command ${cmd_buf} |
| 208 | Should Be Empty ${stderr} msg=BMC execute command error. |
| 209 | Should Be Equal As Integers ${rc} ${0} |
| 210 | ... msg=BMC execute command return code is not zero. |