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