From d9ce598f0ca68caa751e24a478610332ed90eea3 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Thu, 19 Dec 2019 12:53:02 -0600 Subject: [PATCH] Raise hacking version to 2.0.0 We've kept hacking capped for a long time now. This raises the hacking package version to the latest release and fixes the issues that it found. Change-Id: I933d541d9198f9742c95494bae6030cb3e4f2499 Signed-off-by: Sean McGinnis --- cinder/api/contrib/admin_actions.py | 2 +- cinder/api/contrib/cgsnapshots.py | 2 +- cinder/api/openstack/__init__.py | 2 +- cinder/api/v3/attachments.py | 2 +- cinder/brick/local_dev/lvm.py | 5 ++++- cinder/objects/base.py | 2 +- cinder/tests/unit/api/v3/test_snapshots.py | 1 - cinder/tests/unit/image/fake.py | 1 - .../unit/volume/drivers/hpe/test_hpe3par.py | 3 --- .../volume/drivers/ibm/test_storwize_svc.py | 15 ++++++++------ .../volume/flows/test_create_volume_flow.py | 4 ++-- cinder/tests/unit/volume/test_connection.py | 2 +- cinder/transfer/api.py | 2 +- cinder/volume/drivers/dell_emc/vnx/client.py | 2 +- cinder/volume/drivers/huawei/common.py | 4 ++-- cinder/volume/drivers/huawei/replication.py | 2 +- cinder/volume/drivers/ibm/gpfs.py | 2 +- .../drivers/ibm/ibm_storage/xiv_proxy.py | 20 +++++++++---------- .../drivers/inspur/instorage/replication.py | 2 +- cinder/volume/drivers/rsd.py | 2 +- cinder/volume/drivers/stx/client.py | 2 +- cinder/volume/targets/scst.py | 2 +- lower-constraints.txt | 2 +- test-requirements.txt | 2 +- 24 files changed, 43 insertions(+), 42 deletions(-) diff --git a/cinder/api/contrib/admin_actions.py b/cinder/api/contrib/admin_actions.py index 02fef3d67ae..40575bfd183 100644 --- a/cinder/api/contrib/admin_actions.py +++ b/cinder/api/contrib/admin_actions.py @@ -174,7 +174,7 @@ class VolumeAdminController(AdminController): try: self.volume_api.terminate_connection(context, volume, connector) - except exception.VolumeBackendAPIException as error: + except exception.VolumeBackendAPIException: msg = _("Unable to terminate volume connection from backend.") raise webob.exc.HTTPInternalServerError(explanation=msg) diff --git a/cinder/api/contrib/cgsnapshots.py b/cinder/api/contrib/cgsnapshots.py index 5eba06de689..e89f3d29105 100644 --- a/cinder/api/contrib/cgsnapshots.py +++ b/cinder/api/contrib/cgsnapshots.py @@ -68,7 +68,7 @@ class CgsnapshotsController(wsgi.Controller): except exception.InvalidGroupSnapshot as e: raise exc.HTTPBadRequest(explanation=six.text_type(e)) except (exception.GroupSnapshotNotFound, - exception.PolicyNotAuthorized) as e: + exception.PolicyNotAuthorized): # Exceptions will be handled at the wsgi level raise except Exception: diff --git a/cinder/api/openstack/__init__.py b/cinder/api/openstack/__init__.py index 2294135d136..3492f62fde9 100644 --- a/cinder/api/openstack/__init__.py +++ b/cinder/api/openstack/__init__.py @@ -31,7 +31,7 @@ LOG = logging.getLogger(__name__) class APIMapper(routes.Mapper): def routematch(self, url=None, environ=None): - if url is "": + if url == "": result = self._match("", environ) return result[0], result[1] return routes.Mapper.routematch(self, url, environ) diff --git a/cinder/api/v3/attachments.py b/cinder/api/v3/attachments.py index 1d98cd99731..0e6da5cf98b 100644 --- a/cinder/api/v3/attachments.py +++ b/cinder/api/v3/attachments.py @@ -190,7 +190,7 @@ class AttachmentsController(wsgi.Controller): err_msg = _( "Unable to create attachment for volume (%s).") % ex.msg LOG.exception(err_msg) - except Exception as ex: + except Exception: err_msg = _("Unable to create attachment for volume.") LOG.exception(err_msg) finally: diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index 4f929fd88bb..8e29b8f07d0 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -179,7 +179,10 @@ class LVM(executor.Executor): consumed_space = pool_size / 100 * data_percent free_space = pool_size - consumed_space free_space = round(free_space, 2) - except putils.ProcessExecutionError as err: + # Need noqa due to a false error about the 'err' variable being unused + # even though it is used in the logging. Possibly related to + # https://github.com/PyCQA/pyflakes/issues/378. + except putils.ProcessExecutionError as err: # noqa LOG.exception('Error querying thin pool about data_percent') LOG.error('Cmd :%s', err.cmd) LOG.error('StdOut :%s', err.stdout) diff --git a/cinder/objects/base.py b/cinder/objects/base.py index 3dc68e7a69a..336afffbdae 100644 --- a/cinder/objects/base.py +++ b/cinder/objects/base.py @@ -280,7 +280,7 @@ class CinderPersistentObject(object): # registration. try: cls.model = db.get_model_for_versioned_object(cls) - except (ImportError, AttributeError) as e: + except (ImportError, AttributeError): msg = _("Couldn't find ORM model for Persistent Versioned " "Object %s.") % cls.obj_name() LOG.exception("Failed to initialize object.") diff --git a/cinder/tests/unit/api/v3/test_snapshots.py b/cinder/tests/unit/api/v3/test_snapshots.py index e6cd4240663..d5eeede0874 100644 --- a/cinder/tests/unit/api/v3/test_snapshots.py +++ b/cinder/tests/unit/api/v3/test_snapshots.py @@ -44,7 +44,6 @@ def fake_get(self, context, *args, **kwargs): 'host': 'fake-host', 'status': 'available', 'encryption_key_id': None, - 'volume_type_id': None, 'migration_status': None, 'availability_zone': 'fake-zone', 'attach_status': 'detached', diff --git a/cinder/tests/unit/image/fake.py b/cinder/tests/unit/image/fake.py index cce77e2584d..e76469399bd 100644 --- a/cinder/tests/unit/image/fake.py +++ b/cinder/tests/unit/image/fake.py @@ -102,7 +102,6 @@ class _FakeImageService(object): 'updated_at': timestamp, 'deleted_at': None, 'deleted': False, - 'size': 1024, 'status': 'active', 'visibility': 'public', 'protected': True, diff --git a/cinder/tests/unit/volume/drivers/hpe/test_hpe3par.py b/cinder/tests/unit/volume/drivers/hpe/test_hpe3par.py index 269f51777fc..bd9ec43cc1a 100644 --- a/cinder/tests/unit/volume/drivers/hpe/test_hpe3par.py +++ b/cinder/tests/unit/volume/drivers/hpe/test_hpe3par.py @@ -2017,7 +2017,6 @@ class TestHPE3PARDriverBase(HPE3PARBaseDriver): mock_client.getVolume.return_value = { 'name': mock.ANY, - 'snapCPG': mock.ANY, 'comment': "{'display_name': 'Foo Volume'}", 'provisioningType': mock.ANY, 'userCPG': 'OpenStackCPG', @@ -2124,7 +2123,6 @@ class TestHPE3PARDriverBase(HPE3PARBaseDriver): mock_client.getVolume.return_value = { 'name': mock.ANY, - 'snapCPG': mock.ANY, 'comment': "{'display_name': 'Foo Volume'}", 'provisioningType': mock.ANY, 'userCPG': 'OpenStackCPG', @@ -2224,7 +2222,6 @@ class TestHPE3PARDriverBase(HPE3PARBaseDriver): mock_client.getVolume.return_value = { 'name': mock.ANY, - 'snapCPG': mock.ANY, 'comment': "{'display_name': 'Foo Volume'}", 'provisioningType': mock.ANY, 'userCPG': 'OpenStackCPG', diff --git a/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py b/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py index 824ad1e4bb0..be8102ef337 100644 --- a/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py +++ b/cinder/tests/unit/volume/drivers/ibm/test_storwize_svc.py @@ -4069,8 +4069,9 @@ class StorwizeSVCFcDriverTestCase(test.TestCase): volume_fc, connector) # All the wwpns of this host are not configured. - host_site_2 = {'site1': 'ff00000000000000', - 'site1': 'ff00000000000001'} + # TODO: This needs to be fixed. See bug #1857043 + host_site_2 = {'site1': 'ff00000000000000', # noqa + 'site1': 'ff00000000000001'} # noqa self.fc_driver.configuration.set_override( 'storwize_preferred_host_site', host_site_2) self.assertRaises(exception.VolumeDriverException, @@ -4078,8 +4079,9 @@ class StorwizeSVCFcDriverTestCase(test.TestCase): volume_fc, connector) - host_site_3 = {'site1': 'ffff000000000000', - 'site1': 'ffff000000000001'} + # TODO: This needs to be fixed. See bug #1857043 + host_site_3 = {'site1': 'ffff000000000000', # noqa + 'site1': 'ffff000000000001'} # noqa self.fc_driver.configuration.set_override( 'storwize_preferred_host_site', host_site_3) self.fc_driver.initialize_connection(volume_fc, connector) @@ -4088,8 +4090,9 @@ class StorwizeSVCFcDriverTestCase(test.TestCase): host_info = self.fc_driver._helpers.ssh.lshost(host=host_name) self.assertEqual('site1', host_info[0]['site_name']) - host_site_4 = {'site2': 'ffff000000000000', - 'site2': 'ffff000000000001'} + # TODO: This needs to be fixed. See bug #1857043 + host_site_4 = {'site2': 'ffff000000000000', # noqa + 'site2': 'ffff000000000001'} # noqa self.fc_driver.configuration.set_override( 'storwize_preferred_host_site', host_site_4) self.assertRaises(exception.InvalidConfigurationValue, diff --git a/cinder/tests/unit/volume/flows/test_create_volume_flow.py b/cinder/tests/unit/volume/flows/test_create_volume_flow.py index ce7d4270e50..860da11c3dd 100644 --- a/cinder/tests/unit/volume/flows/test_create_volume_flow.py +++ b/cinder/tests/unit/volume/flows/test_create_volume_flow.py @@ -1319,7 +1319,7 @@ class CreateVolumeFlowManagerGlanceCinderBackendCase(test.TestCase): image_id, image_meta, fake_image_service) - if format is 'raw' and not owner and location: + if format == 'raw' and not owner and location: fake_driver.create_cloned_volume.assert_called_once_with( volume, image_volume) handle_bootable.assert_called_once_with(self.ctxt, volume, @@ -1384,7 +1384,7 @@ class CreateVolumeFlowManagerGlanceCinderBackendCase(test.TestCase): image_id, image_meta, fake_image_service) - if format is 'raw' and not owner and location: + if format == 'raw' and not owner and location: fake_driver.create_cloned_volume.assert_called_once_with( volume, image_volume) handle_bootable.assert_called_once_with(self.ctxt, volume, diff --git a/cinder/tests/unit/volume/test_connection.py b/cinder/tests/unit/volume/test_connection.py index ac7b70398fa..b06546f3c8b 100644 --- a/cinder/tests/unit/volume/test_connection.py +++ b/cinder/tests/unit/volume/test_connection.py @@ -88,7 +88,7 @@ class DiscardFlagTestCase(base.BaseVolumeTestCase): self.volume.driver.initialize_connection.return_value = conn_info def _safe_get(key): - if key is 'report_discard_supported': + if key == 'report_discard_supported': return config_discard_flag else: return None diff --git a/cinder/transfer/api.py b/cinder/transfer/api.py index 955eeed14a8..e81cad9b4c0 100644 --- a/cinder/transfer/api.py +++ b/cinder/transfer/api.py @@ -209,7 +209,7 @@ class API(base.Base): donor_reservations = QUOTAS.reserve(context, project_id=donor_id, **reserve_opts) - except exception.OverQuota as e: + except exception.OverQuota: donor_reservations = None LOG.exception("Failed to update volume providing snapshots quota:" " Over quota.") diff --git a/cinder/volume/drivers/dell_emc/vnx/client.py b/cinder/volume/drivers/dell_emc/vnx/client.py index 46e3f1ebcbf..86e82fd3604 100644 --- a/cinder/volume/drivers/dell_emc/vnx/client.py +++ b/cinder/volume/drivers/dell_emc/vnx/client.py @@ -505,7 +505,7 @@ class Client(object): """Adds the `lun` to `storage_group`.""" try: return storage_group.attach_alu(lun, max_retries) - except storops_ex.VNXAluAlreadyAttachedError as ex: + except storops_ex.VNXAluAlreadyAttachedError: # Ignore the failure due to retry. return storage_group.get_hlu(lun) except storops_ex.VNXNoHluAvailableError as ex: diff --git a/cinder/volume/drivers/huawei/common.py b/cinder/volume/drivers/huawei/common.py index 3b80534306b..ac02eb67ff3 100644 --- a/cinder/volume/drivers/huawei/common.py +++ b/cinder/volume/drivers/huawei/common.py @@ -315,7 +315,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): replica_info = self.replica.create_replica(lun_info, replica_model) model_update.update(replica_info) - except Exception as err: + except Exception: LOG.exception('Create replication volume error.') self._delete_lun_with_check(lun_id) raise @@ -392,7 +392,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): if replica_data: try: self.replica.delete_replica(volume) - except exception.VolumeBackendAPIException as err: + except exception.VolumeBackendAPIException: with excutils.save_and_reraise_exception(): LOG.exception("Delete replication error.") self._delete_volume(volume) diff --git a/cinder/volume/drivers/huawei/replication.py b/cinder/volume/drivers/huawei/replication.py index 55d55684e5a..97ea2dab3ce 100644 --- a/cinder/volume/drivers/huawei/replication.py +++ b/cinder/volume/drivers/huawei/replication.py @@ -199,7 +199,7 @@ class ReplicaCommonDriver(object): try: self.wait_expect_state(replica_id, running_status) - except Exception as err: + except Exception: msg = _('Split replication failed.') LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) diff --git a/cinder/volume/drivers/ibm/gpfs.py b/cinder/volume/drivers/ibm/gpfs.py index e32c9c726f2..439b8f629d9 100644 --- a/cinder/volume/drivers/ibm/gpfs.py +++ b/cinder/volume/drivers/ibm/gpfs.py @@ -250,7 +250,7 @@ class GPFSDriver(driver.CloneableImageVD, try: fileset = fs_regex.match(out).group('fileset') return fileset - except AttributeError as exc: + except AttributeError: msg = (_('Failed to find fileset for path %(path)s, command ' 'output: %(cmdout)s.') % {'path': path, diff --git a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py index 54093e03092..df07fa3510b 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py +++ b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py @@ -1801,12 +1801,12 @@ class XIVProxy(proxy.IBMStorageProxy): "cg_create", cg=cgname, pool=self.storage_info[ storage.FLAG_KEYS['storage_pool']]).as_list - except errors.CgNameExistsError as e: + except errors.CgNameExistsError: error = (_("consistency group %s already exists on backend") % cgname) LOG.error(error) raise self._get_exception()(error) - except errors.CgLimitReachedError as e: + except errors.CgLimitReachedError: error = _("Reached Maximum number of consistency groups") LOG.error(error) raise self._get_exception()(error) @@ -2176,37 +2176,37 @@ class XIVProxy(proxy.IBMStorageProxy): self._call_xiv_xcli( "cg_snapshots_create", cg=cgname, snap_group=groupname).as_list - except errors.CgDoesNotExistError as e: + except errors.CgDoesNotExistError: error = (_("Consistency group %s does not exist on backend") % cgname) LOG.error(error) raise self._get_exception()(error) - except errors.CgBadNameError as e: + except errors.CgBadNameError: error = (_("Consistency group %s has an illegal name") % cgname) LOG.error(error) raise self._get_exception()(error) - except errors.SnapshotGroupDoesNotExistError as e: + except errors.SnapshotGroupDoesNotExistError: error = (_("Snapshot group %s has an illegal name") % cgname) LOG.error(error) raise self._get_exception()(error) - except errors.PoolSnapshotLimitReachedError as e: + except errors.PoolSnapshotLimitReachedError: error = _("Reached maximum snapshots allocation size") LOG.error(error) raise self._get_exception()(error) - except errors.CgEmptyError as e: + except errors.CgEmptyError: error = (_("Consistency group %s is empty") % cgname) LOG.error(error) raise self._get_exception()(error) except (errors.MaxVolumesReachedError, - errors.DomainMaxVolumesReachedError) as e: + errors.DomainMaxVolumesReachedError): error = _("Reached Maximum number of volumes") LOG.error(error) raise self._get_exception()(error) - except errors.SnapshotGroupIsReservedError as e: + except errors.SnapshotGroupIsReservedError: error = (_("Consistency group %s name is reserved") % cgname) LOG.error(error) raise self._get_exception()(error) - except errors.SnapshotGroupAlreadyExistsError as e: + except errors.SnapshotGroupAlreadyExistsError: error = (_("Snapshot group %s already exists") % groupname) LOG.error(error) raise self._get_exception()(error) diff --git a/cinder/volume/drivers/inspur/instorage/replication.py b/cinder/volume/drivers/inspur/instorage/replication.py index ddfedc12659..e9df361bdc9 100644 --- a/cinder/volume/drivers/inspur/instorage/replication.py +++ b/cinder/volume/drivers/inspur/instorage/replication.py @@ -176,7 +176,7 @@ class InStorageMCSReplication(object): # Reverse the role of the primary and secondary volumes self.target_assistant.switch_relationship(rel_info['name']) return {'replication_status': fields.ReplicationStatus.FAILED_OVER} - except Exception as e: + except Exception: LOG.exception('Unable to fail-over the volume %(id)s to the ' 'secondary back-end by switchrcrelationship ' 'command.', {"id": vref.id}) diff --git a/cinder/volume/drivers/rsd.py b/cinder/volume/drivers/rsd.py index e786634cfa8..98bf82ec648 100644 --- a/cinder/volume/drivers/rsd.py +++ b/cinder/volume/drivers/rsd.py @@ -417,7 +417,7 @@ class RSDClient(object): detail=(_("Volume %s already attached") % volume_url)) node.attach_endpoint(volume.path) - except sushy_exceptions.InvalidParameterValueError as e: + except sushy_exceptions.InvalidParameterValueError: LOG.exception("Attach volume failed (not allowable)") raise RSDRetryableException( reason=(_("Not allowed to attach from " diff --git a/cinder/volume/drivers/stx/client.py b/cinder/volume/drivers/stx/client.py index e43496ce21e..6c6aef2f5ce 100644 --- a/cinder/volume/drivers/stx/client.py +++ b/cinder/volume/drivers/stx/client.py @@ -395,7 +395,7 @@ class STXClient(object): LOG.debug("volume '{}' is already mapped to {} at lun {}". format(volume_name, iid, lun)) return int(lun) - except Exception as e: + except Exception: LOG.exception("failed to look up mappings for volume '%s'", volume_name) raise diff --git a/cinder/volume/targets/scst.py b/cinder/volume/targets/scst.py index 2c62c083ac9..eb8ac968424 100644 --- a/cinder/volume/targets/scst.py +++ b/cinder/volume/targets/scst.py @@ -223,7 +223,7 @@ class SCSTAdm(iscsi.ISCSITarget): # starts try: self.scst_execute('-write_config', '/etc/scst.conf') - except putils.ProcessExecutionError as e: + except putils.ProcessExecutionError: LOG.error("Failed to write in /etc/scst.conf.") raise exception.ISCSITargetHelperCommandFailed( error_message="Failed to write in /etc/scst.conf.") diff --git a/lower-constraints.txt b/lower-constraints.txt index f8f010d2a08..6023c08ad60 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -38,7 +38,7 @@ gitdb2==2.0.3 GitPython==2.1.8 google-api-python-client==1.4.2 greenlet==0.4.10 -hacking==1.1.0 +hacking==2.0.0 httplib2==0.9.1 idna==2.6 imagesize==1.0.0 diff --git a/test-requirements.txt b/test-requirements.txt index beb5762a2c2..8dcedcdb4cf 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,7 +3,7 @@ # process, which may cause wedges in the gate later. # Install bounded pep8/pyflakes first, then let flake8 install -hacking>=1.1.0,<1.2.0 # Apache-2.0 +hacking>=2.0.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.2.1 # MIT