Replace deprecated functions in datetime

The datetime.utcfromtimestamp() and datetime.utcnow()
are deprecated in Python 3.12.
Replace datetime.utcfromtimestamp() with datetime.fromtimestamp().
Replace datetime.utcnow() with oslo_utils.timeutils.utcnow() or
datetime.now().
This bumps oslo.utils to 7.0.0.

Change-Id: I0fc609cbc5f9341210097920ca1eb8e43875449c
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
This commit is contained in:
Takashi Natsume
2024-10-01 20:38:23 +09:00
parent 35c6ca5e20
commit aae3726eaf
7 changed files with 13 additions and 10 deletions

View File

@@ -102,8 +102,9 @@ class ViewBuilder(common.ViewBuilder):
return limits return limits
def _build_rate_limit(self, rate_limit): def _build_rate_limit(self, rate_limit):
_get_utc = datetime.datetime.utcfromtimestamp next_avail = datetime.datetime.fromtimestamp(
next_avail = _get_utc(rate_limit["resetTime"]) rate_limit["resetTime"],
tz=datetime.timezone.utc).replace(tzinfo=None)
return { return {
"verb": rate_limit["verb"], "verb": rate_limit["verb"],
"value": rate_limit["value"], "value": rate_limit["value"],

View File

@@ -2882,7 +2882,9 @@ class NetAppCmodeFileStorageLibrary(object):
# than twice the replication schedule. # than twice the replication schedule.
if (last_update_timestamp and if (last_update_timestamp and
(timeutils.is_older_than( (timeutils.is_older_than(
datetime.datetime.utcfromtimestamp(last_update_timestamp) datetime.datetime.fromtimestamp(
last_update_timestamp,
tz=datetime.timezone.utc).replace(tzinfo=None)
.isoformat(), (2 * self._snapmirror_schedule)))): .isoformat(), (2 * self._snapmirror_schedule)))):
return constants.REPLICA_STATE_OUT_OF_SYNC return constants.REPLICA_STATE_OUT_OF_SYNC

View File

@@ -37,7 +37,7 @@ class MessageApiTest(test.TestCase):
@mock.patch.object(timeutils, 'utcnow') @mock.patch.object(timeutils, 'utcnow')
def test_create(self, mock_utcnow): def test_create(self, mock_utcnow):
CONF.set_override('message_ttl', 300) CONF.set_override('message_ttl', 300)
now = datetime.datetime.utcnow() now = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
mock_utcnow.return_value = now mock_utcnow.return_value = now
expected_expires_at = now + datetime.timedelta( expected_expires_at = now + datetime.timedelta(
seconds=300) seconds=300)

View File

@@ -120,7 +120,7 @@ class ShareAPITestCase(test.TestCase):
self.mock_object(quota.QUOTAS, 'reserve', self.mock_object(quota.QUOTAS, 'reserve',
lambda *args, **kwargs: None) lambda *args, **kwargs: None)
self.dt_utc = datetime.datetime.utcnow() self.dt_utc = timeutils.utcnow()
self.mock_object(timeutils, 'utcnow', self.mock_object(timeutils, 'utcnow',
mock.Mock(return_value=self.dt_utc)) mock.Mock(return_value=self.dt_utc))
self.mock_object(share_api.policy, 'check_policy') self.mock_object(share_api.policy, 'check_policy')

View File

@@ -93,7 +93,7 @@ class ShareGroupsAPITestCase(test.TestCase):
self.mock_object(self.api, 'share_api', self.share_api) self.mock_object(self.api, 'share_api', self.share_api)
self.mock_object(self.api, 'scheduler_rpcapi', self.scheduler_rpcapi) self.mock_object(self.api, 'scheduler_rpcapi', self.scheduler_rpcapi)
dt_utc = datetime.datetime.utcnow() dt_utc = timeutils.utcnow()
self.mock_object(timeutils, 'utcnow', mock.Mock(return_value=dt_utc)) self.mock_object(timeutils, 'utcnow', mock.Mock(return_value=dt_utc))
self.fake_share_type = { self.fake_share_type = {
'name': 'default', 'name': 'default',

View File

@@ -21,13 +21,13 @@
Unit Tests for remote procedure calls using queue Unit Tests for remote procedure calls using queue
""" """
from datetime import datetime
from datetime import timedelta from datetime import timedelta
from unittest import mock from unittest import mock
import ddt import ddt
from oslo_config import cfg from oslo_config import cfg
from oslo_service import wsgi from oslo_service import wsgi
from oslo_utils import timeutils
from manila import context from manila import context
from manila import db from manila import db
@@ -300,9 +300,9 @@ class ServiceTestCase(test.TestCase):
if cleanup_interval_done: if cleanup_interval_done:
service_ref_stopped['updated_at'] = ( service_ref_stopped['updated_at'] = (
datetime.utcnow() - timedelta(minutes=10)) timeutils.utcnow() - timedelta(minutes=10))
else: else:
service_ref_stopped['updated_at'] = datetime.utcnow() service_ref_stopped['updated_at'] = timeutils.utcnow()
mock_db.service_get_all_by_topic.return_value = [ mock_db.service_get_all_by_topic.return_value = [
service_ref_stopped] service_ref_stopped]
serv.stop() serv.stop()

View File

@@ -25,7 +25,7 @@ oslo.rootwrap>=6.2.0 # Apache-2.0
oslo.serialization>=4.0.1 # Apache-2.0 oslo.serialization>=4.0.1 # Apache-2.0
oslo.service>=2.4.0 # Apache-2.0 oslo.service>=2.4.0 # Apache-2.0
oslo.upgradecheck>=1.3.0 # Apache-2.0 oslo.upgradecheck>=1.3.0 # Apache-2.0
oslo.utils>=4.7.0 # Apache-2.0 oslo.utils>=7.0.0 # Apache-2.0
oslo.concurrency>=4.3.0 # Apache-2.0 oslo.concurrency>=4.3.0 # Apache-2.0
osprofiler>=3.4.0 # Apache-2.0 osprofiler>=3.4.0 # Apache-2.0
paramiko>=2.7.2 # LGPLv2.1+ paramiko>=2.7.2 # LGPLv2.1+