From 7a714aeb13e99b95a8f495765a1fa57297f92d30 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Wed, 11 Apr 2018 00:47:20 +0900 Subject: [PATCH] Fix pep8 errors Recent pep8 upgrade and corresponding pycodestyle update break pep8 job due to the new rules. This commit fixes the following new errors: - E266 too many leading '#' for block comment - E501 line too long - H903 Windows style line endings not allowed in code The following errors are added to the ignore list as there are many errors: - E402 module level import not at top of file - E731 do not assign a lambda expression, use a def - W503 line break before binary operator Change-Id: I1fd3357479bb2ba3d89de92739ffac99900761b6 --- .../openvswitch/agent/common/constants.py | 10 +- .../functional/agent/windows/test_ip_lib.py | 88 +++--- .../tests/unit/agent/windows/test_ip_lib.py | 254 +++++++++--------- .../agent/test_linuxbridge_neutron_agent.py | 3 +- tox.ini | 6 +- 5 files changed, 183 insertions(+), 178 deletions(-) diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/common/constants.py b/neutron/plugins/ml2/drivers/openvswitch/agent/common/constants.py index 3e0e3b18639..27dd3878d2d 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/common/constants.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/common/constants.py @@ -35,9 +35,9 @@ NONEXISTENT_PEER = 'nonexistent-peer' TUNNEL_NETWORK_TYPES = [p_const.TYPE_GRE, p_const.TYPE_VXLAN, p_const.TYPE_GENEVE] -### OpenFlow table IDs +# --- OpenFlow table IDs -## Integration bridge (int_br) +# --- Integration bridge (int_br) LOCAL_SWITCHING = 0 @@ -76,7 +76,7 @@ ACCEPTED_EGRESS_TRAFFIC_TABLE = 91 ACCEPTED_INGRESS_TRAFFIC_TABLE = 92 DROPPED_TRAFFIC_TABLE = 93 -## Tunnel bridge (tun_br) +# --- Tunnel bridge (tun_br) # Various tables for tunneling flows DVR_PROCESS = 1 @@ -91,14 +91,14 @@ UCAST_TO_TUN = 20 ARP_RESPONDER = 21 FLOOD_TO_TUN = 22 -## Physical Bridges (phys_brs) +# --- Physical Bridges (phys_brs) # Various tables for DVR use of physical bridge flows DVR_PROCESS_VLAN = 1 LOCAL_VLAN_TRANSLATION = 2 DVR_NOT_LEARN_VLAN = 3 -### end of OpenFlow table IDs +# --- end of OpenFlow table IDs # type for ARP reply in ARP header ARP_REPLY = '0x2' diff --git a/neutron/tests/functional/agent/windows/test_ip_lib.py b/neutron/tests/functional/agent/windows/test_ip_lib.py index 123d7ef86fd..3bac62b942f 100644 --- a/neutron/tests/functional/agent/windows/test_ip_lib.py +++ b/neutron/tests/functional/agent/windows/test_ip_lib.py @@ -1,44 +1,44 @@ -# Copyright 2016 Cloudbase Solutions. -# All Rights Reserved. -# -# 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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.agent.windows import ip_lib -from neutron.tests import base - -WRONG_IP = '0.0.0.0' -TEST_IP = '127.0.0.1' -TEST_MAC = '00:00:00:00:00:00' - - -class IpLibTestCase(base.BaseTestCase): - - def test_ipwrapper_get_device_by_ip_None(self): - self.assertIsNone(ip_lib.IPWrapper().get_device_by_ip(WRONG_IP)) - - def test_ipwrapper_get_device_by_ip(self): - ip_dev = ip_lib.IPWrapper().get_device_by_ip(TEST_IP) - self.assertEqual('lo', ip_dev.name) - - def test_device_has_ip(self): - not_a_device = ip_lib.IPDevice('#!#._not_a_device_bleargh!!@@@') - self.assertFalse(not_a_device.device_has_ip(TEST_IP)) - - def test_ip_link_read_mac_address(self): - ip_dev = ip_lib.IPWrapper().get_device_by_ip(TEST_IP) - self.assertEqual([TEST_MAC], ip_lib.IPLink(ip_dev).address) - - def test_ip_link_read_mac_address_wrong(self): - not_a_device = ip_lib.IPDevice('#!#._not_a_device_bleargh!!@@@') - mac_addr = ip_lib.IPLink(not_a_device).address - self.assertFalse(mac_addr) +# Copyright 2016 Cloudbase Solutions. +# All Rights Reserved. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron.agent.windows import ip_lib +from neutron.tests import base + +WRONG_IP = '0.0.0.0' +TEST_IP = '127.0.0.1' +TEST_MAC = '00:00:00:00:00:00' + + +class IpLibTestCase(base.BaseTestCase): + + def test_ipwrapper_get_device_by_ip_None(self): + self.assertIsNone(ip_lib.IPWrapper().get_device_by_ip(WRONG_IP)) + + def test_ipwrapper_get_device_by_ip(self): + ip_dev = ip_lib.IPWrapper().get_device_by_ip(TEST_IP) + self.assertEqual('lo', ip_dev.name) + + def test_device_has_ip(self): + not_a_device = ip_lib.IPDevice('#!#._not_a_device_bleargh!!@@@') + self.assertFalse(not_a_device.device_has_ip(TEST_IP)) + + def test_ip_link_read_mac_address(self): + ip_dev = ip_lib.IPWrapper().get_device_by_ip(TEST_IP) + self.assertEqual([TEST_MAC], ip_lib.IPLink(ip_dev).address) + + def test_ip_link_read_mac_address_wrong(self): + not_a_device = ip_lib.IPDevice('#!#._not_a_device_bleargh!!@@@') + mac_addr = ip_lib.IPLink(not_a_device).address + self.assertFalse(mac_addr) diff --git a/neutron/tests/unit/agent/windows/test_ip_lib.py b/neutron/tests/unit/agent/windows/test_ip_lib.py index bf4cd73c54e..1b20d9ca71f 100644 --- a/neutron/tests/unit/agent/windows/test_ip_lib.py +++ b/neutron/tests/unit/agent/windows/test_ip_lib.py @@ -1,127 +1,127 @@ -# Copyright 2016 Cloudbase Solutions. -# All Rights Reserved. -# -# 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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -import netifaces - -from neutron.agent.windows import ip_lib -from neutron.tests import base - - -class TestIpWrapper(base.BaseTestCase): - - def test_get_device_by_ip_no_ip(self): - ret = ip_lib.IPWrapper().get_device_by_ip(None) - self.assertIsNone(ret) - - @mock.patch.object(ip_lib.IPWrapper, 'get_devices') - def test_get_device_by_ip(self, mock_get_devices): - mock_dev1 = mock.MagicMock() - mock_dev2 = mock.MagicMock() - mock_dev1.device_has_ip.return_value = False - mock_dev2.device_has_ip.return_value = True - mock_get_devices.return_value = [mock_dev1, mock_dev2] - ret = ip_lib.IPWrapper().get_device_by_ip('fake_ip') - - self.assertEqual(mock_dev2, ret) - - @mock.patch('netifaces.interfaces') - def test_get_devices(self, mock_interfaces): - mock_interfaces.return_value = [mock.sentinel.dev1, - mock.sentinel.dev2] - - ret = ip_lib.IPWrapper().get_devices() - self.assertEqual(mock.sentinel.dev1, ret[0].name) - self.assertEqual(mock.sentinel.dev2, ret[1].name) - - @mock.patch('netifaces.interfaces') - def test_get_devices_error(self, mock_interfaces): - mock_interfaces.side_effect = OSError - ret = ip_lib.IPWrapper().get_devices() - - self.assertEqual([], ret) - - -class TestIpDevice(base.BaseTestCase): - - @mock.patch('netifaces.ifaddresses') - def test_read_ifaddresses(self, mock_netifaces): - mock_address = {'addr': mock.sentinel.fake_addr} - mock_netifaces.return_value = {netifaces.AF_INET: [mock_address]} - ret = ip_lib.IPDevice("fake_dev").read_ifaddresses() - self.assertTrue(ret) - - @mock.patch('netifaces.ifaddresses') - def test_read_ifaddresses_no_ip(self, mock_netifaces): - mock_netifaces.return_value = {} - ret = ip_lib.IPDevice("fake_dev").read_ifaddresses() - self.assertFalse(ret) - - @mock.patch('netifaces.ifaddresses') - def test_read_ifaddresses_ip_error(self, mock_netifaces): - mock_netifaces.side_effect = OSError - ret = ip_lib.IPDevice("fake_dev").read_ifaddresses() - self.assertFalse(ret) - - @mock.patch('netifaces.ifaddresses') - def test_read_faddresses_not_found(self, mock_netifaces): - mock_netifaces.side_effect = ValueError - ret = ip_lib.IPDevice("fake_dev").read_ifaddresses() - self.assertFalse(ret) - - def test_device_has_ip(self): - mock_address = {'addr': mock.sentinel.fake_addr} - ip_device = ip_lib.IPDevice("fake_dev") - with mock.patch.object(ip_device, "read_ifaddresses", return_value=( - {netifaces.AF_INET: [mock_address]})): - ret = ip_device.device_has_ip(mock.sentinel.fake_addr) - self.assertTrue(ret) - - def test_device_has_ip_false(self): - ip_device = ip_lib.IPDevice("fake_dev") - with mock.patch.object(ip_device, "read_ifaddresses", return_value={}): - ret = ip_device.device_has_ip(mock.sentinel.fake_addr) - self.assertFalse(ret) - - def test_device_has_ip_error(self): - ip_device = ip_lib.IPDevice("fake_dev") - with mock.patch.object(ip_device, "read_ifaddresses", - return_value=None): - ret = ip_device.device_has_ip(mock.sentinel.fake_addr) - self.assertFalse(ret) - - -class TestIPLink(base.BaseTestCase): - - def setUp(self): - super(TestIPLink, self).setUp() - parent = ip_lib.IPDevice("fake_dev") - self.ip_link = ip_lib.IPLink(parent) - self.ip_link._parent.read_ifaddresses = mock.Mock() - - def test_address(self): - mock_address = {'addr': mock.sentinel.fake_addr} - self.ip_link._parent.read_ifaddresses.return_value = { - netifaces.AF_LINK: [mock_address]} - self.assertEqual([mock_address['addr']], self.ip_link.address) - - def test_address_no_address(self): - self.ip_link._parent.read_ifaddresses.return_value = { - netifaces.AF_LINK: []} - self.assertEqual([], self.ip_link.address) - - def test_address_error(self): - self.ip_link._parent.read_ifaddresses.return_value = None - self.assertFalse(self.ip_link.address) +# Copyright 2016 Cloudbase Solutions. +# All Rights Reserved. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock +import netifaces + +from neutron.agent.windows import ip_lib +from neutron.tests import base + + +class TestIpWrapper(base.BaseTestCase): + + def test_get_device_by_ip_no_ip(self): + ret = ip_lib.IPWrapper().get_device_by_ip(None) + self.assertIsNone(ret) + + @mock.patch.object(ip_lib.IPWrapper, 'get_devices') + def test_get_device_by_ip(self, mock_get_devices): + mock_dev1 = mock.MagicMock() + mock_dev2 = mock.MagicMock() + mock_dev1.device_has_ip.return_value = False + mock_dev2.device_has_ip.return_value = True + mock_get_devices.return_value = [mock_dev1, mock_dev2] + ret = ip_lib.IPWrapper().get_device_by_ip('fake_ip') + + self.assertEqual(mock_dev2, ret) + + @mock.patch('netifaces.interfaces') + def test_get_devices(self, mock_interfaces): + mock_interfaces.return_value = [mock.sentinel.dev1, + mock.sentinel.dev2] + + ret = ip_lib.IPWrapper().get_devices() + self.assertEqual(mock.sentinel.dev1, ret[0].name) + self.assertEqual(mock.sentinel.dev2, ret[1].name) + + @mock.patch('netifaces.interfaces') + def test_get_devices_error(self, mock_interfaces): + mock_interfaces.side_effect = OSError + ret = ip_lib.IPWrapper().get_devices() + + self.assertEqual([], ret) + + +class TestIpDevice(base.BaseTestCase): + + @mock.patch('netifaces.ifaddresses') + def test_read_ifaddresses(self, mock_netifaces): + mock_address = {'addr': mock.sentinel.fake_addr} + mock_netifaces.return_value = {netifaces.AF_INET: [mock_address]} + ret = ip_lib.IPDevice("fake_dev").read_ifaddresses() + self.assertTrue(ret) + + @mock.patch('netifaces.ifaddresses') + def test_read_ifaddresses_no_ip(self, mock_netifaces): + mock_netifaces.return_value = {} + ret = ip_lib.IPDevice("fake_dev").read_ifaddresses() + self.assertFalse(ret) + + @mock.patch('netifaces.ifaddresses') + def test_read_ifaddresses_ip_error(self, mock_netifaces): + mock_netifaces.side_effect = OSError + ret = ip_lib.IPDevice("fake_dev").read_ifaddresses() + self.assertFalse(ret) + + @mock.patch('netifaces.ifaddresses') + def test_read_faddresses_not_found(self, mock_netifaces): + mock_netifaces.side_effect = ValueError + ret = ip_lib.IPDevice("fake_dev").read_ifaddresses() + self.assertFalse(ret) + + def test_device_has_ip(self): + mock_address = {'addr': mock.sentinel.fake_addr} + ip_device = ip_lib.IPDevice("fake_dev") + with mock.patch.object(ip_device, "read_ifaddresses", return_value=( + {netifaces.AF_INET: [mock_address]})): + ret = ip_device.device_has_ip(mock.sentinel.fake_addr) + self.assertTrue(ret) + + def test_device_has_ip_false(self): + ip_device = ip_lib.IPDevice("fake_dev") + with mock.patch.object(ip_device, "read_ifaddresses", return_value={}): + ret = ip_device.device_has_ip(mock.sentinel.fake_addr) + self.assertFalse(ret) + + def test_device_has_ip_error(self): + ip_device = ip_lib.IPDevice("fake_dev") + with mock.patch.object(ip_device, "read_ifaddresses", + return_value=None): + ret = ip_device.device_has_ip(mock.sentinel.fake_addr) + self.assertFalse(ret) + + +class TestIPLink(base.BaseTestCase): + + def setUp(self): + super(TestIPLink, self).setUp() + parent = ip_lib.IPDevice("fake_dev") + self.ip_link = ip_lib.IPLink(parent) + self.ip_link._parent.read_ifaddresses = mock.Mock() + + def test_address(self): + mock_address = {'addr': mock.sentinel.fake_addr} + self.ip_link._parent.read_ifaddresses.return_value = { + netifaces.AF_LINK: [mock_address]} + self.assertEqual([mock_address['addr']], self.ip_link.address) + + def test_address_no_address(self): + self.ip_link._parent.read_ifaddresses.return_value = { + netifaces.AF_LINK: []} + self.assertEqual([], self.ip_link.address) + + def test_address_error(self): + self.ip_link._parent.read_ifaddresses.return_value = None + self.assertFalse(self.ip_link.address) diff --git a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py index 2f9417aa643..8882e3206fb 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py @@ -387,7 +387,8 @@ class TestLinuxBridgeManager(base.BaseTestCase): de_fn.return_value = False vxlan_dev = FakeIpDevice() with mock.patch.object(vxlan_dev, 'disable_ipv6') as dv6_fn,\ - mock.patch.object(vxlan_dev.link, 'set_mtu') as set_mtu_fn,\ + mock.patch.object(vxlan_dev.link, + 'set_mtu') as set_mtu_fn,\ mock.patch.object(ip_lib, 'get_device_mtu', return_value=physical_mtu),\ mock.patch.object(self.lbm.ip, 'add_vxlan', diff --git a/tox.ini b/tox.ini index c93cc80e06a..5e79f53c13d 100644 --- a/tox.ini +++ b/tox.ini @@ -145,7 +145,11 @@ commands = sphinx-build -W -b linkcheck doc/source doc/build/linkcheck # TODO(ihrachys) figure out what to do with N534 and N536 # N534 Untranslated exception message # N536 Use assertIsNone rather than assertEqual to check for None values -ignore = E125,E126,E128,E129,E265,H404,H405,N530,N534,N536 +# TODO(amotoki) check the following new rules should be fixed or ignored +# E402 module level import not at top of file +# E731 do not assign a lambda expression, use a def +# W503 line break before binary operator +ignore = E125,E126,E128,E129,E265,E402,E731,W503,H404,H405,N530,N534,N536 # 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