1*** Settings ***
2Documentation      Utility keywords for FFDC
3
4Library            String
5Library            DateTime
6Library            openbmc_ffdc_list.py
7Resource           resource.txt
8Resource           connection_client.robot
9Resource           utils.robot
10
11*** Variables ***
12
13${PRINT_LINE}      ------------------------------------------------------------------------
14
15${MSG_INTRO}       This report contains the following information:
16${MSG_DETAIL}      ${\n}\t\t[ Detailed Logs Captured Section ]
17${HEADER_MSG}      ${\n}\t\t---------------------------
18...                ${\n}\t\t FIRST FAILURE DATA CAPTURE
19...                ${\n}\t\t---------------------------
20${FOOTER_MSG}      ${\n}${PRINT_LINE} ${\n}
21
22${FFDC_LOG_PATH}   ${EXECDIR}${/}logs${/}
23${TEST_HISTORY}    ${FFDC_LOG_PATH}${/}test_history.txt
24
25*** Keywords ***
26
27Get Test Dir and Name
28    [Documentation]    SUITE_NAME and TEST_NAME are automatic variables
29    ...                and is populated dynamically by the robot framework
30    ...                during execution
31    ${suite_name}=     Get strip string   ${SUITE_NAME}
32    ${suite_name}=     Catenate  SEPARATOR=    ${FFDC_TIME}_   ${suite_name}
33    ${test_name}=      Get strip string   ${TEST_NAME}
34    ${test_name}=   Catenate  SEPARATOR=  ${FFDC_TIME}_   ${test_name}
35    [Return]  ${suite_name}   ${test_name}
36
37
38Create FFDC Directory
39    [Documentation]    Creates directory and report file
40    Create Directory   ${FFDC_DIR_PATH}
41    Create FFDC Report File
42
43
44Create FFDC Report File
45    [Documentation]     Create a generic file name for ffdc
46    Set Suite Variable
47    ...  ${FFDC_FILE_PATH}   ${FFDC_DIR_PATH}${/}${FFDC_TIME}_BMC_general.txt
48    Create File         ${FFDC_FILE_PATH}
49
50
51Write Data To File
52    [Documentation]     Write data to the ffdc report document
53    [Arguments]         ${data}=      ${filepath}=${FFDC_FILE_PATH}
54    Append To File      ${filepath}   ${data}
55
56
57Get Current Time Stamp
58    [Documentation]     Get the current time stamp data
59    ${cur_time}=    Get Current Date   result_format=%Y-%m-%d %H:%M:%S:%f
60    ${cur_time}=    Get strip string   ${cur_time}
61    [Return]   ${cur_time}
62
63
64Header Message
65    [Documentation]     Write header message to the report document manifest
66    ...                 and return a list of generated files.
67    ...                 TEST_NAME, TEST_MESSAGE,SUITE_SOURCE, TEST_DOCUMENTATION
68    ...                 are auto variables and are populated dynamically by the
69    ...                 robot framework during execution.
70    ...                 1. Write opening statement headers message.
71    ...                 2. Add test setup and config information.
72    ...                 3. Print types of data collection.
73
74    ${TEST_NAME}=  Get Variable Value  ${TEST_NAME}
75    ${TEST_MESSAGE}=  Get Variable Value  ${TEST_MESSAGE}
76    ${TEST_DOCUMENTATION}=  Get Variable Value  ${TEST_DOCUMENTATION}
77    Write Data To File  ${HEADER_MSG}
78    Write Data To File  ${FOOTER_MSG}
79    Write Data To File  Test Suite File\t\t: ${SUITE_NAME} ${\n}
80    Write Data To File  Test Case Name\t\t: ${TEST_NAME}${\n}
81    Write Data To File  Test Source File\t: ${SUITE_SOURCE}${\n}
82    Write Data To File  Failure Time Stamp\t: ${FFDC_TIME}${\n}
83    Write Data To File  Test Error Message\t: ${TEST_MESSAGE}${\n}
84    Write Data To File  Test Documentation\t:${\n}${TEST_DOCUMENTATION}${\n}
85    Write Data To File  ${FOOTER_MSG}
86
87    Test Setup Info
88
89    Write Data To File  ${\n}${MSG_INTRO}${\n}
90
91    # --- FFDC header notes ---
92    @{entries}=  Get ffdc cmd index
93    :FOR  ${index}  IN  @{entries}
94    \   Write Data To File  * ${index.upper()}
95    \   Write Data To File  ${\n}
96
97    Write Data To File  ${MSG_DETAIL}
98    ${ffdc_file_list}=  Create List  ${FFDC_FILE_PATH}
99    [Return]  ${ffdc_file_list}
100
101
102Write Cmd Output to FFDC File
103    [Documentation]      Write cmd output data to the report document
104    [Arguments]          ${name_str}   ${cmd}
105
106    Write Data To File   ${FOOTER_MSG}
107    Write Data To File   ${ENTRY_INDEX.upper()} : ${name_str}\t
108    Write Data To File   Executed : ${cmd}
109    Write Data To File   ${FOOTER_MSG}
110
111
112Test Setup Info
113    [Documentation]      BMC IP, Model and other information
114
115    Write Data To File  ${\n}-----------------------${\n}
116    Write Data To File  Test Setup Information:
117    Write Data To File  ${\n}-----------------------${\n}
118    Write Data To File  OPENBMC HOST \t: ${OPENBMC_HOST}${\n}
119    ${model_name}=  Get BMC System Model
120    Write Data To File  SYSTEM TYPE \t: ${model_name}
121
122
123Error Logs Should Not Exist
124    [Documentation]  Verify that error logs do not exist.
125
126    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}list  quiet=${1}
127    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_NOT_FOUND}
128    ...  msg=Unexpected BMC error log(s) present.
129
130
131Error Logs Should Exist
132    [Documentation]  Verify that error logs exist.
133
134    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}list  quiet=${1}
135    Run Keyword If  ${resp.status_code} != ${HTTP_OK}  Fail
136    ...  msg=Expected BMC error log(s) are not present.
137