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.

Change-Id: I8e0c07c76fd0b4c55b66c20ebe29cdb7c07d6f27
Closes-Bug: #1570392
This commit is contained in:
Ihar Hrachyshka 2016-04-14 15:43:29 +02:00
parent 81c61a9939
commit 8a86ba1d01
2 changed files with 42 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import abc
import netaddr
from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import versionutils
import six
from neutron._i18n import _, _LE, _LI, _LW
@ -245,8 +246,16 @@ 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:
versionutils.report_deprecated_feature(
LOG,
_LW('Interface driver does not support MTU parameter. '
'This may not work in future releases.'))
self.plug_new(network_id, port_id, device_name, mac_address,
bridge, namespace, prefix)
else:
LOG.info(_LI("Device %s already exists"), device_name)

View File

@ -14,6 +14,7 @@
# under the License.
import mock
from oslo_log import versionutils
import testtools
from neutron.agent.common import config
@ -55,6 +56,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 +86,19 @@ 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
with mock.patch.object(
versionutils, 'report_deprecated_feature') as report:
driver.plug(
mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock(), mtu=9000)
self.assertTrue(driver.plug_called)
self.assertTrue(report.called)
class TestABCDriver(TestBase):
def setUp(self):
super(TestABCDriver, self).setUp()