|
13 | 13 | from requests.exceptions import ConnectionError
|
14 | 14 | import tempfile
|
15 | 15 | from unittest import TestCase, mock
|
| 16 | +from decimal import Decimal |
16 | 17 |
|
17 | 18 | from openshift_metrics import utils, invoice
|
18 | 19 | import os
|
19 | 20 | from datetime import datetime, UTC
|
20 | 21 |
|
| 22 | +RATES = invoice.Rates( |
| 23 | + cpu = Decimal("0.013"), |
| 24 | + gpu_a100sxm4 = Decimal("2.078"), |
| 25 | + gpu_a100 = Decimal("1.803"), |
| 26 | + gpu_v100 = Decimal("1.214") |
| 27 | + ) |
| 28 | + |
21 | 29 | class TestGetNamespaceAnnotations(TestCase):
|
22 | 30 |
|
23 | 31 | @mock.patch('openshift_metrics.utils.requests.post')
|
@@ -241,7 +249,12 @@ def test_write_metrics_log(self, mock_gna):
|
241 | 249 | "2023-01,namespace2,namespace2,PI2,,,,,48,OpenShift GPUA100SXM4,2.078,99.74\n")
|
242 | 250 |
|
243 | 251 | with tempfile.NamedTemporaryFile(mode="w+") as tmp:
|
244 |
| - utils.write_metrics_by_namespace(test_metrics_dict, tmp.name, "2023-01") |
| 252 | + utils.write_metrics_by_namespace( |
| 253 | + condensed_metrics_dict=test_metrics_dict, |
| 254 | + file_name=tmp.name, |
| 255 | + report_month="2023-01", |
| 256 | + rates=RATES |
| 257 | + ) |
245 | 258 | self.assertEqual(tmp.read(), expected_output)
|
246 | 259 |
|
247 | 260 |
|
@@ -286,14 +299,22 @@ def test_write_metrics_by_namespace_decimal(self, mock_gna):
|
286 | 299 | "2023-01,namespace1,namespace1,PI1,,,,76,35,OpenShift CPU,0.013,0.46\n")
|
287 | 300 |
|
288 | 301 | with tempfile.NamedTemporaryFile(mode="w+") as tmp:
|
289 |
| - utils.write_metrics_by_namespace(test_metrics_dict, tmp.name, "2023-01") |
| 302 | + utils.write_metrics_by_namespace( |
| 303 | + condensed_metrics_dict=test_metrics_dict, |
| 304 | + file_name=tmp.name, |
| 305 | + report_month="2023-01", |
| 306 | + rates=RATES |
| 307 | + ) |
290 | 308 | self.assertEqual(tmp.read(), expected_output)
|
291 | 309 |
|
292 | 310 |
|
293 | 311 | class TestWriteMetricsWithIgnoreHours(TestCase):
|
294 | 312 | def setUp(self):
|
295 | 313 | """Creates a test dictionary with condensed data that can be used to test WriteMetricsByPod and WriteMetricsByNamespace"""
|
296 | 314 | start_dt = int(datetime.fromisoformat("2024-04-10T11:00:00Z").timestamp())
|
| 315 | + |
| 316 | + |
| 317 | + |
297 | 318 | self.ignore_times = [
|
298 | 319 | (
|
299 | 320 | datetime(2024, 4, 9, 11, 0, 0, tzinfo=UTC),
|
@@ -371,7 +392,11 @@ def test_write_metrics_by_namespace_with_ignore_hours(self, mock_gna):
|
371 | 392 |
|
372 | 393 | with tempfile.NamedTemporaryFile(mode="w+") as tmp:
|
373 | 394 | utils.write_metrics_by_namespace(
|
374 |
| - self.test_metrics_dict, tmp.name, "2023-01", self.ignore_times |
| 395 | + condensed_metrics_dict=self.test_metrics_dict, |
| 396 | + file_name=tmp.name, |
| 397 | + report_month="2023-01", |
| 398 | + rates=RATES, |
| 399 | + ignore_hours=self.ignore_times |
375 | 400 | )
|
376 | 401 | self.assertEqual(tmp.read(), expected_output)
|
377 | 402 |
|
|
0 commit comments