]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Leverage timeutils, drop strtime() usage
authorJulien Danjou <julien@danjou.info>
Thu, 19 Mar 2015 12:24:00 +0000 (13:24 +0100)
committerJulien Danjou <julien@danjou.info>
Thu, 23 Apr 2015 08:33:55 +0000 (10:33 +0200)
This patch remove some code that tried to parse time in different way by
leveraging timeutils instead. It also drops strtime() usage as it's
going to be deprecated in oslo_utils (see
I8b5119e64369ccac3423dccc04421f99912df733).

Change-Id: Icb2906ccd4b381f80064e0f1348fc64e389031dd

HACKING.rst
cinder/backup/drivers/swift.py
cinder/context.py
cinder/hacking/checks.py
cinder/tests/unit/test_hacking.py
cinder/volume/drivers/solidfire.py

index 54dcecdb2fb793e1c11b60ce3d0e3c65d5dec2ee..199d05b5d008b9e4d533ce775a180aa551b58cc9 100644 (file)
@@ -21,6 +21,7 @@ Cinder Specific Commandments
 - [C303] Ensure that there are no 'print()' statements in code that is being committed.
 - [C304] Enforce no use of LOG.audit messages.  LOG.info should be used instead.
 - [C305] Prevent use of deprecated contextlib.nested.
+- [C306] timeutils.strtime() must not be used (deprecated).
 
 
 General
index 70d3d263cd2b00e99cec79101dced6143859fc71..178823e6d2a1f93a79f4da9f49bba078888c0d71 100644 (file)
@@ -274,7 +274,7 @@ class SwiftBackupDriver(chunkeddriver.ChunkedBackupDriver):
         az = 'az_%s' % self.az
         backup_name = '%s_backup_%s' % (az, backup['id'])
         volume = 'volume_%s' % (backup['volume_id'])
-        timestamp = timeutils.strtime(fmt="%Y%m%d%H%M%S")
+        timestamp = timeutils.utcnow().strftime("%Y%m%d%H%M%S")
         prefix = volume + '/' + timestamp + '/' + backup_name
         LOG.debug('generate_object_name_prefix: %s', prefix)
         return prefix
index 88139ad61f27ef7c4b7f3ade1ddf0da808fb8420..9370cdad55bbecdb6d53c89ff98631af88d00ff1 100644 (file)
@@ -69,8 +69,8 @@ class RequestContext(context.RequestContext):
         self.remote_address = remote_address
         if not timestamp:
             timestamp = timeutils.utcnow()
-        if isinstance(timestamp, basestring):
-            timestamp = timeutils.parse_strtime(timestamp)
+        elif isinstance(timestamp, basestring):
+            timestamp = timeutils.parse_isotime(timestamp)
         self.timestamp = timestamp
         self.quota_class = quota_class
 
@@ -115,7 +115,7 @@ class RequestContext(context.RequestContext):
                  'read_deleted': self.read_deleted,
                  'roles': self.roles,
                  'remote_address': self.remote_address,
-                 'timestamp': timeutils.strtime(self.timestamp),
+                 'timestamp': timeutils.isotime(self.timestamp, True),
                  'quota_class': self.quota_class,
                  'service_catalog': self.service_catalog,
                  'request_id': self.request_id}
index 9b2451411fac95fa96f08f54e53d3b3b801ca766..71ca919fefdc042551acec593484e71f68d1aa49 100644 (file)
@@ -219,6 +219,13 @@ def check_no_contextlib_nested(logical_line):
         yield(0, msg)
 
 
+def check_timeutils_strtime(logical_line):
+    msg = ("C306: Found timeutils.strtime(). "
+           "Please use oslo_utils.timeutils.isotime() or datetime.strftime()")
+    if 'timeutils.strtime' in logical_line:
+        yield(0, msg)
+
+
 def factory(register):
     register(no_vi_headers)
     register(no_translate_debug_logs)
@@ -227,6 +234,7 @@ def factory(register):
     register(check_assert_called_once)
     register(check_oslo_namespace_imports)
     register(check_datetime_now)
+    register(check_timeutils_strtime)
     register(validate_log_translations)
     register(check_unicode_usage)
     register(check_no_print_statements)
index 400506d6ba0dbf824bf34ad57faf4f8216d2572b..1414851090bec49556f49658eb551f0d579f5583 100644 (file)
@@ -184,6 +184,12 @@ class HackingTestCase(test.TestCase):
         self.assertEqual(0, len(list(checks.check_datetime_now(
                                      "datetime.now()  # noqa", True))))
 
+    def test_check_timeutils_strtime(self):
+        self.assertEqual(1, len(list(checks.check_timeutils_strtime(
+            "timeutils.strtime"))))
+        self.assertEqual(0, len(list(checks.check_timeutils_strtime(
+            "strftime"))))
+
     def test_validate_log_translations(self):
         self.assertEqual(1, len(list(checks.validate_log_translations(
             "LOG.info('foo')", "foo.py"))))
index 27d0d0829e5f97c7efff25a4d0e67e86b28c0234..e50643302e11c427da4faafbb16d9b0fabb93729 100644 (file)
@@ -394,7 +394,7 @@ class SolidFireDriver(san.SanISCSIDriver):
         # to set any that were provided
         params = {'volumeID': sf_volume_id}
 
-        create_time = timeutils.strtime(v_ref['created_at'])
+        create_time = timeutils.isotime(v_ref['created_at'], True)
         attributes = {'uuid': v_ref['id'],
                       'is_clone': 'True',
                       'src_uuid': src_uuid,
@@ -698,7 +698,7 @@ class SolidFireDriver(san.SanISCSIDriver):
         if type_id is not None:
             qos = self._set_qos_by_volume_type(ctxt, type_id)
 
-        create_time = timeutils.strtime(volume['created_at'])
+        create_time = timeutils.isotime(volume['created_at'], True)
         attributes = {'uuid': volume['id'],
                       'is_clone': 'False',
                       'created_at': create_time}
@@ -1006,7 +1006,7 @@ class SolidFireDriver(san.SanISCSIDriver):
             raise exception.VolumeNotFound(volume_id=volume['id'])
 
         attributes = sf_vol['attributes']
-        attributes['retyped_at'] = timeutils.strtime()
+        attributes['retyped_at'] = timeutils.isotime(subsecond=True)
         params = {'volumeID': sf_vol['volumeID']}
         qos = self._set_qos_by_volume_type(ctxt, new_type['id'])
 
@@ -1053,7 +1053,7 @@ class SolidFireDriver(san.SanISCSIDriver):
         if type_id is not None:
             qos = self._set_qos_by_volume_type(ctxt, type_id)
 
-        import_time = timeutils.strtime(volume['created_at'])
+        import_time = timeutils.isotime(volume['created_at'], True)
         attributes = {'uuid': volume['id'],
                       'is_clone': 'False',
                       'os_imported_at': import_time,
@@ -1113,7 +1113,7 @@ class SolidFireDriver(san.SanISCSIDriver):
         if sf_vol is None:
             raise exception.VolumeNotFound(volume_id=volume['id'])
 
-        export_time = timeutils.strtime()
+        export_time = timeutils.isotime(subsecond=True)
         attributes = sf_vol['attributes']
         attributes['os_exported_at'] = export_time
         params = {'volumeID': int(sf_vol['volumeID']),