From 2d6bcaa7e55be9fd070bade12824709ac848f8fe Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 11 Apr 2018 12:37:36 +0200 Subject: [PATCH] Fix code to pass pep8 Tox environment. Command tox -e pep8 is failing making CI to fail: this fixes it. Change-Id: I5b1acfc4ba2e0eb16f50bfd1cdaa8edc361923d1 --- .../compute/servers/test_device_tagging.py | 4 +-- tempest/api/image/v1/test_images.py | 12 ++++----- tempest/api/volume/admin/test_volume_hosts.py | 4 +-- tempest/cmd/cleanup_service.py | 27 ++++++++++--------- tempest/hacking/checks.py | 14 +++++----- tempest/lib/base.py | 5 ++-- tempest/lib/cli/output_parser.py | 4 +-- tempest/lib/cmd/check_uuid.py | 14 +++++----- tempest/lib/common/dynamic_creds.py | 10 +++---- tempest/scenario/manager.py | 8 +++--- .../test_network_advanced_server_ops.py | 4 +-- tempest/scenario/test_network_basic_ops.py | 4 +-- tempest/scenario/test_network_v6.py | 8 +++--- tempest/test.py | 12 ++++----- 14 files changed, 66 insertions(+), 64 deletions(-) diff --git a/tempest/api/compute/servers/test_device_tagging.py b/tempest/api/compute/servers/test_device_tagging.py index 43046ca577..b0d527cef3 100644 --- a/tempest/api/compute/servers/test_device_tagging.py +++ b/tempest/api/compute/servers/test_device_tagging.py @@ -47,8 +47,8 @@ class DeviceTaggingTest(base.BaseV2ComputeTest): raise cls.skipException('Neutron is required') if not CONF.validation.run_validation: raise cls.skipException('Validation must be enabled') - if (not CONF.compute_feature_enabled.config_drive - and not CONF.compute_feature_enabled.metadata_service): + if (not CONF.compute_feature_enabled.config_drive and + not CONF.compute_feature_enabled.metadata_service): raise cls.skipException('One of metadata or config drive must be ' 'enabled') diff --git a/tempest/api/image/v1/test_images.py b/tempest/api/image/v1/test_images.py index 76723f4961..2432c8b35a 100644 --- a/tempest/api/image/v1/test_images.py +++ b/tempest/api/image/v1/test_images.py @@ -132,8 +132,8 @@ class ListImagesTest(base.BaseV1ImageTest): @classmethod def skip_checks(cls): super(ListImagesTest, cls).skip_checks() - if (len(CONF.image.container_formats) < 2 - or len(CONF.image.disk_formats) < 2): + if (len(CONF.image.container_formats) < 2 or + len(CONF.image.disk_formats) < 2): skip_msg = ("%s skipped as multiple container formats " "or disk formats are not available." % cls.__name__) raise cls.skipException(skip_msg) @@ -227,8 +227,8 @@ class ListImagesTest(base.BaseV1ImageTest): self.assertEqual(image['disk_format'], self.disk_format_alt) result_set = set(map(lambda x: x['id'], images_list)) self.assertTrue(self.same_disk_format_set <= result_set) - self.assertFalse(self.created_set - self.same_disk_format_set - <= result_set) + self.assertFalse(self.created_set - self.same_disk_format_set <= + result_set) @decorators.idempotent_id('2143655d-96d9-4bec-9188-8674206b4b3b') def test_index_container_format(self): @@ -238,8 +238,8 @@ class ListImagesTest(base.BaseV1ImageTest): self.assertEqual(image['container_format'], self.container_format) result_set = set(map(lambda x: x['id'], images_list)) self.assertTrue(self.same_container_format_set <= result_set) - self.assertFalse(self.created_set - self.same_container_format_set - <= result_set) + self.assertFalse(self.created_set - self.same_container_format_set <= + result_set) @decorators.idempotent_id('feb32ac6-22bb-4a16-afd8-9454bb714b14') def test_index_max_size(self): diff --git a/tempest/api/volume/admin/test_volume_hosts.py b/tempest/api/volume/admin/test_volume_hosts.py index ce0cbd2899..7e53ce8182 100644 --- a/tempest/api/volume/admin/test_volume_hosts.py +++ b/tempest/api/volume/admin/test_volume_hosts.py @@ -46,8 +46,8 @@ class VolumeHostsAdminTestsJSON(base.BaseVolumeAdminTest): # show host API should fail (return code: 404). The cinder-volume host # is presented in format: @driver-name. c_vol_hosts = [host['host_name'] for host in hosts - if (host['service'] == 'cinder-volume' - and host['service-state'] == 'enabled')] + if (host['service'] == 'cinder-volume' and + host['service-state'] == 'enabled')] self.assertNotEmpty(c_vol_hosts, "No available cinder-volume host is found, " "all hosts that found are: %s" % hosts) diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py index 025959ac5f..27e1bc1b5f 100644 --- a/tempest/cmd/cleanup_service.py +++ b/tempest/cmd/cleanup_service.py @@ -104,11 +104,11 @@ class BaseService(object): self.tenant_filter['tenant_id'] = self.tenant_id def _filter_by_tenant_id(self, item_list): - if (item_list is None - or not item_list - or not hasattr(self, 'tenant_id') - or self.tenant_id is None - or 'tenant_id' not in item_list[0]): + if (item_list is None or + not item_list or + not hasattr(self, 'tenant_id') or + self.tenant_id is None or + 'tenant_id' not in item_list[0]): return item_list return [item for item in item_list @@ -816,8 +816,8 @@ class RoleService(BaseService): if not self.is_save_state: roles = [role for role in roles if (role['id'] not in - self.saved_state_json['roles'].keys() - and role['name'] != CONF.identity.admin_role)] + self.saved_state_json['roles'].keys() and + role['name'] != CONF.identity.admin_role)] LOG.debug("List count, %s Roles after reconcile", len(roles)) return roles except Exception: @@ -852,13 +852,16 @@ class ProjectService(BaseService): def list(self): projects = self.client.list_projects()['projects'] if not self.is_save_state: - projects = [project for project in projects if (project['id'] - not in self.saved_state_json['projects'].keys() - and project['name'] != CONF.auth.admin_project_name)] + project_ids = self.saved_state_json['projects'] + projects = [project + for project in projects + if (project['id'] not in project_ids and + project['name'] != CONF.auth.admin_project_name)] if self.is_preserve: - projects = [project for project in projects if project['name'] - not in CONF_PROJECTS] + projects = [project + for project in projects + if project['name'] not in CONF_PROJECTS] LOG.debug("List count, %s Projects after reconcile", len(projects)) return projects diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py index aae685cb59..b6e7f8c245 100644 --- a/tempest/hacking/checks.py +++ b/tempest/hacking/checks.py @@ -228,12 +228,12 @@ def dont_import_local_tempest_into_lib(logical_line, filename): if 'tempest/lib/' not in filename: return - if not ('from tempest' in logical_line - or 'import tempest' in logical_line): + if not ('from tempest' in logical_line or + 'import tempest' in logical_line): return - if ('from tempest.lib' in logical_line - or 'import tempest.lib' in logical_line): + if ('from tempest.lib' in logical_line or + 'import tempest.lib' in logical_line): return msg = ("T112: tempest.lib should not import local tempest code to avoid " @@ -266,9 +266,9 @@ def dont_use_config_in_tempest_lib(logical_line, filename): if 'tempest/lib/' not in filename: return - if ('tempest.config' in logical_line - or 'from tempest import config' in logical_line - or 'oslo_config' in logical_line): + if ('tempest.config' in logical_line or + 'from tempest import config' in logical_line or + 'oslo_config' in logical_line): msg = ('T114: tempest.lib can not have any dependency on tempest ' 'config.') yield(0, msg) diff --git a/tempest/lib/base.py b/tempest/lib/base.py index 33a32eefcd..3be55c048c 100644 --- a/tempest/lib/base.py +++ b/tempest/lib/base.py @@ -43,8 +43,7 @@ class BaseTestCase(testtools.testcase.WithAttributes, testtools.TestCase): super(BaseTestCase, self).setUp() if not self.setUpClassCalled: raise RuntimeError("setUpClass does not calls the super's " - "setUpClass in the " - + self.__class__.__name__) + "setUpClass in {!r}".format(type(self))) test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: test_timeout = int(test_timeout) @@ -62,7 +61,7 @@ class BaseTestCase(testtools.testcase.WithAttributes, testtools.TestCase): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) if (os.environ.get('OS_LOG_CAPTURE') != 'False' and - os.environ.get('OS_LOG_CAPTURE') != '0'): + os.environ.get('OS_LOG_CAPTURE') != '0'): self.useFixture(fixtures.LoggerFixture(nuke_handlers=False, format=self.log_format, level=None)) diff --git a/tempest/lib/cli/output_parser.py b/tempest/lib/cli/output_parser.py index 2edd5c16f4..a7d5e495c3 100644 --- a/tempest/lib/cli/output_parser.py +++ b/tempest/lib/cli/output_parser.py @@ -37,8 +37,8 @@ def details_multiple(output_lines, with_label=False): items = [] tables_ = tables(output_lines) for table_ in tables_: - if ('Property' not in table_['headers'] - or 'Value' not in table_['headers']): + if ('Property' not in table_['headers'] or + 'Value' not in table_['headers']): raise exceptions.InvalidStructure() item = {} for value in table_['values']: diff --git a/tempest/lib/cmd/check_uuid.py b/tempest/lib/cmd/check_uuid.py index 101d692c25..d1f0888853 100755 --- a/tempest/lib/cmd/check_uuid.py +++ b/tempest/lib/cmd/check_uuid.py @@ -103,7 +103,7 @@ class TestChecker(object): def _modules_search(self): """Recursive search for python modules in base package""" modules = [] - for root, dirs, files in os.walk(self.base_path): + for root, _, files in os.walk(self.base_path): if not os.path.exists(os.path.join(root, '__init__.py')): continue root_package = self._path_to_package(root) @@ -121,10 +121,10 @@ class TestChecker(object): idempotent_id = None for decorator in test_node.decorator_list: if (hasattr(decorator, 'func') and - hasattr(decorator.func, 'attr') and - decorator.func.attr == DECORATOR_NAME and - hasattr(decorator.func, 'value') and - decorator.func.value.id == DECORATOR_MODULE): + hasattr(decorator.func, 'attr') and + decorator.func.attr == DECORATOR_NAME and + hasattr(decorator.func, 'value') and + decorator.func.value.id == DECORATOR_MODULE): for arg in decorator.args: idempotent_id = ast.literal_eval(arg) return idempotent_id @@ -165,8 +165,8 @@ class TestChecker(object): @staticmethod def _is_test_method(node): - return (node.__class__ is ast.FunctionDef - and node.name.startswith('test_')) + return (node.__class__ is ast.FunctionDef and + node.name.startswith('test_')) @staticmethod def _next_node(body, node): diff --git a/tempest/lib/common/dynamic_creds.py b/tempest/lib/common/dynamic_creds.py index 4f1a883dc0..f27e926a7d 100644 --- a/tempest/lib/common/dynamic_creds.py +++ b/tempest/lib/common/dynamic_creds.py @@ -338,15 +338,15 @@ class DynamicCredentialProvider(cred_provider.CredentialProvider): credentials = self._create_creds(roles=credential_type) self._creds[str(credential_type)] = credentials # Maintained until tests are ported - LOG.info("Acquired dynamic creds:\n credentials: %s", credentials) - if (self.neutron_available and - self.create_networks): + LOG.info("Acquired dynamic creds:\n" + " credentials: %s", credentials) + if (self.neutron_available and self.create_networks): network, subnet, router = self._create_network_resources( credentials.tenant_id) credentials.set_resources(network=network, subnet=subnet, router=router) - LOG.info("Created isolated network resources for : \n" - + " credentials: %s", credentials) + LOG.info("Created isolated network resources for:\n" + " credentials: %s", credentials) return credentials def get_primary_creds(self): diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py index c78646f23e..cf53b67206 100644 --- a/tempest/scenario/manager.py +++ b/tempest/scenario/manager.py @@ -662,8 +662,8 @@ class ScenarioTest(tempest.test.BaseTestCase): addresses = (server['addresses'][network['name']] if network else []) for address in addresses: - if (address['version'] == CONF.validation.ip_version_for_ssh - and address['OS-EXT-IPS:type'] == 'fixed'): + if (address['version'] == CONF.validation.ip_version_for_ssh and # noqa + address['OS-EXT-IPS:type'] == 'fixed'): return address['addr'] raise exceptions.ServerUnreachable(server_id=server['id']) else: @@ -792,8 +792,8 @@ class NetworkScenarioTest(ScenarioTest): port_map = [(p["id"], fxip["ip_address"]) for p in ports for fxip in p["fixed_ips"] - if netutils.is_valid_ipv4(fxip["ip_address"]) - and p['status'] in p_status] + if (netutils.is_valid_ipv4(fxip["ip_address"]) and + p['status'] in p_status)] inactive = [p for p in ports if p['status'] != 'ACTIVE'] if inactive: LOG.warning("Instance has ports that are not ACTIVE: %s", inactive) diff --git a/tempest/scenario/test_network_advanced_server_ops.py b/tempest/scenario/test_network_advanced_server_ops.py index e4ab11cd5f..87ce951e2f 100644 --- a/tempest/scenario/test_network_advanced_server_ops.py +++ b/tempest/scenario/test_network_advanced_server_ops.py @@ -43,8 +43,8 @@ class TestNetworkAdvancedServerOps(manager.NetworkScenarioTest): @classmethod def skip_checks(cls): super(TestNetworkAdvancedServerOps, cls).skip_checks() - if not (CONF.network.project_networks_reachable - or CONF.network.public_network_id): + if not (CONF.network.project_networks_reachable or + CONF.network.public_network_id): msg = ('Either project_networks_reachable must be "true", or ' 'public_network_id must be defined.') raise cls.skipException(msg) diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py index fd9c98501a..bcd4ddb962 100644 --- a/tempest/scenario/test_network_basic_ops.py +++ b/tempest/scenario/test_network_basic_ops.py @@ -81,8 +81,8 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest): @classmethod def skip_checks(cls): super(TestNetworkBasicOps, cls).skip_checks() - if not (CONF.network.project_networks_reachable - or CONF.network.public_network_id): + if not (CONF.network.project_networks_reachable or + CONF.network.public_network_id): msg = ('Either project_networks_reachable must be "true", or ' 'public_network_id must be defined.') raise cls.skipException(msg) diff --git a/tempest/scenario/test_network_v6.py b/tempest/scenario/test_network_v6.py index 9f4e62b6e1..e4e39c35e8 100644 --- a/tempest/scenario/test_network_v6.py +++ b/tempest/scenario/test_network_v6.py @@ -38,11 +38,11 @@ class TestGettingAddress(manager.NetworkScenarioTest): @classmethod def skip_checks(cls): super(TestGettingAddress, cls).skip_checks() - if not (CONF.network_feature_enabled.ipv6 - and CONF.network_feature_enabled.ipv6_subnet_attributes): + if not (CONF.network_feature_enabled.ipv6 and + CONF.network_feature_enabled.ipv6_subnet_attributes): raise cls.skipException('IPv6 or its attributes not supported') - if not (CONF.network.project_networks_reachable - or CONF.network.public_network_id): + if not (CONF.network.project_networks_reachable or + CONF.network.public_network_id): msg = ('Either project_networks_reachable must be "true", or ' 'public_network_id must be defined.') raise cls.skipException(msg) diff --git a/tempest/test.py b/tempest/test.py index 27e01650f4..f2babbb961 100644 --- a/tempest/test.py +++ b/tempest/test.py @@ -68,9 +68,9 @@ at_exit_set = set() def validate_tearDownClass(): if at_exit_set: LOG.error( - "tearDownClass does not call the super's " - "tearDownClass in these classes: \n" - + str(at_exit_set)) + "tearDownClass does not call the super's tearDownClass in " + "these classes:\n" + " %s", at_exit_set) atexit.register(validate_tearDownClass) @@ -582,8 +582,8 @@ class BaseTestCase(testtools.testcase.WithAttributes, super(BaseTestCase, self).setUp() if not self.__setupclass_called: raise RuntimeError("setUpClass does not calls the super's" - "setUpClass in the " - + self.__class__.__name__) + "setUpClass in the " + + self.__class__.__name__) at_exit_set.add(self.__class__) test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) try: @@ -602,7 +602,7 @@ class BaseTestCase(testtools.testcase.WithAttributes, stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) if (os.environ.get('OS_LOG_CAPTURE') != 'False' and - os.environ.get('OS_LOG_CAPTURE') != '0'): + os.environ.get('OS_LOG_CAPTURE') != '0'): self.useFixture(fixtures.LoggerFixture(nuke_handlers=False, format=self.log_format, level=None))