diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc26b97847..16f482bf0c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,7 +32,7 @@ repos: - id: flake8 name: flake8 additional_dependencies: - - hacking>=3.1.0,<3.2.0 + - hacking>=6.1.0,<6.2.0 language: python entry: flake8 files: '^.*\.py$' diff --git a/contrib/share_driver_hooks/zaqar_notification_example_consumer.py b/contrib/share_driver_hooks/zaqar_notification_example_consumer.py index cef64bfa5f..3052519022 100755 --- a/contrib/share_driver_hooks/zaqar_notification_example_consumer.py +++ b/contrib/share_driver_hooks/zaqar_notification_example_consumer.py @@ -219,7 +219,7 @@ def main(): # Run consumer print_with_time("Consumer was successfully run.") - while(True): + while True: messages = pop_zaqar_messages( zaqarclientwrapper.ZAQARCLIENT, CONF.zaqar.zaqar_queues) if not messages: diff --git a/manila/api/common.py b/manila/api/common.py index f260eff8ac..2b58e00ee8 100644 --- a/manila/api/common.py +++ b/manila/api/common.py @@ -438,7 +438,7 @@ def validate_common_name(access): common name. The meaning of a string depends on its interpretation and is limited to 64 characters. """ - if not(0 < len(access) < 65): + if not (0 < len(access) < 65): exc_str = _('Invalid CN (common name). Must be 1-64 chars long.') raise webob.exc.HTTPBadRequest(explanation=exc_str) diff --git a/manila/api/openstack/api_version_request.py b/manila/api/openstack/api_version_request.py index 228cfe6757..40a2ad555a 100644 --- a/manila/api/openstack/api_version_request.py +++ b/manila/api/openstack/api_version_request.py @@ -267,7 +267,7 @@ class APIVersionRequest(utils.ComparableMixin): @experimental.setter def experimental(self, value): - if type(value) != bool: + if not isinstance(value, bool): msg = _('The experimental property must be a bool value.') raise exception.InvalidParameterValue(err=msg) self._experimental = value @@ -275,7 +275,7 @@ class APIVersionRequest(utils.ComparableMixin): def matches_versioned_method(self, method): """Compares this version to that of a versioned method.""" - if type(method) != versioned_method.VersionedMethod: + if not isinstance(method, versioned_method.VersionedMethod): msg = _('An API version request must be compared ' 'to a VersionedMethod object.') raise exception.InvalidParameterValue(err=msg) diff --git a/manila/api/v1/share_snapshots.py b/manila/api/v1/share_snapshots.py index fad1aa52ec..6845b41e2e 100644 --- a/manila/api/v1/share_snapshots.py +++ b/manila/api/v1/share_snapshots.py @@ -56,7 +56,7 @@ class ShareSnapshotMixin(object): snapshot = self.share_api.get_snapshot(context, id) # Snapshot with no instances is filtered out. - if(snapshot.get('status') is None): + if snapshot.get('status') is None: raise exc.HTTPNotFound() except exception.NotFound: raise exc.HTTPNotFound() diff --git a/manila/api/v2/share_networks.py b/manila/api/v2/share_networks.py index 403701b0a9..916debf506 100644 --- a/manila/api/v2/share_networks.py +++ b/manila/api/v2/share_networks.py @@ -142,11 +142,11 @@ class ShareNetworkController(wsgi.Controller, wsgi.AdminActionsMixin): id, security_service['id']) except Exception: - LOG.exception( - "Failed to delete security association of network " - "{net_id} and security service " - "{sec_id}".format(net_id=id, - sec_id=security_service['id'])) + msg = ("Failed to delete security association of network " + "{net_id} and security service " + "{sec_id}".format(net_id=id, + sec_id=security_service['id'])) + LOG.exception(msg) db_api.share_network_delete(context, id) diff --git a/manila/network/linux/ip_lib.py b/manila/network/linux/ip_lib.py index 3d246c7cde..351f3e0960 100644 --- a/manila/network/linux/ip_lib.py +++ b/manila/network/linux/ip_lib.py @@ -352,11 +352,11 @@ class IpRouteCommand(IpDeviceCommandBase): 'list', 'proto', 'kernel', 'exact', subnet).split('\n') for subnet_route_line in subnet_route_list_lines: i = iter(subnet_route_line.split()) - while(next(i) != 'dev'): + while next(i) != 'dev': pass device = next(i) try: - while(next(i) != 'src'): + while next(i) != 'src': pass src = next(i) except Exception: diff --git a/manila/scheduler/evaluator/evaluator.py b/manila/scheduler/evaluator/evaluator.py index 88bfc3d765..ae41554ecc 100644 --- a/manila/scheduler/evaluator/evaluator.py +++ b/manila/scheduler/evaluator/evaluator.py @@ -28,7 +28,7 @@ def _operatorOperands(tokenList): try: op1 = next(it) op2 = next(it) - yield(op1, op2) + yield (op1, op2) except StopIteration: break diff --git a/manila/share/drivers/cephfs/driver.py b/manila/share/drivers/cephfs/driver.py index de864b973e..17e01a6ccb 100644 --- a/manila/share/drivers/cephfs/driver.py +++ b/manila/share/drivers/cephfs/driver.py @@ -587,8 +587,8 @@ class CephFSDriver(driver.ExecuteMixin, driver.GaneshaMixin, if share['share_group_id'] is not None: argdict.update({"group_name": share["share_group_id"]}) - LOG.debug("extend_share {id} {size}".format( - id=share['id'], size=new_size)) + LOG.debug("extend_share {id} {size}", + {"id": share['id'], "size": new_size}) rados_command(self.rados_client, "fs subvolume resize", argdict) diff --git a/manila/share/drivers/dell_emc/plugins/powermax/object_manager.py b/manila/share/drivers/dell_emc/plugins/powermax/object_manager.py index e208d517e3..28f05e1f7e 100644 --- a/manila/share/drivers/dell_emc/plugins/powermax/object_manager.py +++ b/manila/share/drivers/dell_emc/plugins/powermax/object_manager.py @@ -2032,7 +2032,7 @@ class NFSShare(StorageObject): access_hosts = set() try: access_hosts.remove('-0.0.0.0/0.0.0.0') - except(ValueError, KeyError): + except (ValueError, KeyError): pass access_str = ('access=%(access)s' % {'access': ':'.join( diff --git a/manila/share/drivers/ganesha/manager.py b/manila/share/drivers/ganesha/manager.py index 48b4917c3c..40aa411832 100644 --- a/manila/share/drivers/ganesha/manager.py +++ b/manila/share/drivers/ganesha/manager.py @@ -305,7 +305,7 @@ class GaneshaManager(object): try: self.execute('mv', tmpf, path) except exception.ProcessExecutionError as e: - LOG.error('mv temp file ({0}) to {1} failed.'.format(tmpf, path)) + LOG.error('mv temp file (%s) to %s failed.', tmpf, path) self.execute('rm', tmpf) raise exception.GaneshaCommandFailure( stdout=e.stdout, stderr=e.stderr, exit_code=e.exit_code, @@ -546,8 +546,8 @@ class GaneshaManager(object): bytes_read = ioctx.read(object_name, max_size) if ((len(bytes_read) == max_size) and (ioctx.read(object_name, 1, offset=max_size))): - LOG.warning("Size of object {0} exceeds '{1}' bytes " - "read".format(object_name, max_size)) + LOG.warning("Size of object %s exceeds '%d' bytes " + "read", object_name, max_size) finally: ioctx.close() @@ -595,7 +595,7 @@ class GaneshaManager(object): try: ioctx.remove_object(object_name) except rados.ObjectNotFound: - LOG.warning("Object '{0}' was already removed".format(object_name)) + LOG.warning("Object '%s' was already removed", object_name) finally: ioctx.close() diff --git a/manila/share/drivers/glusterfs/layout.py b/manila/share/drivers/glusterfs/layout.py index f340d5dc5f..055f5f1a4a 100644 --- a/manila/share/drivers/glusterfs/layout.py +++ b/manila/share/drivers/glusterfs/layout.py @@ -81,7 +81,7 @@ class GlusterfsShareDriverBase(driver.ShareDriver): False) def _setup_via_manager(self, share_mgr, share_mgr_parent=None): - """Callback for layout's `create_share` and `create_share_from_snapshot` + """Callback for layout's `create_share`/`create_share_from_snapshot` :param share_mgr: a {'share': , 'manager': } dict where is the share created diff --git a/manila/share/drivers/huawei/v3/helper.py b/manila/share/drivers/huawei/v3/helper.py index f9e3df75c2..32a740415f 100644 --- a/manila/share/drivers/huawei/v3/helper.py +++ b/manila/share/drivers/huawei/v3/helper.py @@ -113,7 +113,7 @@ class RestHelper(object): result = self.do_call(url, data, 'POST', calltimeout=constants.LOGIN_SOCKET_TIMEOUT) - if((result['error']['code'] != 0) + if ((result['error']['code'] != 0) or ("data" not in result) or (result['data']['deviceid'] is None)): LOG.error("Login to %s failed, try another.", item_url) @@ -142,7 +142,7 @@ class RestHelper(object): old_url = self.url result = self.do_call(url, data, method) error_code = result['error']['code'] - if(error_code == constants.ERROR_CONNECT_TO_SERVER + if (error_code == constants.ERROR_CONNECT_TO_SERVER or error_code == constants.ERROR_UNAUTHORIZED_TO_SERVER): LOG.error("Can't open the recent url, re-login.") deviceid = self.login() diff --git a/manila/share/manager.py b/manila/share/manager.py index fc65c5dac5..9a8b9d492c 100644 --- a/manila/share/manager.py +++ b/manila/share/manager.py @@ -2690,8 +2690,8 @@ class ShareManager(manager.SchedulerDependentManager): updated_export_locs = updated_replica.get( 'export_locations') - if(updated_export_locs is not None - and isinstance(updated_export_locs, list)): + if updated_export_locs is not None \ + and isinstance(updated_export_locs, list): self.db.export_locations_update( context, updated_replica['id'], updated_export_locs) diff --git a/manila/test.py b/manila/test.py index 0e0fa9bd60..f1f7fa5651 100644 --- a/manila/test.py +++ b/manila/test.py @@ -406,7 +406,7 @@ class TestCase(base_test.BaseTestCase): try: f = super(TestCase, self).assertIn except AttributeError: - self.assertTrue(a in b, *args, **kwargs) + self.assertIn(a, b, *args, **kwargs) else: f(a, b, *args, **kwargs) @@ -415,7 +415,7 @@ class TestCase(base_test.BaseTestCase): try: f = super(TestCase, self).assertNotIn except AttributeError: - self.assertFalse(a in b, *args, **kwargs) + self.assertNotIn(a, b, *args, **kwargs) else: f(a, b, *args, **kwargs) diff --git a/manila/tests/db/sqlalchemy/test_api.py b/manila/tests/db/sqlalchemy/test_api.py index 5f0539afdd..ed0fc2aab4 100644 --- a/manila/tests/db/sqlalchemy/test_api.py +++ b/manila/tests/db/sqlalchemy/test_api.py @@ -166,7 +166,7 @@ class ShareAccessDatabaseAPITestCase(test.TestCase): share_access_keys_present = True if with_share_access_data else False actual_access_ids = [r['access_id'] for r in rules] - self.assertTrue(isinstance(actual_access_ids, list)) + self.assertIsInstance(actual_access_ids, list) expected = [access_1['id'], access_2['id']] self.assertEqual(len(expected), len(actual_access_ids)) for pool in expected: @@ -3649,9 +3649,9 @@ class ShareServerDatabaseAPITestCase(test.TestCase): self.assertEqual(2, len(servers)) ids = [s['id'] for s in servers] - self.assertTrue(valid['id'] in ids) - self.assertTrue(other['id'] in ids) - self.assertFalse(invalid['id'] in ids) + self.assertIn(valid['id'], ids) + self.assertIn(other['id'], ids) + self.assertNotIn(invalid['id'], ids) def test_get_all_by_host_and_share_subnet_not_found(self): self.assertRaises( @@ -5615,8 +5615,7 @@ class ResourceLocksTestCase(test.TestCase): ] self.assertEqual(order_expected, [lock['id'] for lock in all_project_locks]) - self.assertTrue(lk_5['project_id'] - not in [self.project_id, project_id_2]) + self.assertNotIn(lk_5['project_id'], [self.project_id, project_id_2]) self.assertIsNone(count) filtered_locks, count = db_api.resource_lock_get_all( diff --git a/manila/tests/hacking/checks.py b/manila/tests/hacking/checks.py index d919dd6c98..fee921cf25 100644 --- a/manila/tests/hacking/checks.py +++ b/manila/tests/hacking/checks.py @@ -17,7 +17,6 @@ import ast import re from hacking import core -import pycodestyle """ @@ -104,7 +103,7 @@ class BaseASTChecker(ast.NodeVisitor): @core.flake8ext def no_translate_logs(logical_line): if translated_log.match(logical_line): - yield(0, "M359 Don't translate log messages!") + yield (0, "M359 Don't translate log messages!") class CheckLoggingFormatArgs(BaseASTChecker): @@ -193,7 +192,7 @@ def check_explicit_underscore_import(logical_line, filename): custom_underscore_check.match(logical_line)): UNDERSCORE_IMPORT_FILES.append(filename) elif string_translation.match(logical_line): - yield(0, "M323: Found use of _() without explicit import of _ !") + yield (0, "M323: Found use of _() without explicit import of _ !") class CheckForTransAdd(BaseASTChecker): @@ -221,14 +220,14 @@ class CheckForTransAdd(BaseASTChecker): @core.flake8ext -def check_oslo_namespace_imports(physical_line, logical_line, filename): - if pycodestyle.noqa(physical_line): +def check_oslo_namespace_imports(logical_line, filename, noqa): + if noqa: return if re.match(oslo_namespace_imports, logical_line): msg = ("M333: '%s' must be used instead of '%s'.") % ( logical_line.replace('oslo.', 'oslo_'), logical_line) - yield(0, msg) + yield (0, msg) @core.flake8ext @@ -243,7 +242,7 @@ def dict_constructor_with_list_copy(logical_line): @core.flake8ext def no_xrange(logical_line): if assert_no_xrange_re.match(logical_line): - yield(0, "M337: Do not use xrange().") + yield (0, "M337: Do not use xrange().") @core.flake8ext @@ -251,7 +250,7 @@ def validate_assertTrue(logical_line): if re.match(assert_True, logical_line): msg = ("M313: Unit tests should use assertTrue(value) instead" " of using assertEqual(True, value).") - yield(0, msg) + yield (0, msg) @core.flake8ext @@ -284,7 +283,7 @@ def no_log_warn_check(logical_line): """ msg = ("M338: LOG.warn is deprecated, use LOG.warning.") if re.match(no_log_warn, logical_line): - yield(0, msg) + yield (0, msg) @core.flake8ext @@ -295,4 +294,4 @@ def no_third_party_mock(logical_line): re.match(from_third_party_mock, logical_line)): msg = ('M339: Unit tests should use the standard library "mock" ' 'module, not the third party mock library.') - yield(0, msg) + yield (0, msg) diff --git a/manila/tests/scheduler/test_host_manager.py b/manila/tests/scheduler/test_host_manager.py index 9f3afaf964..6a4850c8a6 100644 --- a/manila/tests/scheduler/test_host_manager.py +++ b/manila/tests/scheduler/test_host_manager.py @@ -638,7 +638,7 @@ class HostManagerTestCase(test.TestCase): }, }, ] - self.assertTrue(isinstance(res, list)) + self.assertIsInstance(res, list) self.assertEqual(len(expected), len(res)) for pool in expected: self.assertIn(pool, res) diff --git a/manila/tests/share/drivers/ganesha/test_manager.py b/manila/tests/share/drivers/ganesha/test_manager.py index 2c98fdfc01..2b57b5a5e7 100644 --- a/manila/tests/share/drivers/ganesha/test_manager.py +++ b/manila/tests/share/drivers/ganesha/test_manager.py @@ -144,7 +144,7 @@ class GaneshaConfigTests(test.TestCase): # whitespace-split expressions to tokens with # (equality is forced to be treated as token by # sandwiching in space) - conf = map(lambda l: l.replace("=", " = ").split(), conf) + conf = map(lambda line: line.replace("=", " = ").split(), conf) # get rid of by-product empty lists (derived from superflouous # ";"-s that might have crept in due to "sandwiching") conf = map(lambda x: x, conf) diff --git a/manila/tests/share/drivers/glusterfs/test_layout.py b/manila/tests/share/drivers/glusterfs/test_layout.py index a82b830ca0..327f5f0c1f 100644 --- a/manila/tests/share/drivers/glusterfs/test_layout.py +++ b/manila/tests/share/drivers/glusterfs/test_layout.py @@ -87,7 +87,7 @@ class GlusterfsShareDriverBaseTestCase(test.TestCase): if layout_name is not None: conf.glusterfs_share_layout = layout_name if has_snap is None: - del(_layout._snapshots_are_supported) + del _layout._snapshots_are_supported else: _layout._snapshots_are_supported = has_snap diff --git a/manila/tests/share/drivers/glusterfs/test_layout_volume.py b/manila/tests/share/drivers/glusterfs/test_layout_volume.py index a27eaea5ef..ac34c95f7c 100644 --- a/manila/tests/share/drivers/glusterfs/test_layout_volume.py +++ b/manila/tests/share/drivers/glusterfs/test_layout_volume.py @@ -257,7 +257,7 @@ class GlusterfsVolumeMappedLayoutTestCase(test.TestCase): test_args = ('volume', 'list') def raise_exception(*args, **kwargs): - if(args == test_args): + if args == test_args: raise exception.GlusterfsException() self._layout.configuration.glusterfs_servers = [self.glusterfs_server1] @@ -438,8 +438,8 @@ class GlusterfsVolumeMappedLayoutTestCase(test.TestCase): self._layout._push_gluster_vol(self.glusterfs_target2) self.assertEqual(1, len(self._layout.gluster_used_vols)) - self.assertFalse( - self.glusterfs_target2 in self._layout.gluster_used_vols) + self.assertNotIn(self.glusterfs_target2, + self._layout.gluster_used_vols) def test_push_gluster_vol_excp(self): self._layout.gluster_used_vols = set([self.glusterfs_target1]) diff --git a/manila/tests/share/drivers/hitachi/hnas/test_ssh.py b/manila/tests/share/drivers/hitachi/hnas/test_ssh.py index e68521f89c..f819e5c731 100644 --- a/manila/tests/share/drivers/hitachi/hnas/test_ssh.py +++ b/manila/tests/share/drivers/hitachi/hnas/test_ssh.py @@ -286,7 +286,7 @@ HNAS_RESULT_tree_job_status_fail = """JOB ID : d933100a-b5f6-11d0-91d9-836896aad Source files missing : 0 Source files skipped : 801 Skipping details : 104 symlinks, 452 hard links, -47 block special devices, 25 character devices""" +47 block special devices, 25 character devices""" # noqa HNAS_RESULT_job_completed = """JOB ID : ab4211b8-aac8-11ce-91af-39e0822ea368 Job request diff --git a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode_rest.py b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode_rest.py index a5824dea67..3be0e0e0e3 100644 --- a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode_rest.py +++ b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode_rest.py @@ -2747,8 +2747,8 @@ class NetAppRestCmodeClientTestCase(test.TestCase): @ddt.data(True, False) def test_update_volume_efficiency_attributes(self, status): response = { - 'dedupe': not(status), - 'compression': not(status) + 'dedupe': not status, + 'compression': not status } self.mock_object(self.client, 'get_volume_efficiency_status', mock.Mock(return_value=response)) @@ -6089,7 +6089,7 @@ class NetAppRestCmodeClientTestCase(test.TestCase): def test__create_vlan(self, code): self.mock_object(self.client, 'send_request', mock.Mock(side_effect=self._mock_api_error(code))) - if not(code): + if not code: self.assertRaises(exception.NetAppException, self.client._create_vlan, fake.NODE_NAME, @@ -6114,7 +6114,7 @@ class NetAppRestCmodeClientTestCase(test.TestCase): mock.Mock(return_value=volume)) self.mock_object(self.client, 'send_request', mock.Mock(side_effect=self._mock_api_error(code))) - if not(code): + if not code: self.assertRaises(exception.NetAppException, self.client.delete_fpolicy_event, fake.SHARE_NAME, 'fake_event') @@ -6129,7 +6129,7 @@ class NetAppRestCmodeClientTestCase(test.TestCase): mock.Mock(return_value=volume)) self.mock_object(self.client, 'send_request', mock.Mock(side_effect=self._mock_api_error(code))) - if not(code): + if not code: self.assertRaises(exception.NetAppException, self.client.delete_fpolicy_policy, fake.SHARE_NAME, 'fake_policy') @@ -6545,7 +6545,7 @@ class NetAppRestCmodeClientTestCase(test.TestCase): netapp_api.api.NaApiError(code=code)] self.mock_object(self.client, 'send_request', mock.Mock(side_effect=responses)) - if not(code): + if not code: self.assertRaises(netapp_api.api.NaApiError, self.client.remove_cifs_share, fake.SHARE_NAME) diff --git a/manila/tests/share/drivers/test_service_instance.py b/manila/tests/share/drivers/test_service_instance.py index 2a94281fb1..69b4616fc2 100644 --- a/manila/tests/share/drivers/test_service_instance.py +++ b/manila/tests/share/drivers/test_service_instance.py @@ -300,7 +300,7 @@ class ServiceInstanceManagerTestCase(test.TestCase): self.fake_time = 0 def fake_connect(addr): - if not(is_ok and self.fake_time > 1): + if not (is_ok and self.fake_time > 1): raise service_instance.socket.error def fake_time(): diff --git a/manila/tests/share/test_access.py b/manila/tests/share/test_access.py index 28fabeb288..60aa8ca35c 100644 --- a/manila/tests/share/test_access.py +++ b/manila/tests/share/test_access.py @@ -453,7 +453,7 @@ class ShareInstanceAccessTestCase(test.TestCase): # Asserts self.assertIsNone(retval) self.assertEqual(share_instance_id, call_args[1]['id']) - self.assertTrue(isinstance(access_rules_to_be_on_share, list)) + self.assertIsInstance(access_rules_to_be_on_share, list) self.assertEqual(len(expected_rules_to_be_on_share), len(access_rules_to_be_on_share)) for pool in expected_rules_to_be_on_share: @@ -661,7 +661,7 @@ class ShareInstanceAccessTestCase(test.TestCase): self.assertIsNone(retval) self.assertEqual(instance['id'], call_args[1]['id']) - self.assertTrue(isinstance(access_rules_to_be_on_share, list)) + self.assertIsInstance(access_rules_to_be_on_share, list) self.assertEqual(len(expected_rules_to_be_on_share), len(access_rules_to_be_on_share)) for pool in expected_rules_to_be_on_share: diff --git a/manila/tests/share/test_manager.py b/manila/tests/share/test_manager.py index 1171f383d2..9373f3ebed 100644 --- a/manila/tests/share/test_manager.py +++ b/manila/tests/share/test_manager.py @@ -6280,7 +6280,7 @@ class ShareManagerTestCase(test.TestCase): mock.call(self.context, new_instance['id'], with_share_data=True) ]) - cancelled = not(status == constants.TASK_STATE_DATA_COPYING_CANCELLED) + cancelled = not (status == constants.TASK_STATE_DATA_COPYING_CANCELLED) if status != 'other': helper.cleanup_new_instance.assert_called_once_with(new_instance) (self.share_manager._reset_read_only_access_rules. diff --git a/test-requirements.txt b/test-requirements.txt index 82020f504a..e0956c1bfe 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,4 @@ -hacking>=3.1.0,<3.2.0 # Apache-2.0 +hacking>=6.1.0,<6.2.0 # Apache-2.0 coverage>=5.2.1 # Apache-2.0 ddt>=1.4.1 # MIT