From 5cc622f42ade53cdcf614a7cdc6366ed2578a74b Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Wed, 5 Jul 2017 13:25:32 +0300 Subject: [PATCH] Enforce multiple previously ignored pep8 rules This commit removes almost all the pep8 rules from ignore list. Most of these rules only required minor changes or were redundant and could be enabled without any changes. The only rule exclusion left active is E128 to keep the commit small enough. Change-Id: Iec4f00cff9e023515082caae525207054341b94b --- kuryr_libnetwork/controllers.py | 16 ++++++------- kuryr_libnetwork/port_driver/driver.py | 2 +- .../port_driver/drivers/nested.py | 10 ++++---- kuryr_libnetwork/schemata/commons.py | 4 ++-- .../unit/port_driver/drivers/test_nested.py | 20 +++++++++------- .../unit/port_driver/drivers/test_vlan.py | 2 +- .../tests/unit/port_driver/test_driver.py | 5 ++-- kuryr_libnetwork/tests/unit/test_config.py | 12 +++++----- .../tests/unit/test_external_connectivity.py | 2 +- kuryr_libnetwork/tests/unit/test_kuryr.py | 24 +++++++++---------- .../tests/unit/test_kuryr_existing_network.py | 8 +++---- .../tests/unit/test_kuryr_ipam.py | 8 +++---- rally-jobs/plugins/scenarios/utils.py | 4 ++-- tox.ini | 8 +------ 14 files changed, 63 insertions(+), 62 deletions(-) diff --git a/kuryr_libnetwork/controllers.py b/kuryr_libnetwork/controllers.py index 15b96faf..10be7aee 100644 --- a/kuryr_libnetwork/controllers.py +++ b/kuryr_libnetwork/controllers.py @@ -68,7 +68,7 @@ def check_for_neutron_ext_support(): except n_exceptions.NeutronClientException as e: if e.status_code == n_exceptions.NotFound.status_code: raise exceptions.MandatoryApiMissing( - "Neutron extension with alias '{0}' not found" + "Neutron extension with alias '{0}' not found" .format(MANDATORY_NEUTRON_EXTENSION)) @@ -160,9 +160,9 @@ def _get_subnets_by_interface_cidr(neutron_network_id, network_id=neutron_network_id, cidr=six.text_type(iface.network)) if len(subnets) > 2: raise exceptions.DuplicatedResourceException( - "Multiple Neutron subnets exist for the network_id={0}" - "and cidr={1}" - .format(neutron_network_id, iface.network)) + "Multiple Neutron subnets exist for the network_id={0}" + "and cidr={1}" + .format(neutron_network_id, iface.network)) return subnets @@ -554,8 +554,8 @@ def _create_kuryr_subnetpool(pool_cidr): pools = _get_subnetpools_by_attrs(name=pool_name) if len(pools): raise exceptions.KuryrException( - "Another pool with same cidr exist. ipam and network" - " options not used to pass pool name") + "Another pool with same cidr exist. ipam and network" + " options not used to pass pool name") cidr = ipaddress.ip_network(six.text_type(pool_cidr)) new_subnetpool = { @@ -821,8 +821,8 @@ def network_driver_create_network(): specified_network = neutron_name if not networks: raise exceptions.KuryrException( - ("Specified network id/name({0}) does not " - "exist.").format(specified_network)) + ("Specified network id/name({0}) does not " + "exist.").format(specified_network)) network_id = networks[0]['id'] except n_exceptions.NeutronClientException as ex: LOG.error("Error happened during listing " diff --git a/kuryr_libnetwork/port_driver/driver.py b/kuryr_libnetwork/port_driver/driver.py index db984bff..2c7026e5 100644 --- a/kuryr_libnetwork/port_driver/driver.py +++ b/kuryr_libnetwork/port_driver/driver.py @@ -1,4 +1,4 @@ -#Licensed under the Apache License, Version 2.0 (the "License"); you may +# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # diff --git a/kuryr_libnetwork/port_driver/drivers/nested.py b/kuryr_libnetwork/port_driver/drivers/nested.py index f7871001..e6dd3d3d 100644 --- a/kuryr_libnetwork/port_driver/drivers/nested.py +++ b/kuryr_libnetwork/port_driver/drivers/nested.py @@ -146,10 +146,12 @@ class NestedDriver(base.BaseNestedDriver): def _update_port_address_pairs(self, port_id, address_pairs): try: app.neutron.update_port( - port_id, - {'port': { - 'allowed_address_pairs': address_pairs - }}) + port_id, + { + 'port': { + 'allowed_address_pairs': address_pairs + } + }) except n_exceptions.NeutronClientException as ex: LOG.error("Error happened during updating Neutron " "port %(port_id)s: %(ex)s", port_id, ex) diff --git a/kuryr_libnetwork/schemata/commons.py b/kuryr_libnetwork/schemata/commons.py index 75ed4d48..8b5a3a73 100755 --- a/kuryr_libnetwork/schemata/commons.py +++ b/kuryr_libnetwork/schemata/commons.py @@ -15,7 +15,7 @@ IPV4_PATTERN_BASE = (u'((25[0-5]|2[0-4][0-9]|1?[0-9]?[0-9])\\.){3}' u'(25[0-5]|2[0-4][0-9]|1?[0-9]?[0-9])') IPV4_PATTERN = EPSILON_PATTERN + u'|^' + IPV4_PATTERN_BASE + u'$' CIDRV4_PATTERN = EPSILON_PATTERN + '|^(' + IPV4_PATTERN_BASE + \ - u'(/(1[0-2][0-8]|[1-9]?[0-9]))' + u')$' + u'(/(1[0-2][0-8]|[1-9]?[0-9]))' + u')$' IPV6_PATTERN_BASE = (u'(' u'([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|' @@ -36,7 +36,7 @@ IPV6_PATTERN_BASE = (u'(' u'(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))') IPV6_PATTERN = EPSILON_PATTERN + u'|^' + IPV6_PATTERN_BASE + u'$' CIDRV6_PATTERN = EPSILON_PATTERN + u'|^(' + IPV6_PATTERN_BASE + \ - u'(/(1[0-2][0-8]|[1-9]?[0-9]))' + u')$' + u'(/(1[0-2][0-8]|[1-9]?[0-9]))' + u')$' IPV4_OR_IPV6_PATTERN = IPV4_PATTERN + u'|^' + IPV6_PATTERN_BASE + u'$' CIDRV4_OR_CIDRV6_PATTERN = CIDRV4_PATTERN + u'|^' + CIDRV6_PATTERN + u'$' UUID_BASE = u'^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' diff --git a/kuryr_libnetwork/tests/unit/port_driver/drivers/test_nested.py b/kuryr_libnetwork/tests/unit/port_driver/drivers/test_nested.py index 762b520f..ee2847ff 100644 --- a/kuryr_libnetwork/tests/unit/port_driver/drivers/test_nested.py +++ b/kuryr_libnetwork/tests/unit/port_driver/drivers/test_nested.py @@ -58,8 +58,9 @@ class TestNestedDriver(base.TestKuryrBase): @mock.patch.object(binding, 'port_bind') @mock.patch('kuryr_libnetwork.app.neutron.update_port') @mock.patch.object(nested.NestedDriver, '_get_port_from_host_iface') - def test_create_host_iface(self, mock_get_port_from_host, - mock_update_port, mock_port_bind, mock_conf): + def test_create_host_iface( + self, mock_get_port_from_host, + mock_update_port, mock_port_bind, mock_conf): mock_conf.binding.link_iface = 'eth0' fake_endpoint_id = lib_utils.get_hash() @@ -109,9 +110,10 @@ class TestNestedDriver(base.TestKuryrBase): mock_get_port_from_host.assert_called_with('eth0') mock_port_bind.assert_called_with(fake_endpoint_id, fake_neutron_port, fake_subnets, fake_network, fake_vm_port) - mock_update_port.assert_called_with(fake_vm_port['id'], + mock_update_port.assert_called_with( + fake_vm_port['id'], {'port': { - 'allowed_address_pairs': updated_allowed_pairs + 'allowed_address_pairs': updated_allowed_pairs }}) self.assertEqual(response, fake_exec_response) @@ -120,8 +122,9 @@ class TestNestedDriver(base.TestKuryrBase): @mock.patch.object(binding, 'port_unbind') @mock.patch('kuryr_libnetwork.app.neutron.update_port') @mock.patch.object(nested.NestedDriver, '_get_port_from_host_iface') - def test_delete_host_iface(self, mock_get_port_from_host, - mock_update_port, mock_port_unbind, mock_conf): + def test_delete_host_iface( + self, mock_get_port_from_host, + mock_update_port, mock_port_unbind, mock_conf): mock_conf.binding.link_iface = 'eth0' fake_endpoint_id = lib_utils.get_hash() @@ -163,9 +166,10 @@ class TestNestedDriver(base.TestKuryrBase): fake_neutron_port) mock_get_port_from_host.assert_called_with('eth0') - mock_update_port.assert_called_with(fake_vm_port['id'], + mock_update_port.assert_called_with( + fake_vm_port['id'], {'port': { - 'allowed_address_pairs': updated_allowed_pairs + 'allowed_address_pairs': updated_allowed_pairs }}) mock_port_unbind.assert_called_with(fake_endpoint_id, fake_neutron_port) diff --git a/kuryr_libnetwork/tests/unit/port_driver/drivers/test_vlan.py b/kuryr_libnetwork/tests/unit/port_driver/drivers/test_vlan.py index c6f97c89..a088b824 100644 --- a/kuryr_libnetwork/tests/unit/port_driver/drivers/test_vlan.py +++ b/kuryr_libnetwork/tests/unit/port_driver/drivers/test_vlan.py @@ -159,7 +159,7 @@ class TestVlanDriver(base.TestKuryrBase): fake_neutron_port) mock_trunk_remove_subports.assert_called_with(fake_neutron_trunk_id, {'sub_ports': [{ - 'port_id': fake_neutron_port_id + 'port_id': fake_neutron_port_id }]}) mock_release_seg_id.assert_called_with(fake_neutron_port_id) diff --git a/kuryr_libnetwork/tests/unit/port_driver/test_driver.py b/kuryr_libnetwork/tests/unit/port_driver/test_driver.py index 8687de74..62dff64b 100644 --- a/kuryr_libnetwork/tests/unit/port_driver/test_driver.py +++ b/kuryr_libnetwork/tests/unit/port_driver/test_driver.py @@ -28,8 +28,9 @@ class TestDriver(base.TestKuryrBase): @mock.patch.object(driver, '_verify_port_driver_compliancy') @mock.patch.object(importutils, 'import_object') @mock.patch.object(driver, '_parse_port_driver_config') - def test_get_driver_instance(self, mock_parse_config, mock_import_object, - mock_verify_compliancy, mock_verify_compatibility): + def test_get_driver_instance( + self, mock_parse_config, mock_import_object, + mock_verify_compliancy, mock_verify_compatibility): module = 'kuryr_libnetwork.port_driver.drivers.veth' mock_parse_config.return_value = (module, 'veth', 'VethDriver') fake_driver = mock.Mock(spec=driver.Driver) diff --git a/kuryr_libnetwork/tests/unit/test_config.py b/kuryr_libnetwork/tests/unit/test_config.py index 8aa3117d..a635e290 100644 --- a/kuryr_libnetwork/tests/unit/test_config.py +++ b/kuryr_libnetwork/tests/unit/test_config.py @@ -73,8 +73,8 @@ class ConfigurationTest(base.TestKuryrBase): ext_alias = "subnet_allocation" err = n_exceptions.NotFound.status_code ext_not_found_ex = n_exceptions.NeutronClientException( - status_code=err, - message="") + status_code=err, + message="") mock_extension.side_effect = ext_not_found_ex ex = exceptions.MandatoryApiMissing self.assertRaises(ex, controllers.check_for_neutron_ext_support) @@ -87,8 +87,8 @@ class ConfigurationTest(base.TestKuryrBase): mock_extension): err = n_exceptions.NotFound.status_code ext_not_found_ex = n_exceptions.NeutronClientException( - status_code=err, - message="") + status_code=err, + message="") mock_extension.side_effect = ext_not_found_ex controllers.check_for_neutron_tag_support(ext_name) mock_extension.assert_called_once_with(ext_name) @@ -101,8 +101,8 @@ class ConfigurationTest(base.TestKuryrBase): mock_extension): err = n_exceptions.NotFound.status_code ext_not_found_ex = n_exceptions.NeutronClientException( - status_code=err, - message="") + status_code=err, + message="") mock_extension.side_effect = ext_not_found_ex controllers.check_for_neutron_tag_support(ext_name) mock_extension.assert_called_once_with(ext_name) diff --git a/kuryr_libnetwork/tests/unit/test_external_connectivity.py b/kuryr_libnetwork/tests/unit/test_external_connectivity.py index f813a5f1..aef3214b 100644 --- a/kuryr_libnetwork/tests/unit/test_external_connectivity.py +++ b/kuryr_libnetwork/tests/unit/test_external_connectivity.py @@ -207,7 +207,7 @@ class TestExternalConnectivityKuryr(base.TestKuryrBase): mock_list_security_groups.assert_called_with( name=utils.get_sg_expose_name(fake_neutron_port_id)) mock_delete_security_groups.assert_called_with( - fake_neutron_sec_group_id) + fake_neutron_sec_group_id) mock_show_port.assert_called_with(fake_neutron_port_id) mock_update_port.assert_called_with(fake_neutron_port_id, {'port': {'security_groups': sgs}}) diff --git a/kuryr_libnetwork/tests/unit/test_kuryr.py b/kuryr_libnetwork/tests/unit/test_kuryr.py index 6f878e45..ad6e70dd 100644 --- a/kuryr_libnetwork/tests/unit/test_kuryr.py +++ b/kuryr_libnetwork/tests/unit/test_kuryr.py @@ -1253,9 +1253,9 @@ class TestKuryr(base.TestKuryrBase): 'Gateway': 'fe80::f816:3eff:fe20:57c3/64', }], 'Options': { - constants.NETWORK_GENERIC_OPTIONS: { - constants.NEUTRON_UUID_OPTION: fake_neutron_net_id - } + constants.NETWORK_GENERIC_OPTIONS: { + constants.NEUTRON_UUID_OPTION: fake_neutron_net_id + } } } @@ -1294,8 +1294,8 @@ class TestKuryr(base.TestKuryrBase): @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_networks') @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_subnetpools') - def test_network_driver_create_network_with_network_name_not_exist(self, - mock_list_subnetpools, mock_list_networks): + def test_network_driver_create_network_with_network_name_not_exist( + self, mock_list_subnetpools, mock_list_networks): docker_network_id = lib_utils.get_hash() fake_neutron_network_name = "fake_network" network_request = { @@ -1310,9 +1310,9 @@ class TestKuryr(base.TestKuryrBase): 'Gateway': 'fe80::f816:3eff:fe20:57c3/64', }], 'Options': { - constants.NETWORK_GENERIC_OPTIONS: { - constants.NEUTRON_NAME_OPTION: fake_neutron_network_name - } + constants.NETWORK_GENERIC_OPTIONS: { + constants.NEUTRON_NAME_OPTION: fake_neutron_network_name + } } } @@ -1941,7 +1941,7 @@ class TestKuryr(base.TestKuryrBase): @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_ports') @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_subnets') @mock.patch( - 'kuryr_libnetwork.controllers.app.driver.get_container_iface_name') + 'kuryr_libnetwork.controllers.app.driver.get_container_iface_name') def test_network_driver_join(self, mock_get_container_iface_name, mock_list_subnets, mock_list_ports, mock_list_networks, mock_get_veth_pair_names): @@ -2024,7 +2024,7 @@ class TestKuryr(base.TestKuryrBase): @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_ports') @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_subnets') @mock.patch( - 'kuryr_libnetwork.controllers.app.driver.get_container_iface_name') + 'kuryr_libnetwork.controllers.app.driver.get_container_iface_name') def test_network_driver_join_multiple_subnets( self, mock_get_container_iface_name, mock_list_subnets, mock_list_ports, mock_list_networks, @@ -2141,7 +2141,7 @@ class TestKuryr(base.TestKuryrBase): @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_ports') @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_subnets') @mock.patch( - 'kuryr_libnetwork.controllers.app.driver.get_container_iface_name') + 'kuryr_libnetwork.controllers.app.driver.get_container_iface_name') @mock.patch('kuryr_libnetwork.controllers.app') @ddt.data(True, False) def test_network_driver_join_with_static_route_return(self, @@ -2279,7 +2279,7 @@ class TestKuryr(base.TestKuryrBase): response = self.app.post('/NetworkDriver.AllocateNetwork', content_type='application/json', data=jsonutils.dumps( - allocate_network_request)) + allocate_network_request)) self.assertEqual(200, response.status_code) decoded_json = jsonutils.loads(response.data) self.assertEqual(constants.SCHEMA['SUCCESS'], decoded_json) diff --git a/kuryr_libnetwork/tests/unit/test_kuryr_existing_network.py b/kuryr_libnetwork/tests/unit/test_kuryr_existing_network.py index 0aafb6d1..641da8ff 100644 --- a/kuryr_libnetwork/tests/unit/test_kuryr_existing_network.py +++ b/kuryr_libnetwork/tests/unit/test_kuryr_existing_network.py @@ -187,10 +187,10 @@ class TestKuryrNetworkPreExisting(base.TestKuryrBase): @mock.patch('kuryr_libnetwork.controllers.app') @ddt.data((True), (False)) def test_create_network_and_subnet_pre_existing_add_tag_for_subnet( - self, use_tags, mock_tag, mock_show_extension, - mock_list_subnetpools, mock_list_networks, - mock_add_tag, mock_update_network, - mock_list_subnets): + self, use_tags, mock_tag, mock_show_extension, + mock_list_subnetpools, mock_list_networks, + mock_add_tag, mock_update_network, + mock_list_subnets): if use_tags: mock_tag.tag = use_tags diff --git a/kuryr_libnetwork/tests/unit/test_kuryr_ipam.py b/kuryr_libnetwork/tests/unit/test_kuryr_ipam.py index 63f1913d..d4b4521b 100644 --- a/kuryr_libnetwork/tests/unit/test_kuryr_ipam.py +++ b/kuryr_libnetwork/tests/unit/test_kuryr_ipam.py @@ -887,9 +887,9 @@ class TestKuryrIpam(base.TestKuryrBase): @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_subnetpools') @mock.patch('kuryr_libnetwork.controllers.app') @ddt.data((False), (True)) - def test_ipam_driver_request_address_overlapping_cidr_in_kuryr(self, - use_tag_ext, mock_app, mock_list_subnetpools, mock_list_subnets, - mock_create_port, mock_port_add_tag): + def test_ipam_driver_request_address_overlapping_cidr_in_kuryr( + self, use_tag_ext, mock_app, mock_list_subnetpools, + mock_list_subnets, mock_create_port, mock_port_add_tag): mock_app.tag_ext = use_tag_ext # faking list_subnetpools fake_kuryr_subnetpool_id = uuidutils.generate_uuid() @@ -1043,7 +1043,7 @@ class TestKuryrIpam(base.TestKuryrBase): self.assertIn('Err', decoded_json) err_message = ("Requested gateway {0} does not match with " "gateway {1} in existed network.").format( - '10.0.0.5', '10.0.0.1') + '10.0.0.5', '10.0.0.1') self.assertEqual({'Err': err_message}, decoded_json) @mock.patch('kuryr_libnetwork.controllers.app.neutron.delete_port') diff --git a/rally-jobs/plugins/scenarios/utils.py b/rally-jobs/plugins/scenarios/utils.py index beb7f939..c37ee8af 100644 --- a/rally-jobs/plugins/scenarios/utils.py +++ b/rally-jobs/plugins/scenarios/utils.py @@ -80,8 +80,8 @@ class KuryrScenario(scenario.OpenStackScenario): def _start_container(self, container_create_args=None): """Start Container on docker network.""" network_config = self.docker_client.create_networking_config( - {self.context.get("netname"): - self.docker_client.create_endpoint_config()}) + {self.context.get("netname"): + self.docker_client.create_endpoint_config()}) container = self.docker_client.create_container( image='kuryr/busybox', command='/bin/sleep 600', diff --git a/tox.ini b/tox.ini index 3fd76019..16d5eb4d 100644 --- a/tox.ini +++ b/tox.ini @@ -51,14 +51,8 @@ commands = commands = python setup.py build_sphinx [flake8] -# E125 continuation line does not distinguish itself from next logical line -# E126 continuation line over-indented for hanging indent # E128 continuation line under-indented for visual indent -# E129 visually indented line with same indent as next logical line -# E265 block comment should start with '# ' -# N530 direct neutron imports not allowed -# N531 Log messages require translation hints -ignore = E125,E126,E128,E129,E265,H301,N530,N531 +ignore = E128 show-source = true exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,.ropeproject,rally-scenarios,releasenotes