Replace deprecated datetime.utcnow()

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

Change-Id: I37aa282a3eb35f64ac3c0bc6e941b3138badceff
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
This commit is contained in:
Takashi Natsume
2024-10-01 00:36:55 +09:00
parent 5666bd0b61
commit 20c3119202
3 changed files with 5 additions and 14 deletions

View File

@@ -28,7 +28,7 @@ FIRST_LEASE = 'd1e43d6d-8f6f-4c2e-b0a9-2982b39dc698'
SECOND_LEASE = '424d21c3-45a2-448a-81ad-32eddc888375'
@mock.patch('blazarclient.v1.shell_commands.leases._utc_now', mock_time)
@mock.patch('oslo_utils.timeutils.utcnow', mock_time)
class CreateLeaseTestCase(tests.TestCase):
def setUp(self):

View File

@@ -20,6 +20,7 @@ import re
from oslo_serialization import jsonutils
from oslo_utils import strutils
from oslo_utils import timeutils
from blazarclient import command
from blazarclient import exception
@@ -64,16 +65,6 @@ CREATE_RESERVATION_KEYS = {
}
def _utc_now():
"""Wrap datetime.datetime.utcnow so it can be mocked in unit tests.
This is required because some of the tests require understanding the
'current time'; simply mocking utcnow() is made very difficult by
the many different ways the datetime package is used in this module.
"""
return datetime.datetime.utcnow()
class ListLeases(command.ListCommand):
"""Print a list of leases."""
resource = 'lease'
@@ -113,7 +104,7 @@ class CreateLeaseBase(command.CreateCommand):
json_indent = 4
log = logging.getLogger(__name__ + '.CreateLease')
default_start = 'now'
default_end = _utc_now() + datetime.timedelta(days=1)
default_end = timeutils.utcnow() + datetime.timedelta(days=1)
def get_parser(self, prog_name):
parser = super(CreateLeaseBase, self).get_parser(prog_name)
@@ -189,7 +180,7 @@ class CreateLeaseBase(command.CreateCommand):
raise exception.IncorrectLease
if parsed_args.start == 'now':
start = _utc_now()
start = timeutils.utcnow()
else:
start = parsed_args.start

View File

@@ -10,6 +10,6 @@ cliff!=2.9.0,>=2.8.0 # Apache-2.0
PrettyTable>=0.7.1 # BSD
oslo.i18n>=3.15.3 # Apache-2.0
oslo.log>=3.36.0 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0
oslo.utils>=7.0.0 # Apache-2.0
keystoneauth1>=3.4.0 # Apache-2.0
osc-lib>=1.3.0 # Apache-2.0