Merge "Support interface drivers that don't support mtu parameter for plug_new"
This commit is contained in:
commit
d54e03d233
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user