Use LOG.warning instead of deprecated LOG.warn
The LOG.warn method is deprecated[1] and the LOG.warning method should be used instead. [1] https://docs.python.org/3/library/logging.html#logging.warning Change-Id: I87d33f215a064a70cea989d524dc26affeea0c3e
This commit is contained in:
parent
83194a5f4f
commit
a03e10ceb0
@ -24,6 +24,7 @@ Cinder Specific Commandments
|
|||||||
sequence of key-value pairs.
|
sequence of key-value pairs.
|
||||||
- [C337] Ensure the standard library mock modules is used and not the third
|
- [C337] Ensure the standard library mock modules is used and not the third
|
||||||
party mock library that was needed for Python 2 support.
|
party mock library that was needed for Python 2 support.
|
||||||
|
- [C338] Log.warn is deprecated. Enforce use of LOG.warning.
|
||||||
|
|
||||||
General
|
General
|
||||||
-------
|
-------
|
||||||
|
@ -386,3 +386,16 @@ def no_third_party_mock(logical_line):
|
|||||||
msg = ('C337: Unit tests should use the standard library "mock" '
|
msg = ('C337: Unit tests should use the standard library "mock" '
|
||||||
'module, not the third party mock lib.')
|
'module, not the third party mock lib.')
|
||||||
yield(0, msg)
|
yield(0, msg)
|
||||||
|
|
||||||
|
|
||||||
|
@core.flake8ext
|
||||||
|
def no_log_warn(logical_line):
|
||||||
|
"""Disallow 'LOG.warn('
|
||||||
|
|
||||||
|
Use LOG.warning() instead of Deprecated LOG.warn().
|
||||||
|
https://docs.python.org/3/library/logging.html#logging.warning
|
||||||
|
"""
|
||||||
|
|
||||||
|
msg = ("C338: LOG.warn is deprecated, please use LOG.warning!")
|
||||||
|
if "LOG.warn(" in logical_line:
|
||||||
|
yield (0, msg)
|
||||||
|
@ -209,6 +209,18 @@ class HackingTestCase(test.TestCase):
|
|||||||
self.assertEqual(1, len(list(checks.no_mutable_default_args(
|
self.assertEqual(1, len(list(checks.no_mutable_default_args(
|
||||||
"def foo (bar={}):"))))
|
"def foo (bar={}):"))))
|
||||||
|
|
||||||
|
def test_no_log_warn(self):
|
||||||
|
code = """
|
||||||
|
LOG.warn("LOG.warn is deprecated")
|
||||||
|
"""
|
||||||
|
errors = [(1, 0, 'C338')]
|
||||||
|
self._assert_has_errors(code, checks.no_log_warn,
|
||||||
|
expected_errors=errors)
|
||||||
|
code = """
|
||||||
|
LOG.warning("LOG.warn is deprecated")
|
||||||
|
"""
|
||||||
|
self._assert_has_no_errors(code, checks.no_log_warn)
|
||||||
|
|
||||||
def test_check_datetime_now(self):
|
def test_check_datetime_now(self):
|
||||||
self.assertEqual(1, len(list(checks.check_datetime_now(
|
self.assertEqual(1, len(list(checks.check_datetime_now(
|
||||||
"datetime.now", False))))
|
"datetime.now", False))))
|
||||||
|
@ -677,10 +677,10 @@ class NetAppBlockStorageCmodeLibrary(block_base.NetAppBlockStorageLibrary,
|
|||||||
try:
|
try:
|
||||||
dest_client.destroy_lun(lun_path)
|
dest_client.destroy_lun(lun_path)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.warn('Error cleaning up LUN %s in destination volume. '
|
LOG.warning('Error cleaning up LUN %s in destination volume. '
|
||||||
'Verify if destination volume still exists in pool '
|
'Verify if destination volume still exists in '
|
||||||
'%s and delete it manually to avoid unused '
|
'pool %s and delete it manually to avoid unused '
|
||||||
'resources.', lun_path, dest_pool)
|
'resources.', lun_path, dest_pool)
|
||||||
|
|
||||||
def _copy_lun(self, volume, src_ontap_volume, src_vserver,
|
def _copy_lun(self, volume, src_ontap_volume, src_vserver,
|
||||||
dest_ontap_volume, dest_vserver, dest_lun_name=None,
|
dest_ontap_volume, dest_vserver, dest_lun_name=None,
|
||||||
@ -803,7 +803,7 @@ class NetAppBlockStorageCmodeLibrary(block_base.NetAppBlockStorageLibrary,
|
|||||||
'performing operations with this volume. Check the '
|
'performing operations with this volume. Check the '
|
||||||
'migration status on the storage side and set '
|
'migration status on the storage side and set '
|
||||||
'volume status manually if migration succeeded.'))
|
'volume status manually if migration succeeded.'))
|
||||||
LOG.warn(error_msg, volume.id)
|
LOG.warning(error_msg, volume.id)
|
||||||
updates['status'] = fields.VolumeStatus.MAINTENANCE
|
updates['status'] = fields.VolumeStatus.MAINTENANCE
|
||||||
except na_utils.NetAppDriverException as e:
|
except na_utils.NetAppDriverException as e:
|
||||||
error_msg = (_('Failed to migrate volume %(vol)s from pool '
|
error_msg = (_('Failed to migrate volume %(vol)s from pool '
|
||||||
|
@ -1085,10 +1085,10 @@ class NetAppCmodeNfsDriver(nfs_base.NetAppNfsDriver,
|
|||||||
try:
|
try:
|
||||||
dest_client.delete_file(file_path)
|
dest_client.delete_file(file_path)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.warn('Error cleaning up file %s in destination volume. '
|
LOG.warning('Error cleaning up file %s in destination volume. '
|
||||||
'Verify if destination volume still exists in pool '
|
'Verify if destination volume still exists in '
|
||||||
'%s and delete it manually to avoid unused '
|
'pool %s and delete it manually to avoid unused '
|
||||||
'resources.', file_path, dest_pool)
|
'resources.', file_path, dest_pool)
|
||||||
|
|
||||||
def _copy_file(self, volume, src_ontap_volume, src_vserver,
|
def _copy_file(self, volume, src_ontap_volume, src_vserver,
|
||||||
dest_ontap_volume, dest_vserver, dest_file_name=None,
|
dest_ontap_volume, dest_vserver, dest_file_name=None,
|
||||||
|
@ -642,10 +642,10 @@ class Acs5000CommonDriver(san.SanDriver,
|
|||||||
'wanted': wanted_name})
|
'wanted': wanted_name})
|
||||||
is_existed = self._cmd.get_volume(wanted_name)
|
is_existed = self._cmd.get_volume(wanted_name)
|
||||||
if len(is_existed) == 1:
|
if len(is_existed) == 1:
|
||||||
LOG.warn('volume name %(wanted)s is existed, The two volumes '
|
LOG.warning('volume name %(wanted)s is existed, The two volumes '
|
||||||
'%(wanted)s and %(new)s may be on the same system.',
|
'%(wanted)s and %(new)s may be on the same system.',
|
||||||
{'new': existing_name,
|
{'new': existing_name,
|
||||||
'wanted': wanted_name})
|
'wanted': wanted_name})
|
||||||
return {'_name_id': new_volume['_name_id'] or new_volume['id']}
|
return {'_name_id': new_volume['_name_id'] or new_volume['id']}
|
||||||
else:
|
else:
|
||||||
self._cmd.set_volume_property(existing_name,
|
self._cmd.set_volume_property(existing_name,
|
||||||
@ -730,10 +730,10 @@ class Acs5000CommonDriver(san.SanDriver,
|
|||||||
size = int(vol_backend.get('size_mb', 0))
|
size = int(vol_backend.get('size_mb', 0))
|
||||||
size_gb = int(math.ceil(size / 1024))
|
size_gb = int(math.ceil(size / 1024))
|
||||||
if (size_gb * 1024) > size:
|
if (size_gb * 1024) > size:
|
||||||
LOG.warn('Volume %(vol)s capacity is %(mb)s MB, '
|
LOG.warning('Volume %(vol)s capacity is %(mb)s MB, '
|
||||||
'extend to %(gb)s GB.', {'vol': ref['source-name'],
|
'extend to %(gb)s GB.', {'vol': ref['source-name'],
|
||||||
'mb': size,
|
'mb': size,
|
||||||
'gb': size_gb})
|
'gb': size_gb})
|
||||||
self._cmd.extend_volume(ref['source-name'], size_gb)
|
self._cmd.extend_volume(ref['source-name'], size_gb)
|
||||||
return size_gb
|
return size_gb
|
||||||
|
|
||||||
|
@ -139,9 +139,9 @@ class Acs5000FCDriver(acs5000_common.Acs5000CommonDriver):
|
|||||||
target_wwpns = self._get_connected_wwpns()
|
target_wwpns = self._get_connected_wwpns()
|
||||||
if len(target_wwpns) == 0:
|
if len(target_wwpns) == 0:
|
||||||
target_wwpns = []
|
target_wwpns = []
|
||||||
LOG.warn('terminate_connection: Did not find '
|
LOG.warning('terminate_connection: Did not find '
|
||||||
'available fc wwpns when volume %s '
|
'available fc wwpns when volume %s '
|
||||||
'delete lun map.', volume.id)
|
'delete lun map.', volume.id)
|
||||||
|
|
||||||
initiator_target = {}
|
initiator_target = {}
|
||||||
for i_wwpn in initiator_wwpns:
|
for i_wwpn in initiator_wwpns:
|
||||||
@ -155,9 +155,9 @@ class Acs5000FCDriver(acs5000_common.Acs5000CommonDriver):
|
|||||||
self.protocol,
|
self.protocol,
|
||||||
initiator_wwpns)
|
initiator_wwpns)
|
||||||
else:
|
else:
|
||||||
LOG.warn('volume %s has been mapped to multi VMs, and these VMs '
|
LOG.warning('volume %s has been mapped to multi VMs, and these '
|
||||||
'belong to the same host. The mapping cancellation '
|
'VMs belong to the same host. The mapping '
|
||||||
'request is aborted.', volume.id)
|
'cancellation request is aborted.', volume.id)
|
||||||
zone_utils.remove_fc_zone(properties)
|
zone_utils.remove_fc_zone(properties)
|
||||||
LOG.debug('leave: terminate_connection: volume '
|
LOG.debug('leave: terminate_connection: volume '
|
||||||
'%(vol)s with connector %(conn)s',
|
'%(vol)s with connector %(conn)s',
|
||||||
|
@ -115,9 +115,9 @@ class Acs5000ISCSIDriver(acs5000_common.Acs5000CommonDriver):
|
|||||||
self.protocol,
|
self.protocol,
|
||||||
initiator)
|
initiator)
|
||||||
else:
|
else:
|
||||||
LOG.warn('volume %s has been mapped to multi VMs, and these VMs '
|
LOG.warning('volume %s has been mapped to multi VMs, and these '
|
||||||
'belong to the same host. The mapping cancellation '
|
'VMs belong to the same host. The mapping '
|
||||||
'request is aborted.', volume.id)
|
'cancellation request is aborted.', volume.id)
|
||||||
LOG.debug('leave: terminate_connection: volume '
|
LOG.debug('leave: terminate_connection: volume '
|
||||||
'%(vol)s with connector %(conn)s',
|
'%(vol)s with connector %(conn)s',
|
||||||
{'vol': volume.id, 'conn': connector})
|
{'vol': volume.id, 'conn': connector})
|
||||||
|
1
tox.ini
1
tox.ini
@ -222,6 +222,7 @@ extension =
|
|||||||
C313 = checks:validate_assertTrue
|
C313 = checks:validate_assertTrue
|
||||||
C336 = checks:dict_constructor_with_list_copy
|
C336 = checks:dict_constructor_with_list_copy
|
||||||
C337 = checks:no_third_party_mock
|
C337 = checks:no_third_party_mock
|
||||||
|
C338 = checks:no_log_warn
|
||||||
paths = ./cinder/tests/hacking
|
paths = ./cinder/tests/hacking
|
||||||
|
|
||||||
[doc8]
|
[doc8]
|
||||||
|
Loading…
Reference in New Issue
Block a user