diff options
author | Amrith Kumar <amrith@tesora.com> | 2016-06-07 08:15:24 -0400 |
---|---|---|
committer | Amrith Kumar <amrith.kumar@gmail.com> | 2017-06-09 16:22:11 +0000 |
commit | 109ff949511c0185ab1dd0beffeb03a8a3332005 (patch) | |
tree | 75adba86b2c07ee9da54c7ea6e8896358f6f2952 /trove/extensions | |
parent | fb870b306ec044e8100fe67886d20be84f5807ef (diff) | |
download | trove-109ff949511c0185ab1dd0beffeb03a8a3332005.tar.gz |
Handle isotime deprecation in oslo_utils.timeutils
oslo_utils.timeutils is deprecating isotime(). In reality they are
deprecating some other things as well but Trove doesn't (currently)
use any of those things.
Much has been written on the subject of this deprecation. I think the
proposal to merely replace isotime with datetime.datetime.isoformat()
is a little simplistic. Well intentioned, but nonetheless I believe
that it is simplistic.
The primary issue I could find with oslo_utils.timeutils.isotime() was
the fact that it was naive. I think it could well have been fixed in
oslo_utils but for whatever reason(s) oslo decided not to want to go
that route.
The primary challenge from Trove's perspective is that I want to
respect the existing API contract while at the same time get an
implementation of time handling that is not identical in its flaws
with oslo_utils.timeutils.isotime().
This change set attempts to address that by making
trove.common.timeutils.isotime() that is aware. It also implements a
utcnow_aware() function that is aware.
ISO 8601 allows for four representations of timezone and those are
<time>Z
<time>[+-]hh:mm
<time>[+-]hhmm
<time>[+-]hh
Trove conventionally used the first one, even if the time wasn't
really a UTC time. That's one of the things being fixed here.
In review cp16net asked whether this change removes the 'Z' at the end
of time strings generated by the isotime() function. The answer is
NO. The new isotime() function performs identical to the old and now
deprecated function in oslo_utils.timeutils for UTC (Z) times.
There was a utcnow() function in trove.common.utils which just wrapped
datetime.datetime.utcnow(). That has been moved now to
trove.common.timeutils with the other new time related functions.
There were a couple of places in Trove where code was using
datetime.now() which was not ideal. Those have been corrected now as
well.
Unit tests have been proposed for the new routines.
Closes-Bug: #1532120
Change-Id: Ic5abf6669edd4f1a9fd62e61f437565aa887aebe
Diffstat (limited to 'trove/extensions')
-rw-r--r-- | trove/extensions/common/models.py | 4 | ||||
-rw-r--r-- | trove/extensions/mgmt/instances/models.py | 13 |
2 files changed, 8 insertions, 9 deletions
diff --git a/trove/extensions/common/models.py b/trove/extensions/common/models.py index 4102a425..c67438d0 100644 --- a/trove/extensions/common/models.py +++ b/trove/extensions/common/models.py @@ -18,7 +18,7 @@ from oslo_log import log as logging from trove.common.db import models as guest_models from trove.common import exception from trove.common.remote import create_guest_client -from trove.common import utils +from trove.common import timeutils from trove.db import get_db_api from trove.instance import models as base_models @@ -106,7 +106,7 @@ class RootHistory(object): def __init__(self, instance_id, user): self.id = instance_id self.user = user - self.created = utils.utcnow() + self.created = timeutils.utcnow() def save(self): LOG.debug("Saving %(name)s: %(dict)s", diff --git a/trove/extensions/mgmt/instances/models.py b/trove/extensions/mgmt/instances/models.py index b2b6fb0d..64da1a1e 100644 --- a/trove/extensions/mgmt/instances/models.py +++ b/trove/extensions/mgmt/instances/models.py @@ -19,7 +19,7 @@ from trove.common import cfg from trove.common import exception from trove.common.i18n import _ from trove.common import remote -from trove.common import utils +from trove.common import timeutils from trove.extensions.mysql import models as mysql_models from trove.instance import models as instance_models from trove import rpc @@ -186,12 +186,11 @@ class NotificationTransformer(object): @staticmethod def _get_audit_period(): - now = datetime.datetime.now() - audit_start = utils.isotime( - now - datetime.timedelta( - seconds=CONF.exists_notification_interval), - subsecond=True) - audit_end = utils.isotime(now, subsecond=True) + now = timeutils.utcnow() + start_time = now - datetime.timedelta( + seconds=CONF.exists_notification_interval) + audit_start = timeutils.isotime(start_time) + audit_end = timeutils.isotime(now) return audit_start, audit_end def _get_service_id(self, datastore_manager, id_map): |