Replace datetime.datetime.utcnow()

... because it was deprecated in Python 3.12.

Change-Id: I4b5fc30e68f7d8f0ecde8b1c684ae42392c0550c
This commit is contained in:
Takashi Kajinami 2023-12-19 01:11:53 +09:00
parent 8d920ce880
commit ae78c7edf9
3 changed files with 5 additions and 7 deletions

View File

@ -13,7 +13,6 @@
import collections import collections
import contextlib import contextlib
import datetime as dt
import itertools import itertools
import pydoc import pydoc
import re import re
@ -24,6 +23,7 @@ from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
from oslo_utils import reflection from oslo_utils import reflection
from oslo_utils import timeutils as oslo_timeutils
from heat.common import exception from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _
@ -58,8 +58,6 @@ cfg.CONF.import_opt('error_wait_time', 'heat.common.config')
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
datetime = dt.datetime
def _register_class(resource_type, resource_class): def _register_class(resource_type, resource_class):
resources.global_env().register_class(resource_type, resource_class) resources.global_env().register_class(resource_type, resource_class)
@ -1675,7 +1673,7 @@ class Resource(status.ResourceStatus):
LOG.info('updating %s', self) LOG.info('updating %s', self)
self.updated_time = datetime.utcnow() self.updated_time = oslo_timeutils.utcnow()
if new_requires is not None: if new_requires is not None:
self.requires = self.requires | new_requires self.requires = self.requires | new_requires

View File

@ -604,7 +604,7 @@ class WaitConditionUpdateTest(common.HeatTestCase):
now = timeutils.utcnow() now = timeutils.utcnow()
fake_clock = [now + datetime.timedelta(0, t) fake_clock = [now + datetime.timedelta(0, t)
for t in (0, 0.001, 0.1, 4.1, 5.1)] for t in (0, 0, 0.001, 0.1, 4.1, 5.1, 5.1)]
timeutils.set_time_override(fake_clock) timeutils.set_time_override(fake_clock)
self.addCleanup(timeutils.clear_time_override) self.addCleanup(timeutils.clear_time_override)

View File

@ -12,7 +12,6 @@
# under the License. # under the License.
import collections import collections
import datetime
import itertools import itertools
import json import json
import os import os
@ -22,6 +21,7 @@ import uuid
import eventlet import eventlet
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import timeutils as oslo_timeutils
from heat.common import exception from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _
@ -600,7 +600,7 @@ class ResourceTest(common.HeatTestCase):
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack) res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
res.store() res.store()
self.assertIsNone(res.updated_time) self.assertIsNone(res.updated_time)
res.updated_time = datetime.datetime.utcnow() res.updated_time = oslo_timeutils.utcnow()
res.store() res.store()
self.assertIsNotNone(res.updated_time) self.assertIsNotNone(res.updated_time)