Skip to content

Commit 99960d1

Browse files
committed
Use builtin formatting for isoformat
1 parent 271f32c commit 99960d1

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

openshift_metrics/invoice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ def generate_invoice_rows(self, metadata: ReportMetadata) -> List[str]:
251251
cost = (rate * hours).quantize(Decimal(".01"), rounding=ROUND_HALF_UP)
252252
row = [
253253
metadata.report_month,
254-
metadata.report_start_time.strftime("%Y-%m-%d%H:%M:%SZ"),
255-
metadata.report_end_time.strftime("%Y-%m-%d%H:%M:%SZ"),
254+
metadata.report_start_time.isoformat(),
255+
metadata.report_end_time.isoformat(),
256256
self.project,
257257
self.project_id,
258258
"", # pi
@@ -265,7 +265,7 @@ def generate_invoice_rows(self, metadata: ReportMetadata) -> List[str]:
265265
su_type,
266266
rate,
267267
cost,
268-
metadata.generated_at.strftime("%Y-%m-%d%H:%M:%SZ"),
268+
metadata.generated_at.isoformat(),
269269
]
270270
rows.append(row)
271271
return rows

openshift_metrics/tests/test_utils.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ def test_write_metrics_log(self):
190190

191191
expected_output = (
192192
"Invoice Month,Report Start Time,Report End Time,Project - Allocation,Project - Allocation ID,Manager (PI),Cluster Name,Invoice Email,Invoice Address,Institution,Institution - Specific Code,SU Hours (GBhr or SUhr),SU Type,Rate,Cost,Generated At\n"
193-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace1,namespace1,,test-cluster,,,,,1128,OpenShift CPU,0.013,14.66,2023-01-0500:00:00Z\n"
194-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace2,namespace2,,test-cluster,,,,,96,OpenShift CPU,0.013,1.25,2023-01-0500:00:00Z\n"
195-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace2,namespace2,,test-cluster,,,,,48,OpenShift GPUA100,1.803,86.54,2023-01-0500:00:00Z\n"
196-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace2,namespace2,,test-cluster,,,,,48,OpenShift GPUA100SXM4,2.078,99.74,2023-01-0500:00:00Z\n"
193+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace1,namespace1,,test-cluster,,,,,1128,OpenShift CPU,0.013,14.66,2023-01-05T00:00:00+00:00\n"
194+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace2,namespace2,,test-cluster,,,,,96,OpenShift CPU,0.013,1.25,2023-01-05T00:00:00+00:00\n"
195+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace2,namespace2,,test-cluster,,,,,48,OpenShift GPUA100,1.803,86.54,2023-01-05T00:00:00+00:00\n"
196+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace2,namespace2,,test-cluster,,,,,48,OpenShift GPUA100SXM4,2.078,99.74,2023-01-05T00:00:00+00:00\n"
197197
)
198198

199199
with tempfile.NamedTemporaryFile(mode="w+") as tmp:
@@ -238,8 +238,8 @@ def test_write_metrics_for_vms(self):
238238

239239
expected_output = (
240240
"Invoice Month,Report Start Time,Report End Time,Project - Allocation,Project - Allocation ID,Manager (PI),Cluster Name,Invoice Email,Invoice Address,Institution,Institution - Specific Code,SU Hours (GBhr or SUhr),SU Type,Rate,Cost,Generated At\n"
241-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace1,namespace1,,test-cluster,,,,,24,OpenShift GPUA100SXM4,2.078,49.87,2023-01-0500:00:00Z\n"
242-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace1,namespace1,,test-cluster,,,,,24,OpenShift GPUH100,6.04,144.96,2023-01-0500:00:00Z\n"
241+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace1,namespace1,,test-cluster,,,,,24,OpenShift GPUA100SXM4,2.078,49.87,2023-01-05T00:00:00+00:00\n"
242+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace1,namespace1,,test-cluster,,,,,24,OpenShift GPUH100,6.04,144.96,2023-01-05T00:00:00+00:00\n"
243243
)
244244

245245
with tempfile.NamedTemporaryFile(mode="w+") as tmp:
@@ -338,10 +338,10 @@ def test_write_metrics_log(self):
338338

339339
expected_output = (
340340
"Invoice Month,Report Start Time,Report End Time,Project - Allocation,Project - Allocation ID,Manager (PI),Cluster Name,Invoice Email,Invoice Address,Institution,Institution - Specific Code,SU Hours (GBhr or SUhr),SU Type,Rate,Cost,Generated At\n"
341-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace2:noclass,namespace2:noclass,,test-cluster,,,,,96,OpenShift CPU,0.013,1.25,2023-01-0500:00:00Z\n"
342-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace2:math-201,namespace2:math-201,,test-cluster,,,,,96,OpenShift CPU,0.013,1.25,2023-01-0500:00:00Z\n"
343-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace2:math-201,namespace2:math-201,,test-cluster,,,,,24,OpenShift GPUA100,1.803,43.27,2023-01-0500:00:00Z\n"
344-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace2:cs-101,namespace2:cs-101,,test-cluster,,,,,48,OpenShift GPUA100SXM4,2.078,99.74,2023-01-0500:00:00Z\n"
341+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace2:noclass,namespace2:noclass,,test-cluster,,,,,96,OpenShift CPU,0.013,1.25,2023-01-05T00:00:00+00:00\n"
342+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace2:math-201,namespace2:math-201,,test-cluster,,,,,96,OpenShift CPU,0.013,1.25,2023-01-05T00:00:00+00:00\n"
343+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace2:math-201,namespace2:math-201,,test-cluster,,,,,24,OpenShift GPUA100,1.803,43.27,2023-01-05T00:00:00+00:00\n"
344+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace2:cs-101,namespace2:cs-101,,test-cluster,,,,,48,OpenShift GPUA100SXM4,2.078,99.74,2023-01-05T00:00:00+00:00\n"
345345
)
346346

347347
with tempfile.NamedTemporaryFile(mode="w+") as tmp:
@@ -386,7 +386,7 @@ def test_write_metrics_by_namespace_decimal(self):
386386

387387
expected_output = (
388388
"Invoice Month,Report Start Time,Report End Time,Project - Allocation,Project - Allocation ID,Manager (PI),Cluster Name,Invoice Email,Invoice Address,Institution,Institution - Specific Code,SU Hours (GBhr or SUhr),SU Type,Rate,Cost,Generated At\n"
389-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace1,namespace1,,test-cluster,,,,,35,OpenShift CPU,0.013,0.46,2023-01-0500:00:00Z\n"
389+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace1,namespace1,,test-cluster,,,,,35,OpenShift CPU,0.013,0.46,2023-01-05T00:00:00+00:00\n"
390390
)
391391

392392
with tempfile.NamedTemporaryFile(mode="w+") as tmp:
@@ -472,9 +472,9 @@ def setUp(self):
472472
def test_write_metrics_by_namespace_with_ignore_hours(self):
473473
expected_output = (
474474
"Invoice Month,Report Start Time,Report End Time,Project - Allocation,Project - Allocation ID,Manager (PI),Cluster Name,Invoice Email,Invoice Address,Institution,Institution - Specific Code,SU Hours (GBhr or SUhr),SU Type,Rate,Cost,Generated At\n"
475-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace1,namespace1,,test-cluster,,,,,12,OpenShift CPU,0.013,0.16,2023-01-0500:00:00Z\n"
476-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace2,namespace2,,test-cluster,,,,,170,OpenShift CPU,0.013,2.21,2023-01-0500:00:00Z\n"
477-
"2023-01,2023-01-0100:00:00Z,2023-01-0300:00:00Z,namespace2,namespace2,,test-cluster,,,,,37,OpenShift GPUA100SXM4,2.078,76.89,2023-01-0500:00:00Z\n"
475+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace1,namespace1,,test-cluster,,,,,12,OpenShift CPU,0.013,0.16,2023-01-05T00:00:00+00:00\n"
476+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace2,namespace2,,test-cluster,,,,,170,OpenShift CPU,0.013,2.21,2023-01-05T00:00:00+00:00\n"
477+
"2023-01,2023-01-01T00:00:00+00:00,2023-01-03T00:00:00+00:00,namespace2,namespace2,,test-cluster,,,,,37,OpenShift GPUA100SXM4,2.078,76.89,2023-01-05T00:00:00+00:00\n"
478478
)
479479

480480
with tempfile.NamedTemporaryFile(mode="w+") as tmp:

0 commit comments

Comments
 (0)