blob: 921737b71d99ea5de94436b17d8b615aa1116b3a [file] [log] [blame]
Wludzik, Jozef405c1e42021-01-28 16:24:27 +01001import time
2
Patrick Williams89cf7d72022-12-05 07:59:22 -06003import pytest
4from redfish_requests import Duration, RedfishHttpStatus
5
Wludzik, Jozef405c1e42021-01-28 16:24:27 +01006
7def test_get_telemetry_service(redfish):
8 r = redfish.get(redfish.telemetry_service_path)
Patrick Williams89cf7d72022-12-05 07:59:22 -06009 assert r["Status"]["State"] == "Enabled", "Invalid status of service"
10 assert (
11 Duration.to_seconds(r["MinCollectionInterval"]) > 0
12 ), "Invalid duration format"
13 assert r["MaxReports"] > 0, "Invalid count of max reports"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010014
15
16def test_get_metric_definition_collection(redfish):
17 r = redfish.get(redfish.metric_definition_path)
Patrick Williams89cf7d72022-12-05 07:59:22 -060018 assert "Members" in r, "Missing members property"
19 assert "Members@odata.count" in r, "Missing members count property"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010020
21
22def test_verify_metric_definition_members_if_contains_metrics(redfish):
23 r = redfish.get(redfish.metric_definition_path)
Patrick Williams89cf7d72022-12-05 07:59:22 -060024 for m in r["Members"]:
25 path = m["@odata.id"]
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010026 metricDefinition = redfish.get(path)
Patrick Williams89cf7d72022-12-05 07:59:22 -060027 assert "MetricProperties" in metricDefinition, "Missing metrics"
28 assert len(metricDefinition["MetricProperties"]) > 0, "Missing metrics"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010029
30
31def test_get_metric_definition_that_not_exist_expect_not_found(redfish):
Patrick Williams89cf7d72022-12-05 07:59:22 -060032 redfish.get(
33 f"{redfish.metric_definition_path}/NotExisting",
34 code=RedfishHttpStatus.not_found,
35 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010036
37
38def test_get_metric_report_definition_collection(redfish):
39 r = redfish.get(redfish.metric_report_definition_path)
Patrick Williams89cf7d72022-12-05 07:59:22 -060040 assert "Members" in r, "Missing members property"
41 assert "Members@odata.count" in r, "Missing members count property"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010042
43
Patrick Williams89cf7d72022-12-05 07:59:22 -060044def test_get_metric_report_definition_that_not_exist_expect_not_found(redfish):
45 redfish.get(
46 f"{redfish.metric_report_definition_path}/NotExisting",
47 code=RedfishHttpStatus.not_found,
48 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010049
50
51def test_get_metric_report_collection(redfish):
52 r = redfish.get(redfish.metric_report_path)
Patrick Williams89cf7d72022-12-05 07:59:22 -060053 assert "Members" in r, "Missing members property"
54 assert "Members@odata.count" in r, "Missing members count property"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010055
56
57def test_get_metric_report_that_not_exist_expect_not_found(redfish):
Patrick Williams89cf7d72022-12-05 07:59:22 -060058 redfish.get(
59 f"{redfish.metric_report_path}/NotExisting",
60 code=RedfishHttpStatus.not_found,
61 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010062
63
64def test_post_report_definition_with_empty_body_expect_bad_request(redfish):
Patrick Williams89cf7d72022-12-05 07:59:22 -060065 redfish.post(
66 redfish.metric_report_definition_path,
67 body={},
68 code=RedfishHttpStatus.bad_request,
69 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010070
71
72def test_post_report_definition_with_some_body_expect_bad_request(redfish):
Patrick Williams89cf7d72022-12-05 07:59:22 -060073 redfish.post(
74 redfish.metric_report_definition_path,
75 body={"key": "value"},
76 code=RedfishHttpStatus.bad_request,
77 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010078
79
80def test_delete_non_exisiting_metric_report_definition(redfish):
81 redfish.delete(
Patrick Williams89cf7d72022-12-05 07:59:22 -060082 f"{redfish.metric_report_definition_path}/NonExisitingReport",
83 code=RedfishHttpStatus.not_found,
84 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010085
86
87def test_add_report(redfish, report_definitions):
Patrick Williams89cf7d72022-12-05 07:59:22 -060088 id = "Test"
89 report_definitions.add_report(id)
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010090 assert 1 == len(report_definitions.get_collection())
Patrick Williams89cf7d72022-12-05 07:59:22 -060091 r = redfish.get(f"{redfish.metric_report_definition_path}/{id}")
92 assert r["Id"] == id, "Invalid Id, different then requested"
93 r = redfish.get(f"{redfish.metric_report_path}/{id}")
94 assert r["Id"] == id, "Invalid Id, different then requested"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +010095
96
97def test_add_report_above_max_report_expect_bad_request(
Patrick Williams89cf7d72022-12-05 07:59:22 -060098 telemetry, report_definitions
99):
100 id = "Test"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100101 for i in range(telemetry.max_reports):
102 report_definitions.add_report(id + str(i))
103 assert telemetry.max_reports == len(report_definitions.get_collection())
Patrick Williams89cf7d72022-12-05 07:59:22 -0600104 report_definitions.add_report(
105 id + str(telemetry.max_reports),
106 metrics=[],
107 interval=telemetry.min_interval,
108 code=RedfishHttpStatus.bad_request,
109 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100110
111
112def test_add_report_long_name(report_definitions):
Patrick Williams89cf7d72022-12-05 07:59:22 -0600113 report_definitions.add_report("Test" * 65)
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100114
115
116def test_add_report_twice_expect_bad_request(report_definitions):
Patrick Williams89cf7d72022-12-05 07:59:22 -0600117 report_definitions.add_report("Test")
118 report_definitions.add_report("Test", code=RedfishHttpStatus.bad_request)
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100119
120
121@pytest.mark.parametrize(
Patrick Williams89cf7d72022-12-05 07:59:22 -0600122 "actions",
123 [
124 [],
125 ["RedfishEvent"],
126 ["LogToMetricReportsCollection"],
127 ["RedfishEvent", "LogToMetricReportsCollection"],
128 ],
129)
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100130def test_add_report_with_actions(actions, redfish, report_definitions):
Patrick Williams89cf7d72022-12-05 07:59:22 -0600131 report_definitions.add_report("Test", actions=actions)
132 r = redfish.get(f"{redfish.metric_report_definition_path}/Test")
133 assert (
134 r["ReportActions"] == actions
135 ), "Invalid actions, different then requested"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100136
137
138@pytest.mark.parametrize(
Patrick Williams89cf7d72022-12-05 07:59:22 -0600139 "invalid_actions",
140 [
141 ["NonExisting"],
142 ["RedfishEvent", "Partially"],
143 ["LogToMetricNotThisOne"],
144 ],
145)
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100146def test_add_report_with_invalid_actions_expect_bad_request(
Patrick Williams89cf7d72022-12-05 07:59:22 -0600147 invalid_actions, report_definitions
148):
149 report_definitions.add_report(
150 "Test", actions=invalid_actions, code=RedfishHttpStatus.bad_request
151 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100152
153
Patrick Williams89cf7d72022-12-05 07:59:22 -0600154@pytest.mark.parametrize("invalid_id", ["test_-", "t t", "T.T", "T,t", "T:t"])
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100155def test_add_report_with_invalid_id_expect_bad_request(
Patrick Williams89cf7d72022-12-05 07:59:22 -0600156 invalid_id, report_definitions
157):
158 report_definitions.add_report(
159 invalid_id, code=RedfishHttpStatus.bad_request
160 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100161
162
163def test_add_report_with_metric(redfish, telemetry, report_definitions):
164 if len(telemetry.metrics) <= 0:
Patrick Williams89cf7d72022-12-05 07:59:22 -0600165 pytest.skip("Redfish has no sensor available")
166 metric = {"MetricId": "Id1", "MetricProperties": [telemetry.metrics[0]]}
167 report_definitions.add_report("Test", metrics=[metric])
168 r = redfish.get(redfish.metric_report_definition_path + "/Test")
169 assert len(r["Metrics"]) == 1, "Invalid Metrics, different then requested"
170 assert (
171 r["Metrics"][0]["MetricId"] == metric["MetricId"]
172 ), "Invalid MetricId, different then requested"
173 assert (
174 r["Metrics"][0]["MetricProperties"] == metric["MetricProperties"]
175 ), "Invalid MetricProperties, different then requested"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100176
177
178def test_add_report_with_invalid_metric_expect_bad_request(report_definitions):
179 metric = {
Patrick Williams89cf7d72022-12-05 07:59:22 -0600180 "MetricId": "Id1",
181 "MetricProperties": [
182 "/redfish/v1/Chassis/chassis/Sensors/NonExisting/Reading"
183 ],
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100184 }
Patrick Williams89cf7d72022-12-05 07:59:22 -0600185 report_definitions.add_report(
186 "Test", metrics=[metric], code=RedfishHttpStatus.bad_request
187 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100188
189
190def test_add_report_with_many_metrics(redfish, telemetry, report_definitions):
191 if len(telemetry.metrics) <= 0:
Patrick Williams89cf7d72022-12-05 07:59:22 -0600192 pytest.skip("Redfish has no sensor available")
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100193 metrics = []
194 for i, prop in enumerate(telemetry.metrics):
Patrick Williams89cf7d72022-12-05 07:59:22 -0600195 metrics.append({"MetricId": f"Id{str(i)}", "MetricProperties": [prop]})
196 report_definitions.add_report("Test", metrics=metrics)
197 r = redfish.get(redfish.metric_report_definition_path + "/Test")
198 assert len(r["Metrics"]) == len(
199 telemetry.metrics
200 ), "Invalid Metrics, different then requested"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100201
202
203def test_add_report_on_request_with_metric_expect_updated_metric_report(
Patrick Williams89cf7d72022-12-05 07:59:22 -0600204 redfish, telemetry, report_definitions
205):
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100206 if len(telemetry.metrics) <= 0:
Patrick Williams89cf7d72022-12-05 07:59:22 -0600207 pytest.skip("Redfish has no sensor available")
208 metric = {"MetricId": "Id1", "MetricProperties": [telemetry.metrics[0]]}
209 report_definitions.add_report("Test", metrics=[metric], type="OnRequest")
210 r = redfish.get(redfish.metric_report_path + "/Test")
211 assert len(r["MetricValues"]) > 0, "Missing MetricValues"
212 metric_value = r["MetricValues"][0]
213 assert metric_value["MetricValue"], "Missing MetricValues"
214 assert (
215 metric_value["MetricId"] == metric["MetricId"]
216 ), "Different Id then set in request"
217 assert (
218 metric_value["MetricProperty"] == metric["MetricProperties"][0]
219 ), "Different MetricProperty then set in request"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100220
221
222def test_add_report_periodic_with_metric_expect_updated_metric_report(
Patrick Williams89cf7d72022-12-05 07:59:22 -0600223 redfish, telemetry, report_definitions
224):
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100225 if len(telemetry.metrics) <= 0:
Patrick Williams89cf7d72022-12-05 07:59:22 -0600226 pytest.skip("Redfish has no sensor available")
227 metric = {"MetricId": "Id1", "MetricProperties": [telemetry.metrics[0]]}
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100228 report_definitions.add_report(
Patrick Williams89cf7d72022-12-05 07:59:22 -0600229 "Test",
230 metrics=[metric],
231 type="Periodic",
232 interval=Duration.to_iso8061(telemetry.min_interval),
233 )
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100234 time.sleep(telemetry.min_interval + 1)
Patrick Williams89cf7d72022-12-05 07:59:22 -0600235 r = redfish.get(redfish.metric_report_path + "/Test")
236 assert len(r["MetricValues"]) > 0, "Missing MetricValues"
237 metric_value = r["MetricValues"][0]
238 assert metric_value["MetricValue"], "Missing MetricValues"
239 assert (
240 metric_value["MetricId"] == metric["MetricId"]
241 ), "Different Id then set in request"
242 assert (
243 metric_value["MetricProperty"] == metric["MetricProperties"][0]
244 ), "Different MetricProperty then set in request"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100245
246
Patrick Williams89cf7d72022-12-05 07:59:22 -0600247@pytest.mark.parametrize("interval", [10, 60, 2400, 90000])
248def test_add_report_check_if_duration_is_set(
249 interval, redfish, telemetry, report_definitions
250):
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100251 if interval < telemetry.min_interval:
Patrick Williams89cf7d72022-12-05 07:59:22 -0600252 pytest.skip("Interval is below minimal acceptable value, skipping")
253 id = f"Test{str(interval)}"
254 report_definitions.add_report(
255 id, type="Periodic", interval=Duration.to_iso8061(interval)
256 )
257 r = redfish.get(f"{redfish.metric_report_definition_path}/{id}")
258 assert r["Schedule"]["RecurrenceInterval"], "Missing RecurrenceInterval"
259 r_interval = Duration.to_seconds(r["Schedule"]["RecurrenceInterval"])
260 assert interval == r_interval, "Invalid interval, different then requested"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100261
262
263@pytest.mark.parametrize(
Patrick Williams2d5404f2022-12-08 06:18:23 -0600264 "invalid", ["50000", "P12ST", "PT12S12", "PPPPD222T222H222M222.222S"]
Patrick Williams89cf7d72022-12-05 07:59:22 -0600265)
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100266def test_add_report_with_invalid_duration_response_bad_request(
Patrick Williams89cf7d72022-12-05 07:59:22 -0600267 invalid, report_definitions
268):
269 r = report_definitions.add_report(
270 "Test",
271 type="Periodic",
272 interval=invalid,
273 code=RedfishHttpStatus.bad_request,
274 )
275 assert r["error"]["@Message.ExtendedInfo"][
276 0
277 ], "Wrong response, not an error"
278 info = r["error"]["@Message.ExtendedInfo"][0]
279 assert (
280 "RecurrenceInterval" in info["MessageArgs"]
281 ), 'Wrong response, should contain "RecurrenceInterval"'
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100282
283
284def test_stress_add_reports_with_many_metrics_check_metric_reports(
Patrick Williams89cf7d72022-12-05 07:59:22 -0600285 redfish, telemetry, report_definitions
286):
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100287 if len(telemetry.metrics) <= 0:
Patrick Williams89cf7d72022-12-05 07:59:22 -0600288 pytest.skip("Redfish has no sensor available")
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100289 metrics = []
290 for i, prop in enumerate(telemetry.metrics):
Patrick Williams89cf7d72022-12-05 07:59:22 -0600291 metrics.append({"MetricId": f"Id{str(i)}", "MetricProperties": [prop]})
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100292 for i in range(telemetry.max_reports):
Patrick Williams89cf7d72022-12-05 07:59:22 -0600293 report_definitions.add_report(f"Test{str(i)}", metrics=metrics)
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100294 for i in range(telemetry.max_reports):
Patrick Williams89cf7d72022-12-05 07:59:22 -0600295 r = redfish.get(
296 f"{redfish.metric_report_definition_path}/Test{str(i)}"
297 )
298 assert len(r["Metrics"]) == len(
299 telemetry.metrics
300 ), "Invalid Metrics, different then requested"
Wludzik, Jozef405c1e42021-01-28 16:24:27 +0100301 for i in range(telemetry.max_reports):
Patrick Williams89cf7d72022-12-05 07:59:22 -0600302 r = redfish.get(f"{redfish.metric_report_path}/Test{str(i)}")
303 assert len(r["MetricValues"]) > 0, "Missing MetricValues"