Skip to content

Commit f89a585

Browse files
slawqoralonsoh
authored andcommitted
Reset device namespace when adding to the namespace fails
In case when during adding device to the namespace, device will be "shy" and will disappear for a moment and NetworkInterfaceNotFound exception will be raised, we need to reset device.namespace to be None. Otherwise, in the next attempt of adding interface to namespace, when it will be added back to ovs (and will be in global scope), Neutron will already look for it in the "namespace" and that will always be failing. Closes-bug: #1961740 Change-Id: Ie9331c72c44084b0a382598c3359214cce2f2ebd (cherry picked from commit 7657839)
1 parent 9ce8220 commit f89a585

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

neutron/agent/linux/interface.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ def _add_device_to_namespace(self, ip_wrapper, device, namespace):
365365
LOG.warning("Failed to set interface %s into namespace %s. "
366366
"Interface not found, attempt: %s, retrying.",
367367
device, namespace, i + 1)
368+
# NOTE(slaweq) In such case it's required to reset device's
369+
# namespace as it was already set to the "namespace"
370+
# and after retry neutron will look for it in that namespace
371+
# which is wrong
372+
device.namespace = None
368373
time.sleep(1)
369374
except utils.WaitTimeout:
370375
# NOTE(slaweq): if the exception was WaitTimeout then it means

neutron/tests/unit/agent/linux/test_interface.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,20 @@ def test_unplug(self):
518518
ovs_br.assert_has_calls([mock.call('br-int'),
519519
mock.call().delete_port('tap0')])
520520

521+
def test__add_device_to_namespace_retries(self):
522+
ovs = interface.OVSInterfaceDriver(self.conf)
523+
namespace_obj = self.ip.return_value.ensure_namespace.return_value
524+
self.ip.ensure_namespace.return_value = namespace_obj
525+
namespace_obj.add_device_to_namespace.side_effect = (
526+
ip_lib.NetworkInterfaceNotFound)
527+
device = mock.MagicMock()
528+
self.assertRaises(
529+
ip_lib.NetworkInterfaceNotFound,
530+
ovs._add_device_to_namespace,
531+
self.ip, device, "test-ns")
532+
self.assertEqual(10, namespace_obj.add_device_to_namespace.call_count)
533+
self.assertIsNone(device.namespace)
534+
521535

522536
class TestOVSInterfaceDriverWithVeth(TestOVSInterfaceDriver):
523537

0 commit comments

Comments
 (0)