xref: /openbmc/openbmc-test-automation/lib/logging_utils.robot (revision 77ab16012bb148c73298314a0a84cc68c4b9ecbe)
1*** Settings ***
2Documentation    Error logging utility keywords.
3
4Resource        rest_client.robot
5Variables       ../data/variables.py
6
7*** Keywords ***
8
9Get Logging Entry List
10    [Documentation]  Get logging entry and return the object list.
11
12    ${entry_list}=  Create List
13    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}list  quiet=${1}
14    Return From Keyword If  ${resp.status_code} == ${HTTP_NOT_FOUND}
15    ${jsondata}=  To JSON  ${resp.content}
16
17    :FOR  ${entry}  IN  @{jsondata["data"]}
18    \  Continue For Loop If  '${entry.rsplit('/', 1)[1]}' == 'callout'
19    \  Append To List  ${entry_list}  ${entry}
20
21    # Logging entries list.
22    # ['/xyz/openbmc_project/logging/entry/14',
23    #  '/xyz/openbmc_project/logging/entry/15']
24    [Return]  ${entry_list}
25
26
27Logging Entry Should Exist
28    [Documentation]  Find the matching message id and return the entry id.
29    [Arguments]  ${message_id}
30
31    # Description of argument(s):
32    # message_id    Logging message string.
33    #               Example: "xyz.openbmc_project.Common.Error.InternalFailure"
34
35    ${elog_entries}=  Get Logging Entry List
36
37    :FOR  ${entry}  IN  @{elog_entries}
38    \  ${resp}=  Read Properties  ${entry}
39    \  ${status}=  Run Keyword And Return Status
40    ...  Should Be Equal As Strings  ${message_id}  ${resp["Message"]}
41    \  Return From Keyword If  ${status} == ${TRUE}  ${entry}
42
43    Fail  No ${message_id} logging entry found.
44
45
46Get Error Logs
47    [Documentation]  Return a dictionary which contains the BMC error logs.
48    [Arguments]   ${quiet}=1
49
50    # Description of argument(s):
51    # quiet   Indicates whether this keyword should run without any output to
52    #         the console, 0 = verbose, 1 = quiet.
53
54    #  The length of the returned dictionary indicates how many logs there are.
55    #  Printing of error logs can be done with the keyword Print Error Logs,
56    #  for example, Print Error Logs  ${error_logs}  Message.
57
58    ${status}  ${error_logs}=  Run Keyword And Ignore Error  Read Properties
59    ...  /xyz/openbmc_project/logging/entry/enumerate  quiet=${quiet}
60
61    ${empty_dict}=  Create Dictionary
62    Return From Keyword If  '${status}' == 'FAIL'  ${empty_dict}
63    [Return]  ${error_logs}
64
65
66Get IPMI SEL Setting
67    [Documentation]  Returns status for given IPMI SEL setting.
68    [Arguments]  ${setting}
69    # Description of argument(s):
70    # setting  SEL setting which needs to be read(e.g. "Last Add Time").
71
72    ${resp}=  Run IPMI Standard Command  sel info
73
74    ${setting_line}=  Get Lines Containing String  ${resp}  ${setting}
75    ...  case-insensitive
76    ${setting_status}=  Fetch From Right  ${setting_line}  :${SPACE}
77
78    [Return]  ${setting_status}
79
80
81Verify Watchdog Errorlog Content
82    [Documentation]  Verify watchdog errorlog content.
83    # Example:
84    # "/xyz/openbmc_project/logging/entry/1":
85    #  {
86    #      "AdditionalData": [],
87    #      "Id": 1,
88    #      "Message": "org.open_power.Host.Boot.Error.WatchdogTimedOut",
89    #      "Resolved": 0,
90    #      "Severity": "xyz.openbmc_project.Logging.Entry.Level.Error",
91    #      "Timestamp": 1492715244828,
92    #      "associations": []
93    # },
94
95    ${elog_entry}=  Get URL List  ${BMC_LOGGING_ENTRY}
96    ${elog}=  Read Properties  ${elog_entry[0]}
97    Should Be Equal As Strings
98    ...  ${elog["Message"]}  org.open_power.Host.Boot.Error.WatchdogTimedOut
99    Should Be Equal As Strings
100    ...  ${elog["Severity"]}  xyz.openbmc_project.Logging.Entry.Level.Error
101
102
103Logging Test Binary Exist
104    [Documentation]  Verify existence of prerequisite logging-test.
105    Open Connection And Log In
106    ${out}  ${stderr}=  Execute Command
107    ...  which /tmp/tarball/bin/logging-test  return_stderr=True
108    Should Be Empty  ${stderr}
109    Should Contain  ${out}  logging-test
110
111Clear Existing Error Logs
112    [Documentation]  If error log isn't empty, reboot the BMC to clear the log.
113    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}${1}
114    Return From Keyword If  ${resp.status_code} == ${HTTP_NOT_FOUND}
115    Initiate BMC Reboot
116    Wait Until Keyword Succeeds  10 min  10 sec
117    ...  Is BMC Ready
118    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}${1}
119    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_NOT_FOUND}
120
121Create Test Error Log
122    [Documentation]  Generate test error log.
123    # Test error log entry example:
124    # "/xyz/openbmc_project/logging/entry/1":  {
125    #     "AdditionalData": [
126    #         "STRING=FOO"
127    #     ],
128    #     "Id": 1,
129    #     "Message": "example.xyz.openbmc_project.Example.Elog.AutoTestSimple",
130    #     "Severity": "xyz.openbmc_project.Logging.Entry.Level.Error",
131    #     "Timestamp": 1487743963328,
132    #     "associations": []
133    # }
134
135    Execute Command On BMC  /tmp/tarball/bin/logging-test -c AutoTestSimple
136
137Count Error Entries
138    [Documentation]  Count Error entries.
139    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}
140    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
141    ${jsondata}=  To JSON  ${resp.content}
142    ${count}=  Get Length  ${jsondata["data"]}
143    [Return]  ${count}
144
145Verify Test Error Log
146    [Documentation]  Verify test error log entries.
147    ${elog_entry}=  Get URL List  ${BMC_LOGGING_ENTRY}
148    ${entry_id}=  Read Attribute  ${elog_entry[0]}  Message
149    Should Be Equal  ${entry_id}
150    ...  example.xyz.openbmc_project.Example.Elog.AutoTestSimple
151    ${entry_id}=  Read Attribute  ${elog_entry[0]}  Severity
152    Should Be Equal  ${entry_id}
153    ...  xyz.openbmc_project.Logging.Entry.Level.Error
154
155Delete Error Logs And Verify
156    [Documentation]  Delete all error logs and verify.
157    Delete All Error Logs
158    ${resp}=  OpenBMC Get Request  ${BMC_LOGGING_ENTRY}/list  quiet=${1}
159    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_NOT_FOUND}
160
161
162Install Tarball
163    [Documentation]  Install tarball on BMC.
164    Run Keyword If  '${DEBUG_TARBALL_PATH}' == '${EMPTY}'  Return From Keyword
165    BMC Execute Command  rm -rf /tmp/tarball
166    Install Debug Tarball On BMC  ${DEBUG_TARBALL_PATH}
167