From bd61bec9491af22cf6f2c2915057a16cbd65ad09 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 14 Apr 2016 15:43:29 +0200 Subject: [PATCH] Support interface drivers that don't support mtu parameter for plug_new The method signature before Mitaka did not have the mtu= parameter. We should continue supporting the old signature, since it can be used in out of tree interface drivers. The class is part of public neutron API, so we should make an effort to not break out of tree code. Local modifications: - don't issue a deprecation warning in minor release update. Change-Id: I8e0c07c76fd0b4c55b66c20ebe29cdb7c07d6f27 Closes-Bug: #1570392 (cherry picked from commit 8a86ba1d014a5e758c0569aaf16cfe92492cc7f1) --- neutron/agent/linux/interface.py | 8 ++++-- .../tests/unit/agent/linux/test_interface.py | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/neutron/agent/linux/interface.py b/neutron/agent/linux/interface.py index 50e8ee96467..74e1ea558aa 100644 --- a/neutron/agent/linux/interface.py +++ b/neutron/agent/linux/interface.py @@ -244,8 +244,12 @@ class LinuxInterfaceDriver(object): bridge=None, namespace=None, prefix=None, mtu=None): if not ip_lib.device_exists(device_name, namespace=namespace): - self.plug_new(network_id, port_id, device_name, mac_address, - bridge, namespace, prefix, mtu) + try: + self.plug_new(network_id, port_id, device_name, mac_address, + bridge, namespace, prefix, mtu) + except TypeError: + self.plug_new(network_id, port_id, device_name, mac_address, + bridge, namespace, prefix) else: LOG.info(_LI("Device %s already exists"), device_name) diff --git a/neutron/tests/unit/agent/linux/test_interface.py b/neutron/tests/unit/agent/linux/test_interface.py index ce008cfe2d0..d4418799eb3 100644 --- a/neutron/tests/unit/agent/linux/test_interface.py +++ b/neutron/tests/unit/agent/linux/test_interface.py @@ -55,6 +55,23 @@ class FakePort(object): network_id = network.id +class FakeInterfaceDriverNoMtu(interface.LinuxInterfaceDriver): + # NOTE(ihrachys) this method intentially omit mtu= parameter, since that + # was the method signature before Mitaka. We should make sure the old + # signature still works. + + def __init__(self, *args, **kwargs): + super(FakeInterfaceDriverNoMtu, self).__init__(*args, **kwargs) + self.plug_called = False + + def plug_new(self, network_id, port_id, device_name, mac_address, + bridge=None, namespace=None, prefix=None): + self.plug_called = True + + def unplug(self, device_name, bridge=None, namespace=None, prefix=None): + pass + + class TestBase(base.BaseTestCase): def setUp(self): super(TestBase, self).setUp() @@ -68,6 +85,16 @@ class TestBase(base.BaseTestCase): self.device_exists = self.device_exists_p.start() +class TestABCDriverNoMtu(TestBase): + + def test_plug_with_no_mtu_works(self): + driver = FakeInterfaceDriverNoMtu(self.conf) + self.device_exists.return_value = False + driver.plug( + mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock(), mtu=9000) + self.assertTrue(driver.plug_called) + + class TestABCDriver(TestBase): def setUp(self): super(TestABCDriver, self).setUp()