Merge "Leverage timeutils, drop strtime() usage"
This commit is contained in:
commit
5df1f21904
@ -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
|
||||
|
@ -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
|
||||
|
@ -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}
|
||||
|
@ -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)
|
||||
|
@ -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"))))
|
||||
|
@ -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']),
|
||||
|
Loading…
x
Reference in New Issue
Block a user