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