From d106e6f61b493ce4c822601236bbb73c07b9c8da Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 16 May 2015 14:39:23 +0200 Subject: [PATCH] Stop using deprecated timeutils.isotime() oslo_utils.timeutils.isotime() has been deprecated, stop using it, see: http://docs.openstack.org/developer/oslo.utils/api/timeutils.html#oslo_utils.timeutils.isotime Change-Id: I0176f498db89a3a10c2474e4ae5c4b0929c65ece --- HACKING.rst | 1 + cinder/api/views/limits.py | 4 +--- cinder/context.py | 2 +- cinder/hacking/checks.py | 10 +++++++++- cinder/objects/base.py | 3 +-- cinder/tests/unit/api/v1/test_limits.py | 12 ++++++------ cinder/tests/unit/api/v1/test_types.py | 4 ++-- cinder/tests/unit/api/v2/test_limits.py | 12 ++++++------ cinder/tests/unit/api/v2/test_types.py | 4 ++-- cinder/volume/drivers/solidfire.py | 10 +++++----- cinder/volume/utils.py | 11 +++++++---- 11 files changed, 41 insertions(+), 32 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 88f40adc7..f0cdbad9b 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -25,6 +25,7 @@ Cinder Specific Commandments - [C305] Prevent use of deprecated contextlib.nested. - [C306] timeutils.strtime() must not be used (deprecated). - [C307] LOG.warn is deprecated. Enforce use of LOG.warning. +- [C308] timeutils.isotime() must not be used (deprecated). General ------- diff --git a/cinder/api/views/limits.py b/cinder/api/views/limits.py index d8c22af05..3751b05e2 100644 --- a/cinder/api/views/limits.py +++ b/cinder/api/views/limits.py @@ -15,8 +15,6 @@ import datetime -from oslo_utils import timeutils - class ViewBuilder(object): """OpenStack API base limits view builder.""" @@ -97,5 +95,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": next_avail.isoformat(), } diff --git a/cinder/context.py b/cinder/context.py index 9370cdad5..f99f31480 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -115,7 +115,7 @@ class RequestContext(context.RequestContext): 'read_deleted': self.read_deleted, 'roles': self.roles, 'remote_address': self.remote_address, - 'timestamp': timeutils.isotime(self.timestamp, True), + 'timestamp': self.timestamp.isoformat(), 'quota_class': self.quota_class, 'service_catalog': self.service_catalog, 'request_id': self.request_id} diff --git a/cinder/hacking/checks.py b/cinder/hacking/checks.py index d0c13c8c5..bb33e445e 100644 --- a/cinder/hacking/checks.py +++ b/cinder/hacking/checks.py @@ -293,7 +293,7 @@ def check_no_contextlib_nested(logical_line): def check_timeutils_strtime(logical_line): msg = ("C306: Found timeutils.strtime(). " - "Please use oslo_utils.timeutils.isotime() or datetime.strftime()") + "Please use datetime.datetime.isoformat() or datetime.strftime()") if 'timeutils.strtime' in logical_line: yield(0, msg) @@ -311,6 +311,13 @@ def dict_constructor_with_list_copy(logical_line): yield (0, msg) +def check_timeutils_isotime(logical_line): + msg = ("C308: Found timeutils.isotime(). " + "Please use datetime.datetime.isoformat()") + if 'timeutils.isotime' in logical_line: + yield(0, msg) + + def factory(register): register(no_vi_headers) register(no_translate_debug_logs) @@ -321,6 +328,7 @@ def factory(register): register(check_oslo_namespace_imports) register(check_datetime_now) register(check_timeutils_strtime) + register(check_timeutils_isotime) register(validate_log_translations) register(check_unicode_usage) register(check_no_print_statements) diff --git a/cinder/objects/base.py b/cinder/objects/base.py index dc984e44c..7b687190c 100644 --- a/cinder/objects/base.py +++ b/cinder/objects/base.py @@ -20,7 +20,6 @@ import functools import traceback from oslo_log import log as logging -from oslo_utils import timeutils from oslo_versionedobjects import base from oslo_versionedobjects import fields import six @@ -136,7 +135,7 @@ def serialize_args(fn): not isinstance(value_arg, six.string_types) and value_arg): kwargs[kw] = ''.join(traceback.format_tb(value_arg)) elif isinstance(value_arg, datetime.datetime): - kwargs[kw] = timeutils.isotime(value_arg) + kwargs[kw] = value_arg.isoformat() if hasattr(fn, '__call__'): return fn(obj, *args, **kwargs) # NOTE(danms): We wrap a descriptor, so use that protocol diff --git a/cinder/tests/unit/api/v1/test_limits.py b/cinder/tests/unit/api/v1/test_limits.py index beff81f69..0ddc3fdc5 100644 --- a/cinder/tests/unit/api/v1/test_limits.py +++ b/cinder/tests/unit/api/v1/test_limits.py @@ -127,14 +127,14 @@ class LimitsControllerTest(BaseLimitTestSuite): "limit": [ { "verb": "GET", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "MINUTE", "value": 10, "remaining": 10, }, { "verb": "POST", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "HOUR", "value": 5, "remaining": 5, @@ -147,7 +147,7 @@ class LimitsControllerTest(BaseLimitTestSuite): "limit": [ { "verb": "GET", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "MINUTE", "value": 5, "remaining": 5, @@ -186,7 +186,7 @@ class LimitsControllerTest(BaseLimitTestSuite): "limit": [ { "verb": "GET", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "MINUTE", "value": 10, "remaining": 10, @@ -199,7 +199,7 @@ class LimitsControllerTest(BaseLimitTestSuite): "limit": [ { "verb": "GET", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "MINUTE", "value": 10, "remaining": 10, @@ -777,7 +777,7 @@ class LimitsViewBuilderTest(test.TestCase): "injected_file_content_bytes": 5} def test_build_limits(self): - tdate = "2011-07-21T18:17:06Z" + tdate = "2011-07-21T18:17:06" expected_limits = \ {"limits": {"rate": [{"uri": "*", "regex": ".*", diff --git a/cinder/tests/unit/api/v1/test_types.py b/cinder/tests/unit/api/v1/test_types.py index 60d3e1914..3de504fe1 100644 --- a/cinder/tests/unit/api/v1/test_types.py +++ b/cinder/tests/unit/api/v1/test_types.py @@ -111,7 +111,7 @@ class VolumeTypesApiTest(test.TestCase): def test_view_builder_show(self): view_builder = views_types.ViewBuilder() - now = timeutils.isotime() + now = timeutils.utcnow().isoformat() raw_volume_type = dict(name='new_type', deleted=False, created_at=now, @@ -134,7 +134,7 @@ class VolumeTypesApiTest(test.TestCase): def test_view_builder_list(self): view_builder = views_types.ViewBuilder() - now = timeutils.isotime() + now = timeutils.utcnow().isoformat() raw_volume_types = [] for i in range(0, 10): raw_volume_types.append(dict(name='new_type', diff --git a/cinder/tests/unit/api/v2/test_limits.py b/cinder/tests/unit/api/v2/test_limits.py index 2747204ff..0f1421dea 100644 --- a/cinder/tests/unit/api/v2/test_limits.py +++ b/cinder/tests/unit/api/v2/test_limits.py @@ -128,14 +128,14 @@ class LimitsControllerTest(BaseLimitTestSuite): "limit": [ { "verb": "GET", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "MINUTE", "value": 10, "remaining": 10, }, { "verb": "POST", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "HOUR", "value": 5, "remaining": 5, @@ -148,7 +148,7 @@ class LimitsControllerTest(BaseLimitTestSuite): "limit": [ { "verb": "GET", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "MINUTE", "value": 5, "remaining": 5, @@ -187,7 +187,7 @@ class LimitsControllerTest(BaseLimitTestSuite): "limit": [ { "verb": "GET", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "MINUTE", "value": 10, "remaining": 10, @@ -200,7 +200,7 @@ class LimitsControllerTest(BaseLimitTestSuite): "limit": [ { "verb": "GET", - "next-available": "1970-01-01T00:00:00Z", + "next-available": "1970-01-01T00:00:00", "unit": "MINUTE", "value": 10, "remaining": 10, @@ -782,7 +782,7 @@ class LimitsViewBuilderTest(test.TestCase): "injected_file_content_bytes": 5} def test_build_limits(self): - tdate = "2011-07-21T18:17:06Z" + tdate = "2011-07-21T18:17:06" expected_limits = { "limits": {"rate": [{"uri": "*", "regex": ".*", diff --git a/cinder/tests/unit/api/v2/test_types.py b/cinder/tests/unit/api/v2/test_types.py index 388492a10..2a2cd2307 100644 --- a/cinder/tests/unit/api/v2/test_types.py +++ b/cinder/tests/unit/api/v2/test_types.py @@ -149,7 +149,7 @@ class VolumeTypesApiTest(test.TestCase): def test_view_builder_show(self): view_builder = views_types.ViewBuilder() - now = timeutils.isotime() + now = timeutils.utcnow().isoformat() raw_volume_type = dict( name='new_type', description='new_type_desc', @@ -176,7 +176,7 @@ class VolumeTypesApiTest(test.TestCase): def test_view_builder_list(self): view_builder = views_types.ViewBuilder() - now = timeutils.isotime() + now = timeutils.utcnow().isoformat() raw_volume_types = [] for i in range(0, 10): raw_volume_types.append( diff --git a/cinder/volume/drivers/solidfire.py b/cinder/volume/drivers/solidfire.py index dd7857645..620d5f977 100644 --- a/cinder/volume/drivers/solidfire.py +++ b/cinder/volume/drivers/solidfire.py @@ -396,7 +396,7 @@ class SolidFireDriver(san.SanISCSIDriver): # to set any that were provided params = {'volumeID': sf_volume_id} - create_time = timeutils.isotime(v_ref['created_at'], True) + create_time = v_ref['created_at'].isoformat() attributes = {'uuid': v_ref['id'], 'is_clone': 'True', 'src_uuid': src_uuid, @@ -700,7 +700,7 @@ class SolidFireDriver(san.SanISCSIDriver): if type_id is not None: qos = self._set_qos_by_volume_type(ctxt, type_id) - create_time = timeutils.isotime(volume['created_at'], True) + create_time = volume['created_at'].isoformat() attributes = {'uuid': volume['id'], 'is_clone': 'False', 'created_at': create_time} @@ -1008,7 +1008,7 @@ class SolidFireDriver(san.SanISCSIDriver): raise exception.VolumeNotFound(volume_id=volume['id']) attributes = sf_vol['attributes'] - attributes['retyped_at'] = timeutils.isotime(subsecond=True) + attributes['retyped_at'] = timeutils.utcnow().isoformat() params = {'volumeID': sf_vol['volumeID']} qos = self._set_qos_by_volume_type(ctxt, new_type['id']) @@ -1055,7 +1055,7 @@ class SolidFireDriver(san.SanISCSIDriver): if type_id is not None: qos = self._set_qos_by_volume_type(ctxt, type_id) - import_time = timeutils.isotime(volume['created_at'], True) + import_time = volume['created_at'].isoformat() attributes = {'uuid': volume['id'], 'is_clone': 'False', 'os_imported_at': import_time, @@ -1115,7 +1115,7 @@ class SolidFireDriver(san.SanISCSIDriver): if sf_vol is None: raise exception.VolumeNotFound(volume_id=volume['id']) - export_time = timeutils.isotime(subsecond=True) + export_time = timeutils.utcnow().isoformat() attributes = sf_vol['attributes'] attributes['os_exported_at'] = export_time params = {'volumeID': int(sf_vol['volumeID']), diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index 6e71f0d33..d136cd79f 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -43,6 +43,9 @@ def null_safe_str(s): def _usage_from_volume(volume_ref, **kw): + now = timeutils.utcnow() + launched_at = volume_ref['launched_at'] or now + created_at = volume_ref['created_at'] or now usage_info = dict( tenant_id=volume_ref['project_id'], host=volume_ref['host'], @@ -51,8 +54,8 @@ def _usage_from_volume(volume_ref, **kw): volume_id=volume_ref['id'], volume_type=volume_ref['volume_type_id'], display_name=volume_ref['display_name'], - launched_at=timeutils.isotime(at=volume_ref['launched_at']), - created_at=timeutils.isotime(at=volume_ref['created_at']), + launched_at=launched_at.isoformat(), + created_at=created_at.isoformat(), status=volume_ref['status'], snapshot_id=volume_ref['snapshot_id'], size=volume_ref['size'], @@ -183,7 +186,7 @@ def _usage_from_consistencygroup(group_ref, **kw): availability_zone=group_ref['availability_zone'], consistencygroup_id=group_ref['id'], name=group_ref['name'], - created_at=timeutils.isotime(at=group_ref['created_at']), + created_at=group_ref['created_at'].isoformat(), status=group_ref['status']) usage_info.update(kw) @@ -214,7 +217,7 @@ def _usage_from_cgsnapshot(cgsnapshot_ref, **kw): cgsnapshot_id=cgsnapshot_ref['id'], name=cgsnapshot_ref['name'], consistencygroup_id=cgsnapshot_ref['consistencygroup_id'], - created_at=timeutils.isotime(at=cgsnapshot_ref['created_at']), + created_at=cgsnapshot_ref['created_at'].isoformat(), status=cgsnapshot_ref['status']) usage_info.update(kw) -- 2.45.2