Skip to content

Commit 48076cd

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add sleep before checking if ovs port is in the namespace" into stable/2023.1
2 parents 6e51c13 + c5e70ad commit 48076cd

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
@@ -365,7 +365,7 @@ def _add_device_to_namespace(self, ip_wrapper, device, namespace):
365365
namespace_obj = ip_wrapper.ensure_namespace(namespace)
366366
for i in range(9):
367367
try:
368-
namespace_obj.add_device_to_namespace(device)
368+
namespace_obj.add_device_to_namespace(device, is_ovs_port=True)
369369
break
370370
except ip_lib.NetworkInterfaceNotFound:
371371
# 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
@@ -284,9 +284,9 @@ def garbage_collect_namespace(self):
284284
return True
285285
return False
286286

287-
def add_device_to_namespace(self, device):
287+
def add_device_to_namespace(self, device, is_ovs_port=False):
288288
if self.namespace:
289-
device.link.set_netns(self.namespace)
289+
device.link.set_netns(self.namespace, is_ovs_port=is_ovs_port)
290290

291291
def add_vlan(self, name, physical_interface, vlan_id):
292292
privileged.create_interface(name,
@@ -476,10 +476,15 @@ def set_down(self):
476476
privileged.set_link_attribute(
477477
self.name, self._parent.namespace, state='down')
478478

479-
def set_netns(self, namespace):
479+
def set_netns(self, namespace, is_ovs_port=False):
480480
privileged.set_link_attribute(
481481
self.name, self._parent.namespace, net_ns_fd=namespace)
482482
self._parent.namespace = namespace
483+
if is_ovs_port:
484+
# NOTE(slaweq): because of the "shy port" which may dissapear for
485+
# short time after it's moved to the namespace we need to wait
486+
# a bit before checking if port really exists in the namespace
487+
time.sleep(1)
483488
common_utils.wait_until_true(lambda: self.exists, timeout=5,
484489
sleep=0.5)
485490

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,11 @@ def device_exists(dev, namespace=None):
470470
expected.extend(
471471
[mock.call().ensure_namespace(namespace),
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
mock.call().ensure_namespace().add_device_to_namespace(
477-
mock.ANY)])
477+
mock.ANY, is_ovs_port=True)])
478478
expected.extend([
479479
mock.call(namespace=namespace),
480480
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
@@ -522,7 +522,8 @@ def fake_create_interface(ifname, namespace, kind, **kwargs):
522522
def test_add_device_to_namespace(self):
523523
dev = mock.Mock()
524524
ip_lib.IPWrapper(namespace='ns').add_device_to_namespace(dev)
525-
dev.assert_has_calls([mock.call.link.set_netns('ns')])
525+
dev.assert_has_calls(
526+
[mock.call.link.set_netns('ns', is_ovs_port=False)])
526527

527528
def test_add_device_to_namespace_is_none(self):
528529
dev = mock.Mock()

0 commit comments

Comments
 (0)