datetime.datetime.utcnow() should be replaced
timeutils.utcnow() should be used instead of datetime.datetime.now() or datetime.datetime.utcnow() This patch unifies it. Closes-Bug: #1514748 Change-Id: Icb73746905612661cbda03e679fbfddd80bb6cc2
This commit is contained in:
parent
1c4fdf564e
commit
906d35c775
@ -1055,7 +1055,7 @@ def purge_deleted(age, granularity='days'):
|
||||
elif granularity == 'minutes':
|
||||
age = age * 60
|
||||
|
||||
time_line = datetime.datetime.now() - datetime.timedelta(seconds=age)
|
||||
time_line = timeutils.utcnow() - datetime.timedelta(seconds=age)
|
||||
engine = get_engine()
|
||||
meta = sqlalchemy.MetaData()
|
||||
meta.bind = engine
|
||||
|
@ -25,6 +25,7 @@ import oslo_messaging as messaging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_service import service
|
||||
from oslo_service import threadgroup
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
from osprofiler import profiler
|
||||
import six
|
||||
@ -1791,7 +1792,7 @@ class EngineService(service.Service):
|
||||
def service_manage_cleanup(self):
|
||||
cnxt = context.get_admin_context()
|
||||
last_updated_window = (3 * cfg.CONF.periodic_interval)
|
||||
time_line = datetime.datetime.utcnow() - datetime.timedelta(
|
||||
time_line = timeutils.utcnow() - datetime.timedelta(
|
||||
seconds=last_updated_window)
|
||||
|
||||
service_refs = service_objects.Service.get_all_by_args(
|
||||
|
@ -20,6 +20,7 @@ import re
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import timeutils as oslo_timeutils
|
||||
from oslo_utils import uuidutils
|
||||
from osprofiler import profiler
|
||||
import six
|
||||
@ -894,7 +895,7 @@ class Stack(collections.Mapping):
|
||||
|
||||
@profiler.trace('Stack.check', hide_args=False)
|
||||
def check(self):
|
||||
self.updated_time = datetime.datetime.utcnow()
|
||||
self.updated_time = oslo_timeutils.utcnow()
|
||||
checker = scheduler.TaskRunner(
|
||||
self.stack_task, self.CHECK,
|
||||
post_func=self.supports_check_action,
|
||||
@ -978,7 +979,7 @@ class Stack(collections.Mapping):
|
||||
Update will fail if it exceeds the specified timeout. The default is
|
||||
60 minutes, set in the constructor
|
||||
"""
|
||||
self.updated_time = datetime.datetime.utcnow()
|
||||
self.updated_time = oslo_timeutils.utcnow()
|
||||
updater = scheduler.TaskRunner(self.update_task, newstack,
|
||||
event=event)
|
||||
updater()
|
||||
@ -999,7 +1000,7 @@ class Stack(collections.Mapping):
|
||||
self.current_traversal = uuidutils.generate_uuid()
|
||||
|
||||
if action is not self.CREATE:
|
||||
self.updated_time = datetime.datetime.utcnow()
|
||||
self.updated_time = oslo_timeutils.utcnow()
|
||||
|
||||
if new_stack is not None:
|
||||
self.disable_rollback = new_stack.disable_rollback
|
||||
@ -1525,7 +1526,7 @@ class Stack(collections.Mapping):
|
||||
LOG.info(_LI('%s is already suspended'), six.text_type(self))
|
||||
return
|
||||
|
||||
self.updated_time = datetime.datetime.utcnow()
|
||||
self.updated_time = oslo_timeutils.utcnow()
|
||||
sus_task = scheduler.TaskRunner(
|
||||
self.stack_task,
|
||||
action=self.SUSPEND,
|
||||
@ -1550,7 +1551,7 @@ class Stack(collections.Mapping):
|
||||
LOG.info(_LI('%s is already resumed'), six.text_type(self))
|
||||
return
|
||||
|
||||
self.updated_time = datetime.datetime.utcnow()
|
||||
self.updated_time = oslo_timeutils.utcnow()
|
||||
sus_task = scheduler.TaskRunner(
|
||||
self.stack_task,
|
||||
action=self.RESUME,
|
||||
@ -1561,7 +1562,7 @@ class Stack(collections.Mapping):
|
||||
@profiler.trace('Stack.snapshot', hide_args=False)
|
||||
def snapshot(self, save_snapshot_func):
|
||||
"""Snapshot the stack, invoking handle_snapshot on all resources."""
|
||||
self.updated_time = datetime.datetime.utcnow()
|
||||
self.updated_time = oslo_timeutils.utcnow()
|
||||
sus_task = scheduler.TaskRunner(
|
||||
self.stack_task,
|
||||
action=self.SNAPSHOT,
|
||||
@ -1585,7 +1586,7 @@ class Stack(collections.Mapping):
|
||||
|
||||
Invokes handle_restore on all resources.
|
||||
"""
|
||||
self.updated_time = datetime.datetime.utcnow()
|
||||
self.updated_time = oslo_timeutils.utcnow()
|
||||
env = environment.Environment(snapshot.data['environment'])
|
||||
files = snapshot.data['files']
|
||||
template = tmpl.Template(snapshot.data['template'],
|
||||
|
@ -30,6 +30,7 @@ from oslo_db.sqlalchemy import test_base
|
||||
from oslo_db.sqlalchemy import test_migrations
|
||||
from oslo_db.sqlalchemy import utils
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
import sqlalchemy
|
||||
import testtools
|
||||
@ -229,7 +230,7 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
|
||||
'resource_status_reason': '',
|
||||
'resource_type': '',
|
||||
'resource_properties': None,
|
||||
'created_at': datetime.datetime.now()},
|
||||
'created_at': timeutils.utcnow()},
|
||||
{'id': '11111111-152e-405d-b13a-35d4c816390c',
|
||||
'stack_id': '967aaefb-152e-405d-b13a-35d4c816390c',
|
||||
'resource_action': 'Test',
|
||||
@ -239,7 +240,7 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
|
||||
'resource_status_reason': '',
|
||||
'resource_type': '',
|
||||
'resource_properties': None,
|
||||
'created_at': datetime.datetime.now() +
|
||||
'created_at': timeutils.utcnow() +
|
||||
datetime.timedelta(days=5)}]
|
||||
engine.execute(event_table.insert(), data)
|
||||
return data
|
||||
@ -267,7 +268,7 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
|
||||
'resource_status_reason': '',
|
||||
'resource_type': '',
|
||||
'resource_properties': None,
|
||||
'created_at': datetime.datetime.now()}]
|
||||
'created_at': timeutils.utcnow()}]
|
||||
result = engine.execute(event_table.insert(), data)
|
||||
self.assertEqual(last_id + 1, result.inserted_primary_key[0])
|
||||
|
||||
@ -520,10 +521,10 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
|
||||
username='test_user',
|
||||
disable_rollback=True,
|
||||
parameters='test_params',
|
||||
created_at=datetime.datetime.utcnow(),
|
||||
created_at=timeutils.utcnow(),
|
||||
deleted_at=None)
|
||||
for ll_id, templ_id in stack_ids]
|
||||
data[-1]['deleted_at'] = datetime.datetime.utcnow()
|
||||
data[-1]['deleted_at'] = timeutils.utcnow()
|
||||
|
||||
engine.execute(stack.insert(), data)
|
||||
return data
|
||||
@ -714,7 +715,7 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
|
||||
username='test_user',
|
||||
disable_rollback=True,
|
||||
parameters='test_params',
|
||||
created_at=datetime.datetime.utcnow(),
|
||||
created_at=timeutils.utcnow(),
|
||||
deleted_at=None)
|
||||
for ll_id, templ_id, owner_id in stack_ids]
|
||||
|
||||
|
@ -1862,7 +1862,7 @@ class DBAPIStackTest(common.HeatTestCase):
|
||||
db_api.stack_count_all(self.ctx, tenant_safe=False))
|
||||
|
||||
def test_purge_deleted(self):
|
||||
now = datetime.datetime.now()
|
||||
now = timeutils.utcnow()
|
||||
delta = datetime.timedelta(seconds=3600 * 7)
|
||||
deleted = [now - delta * i for i in range(1, 6)]
|
||||
templates = [create_raw_template(self.ctx) for i in range(5)]
|
||||
@ -1887,7 +1887,7 @@ class DBAPIStackTest(common.HeatTestCase):
|
||||
(), (0, 1, 2, 3, 4))
|
||||
|
||||
def test_purge_deleted_prev_raw_template(self):
|
||||
now = datetime.datetime.now()
|
||||
now = timeutils.utcnow()
|
||||
templates = [create_raw_template(self.ctx) for i in range(2)]
|
||||
stacks = [create_stack(self.ctx, templates[0],
|
||||
create_user_creds(self.ctx),
|
||||
|
@ -16,6 +16,7 @@ import datetime
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_service import threadgroup
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from heat.common import context
|
||||
from heat.common import service_utils
|
||||
@ -89,7 +90,7 @@ class ServiceEngineTest(common.HeatTestCase):
|
||||
mock_service_delete,
|
||||
mock_get_all):
|
||||
mock_admin_context.return_value = self.ctx
|
||||
ages_a_go = datetime.datetime.utcnow() - datetime.timedelta(
|
||||
ages_a_go = timeutils.utcnow() - datetime.timedelta(
|
||||
seconds=4000)
|
||||
mock_get_all.return_value = [{'id': 'foo',
|
||||
'deleted_at': None,
|
||||
|
@ -14,6 +14,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import datetime
|
||||
from oslo_utils import timeutils
|
||||
import uuid
|
||||
|
||||
from heat.common import service_utils
|
||||
@ -31,7 +32,7 @@ class TestServiceUtils(common.HeatTestCase):
|
||||
service.host = 'engine-1'
|
||||
service.report_interval = 60
|
||||
service.topic = 'engine'
|
||||
service.created_at = datetime.datetime.utcnow()
|
||||
service.created_at = timeutils.utcnow()
|
||||
service.deleted_at = None
|
||||
service.updated_at = None
|
||||
|
||||
@ -55,19 +56,19 @@ class TestServiceUtils(common.HeatTestCase):
|
||||
self.assertEqual(service_dict['status'], 'up')
|
||||
|
||||
# check update not happen within report_interval time (60+)
|
||||
service.created_at = (datetime.datetime.utcnow() -
|
||||
service.created_at = (timeutils.utcnow() -
|
||||
datetime.timedelta(0, 70))
|
||||
service_dict = service_utils.format_service(service)
|
||||
self.assertEqual(service_dict['status'], 'down')
|
||||
|
||||
# check update happened after report_interval time (60+)
|
||||
service.updated_at = (datetime.datetime.utcnow() -
|
||||
service.updated_at = (timeutils.utcnow() -
|
||||
datetime.timedelta(0, 70))
|
||||
service_dict = service_utils.format_service(service)
|
||||
self.assertEqual(service_dict['status'], 'down')
|
||||
|
||||
# check update happened within report_interval time (60)
|
||||
service.updated_at = (datetime.datetime.utcnow() -
|
||||
service.updated_at = (timeutils.utcnow() -
|
||||
datetime.timedelta(0, 50))
|
||||
service_dict = service_utils.format_service(service)
|
||||
self.assertEqual(service_dict['status'], 'up')
|
||||
|
@ -11,10 +11,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import oslo_db.exception
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from heat.common import exception
|
||||
from heat.engine import event
|
||||
@ -103,7 +103,7 @@ class EventTest(EventCommon):
|
||||
|
||||
def test_load_with_timestamp(self):
|
||||
self.resource.resource_id_set('resource_physical_id')
|
||||
timestamp = datetime.datetime.utcnow()
|
||||
timestamp = timeutils.utcnow()
|
||||
|
||||
e = event.Event(self.ctx, self.stack, 'TEST', 'IN_PROGRESS', 'Testing',
|
||||
'wibble', self.resource.properties,
|
||||
|
Loading…
Reference in New Issue
Block a user