From a03e10ceb094c222698df0bc90061b70384f5b27 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 29 Nov 2021 14:18:00 +0900 Subject: [PATCH] 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 --- HACKING.rst | 1 + cinder/tests/hacking/checks.py | 13 +++++++++++++ cinder/tests/unit/test_hacking.py | 12 ++++++++++++ .../drivers/netapp/dataontap/block_cmode.py | 10 +++++----- .../volume/drivers/netapp/dataontap/nfs_cmode.py | 8 ++++---- .../drivers/toyou/acs5000/acs5000_common.py | 16 ++++++++-------- .../volume/drivers/toyou/acs5000/acs5000_fc.py | 12 ++++++------ .../drivers/toyou/acs5000/acs5000_iscsi.py | 6 +++--- tox.ini | 1 + 9 files changed, 53 insertions(+), 26 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 357ad47f89c..cf364c8dd30 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -24,6 +24,7 @@ Cinder Specific Commandments sequence of key-value pairs. - [C337] Ensure the standard library mock modules is used and not the third party mock library that was needed for Python 2 support. +- [C338] Log.warn is deprecated. Enforce use of LOG.warning. General ------- diff --git a/cinder/tests/hacking/checks.py b/cinder/tests/hacking/checks.py index 3494c6ef31f..ca3d848a68a 100644 --- a/cinder/tests/hacking/checks.py +++ b/cinder/tests/hacking/checks.py @@ -386,3 +386,16 @@ def no_third_party_mock(logical_line): msg = ('C337: Unit tests should use the standard library "mock" ' 'module, not the third party mock lib.') 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) diff --git a/cinder/tests/unit/test_hacking.py b/cinder/tests/unit/test_hacking.py index 334616861a0..d7bfd92daab 100644 --- a/cinder/tests/unit/test_hacking.py +++ b/cinder/tests/unit/test_hacking.py @@ -209,6 +209,18 @@ class HackingTestCase(test.TestCase): self.assertEqual(1, len(list(checks.no_mutable_default_args( "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): self.assertEqual(1, len(list(checks.check_datetime_now( "datetime.now", False)))) diff --git a/cinder/volume/drivers/netapp/dataontap/block_cmode.py b/cinder/volume/drivers/netapp/dataontap/block_cmode.py index f77f7d19688..4836245579f 100644 --- a/cinder/volume/drivers/netapp/dataontap/block_cmode.py +++ b/cinder/volume/drivers/netapp/dataontap/block_cmode.py @@ -677,10 +677,10 @@ class NetAppBlockStorageCmodeLibrary(block_base.NetAppBlockStorageLibrary, try: dest_client.destroy_lun(lun_path) except Exception: - LOG.warn('Error cleaning up LUN %s in destination volume. ' - 'Verify if destination volume still exists in pool ' - '%s and delete it manually to avoid unused ' - 'resources.', lun_path, dest_pool) + LOG.warning('Error cleaning up LUN %s in destination volume. ' + 'Verify if destination volume still exists in ' + 'pool %s and delete it manually to avoid unused ' + 'resources.', lun_path, dest_pool) def _copy_lun(self, volume, src_ontap_volume, src_vserver, 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 ' 'migration status on the storage side and set ' 'volume status manually if migration succeeded.')) - LOG.warn(error_msg, volume.id) + LOG.warning(error_msg, volume.id) updates['status'] = fields.VolumeStatus.MAINTENANCE except na_utils.NetAppDriverException as e: error_msg = (_('Failed to migrate volume %(vol)s from pool ' diff --git a/cinder/volume/drivers/netapp/dataontap/nfs_cmode.py b/cinder/volume/drivers/netapp/dataontap/nfs_cmode.py index 7a512f98063..54aebb2d463 100644 --- a/cinder/volume/drivers/netapp/dataontap/nfs_cmode.py +++ b/cinder/volume/drivers/netapp/dataontap/nfs_cmode.py @@ -1085,10 +1085,10 @@ class NetAppCmodeNfsDriver(nfs_base.NetAppNfsDriver, try: dest_client.delete_file(file_path) except Exception: - LOG.warn('Error cleaning up file %s in destination volume. ' - 'Verify if destination volume still exists in pool ' - '%s and delete it manually to avoid unused ' - 'resources.', file_path, dest_pool) + LOG.warning('Error cleaning up file %s in destination volume. ' + 'Verify if destination volume still exists in ' + 'pool %s and delete it manually to avoid unused ' + 'resources.', file_path, dest_pool) def _copy_file(self, volume, src_ontap_volume, src_vserver, dest_ontap_volume, dest_vserver, dest_file_name=None, diff --git a/cinder/volume/drivers/toyou/acs5000/acs5000_common.py b/cinder/volume/drivers/toyou/acs5000/acs5000_common.py index 551a313cee5..17b34f8ac82 100644 --- a/cinder/volume/drivers/toyou/acs5000/acs5000_common.py +++ b/cinder/volume/drivers/toyou/acs5000/acs5000_common.py @@ -642,10 +642,10 @@ class Acs5000CommonDriver(san.SanDriver, 'wanted': wanted_name}) is_existed = self._cmd.get_volume(wanted_name) if len(is_existed) == 1: - LOG.warn('volume name %(wanted)s is existed, The two volumes ' - '%(wanted)s and %(new)s may be on the same system.', - {'new': existing_name, - 'wanted': wanted_name}) + LOG.warning('volume name %(wanted)s is existed, The two volumes ' + '%(wanted)s and %(new)s may be on the same system.', + {'new': existing_name, + 'wanted': wanted_name}) return {'_name_id': new_volume['_name_id'] or new_volume['id']} else: self._cmd.set_volume_property(existing_name, @@ -730,10 +730,10 @@ class Acs5000CommonDriver(san.SanDriver, size = int(vol_backend.get('size_mb', 0)) size_gb = int(math.ceil(size / 1024)) if (size_gb * 1024) > size: - LOG.warn('Volume %(vol)s capacity is %(mb)s MB, ' - 'extend to %(gb)s GB.', {'vol': ref['source-name'], - 'mb': size, - 'gb': size_gb}) + LOG.warning('Volume %(vol)s capacity is %(mb)s MB, ' + 'extend to %(gb)s GB.', {'vol': ref['source-name'], + 'mb': size, + 'gb': size_gb}) self._cmd.extend_volume(ref['source-name'], size_gb) return size_gb diff --git a/cinder/volume/drivers/toyou/acs5000/acs5000_fc.py b/cinder/volume/drivers/toyou/acs5000/acs5000_fc.py index 49892c792ce..e974df345e7 100644 --- a/cinder/volume/drivers/toyou/acs5000/acs5000_fc.py +++ b/cinder/volume/drivers/toyou/acs5000/acs5000_fc.py @@ -139,9 +139,9 @@ class Acs5000FCDriver(acs5000_common.Acs5000CommonDriver): target_wwpns = self._get_connected_wwpns() if len(target_wwpns) == 0: target_wwpns = [] - LOG.warn('terminate_connection: Did not find ' - 'available fc wwpns when volume %s ' - 'delete lun map.', volume.id) + LOG.warning('terminate_connection: Did not find ' + 'available fc wwpns when volume %s ' + 'delete lun map.', volume.id) initiator_target = {} for i_wwpn in initiator_wwpns: @@ -155,9 +155,9 @@ class Acs5000FCDriver(acs5000_common.Acs5000CommonDriver): self.protocol, initiator_wwpns) else: - LOG.warn('volume %s has been mapped to multi VMs, and these VMs ' - 'belong to the same host. The mapping cancellation ' - 'request is aborted.', volume.id) + LOG.warning('volume %s has been mapped to multi VMs, and these ' + 'VMs belong to the same host. The mapping ' + 'cancellation request is aborted.', volume.id) zone_utils.remove_fc_zone(properties) LOG.debug('leave: terminate_connection: volume ' '%(vol)s with connector %(conn)s', diff --git a/cinder/volume/drivers/toyou/acs5000/acs5000_iscsi.py b/cinder/volume/drivers/toyou/acs5000/acs5000_iscsi.py index 55883ef8d7c..ce9b4715b70 100644 --- a/cinder/volume/drivers/toyou/acs5000/acs5000_iscsi.py +++ b/cinder/volume/drivers/toyou/acs5000/acs5000_iscsi.py @@ -115,9 +115,9 @@ class Acs5000ISCSIDriver(acs5000_common.Acs5000CommonDriver): self.protocol, initiator) else: - LOG.warn('volume %s has been mapped to multi VMs, and these VMs ' - 'belong to the same host. The mapping cancellation ' - 'request is aborted.', volume.id) + LOG.warning('volume %s has been mapped to multi VMs, and these ' + 'VMs belong to the same host. The mapping ' + 'cancellation request is aborted.', volume.id) LOG.debug('leave: terminate_connection: volume ' '%(vol)s with connector %(conn)s', {'vol': volume.id, 'conn': connector}) diff --git a/tox.ini b/tox.ini index e68f6a6cf2c..291756f5e30 100644 --- a/tox.ini +++ b/tox.ini @@ -222,6 +222,7 @@ extension = C313 = checks:validate_assertTrue C336 = checks:dict_constructor_with_list_copy C337 = checks:no_third_party_mock + C338 = checks:no_log_warn paths = ./cinder/tests/hacking [doc8]