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 Conflicts: neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py Change-Id: I1fd3357479bb2ba3d89de92739ffac99900761b6 (cherry picked from commit 7a714aeb13e99b95a8f495765a1fa57297f92d30)
This commit is contained in:
parent
e53aa131ab
commit
71b305cb9e
@ -35,9 +35,9 @@ NONEXISTENT_PEER = 'nonexistent-peer'
|
|||||||
TUNNEL_NETWORK_TYPES = [p_const.TYPE_GRE, p_const.TYPE_VXLAN,
|
TUNNEL_NETWORK_TYPES = [p_const.TYPE_GRE, p_const.TYPE_VXLAN,
|
||||||
p_const.TYPE_GENEVE]
|
p_const.TYPE_GENEVE]
|
||||||
|
|
||||||
### OpenFlow table IDs
|
# --- OpenFlow table IDs
|
||||||
|
|
||||||
## Integration bridge (int_br)
|
# --- Integration bridge (int_br)
|
||||||
|
|
||||||
LOCAL_SWITCHING = 0
|
LOCAL_SWITCHING = 0
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ ACCEPTED_EGRESS_TRAFFIC_TABLE = 91
|
|||||||
ACCEPTED_INGRESS_TRAFFIC_TABLE = 92
|
ACCEPTED_INGRESS_TRAFFIC_TABLE = 92
|
||||||
DROPPED_TRAFFIC_TABLE = 93
|
DROPPED_TRAFFIC_TABLE = 93
|
||||||
|
|
||||||
## Tunnel bridge (tun_br)
|
# --- Tunnel bridge (tun_br)
|
||||||
|
|
||||||
# Various tables for tunneling flows
|
# Various tables for tunneling flows
|
||||||
DVR_PROCESS = 1
|
DVR_PROCESS = 1
|
||||||
@ -91,14 +91,14 @@ UCAST_TO_TUN = 20
|
|||||||
ARP_RESPONDER = 21
|
ARP_RESPONDER = 21
|
||||||
FLOOD_TO_TUN = 22
|
FLOOD_TO_TUN = 22
|
||||||
|
|
||||||
## Physical Bridges (phys_brs)
|
# --- Physical Bridges (phys_brs)
|
||||||
|
|
||||||
# Various tables for DVR use of physical bridge flows
|
# Various tables for DVR use of physical bridge flows
|
||||||
DVR_PROCESS_VLAN = 1
|
DVR_PROCESS_VLAN = 1
|
||||||
LOCAL_VLAN_TRANSLATION = 2
|
LOCAL_VLAN_TRANSLATION = 2
|
||||||
DVR_NOT_LEARN_VLAN = 3
|
DVR_NOT_LEARN_VLAN = 3
|
||||||
|
|
||||||
### end of OpenFlow table IDs
|
# --- end of OpenFlow table IDs
|
||||||
|
|
||||||
# type for ARP reply in ARP header
|
# type for ARP reply in ARP header
|
||||||
ARP_REPLY = '0x2'
|
ARP_REPLY = '0x2'
|
||||||
|
@ -1,44 +1,44 @@
|
|||||||
# Copyright 2016 Cloudbase Solutions.
|
# Copyright 2016 Cloudbase Solutions.
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron.agent.windows import ip_lib
|
from neutron.agent.windows import ip_lib
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
|
||||||
WRONG_IP = '0.0.0.0'
|
WRONG_IP = '0.0.0.0'
|
||||||
TEST_IP = '127.0.0.1'
|
TEST_IP = '127.0.0.1'
|
||||||
TEST_MAC = '00:00:00:00:00:00'
|
TEST_MAC = '00:00:00:00:00:00'
|
||||||
|
|
||||||
|
|
||||||
class IpLibTestCase(base.BaseTestCase):
|
class IpLibTestCase(base.BaseTestCase):
|
||||||
|
|
||||||
def test_ipwrapper_get_device_by_ip_None(self):
|
def test_ipwrapper_get_device_by_ip_None(self):
|
||||||
self.assertIsNone(ip_lib.IPWrapper().get_device_by_ip(WRONG_IP))
|
self.assertIsNone(ip_lib.IPWrapper().get_device_by_ip(WRONG_IP))
|
||||||
|
|
||||||
def test_ipwrapper_get_device_by_ip(self):
|
def test_ipwrapper_get_device_by_ip(self):
|
||||||
ip_dev = ip_lib.IPWrapper().get_device_by_ip(TEST_IP)
|
ip_dev = ip_lib.IPWrapper().get_device_by_ip(TEST_IP)
|
||||||
self.assertEqual('lo', ip_dev.name)
|
self.assertEqual('lo', ip_dev.name)
|
||||||
|
|
||||||
def test_device_has_ip(self):
|
def test_device_has_ip(self):
|
||||||
not_a_device = ip_lib.IPDevice('#!#._not_a_device_bleargh!!@@@')
|
not_a_device = ip_lib.IPDevice('#!#._not_a_device_bleargh!!@@@')
|
||||||
self.assertFalse(not_a_device.device_has_ip(TEST_IP))
|
self.assertFalse(not_a_device.device_has_ip(TEST_IP))
|
||||||
|
|
||||||
def test_ip_link_read_mac_address(self):
|
def test_ip_link_read_mac_address(self):
|
||||||
ip_dev = ip_lib.IPWrapper().get_device_by_ip(TEST_IP)
|
ip_dev = ip_lib.IPWrapper().get_device_by_ip(TEST_IP)
|
||||||
self.assertEqual([TEST_MAC], ip_lib.IPLink(ip_dev).address)
|
self.assertEqual([TEST_MAC], ip_lib.IPLink(ip_dev).address)
|
||||||
|
|
||||||
def test_ip_link_read_mac_address_wrong(self):
|
def test_ip_link_read_mac_address_wrong(self):
|
||||||
not_a_device = ip_lib.IPDevice('#!#._not_a_device_bleargh!!@@@')
|
not_a_device = ip_lib.IPDevice('#!#._not_a_device_bleargh!!@@@')
|
||||||
mac_addr = ip_lib.IPLink(not_a_device).address
|
mac_addr = ip_lib.IPLink(not_a_device).address
|
||||||
self.assertFalse(mac_addr)
|
self.assertFalse(mac_addr)
|
||||||
|
@ -1,127 +1,127 @@
|
|||||||
# Copyright 2016 Cloudbase Solutions.
|
# Copyright 2016 Cloudbase Solutions.
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import netifaces
|
import netifaces
|
||||||
|
|
||||||
from neutron.agent.windows import ip_lib
|
from neutron.agent.windows import ip_lib
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
|
||||||
|
|
||||||
class TestIpWrapper(base.BaseTestCase):
|
class TestIpWrapper(base.BaseTestCase):
|
||||||
|
|
||||||
def test_get_device_by_ip_no_ip(self):
|
def test_get_device_by_ip_no_ip(self):
|
||||||
ret = ip_lib.IPWrapper().get_device_by_ip(None)
|
ret = ip_lib.IPWrapper().get_device_by_ip(None)
|
||||||
self.assertIsNone(ret)
|
self.assertIsNone(ret)
|
||||||
|
|
||||||
@mock.patch.object(ip_lib.IPWrapper, 'get_devices')
|
@mock.patch.object(ip_lib.IPWrapper, 'get_devices')
|
||||||
def test_get_device_by_ip(self, mock_get_devices):
|
def test_get_device_by_ip(self, mock_get_devices):
|
||||||
mock_dev1 = mock.MagicMock()
|
mock_dev1 = mock.MagicMock()
|
||||||
mock_dev2 = mock.MagicMock()
|
mock_dev2 = mock.MagicMock()
|
||||||
mock_dev1.device_has_ip.return_value = False
|
mock_dev1.device_has_ip.return_value = False
|
||||||
mock_dev2.device_has_ip.return_value = True
|
mock_dev2.device_has_ip.return_value = True
|
||||||
mock_get_devices.return_value = [mock_dev1, mock_dev2]
|
mock_get_devices.return_value = [mock_dev1, mock_dev2]
|
||||||
ret = ip_lib.IPWrapper().get_device_by_ip('fake_ip')
|
ret = ip_lib.IPWrapper().get_device_by_ip('fake_ip')
|
||||||
|
|
||||||
self.assertEqual(mock_dev2, ret)
|
self.assertEqual(mock_dev2, ret)
|
||||||
|
|
||||||
@mock.patch('netifaces.interfaces')
|
@mock.patch('netifaces.interfaces')
|
||||||
def test_get_devices(self, mock_interfaces):
|
def test_get_devices(self, mock_interfaces):
|
||||||
mock_interfaces.return_value = [mock.sentinel.dev1,
|
mock_interfaces.return_value = [mock.sentinel.dev1,
|
||||||
mock.sentinel.dev2]
|
mock.sentinel.dev2]
|
||||||
|
|
||||||
ret = ip_lib.IPWrapper().get_devices()
|
ret = ip_lib.IPWrapper().get_devices()
|
||||||
self.assertEqual(mock.sentinel.dev1, ret[0].name)
|
self.assertEqual(mock.sentinel.dev1, ret[0].name)
|
||||||
self.assertEqual(mock.sentinel.dev2, ret[1].name)
|
self.assertEqual(mock.sentinel.dev2, ret[1].name)
|
||||||
|
|
||||||
@mock.patch('netifaces.interfaces')
|
@mock.patch('netifaces.interfaces')
|
||||||
def test_get_devices_error(self, mock_interfaces):
|
def test_get_devices_error(self, mock_interfaces):
|
||||||
mock_interfaces.side_effect = OSError
|
mock_interfaces.side_effect = OSError
|
||||||
ret = ip_lib.IPWrapper().get_devices()
|
ret = ip_lib.IPWrapper().get_devices()
|
||||||
|
|
||||||
self.assertEqual([], ret)
|
self.assertEqual([], ret)
|
||||||
|
|
||||||
|
|
||||||
class TestIpDevice(base.BaseTestCase):
|
class TestIpDevice(base.BaseTestCase):
|
||||||
|
|
||||||
@mock.patch('netifaces.ifaddresses')
|
@mock.patch('netifaces.ifaddresses')
|
||||||
def test_read_ifaddresses(self, mock_netifaces):
|
def test_read_ifaddresses(self, mock_netifaces):
|
||||||
mock_address = {'addr': mock.sentinel.fake_addr}
|
mock_address = {'addr': mock.sentinel.fake_addr}
|
||||||
mock_netifaces.return_value = {netifaces.AF_INET: [mock_address]}
|
mock_netifaces.return_value = {netifaces.AF_INET: [mock_address]}
|
||||||
ret = ip_lib.IPDevice("fake_dev").read_ifaddresses()
|
ret = ip_lib.IPDevice("fake_dev").read_ifaddresses()
|
||||||
self.assertTrue(ret)
|
self.assertTrue(ret)
|
||||||
|
|
||||||
@mock.patch('netifaces.ifaddresses')
|
@mock.patch('netifaces.ifaddresses')
|
||||||
def test_read_ifaddresses_no_ip(self, mock_netifaces):
|
def test_read_ifaddresses_no_ip(self, mock_netifaces):
|
||||||
mock_netifaces.return_value = {}
|
mock_netifaces.return_value = {}
|
||||||
ret = ip_lib.IPDevice("fake_dev").read_ifaddresses()
|
ret = ip_lib.IPDevice("fake_dev").read_ifaddresses()
|
||||||
self.assertFalse(ret)
|
self.assertFalse(ret)
|
||||||
|
|
||||||
@mock.patch('netifaces.ifaddresses')
|
@mock.patch('netifaces.ifaddresses')
|
||||||
def test_read_ifaddresses_ip_error(self, mock_netifaces):
|
def test_read_ifaddresses_ip_error(self, mock_netifaces):
|
||||||
mock_netifaces.side_effect = OSError
|
mock_netifaces.side_effect = OSError
|
||||||
ret = ip_lib.IPDevice("fake_dev").read_ifaddresses()
|
ret = ip_lib.IPDevice("fake_dev").read_ifaddresses()
|
||||||
self.assertFalse(ret)
|
self.assertFalse(ret)
|
||||||
|
|
||||||
@mock.patch('netifaces.ifaddresses')
|
@mock.patch('netifaces.ifaddresses')
|
||||||
def test_read_faddresses_not_found(self, mock_netifaces):
|
def test_read_faddresses_not_found(self, mock_netifaces):
|
||||||
mock_netifaces.side_effect = ValueError
|
mock_netifaces.side_effect = ValueError
|
||||||
ret = ip_lib.IPDevice("fake_dev").read_ifaddresses()
|
ret = ip_lib.IPDevice("fake_dev").read_ifaddresses()
|
||||||
self.assertFalse(ret)
|
self.assertFalse(ret)
|
||||||
|
|
||||||
def test_device_has_ip(self):
|
def test_device_has_ip(self):
|
||||||
mock_address = {'addr': mock.sentinel.fake_addr}
|
mock_address = {'addr': mock.sentinel.fake_addr}
|
||||||
ip_device = ip_lib.IPDevice("fake_dev")
|
ip_device = ip_lib.IPDevice("fake_dev")
|
||||||
with mock.patch.object(ip_device, "read_ifaddresses", return_value=(
|
with mock.patch.object(ip_device, "read_ifaddresses", return_value=(
|
||||||
{netifaces.AF_INET: [mock_address]})):
|
{netifaces.AF_INET: [mock_address]})):
|
||||||
ret = ip_device.device_has_ip(mock.sentinel.fake_addr)
|
ret = ip_device.device_has_ip(mock.sentinel.fake_addr)
|
||||||
self.assertTrue(ret)
|
self.assertTrue(ret)
|
||||||
|
|
||||||
def test_device_has_ip_false(self):
|
def test_device_has_ip_false(self):
|
||||||
ip_device = ip_lib.IPDevice("fake_dev")
|
ip_device = ip_lib.IPDevice("fake_dev")
|
||||||
with mock.patch.object(ip_device, "read_ifaddresses", return_value={}):
|
with mock.patch.object(ip_device, "read_ifaddresses", return_value={}):
|
||||||
ret = ip_device.device_has_ip(mock.sentinel.fake_addr)
|
ret = ip_device.device_has_ip(mock.sentinel.fake_addr)
|
||||||
self.assertFalse(ret)
|
self.assertFalse(ret)
|
||||||
|
|
||||||
def test_device_has_ip_error(self):
|
def test_device_has_ip_error(self):
|
||||||
ip_device = ip_lib.IPDevice("fake_dev")
|
ip_device = ip_lib.IPDevice("fake_dev")
|
||||||
with mock.patch.object(ip_device, "read_ifaddresses",
|
with mock.patch.object(ip_device, "read_ifaddresses",
|
||||||
return_value=None):
|
return_value=None):
|
||||||
ret = ip_device.device_has_ip(mock.sentinel.fake_addr)
|
ret = ip_device.device_has_ip(mock.sentinel.fake_addr)
|
||||||
self.assertFalse(ret)
|
self.assertFalse(ret)
|
||||||
|
|
||||||
|
|
||||||
class TestIPLink(base.BaseTestCase):
|
class TestIPLink(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestIPLink, self).setUp()
|
super(TestIPLink, self).setUp()
|
||||||
parent = ip_lib.IPDevice("fake_dev")
|
parent = ip_lib.IPDevice("fake_dev")
|
||||||
self.ip_link = ip_lib.IPLink(parent)
|
self.ip_link = ip_lib.IPLink(parent)
|
||||||
self.ip_link._parent.read_ifaddresses = mock.Mock()
|
self.ip_link._parent.read_ifaddresses = mock.Mock()
|
||||||
|
|
||||||
def test_address(self):
|
def test_address(self):
|
||||||
mock_address = {'addr': mock.sentinel.fake_addr}
|
mock_address = {'addr': mock.sentinel.fake_addr}
|
||||||
self.ip_link._parent.read_ifaddresses.return_value = {
|
self.ip_link._parent.read_ifaddresses.return_value = {
|
||||||
netifaces.AF_LINK: [mock_address]}
|
netifaces.AF_LINK: [mock_address]}
|
||||||
self.assertEqual([mock_address['addr']], self.ip_link.address)
|
self.assertEqual([mock_address['addr']], self.ip_link.address)
|
||||||
|
|
||||||
def test_address_no_address(self):
|
def test_address_no_address(self):
|
||||||
self.ip_link._parent.read_ifaddresses.return_value = {
|
self.ip_link._parent.read_ifaddresses.return_value = {
|
||||||
netifaces.AF_LINK: []}
|
netifaces.AF_LINK: []}
|
||||||
self.assertEqual([], self.ip_link.address)
|
self.assertEqual([], self.ip_link.address)
|
||||||
|
|
||||||
def test_address_error(self):
|
def test_address_error(self):
|
||||||
self.ip_link._parent.read_ifaddresses.return_value = None
|
self.ip_link._parent.read_ifaddresses.return_value = None
|
||||||
self.assertFalse(self.ip_link.address)
|
self.assertFalse(self.ip_link.address)
|
||||||
|
6
tox.ini
6
tox.ini
@ -140,7 +140,11 @@ commands = sphinx-build -W -b linkcheck doc/source doc/build/linkcheck
|
|||||||
# TODO(ihrachys) figure out what to do with N534 and N536
|
# TODO(ihrachys) figure out what to do with N534 and N536
|
||||||
# N534 Untranslated exception message
|
# N534 Untranslated exception message
|
||||||
# N536 Use assertIsNone rather than assertEqual to check for None values
|
# 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
|
# H106: Don't put vim configuration in source files
|
||||||
# H203: Use assertIs(Not)None to check for None
|
# H203: Use assertIs(Not)None to check for None
|
||||||
# H904: Delay string interpolations at logging calls
|
# H904: Delay string interpolations at logging calls
|
||||||
|
Loading…
x
Reference in New Issue
Block a user