]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Stop using deprecated timeutils.isotime()
authorJulien Danjou <julien@danjou.info>
Sat, 16 May 2015 12:39:23 +0000 (14:39 +0200)
committerJulien Danjou <julien@danjou.info>
Wed, 27 May 2015 06:28:39 +0000 (08:28 +0200)
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
cinder/api/views/limits.py
cinder/context.py
cinder/hacking/checks.py
cinder/objects/base.py
cinder/tests/unit/api/v1/test_limits.py
cinder/tests/unit/api/v1/test_types.py
cinder/tests/unit/api/v2/test_limits.py
cinder/tests/unit/api/v2/test_types.py
cinder/volume/drivers/solidfire.py
cinder/volume/utils.py

index 88f40adc7af2d0052dff065e728c166e51a852a8..f0cdbad9ba130b4341652eff6c6f440e96b36493 100644 (file)
@@ -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
 -------
index d8c22af0576009e40d7e160ba38db44fe4308e50..3751b05e2938bd1e8a85c6792bbc5a7f29a9e719 100644 (file)
@@ -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(),
         }
index 9370cdad55bbecdb6d53c89ff98631af88d00ff1..f99f314804551ac6e4a4c34c1d35e987e5e16e14 100644 (file)
@@ -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}
index d0c13c8c583a213611ac6b38bc27844b0e9fe60d..bb33e445e93dd9113065870b63eecc1e18c15d4f 100644 (file)
@@ -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)
index dc984e44c739912bb13995ddfbe903981af908ee..7b687190cda696c014d3f9a2e4d10b43e11cff54 100644 (file)
@@ -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
index beff81f69f123c6745362b29ba45bf68f19ccb06..0ddc3fdc5d81930d2b2235df68ba28730ea23ab1 100644 (file)
@@ -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": ".*",
index 60d3e19149519937ae193eb58a8cc0ff57f9d1cb..3de504fe1ed4ae2a42473ff42eb3ed1917e4ca26 100644 (file)
@@ -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',
index 2747204ff8990b2140752e71be9996af71f0d1bb..0f1421dea5fb2a4760987fb9d220df3fce49ec83 100644 (file)
@@ -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": ".*",
index 388492a10281e4558a4d17ab3b2dc41d549a6f82..2a2cd23077be2390e3be76011c0fdb73cb32d4d0 100644 (file)
@@ -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(
index dd785764535809d33f745b59f2db5e8a9704bce3..620d5f9773505803fdd2a463253c3182443416e1 100644 (file)
@@ -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']),
index 6e71f0d3366905f44393282d9025e01bfee7837d..d136cd79f0f114086f06cc25de9224a1e9ffe3d5 100644 (file)
@@ -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)