]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use UTC timezone when handling keys in kasp test library
authorNicki Křížek <nicki@isc.org>
Mon, 21 Oct 2024 10:08:52 +0000 (12:08 +0200)
committerNicki Křížek <nicki@isc.org>
Tue, 22 Oct 2024 07:17:19 +0000 (09:17 +0200)
When working with key timestamps, ensure we correctly set the UTC
timezone in order for the tests to work consistently regardless of the
local time setting.

bin/tests/system/isctest/kasp.py

index ea1ec9878e7d33d01529637ccc4311da8e0a2096..64029984713f47ba24fcc074e761d78390aa4b22 100644 (file)
@@ -17,8 +17,7 @@ import subprocess
 import time
 from typing import Optional, Union
 
-from datetime import datetime
-from datetime import timedelta
+from datetime import datetime, timedelta, timezone
 
 import dns
 import isctest.log
@@ -54,7 +53,9 @@ class KeyTimingMetadata:
     def __init__(self, timestamp: str):
         if int(timestamp) <= 0:
             raise ValueError(f'invalid timing metadata value: "{timestamp}"')
-        self.value = datetime.strptime(timestamp, self.FORMAT)
+        self.value = datetime.strptime(timestamp, self.FORMAT).replace(
+            tzinfo=timezone.utc
+        )
 
     def __repr__(self):
         return self.value.strftime(self.FORMAT)
@@ -95,7 +96,7 @@ class KeyTimingMetadata:
     @staticmethod
     def now() -> "KeyTimingMetadata":
         result = KeyTimingMetadata.__new__(KeyTimingMetadata)
-        result.value = datetime.now()
+        result.value = datetime.now(timezone.utc)
         return result