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    END
53
54    # Attempt another report creation and it should fail.
55    Create Basic Telemetry Report
56    ...   total power  Periodic  LogToMetricReportsCollection  expected_result=fail
57
58    # Now delete the reports created.
59    Delete All Telemetry Reports
60
61
62Verify Basic Telemetry Report Creation For PCIE
63     [Documentation]  Verify basic telemetry report creations for PCIE.
64     [Tags]  Verify_Basic_Telemetry_Report_Creation_For_PCIE
65
66     Create Basic Telemetry Report
67     ...  pcie temperature  OnRequest  LogToMetricReportsCollection
68
69
70*** Keywords ***
71
72Suite Setup Execution
73    [Documentation]  Do test case setup tasks.
74
75    Redfish.Login
76    Redfish Power On  stack_mode=skip
77    ${metric_definitions_list}=
78    ...  Redfish_Utils.Get Member List  /redfish/v1/TelemetryService/MetricDefinitions
79
80    # Create a dictionary of ordinary english naming and actual naming of
81    # telemtry definition.
82    ${english_actual_teleDef}=   Create Dictionary
83
84    Set Suite Variable  ${english_actual_teleDef}
85    Set Suite Variable  ${metric_definitions_list}
86
87    Set To Dictionary  ${english_actual_teleDef}  invalid value  invalid_value
88
89    # Find and collect actual telemetry definitions.
90    FOR    ${key}  IN  @{user_tele_def.keys()}
91      Add To Telemetry definition Record   ${key}   ${user_tele_def['${key}']}
92    END
93
94
95Add To Telemetry definition Record
96    [Documentation]  Find actual telemetry definitions available and store.
97    ...              Definitions are stored in a dictionary as key and value
98    ...              as described in argument documentation.
99    [Arguments]  ${key}  ${value}
100
101    # Description of argument(s):
102    # key       Name of metric definition in plain english.
103    #           Example: ambient temperature
104    # value     Equivalent regex expression of telemetry definition.
105    #           Example:  Ambient.*Temp
106
107    FOR  ${item}  IN  @{metric_definitions_list}
108      ${regex_matching_output}=  Get Regexp Matches  ${item}  ${value}
109      IF  ${regex_matching_output} != []
110          Set To Dictionary  ${english_actual_teleDef}  ${key}=${regex_matching_output}[0]
111          Exit For Loop
112      END
113    END
114
115
116Test Teardown Execution
117    [Documentation]  Do test teardown operation.
118
119    FFDC On Test Case Fail
120    Delete All Telemetry Reports
121
122
123Create Basic Telemetry Report
124    [Documentation]  Create a basic telemetry report with single metric.
125    [Arguments]  ${metric_definition_name}  ${metric_definition_type}
126    ...  ${report_action}  ${append_limit}=10  ${expected_result}=success
127
128    # Description of argument(s):
129    # metric_definition_name    Name of metric definition like Ambient_0_Temp.
130    # metric_definition_type    Name of telemetry report which needs to be created.
131    # report_action             Telemetry report action.
132    # append_limit              Append limit of the metric data in the report.
133    # expected_result           Expected result of report creation - success or fail.
134
135    ${metric_definition_name}=  Set Variable  ${english_actual_teleDef}[${metric_definition_name}]
136    ${resp}=  Redfish.Get Properties
137    ...  /redfish/v1/TelemetryService/MetricDefinitions/${metric_definition_name}
138    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
139    ${telemetry_data_unavailable}=  Run Keyword And Return Status  Should Contain  ${resp}  error
140    IF  ${telemetry_data_unavailable} == ${True}
141        ${metricProperties}=  Set Variable  ""
142    ELSE
143        ${metricProperties}=  Set Variable  ${resp["MetricProperties"]}
144    END
145    # Example of response from above Redfish GET request.
146    # "@odata.id": "/redfish/v1/TelemetryService/MetricDefinitions/Ambient_0_Temp",
147    # "@odata.type": "#MetricDefinition.v1_0_3.MetricDefinition",
148    # "Id": "Ambient_0_Temp",
149    # "IsLinear": true,
150    # "MaxReadingRange": 127.0,
151    # "MetricDataType": "Decimal",
152    # "MetricProperties": [
153    #     "/redfish/v1/Chassis/chassis/Sensors/temperature_Ambient_0_Temp"
154    # ],
155    # "MetricType": "Gauge",
156    # "MinReadingRange": -128.0,
157    # "Name": "Ambient_0_Temp",
158    # "Units": "Cel"
159
160    # Report name is from random generated string with length 16 which
161    # is enough to maintain uniqueness in report name.
162    ${report_name}=  Generate Random String  16  [NUMBERS]abcdef
163    ${body}=  Catenate  {"Id": "${report_name}",
164    ...  "MetricReportDefinitionType": "${metric_definition_type}",
165    ...  "Name": "Report",
166    ...  "ReportActions":["${report_action}"],
167    ...  "Metrics":[{"CollectionDuration": "PT30.000S",
168    ...  "MetricProperties":${metricProperties}}],
169    ...  "ReportUpdates": "AppendWrapsWhenFull",
170    ...  "AppendLimit": ${append_limit},
171    ...  "Schedule": {"RecurrenceInterval": "PT5.000S"}}
172
173    ${body}=  Replace String  ${body}  '  "
174    ${dict}  Evaluate  json.loads('''${body}''')  json
175
176    ${status_code_expected}=  Set Variable If
177    ...  '${expected_result}' == 'success'  [${HTTP_CREATED}]
178    ...  '${expected_result}' == 'fail'  [${HTTP_BAD_REQUEST}]
179
180    Redfish.Post  ${metric_definition_base_uri}  body=&{dict}
181     ...  valid_status_codes=${status_code_expected}
182
183    IF  '${expected_result}' == 'success'
184        # Verify definition of report has attributes provided at the time of creation.
185        ${resp_report}=  Redfish.Get  ${metric_definition_base_uri}/${report_name}
186        ...  valid_status_codes=[${HTTP_OK}]
187        Should Be True  '${resp_report.dict["MetricReportDefinitionType"]}' == '${metric_definition_type}'
188        Should Be True  '${resp_report.dict["AppendLimit"]}' == '${AppendLimit}'
189        Should Be True  '${resp_report.dict["ReportActions"][0]}' == '${report_action}'
190        Should Be True
191        ...  '${resp_report.dict["Metrics"]}[0][MetricProperties][0]' == '${resp["MetricProperties"][0]}'
192    END
193
194
195Delete All Telemetry Reports
196    [Documentation]  Delete all existing telemetry reports.
197
198    ${report_list}=  Redfish_Utils.Get Member List  /redfish/v1/TelemetryService/MetricReportDefinitions
199    FOR  ${report}  IN  @{report_list}
200      Redfish.Delete  ${report}  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
201    END
202