summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlawek Kaplonski <skaplons@redhat.com>2020-05-19 10:04:18 +0200
committerRodolfo Alonso Hernandez <ralonsoh@redhat.com>2020-05-21 08:41:57 +0000
commitbc8c38bda821b0fd989b221dbd9fedb9e3a3d9a2 (patch)
treeeb508ea7ccf47d1bcc055a8b3cbaada283b45f36
parente086606f257df76ec0e53db1833aeb016a4b255d (diff)
downloadneutron-bc8c38bda821b0fd989b221dbd9fedb9e3a3d9a2.tar.gz
Allow usage of legacy 3rd-party interface drivers14.2.0
In the patch [1] we changed definition of the abstract method "plug" in the LinuxInterfaceDriver class. That broke e.g. 3rd-party drivers which still don't accept this new parameter called "link_up" in the plug_new method. So this patch fixes this to make such legacy drivers to be still working with the new base interface driver class. This commit also marks such definition of the plug_new method as deprecated. Possibility of using it without accepting link_up parameter will be removed in the "W" release of the OpenStack. [1] https://review.opendev.org/#/c/707406/ Change-Id: Icd555987a1a57ca0b31fa7e4e830583d6c69c861 Closes-Bug: #1879307 (cherry picked from commit 30d573d5abeb4a5251d08dc5384f5c0ff372eff8) (cherry picked from commit 9c242a032915141d18705198f637cd717a414a26)
-rw-r--r--neutron/agent/linux/interface.py21
-rw-r--r--neutron/tests/unit/agent/linux/test_interface.py33
-rw-r--r--releasenotes/notes/Deprecate-plug_new-method-without-link_up-parameter-27f8310eb1e1910a.yaml10
3 files changed, 62 insertions, 2 deletions
diff --git a/neutron/agent/linux/interface.py b/neutron/agent/linux/interface.py
index 9b242933c0..30b8fd8501 100644
--- a/neutron/agent/linux/interface.py
+++ b/neutron/agent/linux/interface.py
@@ -264,8 +264,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:
@@ -274,6 +275,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."""
diff --git a/neutron/tests/unit/agent/linux/test_interface.py b/neutron/tests/unit/agent/linux/test_interface.py
index 0f29074e26..3ed1bbc011 100644
--- a/neutron/tests/unit/agent/linux/test_interface.py
+++ b/neutron/tests/unit/agent/linux/test_interface.py
@@ -56,6 +56,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()
@@ -659,3 +670,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)
diff --git a/releasenotes/notes/Deprecate-plug_new-method-without-link_up-parameter-27f8310eb1e1910a.yaml b/releasenotes/notes/Deprecate-plug_new-method-without-link_up-parameter-27f8310eb1e1910a.yaml
new file mode 100644
index 0000000000..784a8ca507
--- /dev/null
+++ b/releasenotes/notes/Deprecate-plug_new-method-without-link_up-parameter-27f8310eb1e1910a.yaml
@@ -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.