xref: /openbmc/openbmc-test-automation/redfish/telemetry_service/test_telemetry_report.robot (revision d95d917db7d7422c69a3c991a5bbda9d1a9cff2c)
1*** Settings ***
2
3Documentation       Test telemetry functionality of OpenBMC.
4
5Resource            ../../lib/bmc_redfish_resource.robot
6Resource            ../../lib/openbmc_ffdc.robot
7
8Suite Setup         Suite Setup Execution
9Suite Teardown      Redfish.Logout
10Test Setup          Delete All Telemetry Reports
11Test Teardown       Test Teardown Execution
12
13Test Tags          Telemetry_Report
14
15*** Variables ***
16
17${metric_definition_base_uri}  /redfish/v1/TelemetryService/MetricReportDefinitions
18${metric_report_base_uri}      /redfish/v1/TelemetryService/MetricReports
19&{user_tele_def}               ambient temperature=Ambient.*Temp    pcie temperature=PCIE.*Temp
20...                            processor temperature=proc.*temp    dimm temperature=dimm.*temp
21...                            battery voltage=Battery_Voltage    total power=total_power
22...                            relative humidity=Relative_Humidity
23
24
25*** Test Cases ***
26
27Verify Basic Telemetry Report Creation
28    [Documentation]  Verify basic telemetry report creations for different metrics.
29    [Tags]  Verify_Basic_Telemetry_Report_Creation
30    [Template]  Create Basic Telemetry Report
31
32    # Metric definition   Metric ReportDefinition Type    Report Actions        Append Limit  Expected Result
33    ambient temperature      OnRequest               LogToMetricReportsCollection
34    processor temperature    Periodic                LogToMetricReportsCollection      500
35    dimm temperature         Periodic                LogToMetricReportsCollection      1000
36    total power              OnRequest               LogToMetricReportsCollection
37    invalid value            OnRequest               LogToMetricReportsCollection      100             fail
38    relative humidity        OnRequest               LogToMetricReportsCollection
39    battery voltage          Periodic                LogToMetricReportsCollection      100
40
41
42Verify Error After Exceeding Maximum Report Creation
43    [Documentation]  Verify error while creating telemetry report more than max report limit.
44    [Tags]  Verify_Error_After_Exceeding_Maximum_Report_Creation
45
46    ${report_name}=  Set Variable  Testreport
47
48    # Create maximum number of reports.
49    ${resp}=  Redfish.Get Properties  /redfish/v1/TelemetryService
50    FOR  ${i}  IN RANGE  ${resp["MaxReports"]}
51        Create Basic Telemetry Report   total power  Periodic  LogToMetricReportsCollection
52        ...  delete_report=False
53    END
54
55    # Attempt another report creation and it should fail.
56    Create Basic Telemetry Report
57    ...   total power  Periodic  LogToMetricReportsCollection  expected_result=fail
58
59    # Now delete the reports created.
60    Delete All Telemetry Reports
61
62
63Verify Basic Telemetry Report Creation For PCIE
64     [Documentation]  Verify basic telemetry report creations for PCIE.
65     [Tags]  Verify_Basic_Telemetry_Report_Creation_For_PCIE
66
67     Create Basic Telemetry Report
68     ...  pcie temperature  OnRequest  LogToMetricReportsCollection
69
70Verify Telemetry Service Unsupported Methods
71    [Documentation]  Verify Telemetry Service with Unsupported methods.
72    [Tags]  Verify_Telemetry_Service_Unsupported_Methods
73
74    Verify Supported And Unsupported Methods    uri=/redfish/v1/TelemetryService
75
76Verify Telemetry Service MetricReports Unsupported Methods
77    [Documentation]  Verify Telemetry Service MetricReports with Unsupported methods.
78    [Tags]  Verify_Telemetry_Service_MetricReports_Unsupported_Methods
79
80    Verify Supported And Unsupported Methods    uri=/redfish/v1/TelemetryService/MetricReports
81
82Verify Telemetry Service Defaults
83    [Documentation]  Verify Telemetry Service Defaults.
84    [Tags]  Verify_Telemetry_Service_Defaults
85
86    # Get Telemetry Service Default properties
87    ${telemetryservice}=    Redfish.Get Properties    /redfish/v1/TelemetryService
88    ...    valid_status_codes=[${HTTP_OK}]
89
90    # Validate Telemetry Service properties
91    Valid Value  telemetryservice['@odata.id']  ['/redfish/v1/TelemetryService']
92    Valid Value  telemetryservice['Name']  ['Telemetry Service']
93    Valid Value  telemetryservice['MetricReportDefinitions']['@odata.id']
94    ...    ['/redfish/v1/TelemetryService/MetricReportDefinitions']
95    Valid Value  telemetryservice['MetricReports']['@odata.id']
96    ...  ['/redfish/v1/TelemetryService/MetricReports']
97    Valid Value  telemetryservice['Status']['State']  ['Enabled']
98    Valid Value  telemetryservice['Triggers']['@odata.id']
99    ...  ['/redfish/v1/TelemetryService/Triggers']
100
101
102*** Keywords ***
103
104Verify Supported And Unsupported Methods
105    [Documentation]  Verify Supported And Unsupported Methods for given URI.
106    [Arguments]   ${uri}
107    # Description of argument(s):
108    # uri                 The URI to be tested.
109
110    # GET operation on Telemetry Service
111    Redfish.Get    ${uri}
112    ...    valid_status_codes=[${HTTP_OK}]
113
114    # Put operation on Telemetry Service
115    Redfish.Put  ${uri}
116    ...  valid_status_codes=[${HTTP_METHOD_NOT_ALLOWED}]
117
118    # Post operation on Telemetry Service
119    Redfish.Post  ${uri}
120    ...  valid_status_codes=[${HTTP_METHOD_NOT_ALLOWED}]
121
122    # Delete operation on Telemetry Service
123    Redfish.Delete  ${uri}
124    ...  valid_status_codes=[${HTTP_METHOD_NOT_ALLOWED}]
125
126    # Patch operation on Telemetry Service
127    Redfish.Patch  ${uri}
128    ...  valid_status_codes=[${HTTP_METHOD_NOT_ALLOWED}]
129
130Suite Setup Execution
131    [Documentation]  Do test case setup tasks.
132
133    Redfish.Login
134    Redfish Power On  stack_mode=skip
135    ${metric_definitions_list}=
136    ...  Redfish_Utils.Get Member List  /redfish/v1/TelemetryService/MetricDefinitions
137
138    # Create a dictionary of ordinary english naming and actual naming of
139    # telemetry definition.
140    ${english_actual_teleDef}=   Create Dictionary
141
142    Set Suite Variable  ${english_actual_teleDef}
143    Set Suite Variable  ${metric_definitions_list}
144
145    Set To Dictionary  ${english_actual_teleDef}  invalid value  invalid_value
146
147    # Find and collect actual telemetry definitions.
148    FOR    ${key}  IN  @{user_tele_def.keys()}
149      Add To Telemetry definition Record   ${key}   ${user_tele_def['${key}']}
150    END
151
152
153Add To Telemetry definition Record
154    [Documentation]  Find actual telemetry definitions available and store.
155    ...              Definitions are stored in a dictionary as key and value
156    ...              as described in argument documentation.
157    [Arguments]  ${key}  ${value}
158
159    # Description of argument(s):
160    # key       Name of metric definition in plain english.
161    #           Example: ambient temperature
162    # value     Equivalent regex expression of telemetry definition.
163    #           Example:  Ambient.*Temp
164
165    Set To Dictionary  ${english_actual_teleDef}  ${key}=Not found
166    FOR  ${item}  IN  @{metric_definitions_list}
167      ${regex_matching_output}=  Get Regexp Matches  ${item}  ${value}
168      IF  ${regex_matching_output} != []
169          Set To Dictionary  ${english_actual_teleDef}  ${key}=${regex_matching_output}[0]
170          BREAK
171      END
172    END
173
174
175Test Teardown Execution
176    [Documentation]  Do test teardown operation.
177
178    FFDC On Test Case Fail
179    Delete All Telemetry Reports
180
181
182Create Basic Telemetry Report
183    [Documentation]  Create a basic telemetry report with single metric.
184    [Arguments]  ${metric_definition_name}  ${metric_definition_type}
185    ...  ${report_action}  ${append_limit}=10  ${expected_result}=success  ${delete_report}=True
186
187    # Description of argument(s):
188    # metric_definition_name    Name of metric definition like Ambient_0_Temp.
189    # metric_definition_type    Name of telemetry report which needs to be created.
190    # report_action             Telemetry report action.
191    # append_limit              Append limit of the metric data in the report.
192    # expected_result           Expected result of report creation - success or fail.
193    # delete_report             Flag to decide if telemetry report needs to be deleted after creation.
194
195    ${metric_definition_name}=  Set Variable  ${english_actual_teleDef}[${metric_definition_name}]
196    Skip If  '${metric_definition_name}' == 'Not found'  Metric definition is not found.
197
198    ${resp}=  Redfish.Get Properties
199    ...  /redfish/v1/TelemetryService/MetricDefinitions/${metric_definition_name}
200    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
201    ${telemetry_data_unavailable}=  Run Keyword And Return Status  Should Contain  ${resp}  error
202    IF  ${telemetry_data_unavailable} == ${True}
203        ${metricProperties}=  Set Variable  ""
204    ELSE
205        ${metricProperties}=  Set Variable  ${resp["MetricProperties"]}
206    END
207    # Example of response from above Redfish GET request.
208    # "@odata.id": "/redfish/v1/TelemetryService/MetricDefinitions/Ambient_0_Temp",
209    # "@odata.type": "#MetricDefinition.v1_0_3.MetricDefinition",
210    # "Id": "Ambient_0_Temp",
211    # "IsLinear": true,
212    # "MaxReadingRange": 127.0,
213    # "MetricDataType": "Decimal",
214    # "MetricProperties": [
215    #     "/redfish/v1/Chassis/chassis/Sensors/temperature_Ambient_0_Temp"
216    # ],
217    # "MetricType": "Gauge",
218    # "MinReadingRange": -128.0,
219    # "Name": "Ambient_0_Temp",
220    # "Units": "Cel"
221
222    # Report name is from random generated string with length 16 which
223    # is enough to maintain uniqueness in report name.
224    ${report_name}=  Generate Random String  16  [NUMBERS]abcdef
225    ${body}=  Catenate  {"Id": "${report_name}",
226    ...  "MetricReportDefinitionType": "${metric_definition_type}",
227    ...  "Name": "Report",
228    ...  "ReportActions":["${report_action}"],
229    ...  "Metrics":[{"CollectionDuration": "PT30.000S",
230    ...  "MetricProperties":${metricProperties}}],
231    ...  "ReportUpdates": "AppendWrapsWhenFull",
232    ...  "AppendLimit": ${append_limit},
233    ...  "Schedule": {"RecurrenceInterval": "PT5.000S"}}
234
235    ${body}=  Replace String  ${body}  '  "
236    ${dict}  Evaluate  json.loads('''${body}''')  json
237
238    ${status_code_expected}=  Set Variable If
239    ...  '${expected_result}' == 'success'  [${HTTP_CREATED}]
240    ...  '${expected_result}' == 'fail'  [${HTTP_BAD_REQUEST}]
241
242    Redfish.Post  ${metric_definition_base_uri}  body=&{dict}
243     ...  valid_status_codes=${status_code_expected}
244
245    IF  '${expected_result}' == 'success'
246        # Verify definition of report has attributes provided at the time of creation.
247        ${resp_report}=  Redfish.Get  ${metric_definition_base_uri}/${report_name}
248        ...  valid_status_codes=[${HTTP_OK}]
249        Should Be True  '${resp_report.dict["MetricReportDefinitionType"]}' == '${metric_definition_type}'
250        Should Be True  '${resp_report.dict["AppendLimit"]}' == '${AppendLimit}'
251        Should Be True  '${resp_report.dict["ReportActions"][0]}' == '${report_action}'
252        Should Be True
253        ...  '${resp_report.dict["Metrics"]}[0][MetricProperties][0]' == '${resp["MetricProperties"][0]}'
254    END
255
256    IF  ${delete_report} == ${True}
257       Delete All Telemetry Reports
258    END
259
260
261Delete All Telemetry Reports
262    [Documentation]  Delete all existing telemetry reports.
263
264    ${report_list}=  Redfish_Utils.Get Member List  /redfish/v1/TelemetryService/MetricReportDefinitions
265    FOR  ${report}  IN  @{report_list}
266      Redfish.Delete  ${report}  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
267    END
268