From ae78c7edf95dae88e623a68f2f35b462680e5d71 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 19 Dec 2023 01:11:53 +0900 Subject: [PATCH] Replace datetime.datetime.utcnow() ... because it was deprecated in Python 3.12. Change-Id: I4b5fc30e68f7d8f0ecde8b1c684ae42392c0550c --- heat/engine/resource.py | 6 ++---- heat/tests/aws/test_waitcondition.py | 2 +- heat/tests/test_resource.py | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index ceaf5a72a3..621f562d2e 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -13,7 +13,6 @@ import collections import contextlib -import datetime as dt import itertools import pydoc import re @@ -24,6 +23,7 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import reflection +from oslo_utils import timeutils as oslo_timeutils from heat.common import exception from heat.common.i18n import _ @@ -58,8 +58,6 @@ cfg.CONF.import_opt('error_wait_time', 'heat.common.config') LOG = logging.getLogger(__name__) -datetime = dt.datetime - def _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) - self.updated_time = datetime.utcnow() + self.updated_time = oslo_timeutils.utcnow() if new_requires is not None: self.requires = self.requires | new_requires diff --git a/heat/tests/aws/test_waitcondition.py b/heat/tests/aws/test_waitcondition.py index 0e31cf172f..faabaa9ed5 100644 --- a/heat/tests/aws/test_waitcondition.py +++ b/heat/tests/aws/test_waitcondition.py @@ -604,7 +604,7 @@ class WaitConditionUpdateTest(common.HeatTestCase): now = timeutils.utcnow() 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) self.addCleanup(timeutils.clear_time_override) diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index d4e893971e..a73cc4c58b 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -12,7 +12,6 @@ # under the License. import collections -import datetime import itertools import json import os @@ -22,6 +21,7 @@ import uuid import eventlet from oslo_config import cfg +from oslo_utils import timeutils as oslo_timeutils from heat.common import exception from heat.common.i18n import _ @@ -600,7 +600,7 @@ class ResourceTest(common.HeatTestCase): res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack) res.store() self.assertIsNone(res.updated_time) - res.updated_time = datetime.datetime.utcnow() + res.updated_time = oslo_timeutils.utcnow() res.store() self.assertIsNotNone(res.updated_time)