1*** Settings ***
2Documentation  This module provides general keywords for dump.
3
4Library         bmc_ssh_utils.py
5
6*** Variables ***
7
8*** Keywords ***
9
10Create User Initiated Dump
11    [Documentation]  Generate user initiated dump and return
12    ...  dump id (e.g 1, 2 etc).
13
14    ${data}=  Create Dictionary  data=@{EMPTY}
15    ${resp}=  OpenBMC Post Request
16    ...  ${DUMP_URI}action/CreateDump  data=${data}
17
18    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
19    ${json}=  To JSON  ${resp.content}
20
21    # REST "CreateDump" JSON response.
22    # {
23    #    "data": null,
24    #    "message": "200 OK",
25    #    "status": "ok"
26    # }
27    Run Keyword If  ${json["data"]} == ${None}
28    ...  Fail  Dump id returned null.
29
30    ${dump_id}=  Set Variable  ${json["data"]}
31
32    Wait Until Keyword Succeeds  3 min  15 sec  Check Dump Existence
33    ...  ${dump_id}
34
35    [Return]  ${dump_id}
36
37
38Verify No Dump In Progress
39    [Documentation]  Verify no dump in progress.
40
41    ${dump_progress}  ${stderr}  ${rc}=  BMC Execute Command  ls /tmp
42    Should Not Contain  ${dump_progress}  obmcdump
43
44
45Check Dump Existence
46    [Documentation]  Verify if given dump exist.
47    [Arguments]  ${dump_id}
48
49    # Description of Argument(s):
50    # dump_id  An integer value that identifies a particular dump
51    #          object(e.g. 1, 3, 5).
52
53    ${resp}=  OpenBMC Get Request  ${DUMP_ENTRY_URI}${dump_id}
54    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
55
56
57Delete BMC Dump
58    [Documentation]  Deletes a given bmc dump.
59    [Arguments]  ${dump_id}
60
61    # Description of Argument(s):
62    # dump_id  An integer value that identifies a particular dump (e.g. 1, 3).
63
64    ${data}=  Create Dictionary  data=@{EMPTY}
65    ${resp}=  OpenBMC Post Request
66    ...  ${DUMP_ENTRY_URI}${dump_id}/action/Delete  data=${data}
67
68    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
69
70Delete All Dumps
71    [Documentation]  Delete all dumps.
72
73    # Check if dump entries exist, if not return.
74    ${resp}=  OpenBMC Get Request  ${DUMP_ENTRY_URI}list  quiet=${1}
75    Return From Keyword If  ${resp.status_code} == ${HTTP_NOT_FOUND}
76
77    # Get the list of dump entries and delete them all.
78    ${dump_entries}=  Get URL List  ${DUMP_ENTRY_URI}
79    :FOR  ${entry}  IN  @{dump_entries}
80    \  ${dump_id}=  Fetch From Right  ${entry}  /
81    \  Delete BMC Dump  ${dump_id}
82
83
84Delete All BMC Dump
85    [Documentation]  Delete all BMC dump entries using "DeleteAll" interface.
86
87    ${data}=  Create Dictionary  data=@{EMPTY}
88    ${resp}=  Openbmc Post Request  ${DUMP_URI}action/DeleteAll  data=${data}
89    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
90
91Dump Should Not Exist
92    [Documentation]  Verify that BMC dumps do not exist.
93
94    ${resp}=  OpenBMC Get Request  ${DUMP_ENTRY_URI}list  quiet=${1}
95    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_NOT_FOUND}
96
97Check Existence of BMC Dump file
98    [Documentation]  Verify existence of BMC dump file.
99    [Arguments]  ${dump_id}
100
101    # Description of argument(s):
102    # dump_id  BMC dump identifier
103
104    ${dump_check_cmd}=  Set Variable
105    ...  ls /var/lib/phosphor-debug-collector/dumps
106
107    # Output of sample BMC Execute command with '2' as dump id is as follows
108    # ls /var/lib/phosphor-debug-collector/dumps/2
109    # obmcdump_2_XXXXXXXXXX.tar.xz
110    ${file_there}  ${stderr}  ${rc}=  BMC Execute Command
111    ...  ${dump_check_cmd}/${dump_id}
112    Should End With  ${file_there}  tar.xz  msg=BMC dump file not found.
113
114Get Dump Entries
115    [Documentation]  Return dump entries list.
116
117    ${dump_entries}=  Get URL List  ${DUMP_ENTRY_URI}
118    [Return]  ${dump_entries}
119
120
121Trigger Core Dump
122    [Documentation]  Trigger core dump.
123
124    # Find the pid of the active ipmid and kill it.
125    ${cmd_buf}=  Catenate  kill -s SEGV $(ps | egrep ' ipmid$' |
126    ...  egrep -v grep | \ cut -c1-6)
127
128    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd_buf}
129    Should Be Empty  ${stderr}  msg=BMC execute command error.
130    Should Be Equal As Integers  ${rc}  ${0}
131    ...  msg=BMC execute command return code is not zero.
132