xref: /openbmc/openbmc-test-automation/redfish/managers/test_bmc_dumps.robot (revision ac76512089f08d3e17d24633a664f200aa6c8e51)
1 *** Settings ***
2 
3 Documentation       Test BMC dump functionality of OpenBMC.
4 
5 Resource            ../../lib/openbmc_ffdc.robot
6 Resource            ../../lib/dump_utils.robot
7 
8 Suite Setup         Redfish.Login
9 Test Setup          Redfish Delete All BMC Dumps
10 Test Teardown       Test Teardown Execution
11 
12 *** Variables ***
13 
14 # Total size of the dump in kilo bytes
15 ${BMC_DUMP_TOTAL_SIZE}       ${1024}
16 
17 # Minimum space required for one bmc dump in kilo bytes
18 ${BMC_DUMP_MIN_SPACE_REQD}   ${20}
19 
20 *** Test Cases ***
21 
22 Verify User Initiated BMC Dump When Host Powered Off
23     [Documentation]  Create user initiated BMC dump at host off state and
24     ...  verify dump entry for it.
25     [Tags]  Verify_User_Initiated_BMC_Dump_When_Host_Powered_Off
26 
27     Redfish Power Off  stack_mode=skip
28     ${dump_id}=  Create User Initiated BMC Dump
29     ${dump_entries}=  Get BMC Dump Entries
30     Length Should Be  ${dump_entries}  1
31     List Should Contain Value  ${dump_entries}  ${dump_id}
32 
33 Verify User Initiated BMC Dump When Host Booted
34     [Documentation]  Create user initiated BMC dump at host booted state and
35     ...  verify dump entry for it.
36     [Tags]  Verify_User_Initiated_BMC_Dump_When_Host_Booted
37 
38     Redfish Power On  stack_mode=skip
39     ${dump_id}=  Create User Initiated BMC Dump
40     ${dump_entries}=  Get BMC Dump Entries
41     Length Should Be  ${dump_entries}  1
42     List Should Contain Value  ${dump_entries}  ${dump_id}
43 
44 
45 Verify User Initiated BMC Dump Size
46     [Documentation]  Verify user initiated BMC dump size is under 200 KB.
47     [Tags]  Verify_User_Initiated_BMC_Dump_Size
48 
49     ${dump_id}=  Create User Initiated BMC Dump
50     ${resp}=  Redfish.Get Properties  /redfish/v1/Managers/bmc/LogServices/Dump/Entries/${dump_id}
51 
52     # Example of response from above Redfish GET request.
53     # "@odata.type": "#LogEntry.v1_7_0.LogEntry",
54     # "AdditionalDataSizeBytes": 31644,
55     # "AdditionalDataURI": "/redfish/v1/Managers/bmc/LogServices/Dump/attachment/9",
56     # "Created": "2020-10-23T06:32:53+00:00",
57     # "DiagnosticDataType": "Manager",
58     # "EntryType": "Event",
59     # "Id": "9",
60     # "Name": "BMC Dump Entry"
61 
62     # Max size for dump is 200 KB = 200x1024 Byte.
63     Should Be True  0 < ${resp["AdditionalDataSizeBytes"]} < 204800
64 
65 
66 Verify Dump Persistency On Dump Service Restart
67     [Documentation]  Create user dump, restart dump manager service and verify dump
68     ...  persistency.
69     [Tags]  Verify_Dump_Persistency_On_Dump_Service_Restart
70 
71     Create User Initiated BMC Dump
72     ${dump_entries_before}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
73 
74     # Restart dump service.
75     BMC Execute Command  systemctl restart xyz.openbmc_project.Dump.Manager.service
76     Sleep  10s  reason=Wait for BMC dump service to restart properly
77 
78     ${dump_entries_after}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
79     Lists Should Be Equal  ${dump_entries_before}  ${dump_entries_after}
80 
81 
82 Verify Dump Persistency On BMC Reset
83     [Documentation]  Create user dump, reset BMC and verify dump persistency.
84     [Tags]  Verify_Dump_Persistency_On_BMC_Reset
85 
86     Create User Initiated BMC Dump
87     ${dump_entries_before}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
88 
89     # Reset BMC.
90     OBMC Reboot (off)
91 
92     ${dump_entries_after}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
93     Lists Should Be Equal  ${dump_entries_before}  ${dump_entries_after}
94 
95 
96 Delete User Initiated BMC Dump And Verify
97     [Documentation]  Delete user initiated BMC dump and verify.
98     [Tags]  Delete_User_Initiated_BMC_Dump_And_Verify
99 
100     ${dump_id}=  Create User Initiated BMC Dump
101     Redfish Delete BMC Dump  ${dump_id}
102 
103     ${dump_entries}=  Get BMC Dump Entries
104     Should Be Empty  ${dump_entries}
105 
106 
107 Delete All User Initiated BMC Dumps And Verify
108     [Documentation]  Delete all user initiated BMC dumps and verify.
109     [Tags]  Delete_All_User_Initiated_BMC_Dumps_And_Verify
110 
111     # Create some BMC dump.
112     Create User Initiated BMC Dump
113     Create User Initiated BMC Dump
114 
115     Redfish Delete All BMC Dumps
116     ${dump_entries}=  Get BMC Dump Entries
117     Should Be Empty  ${dump_entries}
118 
119 
120 Create Two User Initiated BMC Dumps
121     [Documentation]  Create two user initiated BMC dumps.
122     [Tags]  Create_Two_User_Initiated_BMC_Dumps
123 
124     ${dump_id1}=  Create User Initiated BMC Dump
125     ${dump_id2}=  Create User Initiated BMC Dump
126 
127     ${dump_entries}=  Get BMC Dump Entries
128     Length Should Be  ${dump_entries}  2
129     Should Contain  ${dump_entries}  ${dump_id1}
130     Should Contain  ${dump_entries}  ${dump_id2}
131 
132 
133 Create Two User Initiated BMC Dumps And Delete One
134     [Documentation]  Create two dumps and delete the first.
135     [Tags]  Create_Two_User_Initiated_BMC_Dumps_And_Delete_One
136 
137     ${dump_id1}=  Create User Initiated BMC Dump
138     ${dump_id2}=  Create User Initiated BMC Dump
139 
140     Redfish Delete BMC Dump  ${dump_id1}
141 
142     ${dump_entries}=  Get BMC Dump Entries
143     Length Should Be  ${dump_entries}  1
144     List Should Contain Value  ${dump_entries}  ${dump_id2}
145 
146 
147 Create And Delete User Initiated BMC Dump Multiple Times
148     [Documentation]  Create and delete user initiated BMC dump multiple times.
149     [Tags]  Create_And_Delete_User_Initiated_BMC_Dump_Multiple_Times
150 
151     FOR  ${INDEX}  IN  1  10
152       ${dump_id}=  Create User Initiated BMC Dump
153       Redfish Delete BMC Dump  ${dump_id}
154     END
155 
156 
157 Verify Maximum BMC Dump Creation
158     [Documentation]  Create maximum BMC dump and verify error when dump runs out of space.
159     [Tags]  Verify_Maximum_BMC_Dump_Creation
160     [Teardown]  Redfish Delete All BMC Dumps
161 
162     # Maximum allowed space for dump is 1024 KB. BMC typically hold 8-14 dumps
163     # before running out of this dump space. So trying to create dumps in 20
164     # iterations to run out of space.
165 
166     FOR  ${n}  IN RANGE  0  20
167       Create User Initiated BMC Dump
168       ${dump_space}=  Get Disk Usage For Dumps
169       Exit For Loop If  ${dump_space} >= (${BMC_DUMP_TOTAL_SIZE} - ${BMC_DUMP_MIN_SPACE_REQD})
170     END
171 
172     # Check error while creating dump when dump size is full.
173     ${payload}=  Create Dictionary  DiagnosticDataType=Manager
174     Redfish.Post  /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData
175     ...  body=${payload}  valid_status_codes=[${HTTP_INTERNAL_SERVER_ERROR}]
176 
177 
178 *** Keywords ***
179 
180 Create User Initiated BMC Dump
181     [Documentation]  Generate user initiated BMC dump and return the dump id number (e.g., "5").
182 
183     ${payload}=  Create Dictionary  DiagnosticDataType=Manager
184     ${resp}=  Redfish.Post  /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData
185     ...  body=${payload}  valid_status_codes=[${HTTP_ACCEPTED}]
186 
187     # Example of response from above Redfish POST request.
188     # "@odata.id": "/redfish/v1/TaskService/Tasks/0",
189     # "@odata.type": "#Task.v1_4_3.Task",
190     # "Id": "0",
191     # "TaskState": "Running",
192     # "TaskStatus": "OK"
193 
194     Wait Until Keyword Succeeds  5 min  15 sec  Is Task Completed  ${resp.dict['Id']}
195     ${task_id}=  Set Variable  ${resp.dict['Id']}
196 
197     ${task_dict}=  Redfish.Get Properties  /redfish/v1/TaskService/Tasks/${task_id}
198 
199     # Example of HttpHeaders field of task details.
200     # "Payload": {
201     #   "HttpHeaders": [
202     #     "Host: <BMC_IP>",
203     #      "Accept-Encoding: identity",
204     #      "Connection: Keep-Alive",
205     #      "Accept: */*",
206     #      "Content-Length: 33",
207     #      "Location: /redfish/v1/Managers/bmc/LogServices/Dump/Entries/2"]
208     #    ],
209     #    "HttpOperation": "POST",
210     #    "JsonBody": "{\"DiagnosticDataType\":\"Manager\"}",
211     #     "TargetUri": "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData"
212     # }
213 
214     [Return]  ${task_dict["Payload"]["HttpHeaders"][-1].split("/")[-1]}
215 
216 
217 Get BMC Dump Entries
218     [Documentation]  Return BMC dump ids list.
219 
220     ${dump_uris}=  redfish_utils.get_member_list  /redfish/v1/Managers/bmc/LogServices/Dump/Entries
221     ${dump_ids}=  Create List
222 
223     FOR  ${dump_uri}  IN  @{dump_uris}
224       ${dump_id}=  Fetch From Right  ${dump_uri}  /
225       Append To List  ${dump_ids}  ${dump_id}
226     END
227 
228     [Return]  ${dump_ids}
229 
230 
231 Get Disk Usage For Dumps
232     [Documentation]  Return disk usage in kilobyte for BMC dumps.
233 
234     ${usage_output}  ${stderr}  ${rc}=  BMC Execute Command  du -s /var/lib/phosphor-debug-collector/dumps
235 
236     # Example of output from above BMC cli command.
237     # $ du -s /var/lib/phosphor-debug-collector/dumps
238     # 516    /var/lib/phosphor-debug-collector/dumps
239 
240     ${usage_output}=  Fetch From Left  ${usage_output}  /
241     ${usage_output}=  Convert To Integer  ${usage_output}
242 
243     [return]  ${usage_output}
244 
245 
246 Is Task Completed
247     [Documentation]  Verify if the given task is completed.
248     [Arguments]   ${task_id}
249 
250     # Description of argument(s):
251     # task_id        Id of task which needs to be checked.
252 
253     ${task_dict}=  Redfish.Get Properties  /redfish/v1/TaskService/Tasks/${task_id}
254     Should Be Equal As Strings  ${task_dict['TaskState']}  Completed
255 
256 
257 Test Teardown Execution
258     [Documentation]  Do test teardown operation.
259 
260     FFDC On Test Case Fail
261     Close All Connections
262