Replace deprecated datetime.utcnow()

The datetime.utcnow() is deprecated in Python 3.12.
Replace datetime.utcnow() with oslo_utils.utcnow().
This bumps oslo.utils to 7.0.0.

Change-Id: I79ca5addecaf70aed468fbf93feb4ee629f7b7f8
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
This commit is contained in:
Takashi Natsume 2024-09-30 00:08:02 +09:00
parent 82b37d1406
commit da14e29722
3 changed files with 8 additions and 8 deletions

View File

@ -13,7 +13,7 @@ oslo.config>=5.2.0 # Apache-2.0
oslo.log>=3.36.0 # Apache-2.0
stestr>=1.0.0 # Apache-2.0
oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
oslo.utils>=4.7.0 # Apache-2.0
oslo.utils>=7.0.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
PyYAML>=3.12 # MIT
python-subunit>=1.0.0 # Apache-2.0/BSD

View File

@ -21,6 +21,7 @@ import re
from urllib import parse as urlparse
from oslo_log import log as logging
from oslo_utils import timeutils
from tempest.lib import exceptions
from tempest.lib.services.identity.v2 import token_client as json_v2id
@ -419,8 +420,7 @@ class KeystoneV2AuthProvider(KeystoneAuthProvider):
def is_expired(self, auth_data):
_, access = auth_data
expiry = self._parse_expiry_time(access['token']['expires'])
return (expiry - self.token_expiry_threshold <=
datetime.datetime.utcnow())
return (expiry - self.token_expiry_threshold <= timeutils.utcnow())
class KeystoneV3AuthProvider(KeystoneAuthProvider):
@ -595,8 +595,7 @@ class KeystoneV3AuthProvider(KeystoneAuthProvider):
def is_expired(self, auth_data):
_, access = auth_data
expiry = self._parse_expiry_time(access['expires_at'])
return (expiry - self.token_expiry_threshold <=
datetime.datetime.utcnow())
return (expiry - self.token_expiry_threshold <= timeutils.utcnow())
def is_identity_version_supported(identity_version):

View File

@ -17,6 +17,7 @@ import copy
import datetime
import fixtures
from oslo_utils import timeutils
import testtools
from tempest.lib import auth
@ -509,15 +510,15 @@ class TestKeystoneV2AuthProvider(BaseAuthTestsSetUp):
self._test_base_url_helper(expected, filters, ('token', auth_data))
def test_token_not_expired(self):
expiry_data = datetime.datetime.utcnow() + datetime.timedelta(days=1)
expiry_data = timeutils.utcnow() + datetime.timedelta(days=1)
self._verify_expiry(expiry_data=expiry_data, should_be_expired=False)
def test_token_expired(self):
expiry_data = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
expiry_data = timeutils.utcnow() - datetime.timedelta(hours=1)
self._verify_expiry(expiry_data=expiry_data, should_be_expired=True)
def test_token_not_expired_to_be_renewed(self):
expiry_data = (datetime.datetime.utcnow() +
expiry_data = (timeutils.utcnow() +
self.auth_provider.token_expiry_threshold / 2)
self._verify_expiry(expiry_data=expiry_data, should_be_expired=True)