From 0f180d8e2ea565e68f73d1e299fea5cc15062c10 Mon Sep 17 00:00:00 2001 From: IWAMOTO Toshihiro Date: Wed, 20 Jun 2018 16:04:28 +0900 Subject: [PATCH] Adopt hacking 1.1.0 This incorporates flake8 2.6.x and pycodestyle will be used instead of older pep8. This ensures future python3 compatibility and a bit better code styling. Change-Id: Ia7c7c5a44727f615a151e1e68dd94c7ed42f974f --- lower-constraints.txt | 6 +++--- neutron/agent/linux/iptables_manager.py | 1 + neutron/api/rpc/callbacks/version_manager.py | 1 + neutron/conf/agent/common.py | 1 + neutron/db/api.py | 1 + neutron/extensions/securitygroup.py | 1 + neutron/plugins/ml2/db.py | 1 + neutron/plugins/ml2/extensions/dns_integration.py | 1 + neutron/services/l3_router/service_providers/base.py | 1 + neutron/services/segments/db.py | 1 + neutron/tests/common/agents/ovs_agent.py | 2 ++ .../tests/functional/agent/linux/bin/ipt_binname.py | 1 + neutron/tests/unit/agent/l3/test_router_info.py | 2 +- .../tests/unit/agent/linux/test_iptables_manager.py | 1 + neutron/tests/unit/agent/test_securitygroups_rpc.py | 2 +- neutron/tests/unit/common/test_utils.py | 4 ++-- neutron/tests/unit/db/quota/test_driver.py | 1 + neutron/tests/unit/hacking/test_checks.py | 10 +++++----- .../ml2/drivers/openvswitch/agent/test_ovs_tunnel.py | 1 + neutron/tests/unit/plugins/ml2/test_plugin.py | 4 ++-- .../unit/services/metering/test_metering_plugin.py | 4 ++-- neutron/tests/unit/services/qos/test_qos_plugin.py | 4 ++-- .../drivers/linuxbridge/agent/test_trunk_plumber.py | 1 + neutron/tests/unit/testlib_api.py | 3 ++- test-requirements.txt | 2 +- tox.ini | 3 ++- 26 files changed, 39 insertions(+), 21 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 65ba26e3c70..79a20f3775d 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -25,13 +25,13 @@ extras==1.0.0 fasteners==0.7.0 fixtures==3.0.0 flake8-import-order==0.12 -flake8==2.5.5 +flake8==2.6.2 future==0.16.0 futurist==1.2.0 gitdb==0.6.4 GitPython==1.0.1 greenlet==0.4.10 -hacking==0.12.0 +hacking==1.1.0 httplib2==0.9.1 imagesize==0.7.1 iso8601==0.1.11 @@ -96,7 +96,7 @@ positional==1.2.1 prettytable==0.7.2 psutil==3.2.2 pycadf==1.1.0 -pycodestyle==2.3.1 +pycodestyle==2.4.0 pycparser==2.18 pyflakes==0.8.1 Pygments==2.2.0 diff --git a/neutron/agent/linux/iptables_manager.py b/neutron/agent/linux/iptables_manager.py index 01ac80e0c83..15d2708d484 100644 --- a/neutron/agent/linux/iptables_manager.py +++ b/neutron/agent/linux/iptables_manager.py @@ -51,6 +51,7 @@ def get_binary_name(): """Grab the name of the binary we're running in.""" return os.path.basename(sys.argv[0])[:16].replace(' ', '_') + binary_name = get_binary_name() # A length of a chain name must be less than or equal to 11 characters. diff --git a/neutron/api/rpc/callbacks/version_manager.py b/neutron/api/rpc/callbacks/version_manager.py index 07d8fad885c..66f52146a9a 100644 --- a/neutron/api/rpc/callbacks/version_manager.py +++ b/neutron/api/rpc/callbacks/version_manager.py @@ -233,6 +233,7 @@ class CachedResourceConsumerTracker(object): self._check_expiration() self._versions.report() + _cached_version_tracker = None diff --git a/neutron/conf/agent/common.py b/neutron/conf/agent/common.py index c1b207976f7..34027f99366 100644 --- a/neutron/conf/agent/common.py +++ b/neutron/conf/agent/common.py @@ -251,6 +251,7 @@ def setup_conf(): conf.register_opts(bind_opts) return conf + # add a logging setup method here for convenience setup_logging = config.setup_logging diff --git a/neutron/db/api.py b/neutron/db/api.py index c05820e58ed..deabaa6d872 100644 --- a/neutron/db/api.py +++ b/neutron/db/api.py @@ -68,6 +68,7 @@ def is_retriable(e): # looking savepoints mangled by deadlocks. see bug/1590298 for details. return _is_nested_instance(e, db_exc.DBError) and '1305' in str(e) + _retry_db_errors = oslo_db_api.wrap_db_retry( max_retries=MAX_RETRIES, retry_interval=0.1, diff --git a/neutron/extensions/securitygroup.py b/neutron/extensions/securitygroup.py index cc793e12946..d2411df01b1 100644 --- a/neutron/extensions/securitygroup.py +++ b/neutron/extensions/securitygroup.py @@ -207,6 +207,7 @@ def _validate_name_not_default(data, max_len=db_const.NAME_FIELD_SIZE): if data.lower() == "default": raise SecurityGroupDefaultAlreadyExists() + validators.add_validator('name_not_default', _validate_name_not_default) sg_supported_protocols = ([None] + list(const.IP_PROTOCOL_MAP.keys())) diff --git a/neutron/plugins/ml2/db.py b/neutron/plugins/ml2/db.py index 7694efbb0f1..1e7d9bf9910 100644 --- a/neutron/plugins/ml2/db.py +++ b/neutron/plugins/ml2/db.py @@ -342,4 +342,5 @@ def subscribe(): resources.SEGMENT, events.BEFORE_DELETE) + subscribe() diff --git a/neutron/plugins/ml2/extensions/dns_integration.py b/neutron/plugins/ml2/extensions/dns_integration.py index d9577189074..0b0730ea0e1 100644 --- a/neutron/plugins/ml2/extensions/dns_integration.py +++ b/neutron/plugins/ml2/extensions/dns_integration.py @@ -531,4 +531,5 @@ def subscribe(): _delete_port_in_external_dns_service, resources.PORT, events.BEFORE_DELETE) + subscribe() diff --git a/neutron/services/l3_router/service_providers/base.py b/neutron/services/l3_router/service_providers/base.py index 8d04cfc7c86..519615dbf3a 100644 --- a/neutron/services/l3_router/service_providers/base.py +++ b/neutron/services/l3_router/service_providers/base.py @@ -31,6 +31,7 @@ class _FeatureFlag(object): raise RuntimeError(_("A driver can't require a feature and not " "support it.")) + UNSUPPORTED = _FeatureFlag(supports=False, requires=False) OPTIONAL = _FeatureFlag(supports=True, requires=False) MANDATORY = _FeatureFlag(supports=True, requires=True) diff --git a/neutron/services/segments/db.py b/neutron/services/segments/db.py index 2eed58da287..5bf4b0f017f 100644 --- a/neutron/services/segments/db.py +++ b/neutron/services/segments/db.py @@ -321,4 +321,5 @@ def subscribe(): resources.NETWORK, events.PRECOMMIT_DELETE) + subscribe() diff --git a/neutron/tests/common/agents/ovs_agent.py b/neutron/tests/common/agents/ovs_agent.py index 6fa2bdd64cc..710c3b58c25 100755 --- a/neutron/tests/common/agents/ovs_agent.py +++ b/neutron/tests/common/agents/ovs_agent.py @@ -40,11 +40,13 @@ def get_tunnel_name_full(cls, network_type, local_ip, remote_ip): return '%s-%s-%s' % (network_type, source_ip_hash, remote_ip_hash) + ovs_neutron_agent.OVSNeutronAgent.get_tunnel_name = get_tunnel_name_full def main(): _main() + if __name__ == "__main__": sys.exit(main()) diff --git a/neutron/tests/functional/agent/linux/bin/ipt_binname.py b/neutron/tests/functional/agent/linux/bin/ipt_binname.py index b41d6217d5d..e0d7a4cc93c 100755 --- a/neutron/tests/functional/agent/linux/bin/ipt_binname.py +++ b/neutron/tests/functional/agent/linux/bin/ipt_binname.py @@ -31,6 +31,7 @@ def print_binary_name(): print(iptables_manager.binary_name) + if __name__ == "__main__": if 'spawn' in sys.argv: eventlet.spawn(print_binary_name).wait() diff --git a/neutron/tests/unit/agent/l3/test_router_info.py b/neutron/tests/unit/agent/l3/test_router_info.py index 364c114251d..5c75bbb87ed 100644 --- a/neutron/tests/unit/agent/l3/test_router_info.py +++ b/neutron/tests/unit/agent/l3/test_router_info.py @@ -190,7 +190,7 @@ class TestRouterInfo(base.BaseTestCase): {}, **self.ri_kwargs) new_mark_ids.pop() self.assertEqual(new_mark_ids, new_ri.available_mark_ids) - self.assertTrue(ri.available_mark_ids != new_ri.available_mark_ids) + self.assertNotEqual(ri.available_mark_ids, new_ri.available_mark_ids) def test_process_delete(self): ri = router_info.RouterInfo(mock.Mock(), _uuid(), {}, **self.ri_kwargs) diff --git a/neutron/tests/unit/agent/linux/test_iptables_manager.py b/neutron/tests/unit/agent/linux/test_iptables_manager.py index e156a643619..8049eb86f8e 100644 --- a/neutron/tests/unit/agent/linux/test_iptables_manager.py +++ b/neutron/tests/unit/agent/linux/test_iptables_manager.py @@ -362,6 +362,7 @@ def _generate_raw_restore_dump(iptables_args): 'COMMIT\n' '# Completed by iptables_manager\n' % iptables_args) + MANGLE_DUMP = _generate_mangle_dump(IPTABLES_ARG) MANGLE_DUMP_V6 = _generate_mangle_dump_v6(IPTABLES_ARG) RAW_DUMP = _generate_raw_dump(IPTABLES_ARG) diff --git a/neutron/tests/unit/agent/test_securitygroups_rpc.py b/neutron/tests/unit/agent/test_securitygroups_rpc.py index d7e9130ffdc..5bef722f4ca 100644 --- a/neutron/tests/unit/agent/test_securitygroups_rpc.py +++ b/neutron/tests/unit/agent/test_securitygroups_rpc.py @@ -1363,9 +1363,9 @@ class SecurityGroupAgentRpcApiTestCase(base.BaseTestCase): None, security_groups=[]) self.assertFalse(self.mock_cast.called) + # Note(nati) bn -> binary_name # id -> device_id - PHYSDEV_MOD = '-m physdev' PHYSDEV_IS_BRIDGED = '--physdev-is-bridged' diff --git a/neutron/tests/unit/common/test_utils.py b/neutron/tests/unit/common/test_utils.py index dec6bc938d0..41ead621339 100644 --- a/neutron/tests/unit/common/test_utils.py +++ b/neutron/tests/unit/common/test_utils.py @@ -439,7 +439,7 @@ class TestThrottler(base.BaseTestCase): def sleep_mock(amount_to_sleep): sleep(amount_to_sleep) - self.assertTrue(threshold > amount_to_sleep) + self.assertGreater(threshold, amount_to_sleep) with mock.patch.object(utils.eventlet, "sleep", side_effect=sleep_mock): @@ -455,7 +455,7 @@ class TestThrottler(base.BaseTestCase): throttled_func() self.assertEqual(3, orig_function.call_count) - self.assertTrue(timestamp < lock_with_timer.timestamp) + self.assertLess(timestamp, lock_with_timer.timestamp) def test_method_docstring_is_preserved(self): class Klass(object): diff --git a/neutron/tests/unit/db/quota/test_driver.py b/neutron/tests/unit/db/quota/test_driver.py index 3cfd2e03b6b..5350eee8ced 100644 --- a/neutron/tests/unit/db/quota/test_driver.py +++ b/neutron/tests/unit/db/quota/test_driver.py @@ -80,6 +80,7 @@ class TestCountableResource(resource.CountableResource): def default(self): return self.flag + PROJECT = 'prj_test' RESOURCE = 'res_test' ALT_RESOURCE = 'res_test_meh' diff --git a/neutron/tests/unit/hacking/test_checks.py b/neutron/tests/unit/hacking/test_checks.py index 8736c4a82d7..63d08c8e1a4 100644 --- a/neutron/tests/unit/hacking/test_checks.py +++ b/neutron/tests/unit/hacking/test_checks.py @@ -14,8 +14,8 @@ import re from flake8 import engine from hacking.tests import test_doctest as hacking_doctest -import pep8 import pkg_resources +import pycodestyle import testscenarios import testtools from testtools import content @@ -235,7 +235,7 @@ class HackingTestCase(base.BaseTestCase): # TODO(amotoki): Migrate existing unit tests above to docstring tests. # NOTE(amotoki): Is it better to enhance HackingDocTestCase in hacking repo to -# pass filename to pep8.Checker so that we can reuse it in this test. +# pass filename to pycodestyle.Checker so that we can reuse it in this test. # I am not sure whether unit test class is public. SELFTEST_REGEX = re.compile(r'\b(Okay|N\d{3})(\((\S+)\))?:\s(.*)') @@ -249,7 +249,7 @@ class HackingDocTestCase(hacking_doctest.HackingTestCase): scenarios = file_cases - def test_pep8(self): + def test_pycodestyle(self): # NOTE(jecarey): Add tests marked as off_by_default to enable testing turn_on = set(['H106']) @@ -258,8 +258,8 @@ class HackingDocTestCase(hacking_doctest.HackingTestCase): self.options.select = tuple(turn_on) self.options.ignore = ('N530',) - report = pep8.BaseReport(self.options) - checker = pep8.Checker(filename=self.filename, lines=self.lines, + report = pycodestyle.BaseReport(self.options) + checker = pycodestyle.Checker(filename=self.filename, lines=self.lines, options=self.options, report=report) checker.check_all() self.addDetail('doctest', content.text_content(self.raw)) diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py index 32c607cae5b..d0cf4b408ea 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py @@ -37,6 +37,7 @@ def nonzero(f): else: return f.__nonzero__() + # Useful global dummy variables. NET_UUID = '3faeebfe-5d37-11e1-a64b-000c29d5f0a7' LS_ID = 420 diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index bc28aedc9bc..c9766b25d65 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -2036,7 +2036,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase, return_value=[]): new_context = plugin._bind_port(context) self.assertEqual(mock_port, new_context.original) - self.assertFalse(new_context == context) + self.assertNotEqual(new_context, context) class TestMl2PortBindingNoSG(TestMl2PortBinding): @@ -2830,7 +2830,7 @@ class TestML2Segments(Ml2PluginV2TestCase): # Assert it is not changed self.assertEqual(seg_id, segment[driver_api.SEGMENTATION_ID]) else: - self.assertTrue(segment[driver_api.SEGMENTATION_ID] > 0) + self.assertGreater(segment[driver_api.SEGMENTATION_ID], 0) return segment diff --git a/neutron/tests/unit/services/metering/test_metering_plugin.py b/neutron/tests/unit/services/metering/test_metering_plugin.py index 84f507725c2..52b8bb5b035 100644 --- a/neutron/tests/unit/services/metering/test_metering_plugin.py +++ b/neutron/tests/unit/services/metering/test_metering_plugin.py @@ -292,9 +292,9 @@ class TestMeteringPlugin(test_db_base_plugin_v2.NeutronDbPluginV2TestCase, with self.router(tenant_id=self.tenant_id, set_context=True): with self.metering_label(tenant_id=self.tenant_id, set_context=True) as label: - l = label['metering_label'] + la = label['metering_label'] self.mock_uuid.return_value = second_uuid - with self.metering_label_rule(l['id']): + with self.metering_label_rule(la['id']): self.mock_add_rule.assert_called_with(self.ctx, expected_add) self._delete('metering-label-rules', second_uuid) diff --git a/neutron/tests/unit/services/qos/test_qos_plugin.py b/neutron/tests/unit/services/qos/test_qos_plugin.py index d6e68e9af42..aa01f41348c 100644 --- a/neutron/tests/unit/services/qos/test_qos_plugin.py +++ b/neutron/tests/unit/services/qos/test_qos_plugin.py @@ -943,5 +943,5 @@ class TestQosPlugin(base.BaseQosTestCase): action_index = mock_manager.mock_calls.index( get_rule_mock_call) - self.assertTrue( - action_index < mock_manager.mock_calls.index(driver_mock_call)) + self.assertLess( + action_index, mock_manager.mock_calls.index(driver_mock_call)) diff --git a/neutron/tests/unit/services/trunk/drivers/linuxbridge/agent/test_trunk_plumber.py b/neutron/tests/unit/services/trunk/drivers/linuxbridge/agent/test_trunk_plumber.py index a10b40d5bf1..2701258ff49 100644 --- a/neutron/tests/unit/services/trunk/drivers/linuxbridge/agent/test_trunk_plumber.py +++ b/neutron/tests/unit/services/trunk/drivers/linuxbridge/agent/test_trunk_plumber.py @@ -95,6 +95,7 @@ class PlumberTestCase(base.BaseTestCase): 'tap47198374-5c'] self.assertEqual(expected, names) + IP_LINK_OUTPUT = """ 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 diff --git a/neutron/tests/unit/testlib_api.py b/neutron/tests/unit/testlib_api.py index a0fbf101d9c..cb75c0541f1 100644 --- a/neutron/tests/unit/testlib_api.py +++ b/neutron/tests/unit/testlib_api.py @@ -308,7 +308,8 @@ class SqlTestCase(BaseSqlTestCase, base.BaseTestCase): class OpportunisticDBTestMixin(object): - """Mixin that converts a BaseSqlTestCase to use the OpportunisticSqlFixture. + """Mixin that converts a BaseSqlTestCase to use the + OpportunisticSqlFixture. """ SKIP_ON_UNAVAILABLE_DB = not base.bool_from_env('OS_FAIL_ON_MISSING_DEPS') diff --git a/test-requirements.txt b/test-requirements.txt index 1308568d6b3..5806b7c5038 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,7 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 +hacking>=1.1.0 # Apache-2.0 bandit>=1.1.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index b07ec9770da..0d996c131da 100644 --- a/tox.ini +++ b/tox.ini @@ -162,7 +162,8 @@ commands = sphinx-build -W -b linkcheck doc/source doc/build/linkcheck # N534 Untranslated exception message # TODO(amotoki) check the following new rules should be fixed or ignored # E731 do not assign a lambda expression, use a def -ignore = E125,E126,E128,E731,H404,H405,N530,N534 +# W504 line break after binary operator +ignore = E125,E126,E128,E731,H404,H405,N530,N534,W504 # H106: Don't put vim configuration in source files # H203: Use assertIs(Not)None to check for None # H204: Use assert(Not)Equal to check for equality