Skip to content

Commit 222c997

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 4575136 commit 222c997

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
@@ -355,7 +355,7 @@ def _add_device_to_namespace(self, ip_wrapper, device, namespace):
355355
namespace_obj = ip_wrapper.ensure_namespace(namespace)
356356
for i in range(9):
357357
try:
358-
namespace_obj.add_device_to_namespace(device)
358+
namespace_obj.add_device_to_namespace(device, is_ovs_port=True)
359359
break
360360
except ip_lib.NetworkInterfaceNotFound:
361361
# 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
@@ -467,11 +467,11 @@ def device_exists(dev, namespace=None):
467467
expected.extend(
468468
[mock.call().ensure_namespace(namespace),
469469
mock.call().ensure_namespace().add_device_to_namespace(
470-
mock.ANY),
470+
mock.ANY, is_ovs_port=True),
471471
mock.call().ensure_namespace().add_device_to_namespace(
472-
mock.ANY),
472+
mock.ANY, is_ovs_port=True),
473473
mock.call().ensure_namespace().add_device_to_namespace(
474-
mock.ANY)])
474+
mock.ANY, is_ovs_port=True)])
475475
expected.extend([
476476
mock.call(namespace=namespace),
477477
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
@@ -507,7 +507,8 @@ def fake_create_interface(ifname, namespace, kind, **kwargs):
507507
def test_add_device_to_namespace(self):
508508
dev = mock.Mock()
509509
ip_lib.IPWrapper(namespace='ns').add_device_to_namespace(dev)
510-
dev.assert_has_calls([mock.call.link.set_netns('ns')])
510+
dev.assert_has_calls(
511+
[mock.call.link.set_netns('ns', is_ovs_port=False)])
511512

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

0 commit comments

Comments
 (0)