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
This commit is contained in:
Slawek Kaplonski 2022-09-07 12:07:38 +02:00
parent ead685b938
commit 76578393ab
2 changed files with 19 additions and 0 deletions

View File

@ -364,6 +364,11 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
LOG.warning("Failed to set interface %s into namespace %s. "
"Interface not found, attempt: %s, retrying.",
device, namespace, i + 1)
# NOTE(slaweq) In such case it's required to reset device's
# namespace as it was already set to the "namespace"
# and after retry neutron will look for it in that namespace
# which is wrong
device.namespace = None
time.sleep(1)
except utils.WaitTimeout:
# NOTE(slaweq): if the exception was WaitTimeout then it means

View File

@ -517,6 +517,20 @@ class TestOVSInterfaceDriver(TestBase):
ovs_br.assert_has_calls([mock.call('br-int'),
mock.call().delete_port('tap0')])
def test__add_device_to_namespace_retries(self):
ovs = interface.OVSInterfaceDriver(self.conf)
namespace_obj = self.ip.return_value.ensure_namespace.return_value
self.ip.ensure_namespace.return_value = namespace_obj
namespace_obj.add_device_to_namespace.side_effect = (
ip_lib.NetworkInterfaceNotFound)
device = mock.MagicMock()
self.assertRaises(
ip_lib.NetworkInterfaceNotFound,
ovs._add_device_to_namespace,
self.ip, device, "test-ns")
self.assertEqual(10, namespace_obj.add_device_to_namespace.call_count)
self.assertIsNone(device.namespace)
class TestOVSInterfaceDriverWithVeth(TestOVSInterfaceDriver):