Replace oslo_utils.timeutils.isotime

Function 'oslo_utils.timeutils.isotime()' is deprecated in version '1.6'
and will be removed in a future version. We can't use
datetime.datetime.isoformat() instead. Because the format of the string
generated by isoformat isn't the same as the format of the string
generated by isotime. The string is used in tokens and other public
APIs and we can't change it without potentially breaking clients.

So the workaround is to copy the current implementation from
oslo_utils.timeutils.isotime() to utils.py

For more informations:
http://docs.openstack.org/developer/oslo.utils/api/timeutils.html#oslo_utils.timeutils.isotime

APIImpact

Closes-Bug: #1694352

Change-Id: I2feb85b7f698ae456493d02a118bb3fb969835da
This commit is contained in:
Luong Anh Tuan 2017-05-29 23:31:39 +07:00 committed by Tuan Luong-Anh
parent a6a1cbcd96
commit ac60df2beb
2 changed files with 30 additions and 2 deletions

View File

@ -15,7 +15,7 @@
import datetime
from oslo_utils import timeutils
from manila import utils
class ViewBuilder(object):
@ -99,5 +99,5 @@ class ViewBuilder(object):
"value": rate_limit["value"],
"remaining": int(rate_limit["remaining"]),
"unit": rate_limit["unit"],
"next-available": timeutils.isotime(at=next_avail),
"next-available": utils.isotime(at=next_avail),
}

View File

@ -54,9 +54,37 @@ from manila.i18n import _
CONF = cfg.CONF
LOG = log.getLogger(__name__)
_ISO8601_TIME_FORMAT_SUBSECOND = '%Y-%m-%dT%H:%M:%S.%f'
_ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
synchronized = lockutils.synchronized_with_prefix('manila-')
def isotime(at=None, subsecond=False):
"""Stringify time in ISO 8601 format."""
# Python provides a similar instance method for datetime.datetime objects
# called isoformat(). The format of the strings generated by isoformat()
# have a couple of problems:
# 1) The strings generated by isotime are used in tokens and other public
# APIs that we can't change without a deprecation period. The strings
# generated by isoformat are not the same format, so we can't just
# change to it.
# 2) The strings generated by isoformat do not include the microseconds if
# the value happens to be 0. This will likely show up as random failures
# as parsers may be written to always expect microseconds, and it will
# parse correctly most of the time.
if not at:
at = timeutils.utcnow()
st = at.strftime(_ISO8601_TIME_FORMAT
if not subsecond
else _ISO8601_TIME_FORMAT_SUBSECOND)
tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC'
st += ('Z' if tz == 'UTC' else tz)
return st
def _get_root_helper():
return 'sudo manila-rootwrap %s' % CONF.rootwrap_config