Skip to content

Commit f4e0b02

Browse files
slawqoralonsoh
authored andcommitted
Add sleep before checking if ovs port is in the namespace
When network device which is ovs internal port is moved to the namespace it may happend sometimes that it will have "shy port syndrome" [1]. Even though there is wait for device to be in namespace in the set_netns method it may happend that device is in namespace during this check but it dissapears for short time later and that causes failures e.g. in functional tests like described in [2]. To avoid that, this patch proposed simple (and ugly) sleep for 1 second before checking if port really exists in the namespace. If it will be "shy" port it should already flap during that 1 second. [1] https://bugs.launchpad.net/neutron/+bug/1618987 [2] https://bugs.launchpad.net/neutron/+bug/1961740 Related-Bug: #1961740 Related-Bug: #1998337 Change-Id: I442587e7ef55917f4ea873e190bf8afbc0e911e1 (cherry picked from commit 2af5fd8)
1 parent 9ce8220 commit f4e0b02

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

neutron/agent/linux/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def _add_device_to_namespace(self, ip_wrapper, device, namespace):
356356
namespace_obj = ip_wrapper.ensure_namespace(namespace)
357357
for i in range(9):
358358
try:
359-
namespace_obj.add_device_to_namespace(device)
359+
namespace_obj.add_device_to_namespace(device, is_ovs_port=True)
360360
break
361361
except ip_lib.NetworkInterfaceNotFound:
362362
# NOTE(slaweq): if the exception was NetworkInterfaceNotFound

neutron/agent/linux/ip_lib.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ def garbage_collect_namespace(self):
270270
return True
271271
return False
272272

273-
def add_device_to_namespace(self, device):
273+
def add_device_to_namespace(self, device, is_ovs_port=False):
274274
if self.namespace:
275-
device.link.set_netns(self.namespace)
275+
device.link.set_netns(self.namespace, is_ovs_port=is_ovs_port)
276276

277277
def add_vlan(self, name, physical_interface, vlan_id):
278278
privileged.create_interface(name,
@@ -462,10 +462,15 @@ def set_down(self):
462462
privileged.set_link_attribute(
463463
self.name, self._parent.namespace, state='down')
464464

465-
def set_netns(self, namespace):
465+
def set_netns(self, namespace, is_ovs_port=False):
466466
privileged.set_link_attribute(
467467
self.name, self._parent.namespace, net_ns_fd=namespace)
468468
self._parent.namespace = namespace
469+
if is_ovs_port:
470+
# NOTE(slaweq): because of the "shy port" which may dissapear for
471+
# short time after it's moved to the namespace we need to wait
472+
# a bit before checking if port really exists in the namespace
473+
time.sleep(1)
469474
common_utils.wait_until_true(lambda: self.exists, timeout=5,
470475
sleep=0.5)
471476

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,11 @@ def device_exists(dev, namespace=None):
468468
expected.extend(
469469
[mock.call().ensure_namespace(namespace),
470470
mock.call().ensure_namespace().add_device_to_namespace(
471-
mock.ANY),
471+
mock.ANY, is_ovs_port=True),
472472
mock.call().ensure_namespace().add_device_to_namespace(
473-
mock.ANY),
473+
mock.ANY, is_ovs_port=True),
474474
mock.call().ensure_namespace().add_device_to_namespace(
475-
mock.ANY)])
475+
mock.ANY, is_ovs_port=True)])
476476
expected.extend([
477477
mock.call(namespace=namespace),
478478
mock.call().device('tap0'),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ def fake_create_interface(ifname, namespace, kind, **kwargs):
506506
def test_add_device_to_namespace(self):
507507
dev = mock.Mock()
508508
ip_lib.IPWrapper(namespace='ns').add_device_to_namespace(dev)
509-
dev.assert_has_calls([mock.call.link.set_netns('ns')])
509+
dev.assert_has_calls(
510+
[mock.call.link.set_netns('ns', is_ovs_port=False)])
510511

511512
def test_add_device_to_namespace_is_none(self):
512513
dev = mock.Mock()

0 commit comments

Comments
 (0)