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
13Force 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
20
21*** Test Cases ***
22
23Verify Basic Telemetry Report Creation
24    [Documentation]  Verify basic telemetry report creations for different metrics.
25    [Tags]  Verify_Basic_Telemetry_Report_Creation
26    [Template]  Create Basic Telemetry Report
27
28    # Metric definition Metric ReportDefinition Type   Report Actions       Append Limit
29    total_power         OnRequest         LogToMetricReportsCollection
30    Battery_Voltage     Periodic          LogToMetricReportsCollection      100
31    Ambient_0_Temp      OnRequest         LogToMetricReportsCollection
32    proc0_core1_1_temp  Periodic          LogToMetricReportsCollection      500
33    PCIE_0_Temp         OnRequest         LogToMetricReportsCollection
34    dimm0_pmic_temp     Periodic          LogToMetricReportsCollection      1000
35    Relative_Humidity   OnRequest         LogToMetricReportsCollection
36    pcie_dcm0_power     Periodic          LogToMetricReportsCollection      32768
37    io_dcm0_power       OnRequest         LogToMetricReportsCollection
38
39
40Verify Error After Exceeding Maximum Report Creation
41    [Documentation]  Verify error while creating telemetry report more than max report limit.
42    [Tags]  Verify_Error_After_Exceeding_Maximum_Report_Creation
43
44    ${report_name}=  Set Variable  Testreport
45
46    # Create maximum number of reports.
47    ${resp}=  Redfish.Get Properties  /redfish/v1/TelemetryService
48    FOR  ${i}  IN RANGE  ${resp["MaxReports"]}
49        Create Basic Telemetry Report   total_power  Periodic  LogToMetricReportsCollection
50    END
51
52    # Attempt another report creation and it should fail.
53    Create Basic Telemetry Report   total_power  Periodic  LogToMetricReportsCollection  expected_result=fail
54
55    # Now delete the reports created.
56    Delete All Telemetry Reports
57
58
59*** Keywords ***
60
61Suite Setup Execution
62    [Documentation]  Do test case setup tasks.
63
64    Redfish.Login
65    Redfish Power On  stack_mode=skip
66
67
68Test Teardown Execution
69    [Documentation]  Do test teardown operation.
70
71    FFDC On Test Case Fail
72    Delete All Telemetry Reports
73
74
75Create Basic Telemetry Report
76    [Documentation]  Create a basic telemetry report with single metric.
77    [Arguments]  ${metric_definition_name}  ${metric_definition_type}
78    ...  ${report_action}  ${append_limit}=10  ${expected_result}=success
79
80    # Description of argument(s):
81    # metric_definition_name    Name of metric definition like Ambient_0_Temp.
82    # metric_definition_type    Name of telemetry report which needs to be created.
83    # report_action             Telemetry report action.
84    # append_limit              Append limit of the metric data in the report.
85    # expected_result           Expected result of report creation - success or fail.
86
87    ${resp}=  Redfish.Get Properties
88    ...  /redfish/v1/TelemetryService/MetricDefinitions/${metric_definition_name}
89    # Example of response from above Redfish GET request.
90    # "@odata.id": "/redfish/v1/TelemetryService/MetricDefinitions/Ambient_0_Temp",
91    # "@odata.type": "#MetricDefinition.v1_0_3.MetricDefinition",
92    # "Id": "Ambient_0_Temp",
93    # "IsLinear": true,
94    # "MaxReadingRange": 127.0,
95    # "MetricDataType": "Decimal",
96    # "MetricProperties": [
97    #     "/redfish/v1/Chassis/chassis/Sensors/temperature_Ambient_0_Temp"
98    # ],
99    # "MetricType": "Gauge",
100    # "MinReadingRange": -128.0,
101    # "Name": "Ambient_0_Temp",
102    # "Units": "Cel"
103
104    # Report name is from random generated string with length 16 which
105    # is enough to maintain uniqueness in report name.
106    ${report_name}=  Generate Random String  16  [NUMBERS]abcdef
107    ${body}=  Catenate  {"Id": "${report_name}",
108    ...  "MetricReportDefinitionType": "${metric_definition_type}",
109    ...  "Name": "Report",
110    ...  "ReportActions":["${report_action}"],
111    ...  "Metrics":[{"CollectionDuration": "PT30.000S",
112    ...  "MetricProperties":${resp["MetricProperties"]}}],
113    ...  "ReportUpdates": "AppendWrapsWhenFull",
114    ...  "AppendLimit": ${append_limit},
115    ...  "Schedule": {"RecurrenceInterval": "PT5.000S"}}
116
117    ${body}=  Replace String  ${body}  '  "
118    ${dict}  Evaluate  json.loads('''${body}''')  json
119
120    ${status_code_expected}=  Set Variable If
121    ...  '${expected_result}' == 'success'  [${HTTP_CREATED}]
122    ...  '${expected_result}' == 'fail'  [${HTTP_BAD_REQUEST}]
123
124    Redfish.Post  ${metric_definition_base_uri}  body=&{dict}
125     ...  valid_status_codes=${status_code_expected}
126
127    IF  '${expected_result}' == 'success'
128        # Verify definition of report has attributes provided at the time of creation.
129        ${resp_report}=  Redfish.Get  ${metric_definition_base_uri}/${report_name}
130        ...  valid_status_codes=[${HTTP_OK}]
131        Should Be True  '${resp_report.dict["MetricReportDefinitionType"]}' == '${metric_definition_type}'
132        Should Be True  '${resp_report.dict["AppendLimit"]}' == '${AppendLimit}'
133        Should Be True  '${resp_report.dict["ReportActions"][0]}' == '${report_action}'
134        Should Be True
135        ...  '${resp_report.dict["Metrics"]}[0][MetricProperties][0]' == '${resp["MetricProperties"][0]}'
136    END
137
138
139Delete All Telemetry Reports
140    [Documentation]  Delete all existing telemetry reports.
141
142    ${report_list}=  Redfish_Utils.Get Member List  /redfish/v1/TelemetryService/MetricReportDefinitions
143    FOR  ${report}  IN  @{report_list}
144      Redfish.Delete  ${report}  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
145    END
146