Browse Source

Merge "Allow usage of legacy 3rd-party interface drivers" into stable/rocky

changes/24/730824/1
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
611a762884
3 changed files with 62 additions and 2 deletions
  1. +19
    -2
      neutron/agent/linux/interface.py
  2. +33
    -0
      neutron/tests/unit/agent/linux/test_interface.py
  3. +10
    -0
      releasenotes/notes/Deprecate-plug_new-method-without-link_up-parameter-27f8310eb1e1910a.yaml

+ 19
- 2
neutron/agent/linux/interface.py View File

@@ -272,8 +272,9 @@ class LinuxInterfaceDriver(object):
bridge=None, namespace=None, prefix=None, mtu=None, link_up=True):
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, link_up)
self._safe_plug_new(
network_id, port_id, device_name, mac_address, bridge,
namespace, prefix, mtu, link_up)
else:
LOG.info("Device %s already exists", device_name)
if mtu:
@@ -282,6 +283,22 @@ class LinuxInterfaceDriver(object):
else:
LOG.warning("No MTU configured for port %s", port_id)

def _safe_plug_new(self, network_id, port_id, device_name, mac_address,
bridge=None, namespace=None, prefix=None, mtu=None, link_up=True):
try:
self.plug_new(
network_id, port_id, device_name, mac_address, bridge,
namespace, prefix, mtu, link_up)
except TypeError:
LOG.warning("Interface driver's plug_new() method should now "
"accept additional optional parameter 'link_up'. "
"Usage of plug_new() method which takes from 5 to 9 "
"positional arguments is now deprecated and will not "
"be possible in W release.")
self.plug_new(
network_id, port_id, device_name, mac_address, bridge,
namespace, prefix, mtu)

@abc.abstractmethod
def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
"""Unplug the interface."""


+ 33
- 0
neutron/tests/unit/agent/linux/test_interface.py View File

@@ -53,6 +53,17 @@ class FakePort(object):
network_id = network.id


class FakeLegacyInterfaceDriver(interface.LinuxInterfaceDriver):

def plug_new(self, network_id, port_id, device_name, mac_address,
bridge=None, namespace=None, prefix=None, mtu=None):
"""This is legacy method which don't accepts link_up argument."""
pass

def unplug(self, device_name, bridge=None, namespace=None, prefix=None):
pass


class TestBase(base.BaseTestCase):
def setUp(self):
super(TestBase, self).setUp()
@@ -619,3 +630,25 @@ class TestBridgeInterfaceDriver(TestBase):

self.ip_dev.assert_has_calls([mock.call('tap0', namespace=None),
mock.call().link.delete()])


class TestLegacyDriver(TestBase):

def test_plug(self):
self.device_exists.return_value = False
with mock.patch('neutron.agent.linux.interface.LOG.warning') as log:
driver = FakeLegacyInterfaceDriver(self.conf)
try:
driver.plug(
'01234567-1234-1234-99', 'port-1234', 'tap0',
'aa:bb:cc:dd:ee:ff')
except TypeError:
self.fail("LinuxInterfaceDriver class can not call properly "
"plug_new method from the legacy drivers that "
"do not accept 'link_up' parameter.")
msg = ("Interface driver's plug_new() method should now accept "
"additional optional parameter 'link_up'. Usage of "
"plug_new() method which takes from 5 to 9 positional "
"arguments is now deprecated and will not be possible in "
"W release.")
log.assert_called_once_with(msg)

+ 10
- 0
releasenotes/notes/Deprecate-plug_new-method-without-link_up-parameter-27f8310eb1e1910a.yaml View File

@@ -0,0 +1,10 @@
---
deprecations:
- |
Abstract method ``plug_new`` from the
neutron.agent.linux.interface.LinuxInterfaceDriver class now accepts
an optional parameter ``link_up``.
Usage of this method, which takes from 5 to 9 positional arguments, without
``link_up`` is now deprecated and will not be possible starting in the W
release. Third-party drivers which inherit from this base class should update
the implementation of their ``plug_new`` method.

Loading…
Cancel
Save