Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use timezone.utc instead of datetime.UTC for backwards compatibility #303

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ipahealthcheck/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import traceback
import warnings

from datetime import datetime, UTC
from datetime import datetime, timezone

from ipahealthcheck.core.config import read_config
from ipahealthcheck.core.exceptions import TimeoutError
Expand Down Expand Up @@ -49,7 +49,7 @@ def signal_handler(signum, frame):
raise TimeoutError('Request timed out')

# manually calculate duration when we create results of our own
start = datetime.now(tz=UTC)
start = datetime.now(tz=timezone.utc)
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(timeout)
try:
Expand Down
10 changes: 5 additions & 5 deletions src/ipahealthcheck/core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

import uuid
from datetime import datetime, UTC
from datetime import datetime, timezone
from functools import wraps

from ipahealthcheck.core.constants import getLevelName, getLevel
Expand All @@ -13,10 +13,10 @@ def duration(f):
"""Compute the duration of execution"""
@wraps(f)
def wrapper(*args, **kwds):
start = datetime.now(tz=UTC)
start = datetime.now(tz=timezone.utc)
end = None
for result in f(*args, **kwds):
end = datetime.now(tz=UTC)
end = datetime.now(tz=timezone.utc)
dur = end - start
result.duration = '%6.6f' % dur.total_seconds()
yield result
Expand Down Expand Up @@ -132,7 +132,7 @@ def __init__(self, plugin, result, source=None, check=None,
start=None, duration=None, when=None, **kw):
self.result = result
self.kw = kw
self.when = when or generalized_time(datetime.now(UTC))
self.when = when or generalized_time(datetime.now(timezone.utc))
self.duration = duration
self.uuid = str(uuid.uuid4())
if None not in (check, source):
Expand All @@ -144,7 +144,7 @@ def __init__(self, plugin, result, source=None, check=None,
self.check = plugin.__class__.__name__
self.source = plugin.__class__.__module__
if start is not None:
dur = datetime.now(tz=UTC) - start
dur = datetime.now(tz=timezone.utc) - start
self.duration = '%6.6f' % dur.total_seconds()

assert getLevelName(result) is not None
Expand Down
6 changes: 3 additions & 3 deletions src/ipahealthcheck/ipa/certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
from __future__ import division

from datetime import datetime, timezone, timedelta, UTC
from datetime import datetime, timezone, timedelta
import itertools
from inspect import signature
import logging
Expand Down Expand Up @@ -378,9 +378,9 @@ def check(self):
'storage type: {store}')
continue

now = datetime.now(tz=UTC)
now = datetime.now(tz=timezone.utc)
# Older versions of IPA provide naive timestamps
notafter = cert.not_valid_after.replace(tzinfo=UTC)
notafter = cert.not_valid_after.replace(tzinfo=timezone.utc)

if now > notafter:
yield Result(self, constants.ERROR,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_ipa_certfile_expiration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
CERT_EXPIRATION_DAYS,
)

from datetime import datetime, timedelta, UTC
from datetime import datetime, timedelta, timezone


class IPACertificate:
Expand All @@ -40,7 +40,7 @@ class TestIPACertificateFile(BaseTest):
def test_certfile_expiration(self, mock_load_cert):
set_requests(remove=1)

cert = IPACertificate(not_valid_after=datetime.now(tz=UTC) +
cert = IPACertificate(not_valid_after=datetime.now(tz=timezone.utc) +
timedelta(days=CERT_EXPIRATION_DAYS))
mock_load_cert.return_value = cert

Expand All @@ -63,7 +63,7 @@ def test_certfile_expiration(self, mock_load_cert):
def test_certfile_expiration_warning(self, mock_load_cert):
set_requests(remove=1)

cert = IPACertificate(not_valid_after=datetime.now(tz=UTC) +
cert = IPACertificate(not_valid_after=datetime.now(tz=timezone.utc) +
timedelta(days=7))
mock_load_cert.return_value = cert

Expand All @@ -87,7 +87,7 @@ def test_certfile_expiration_warning(self, mock_load_cert):
def test_certfile_expiration_expired(self, mock_load_cert):
set_requests(remove=1)

cert = IPACertificate(not_valid_after=datetime.now(tz=UTC) +
cert = IPACertificate(not_valid_after=datetime.now(tz=timezone.utc) +
timedelta(days=-100))
mock_load_cert.return_value = cert

Expand Down