- [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
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
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
'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}
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)
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)
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"))))
# 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,
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}
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'])
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,
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']),