Add retries to get_device_port_at_ovs

Extending retries added to `get_ovs_patch_port_ofport` at [1].

[1] https://review.opendev.org/c/885976

Closes-Bug: #2080258
Change-Id: Id41336ad235159d5fbe125c6c1bbecd2a73a819e
(cherry picked from commit e615106ab8)
This commit is contained in:
Eduardo Olivares 2024-09-10 17:25:00 +02:00
parent 656a427e39
commit 4c7b76f3db
2 changed files with 20 additions and 21 deletions

View File

@ -50,9 +50,24 @@ def get_bridge_flows(bridge, filter_=None):
'ovs-ofctl', args)[0].split('\n')[1:-1]
@tenacity.retry(
retry=tenacity.retry_if_exception_type(agent_exc.PortNotFound),
wait=tenacity.wait_fixed(1),
stop=tenacity.stop_after_delay(5),
reraise=True)
def get_device_port_at_ovs(device):
return ovn_bgp_agent.privileged.ovs_vsctl.ovs_cmd(
'ovs-vsctl', ['get', 'Interface', device, 'ofport'])[0].rstrip()
try:
ofport = ovn_bgp_agent.privileged.ovs_vsctl.ovs_cmd(
'ovs-vsctl', ['get', 'Interface', device, 'ofport']
)[0].rstrip()
except Exception:
raise agent_exc.PortNotFound(port=device)
if ofport == '[]':
# NOTE(ltomasbo): there is a chance the patch port interface was
# created but not yet added to ovs bridge, therefore it exists but
# has an empty ofport. We should retry in this case
raise agent_exc.PortNotFound(port=device)
return ofport
def get_ovs_ports_info(bridge):
@ -71,25 +86,9 @@ def get_ovs_patch_ports_info(bridge, prefix='patch-provnet-'):
return in_ports
@tenacity.retry(
retry=tenacity.retry_if_exception_type(agent_exc.PatchPortNotFound),
wait=tenacity.wait_fixed(1),
stop=tenacity.stop_after_delay(5),
reraise=True)
def get_ovs_patch_port_ofport(patch):
patch_name = "patch-{}-to-br-int".format(patch)
try:
ofport = ovn_bgp_agent.privileged.ovs_vsctl.ovs_cmd(
'ovs-vsctl', ['get', 'Interface', patch_name, 'ofport']
)[0].rstrip()
except Exception:
raise agent_exc.PatchPortNotFound(localnet=patch)
if ofport == '[]':
# NOTE(ltomasbo): there is a chance the patch port interface was
# created but not yet added to ovs bridge, therefore it exists but
# has an empty ofport. We should retry in this case
raise agent_exc.PatchPortNotFound(localnet=patch)
return ofport
return get_device_port_at_ovs(patch_name)
def ensure_mac_tweak_flows(bridge, mac, ports, cookie):

View File

@ -100,7 +100,7 @@ class TestOVS(test_base.TestCase):
patch = 'fake-patch'
self.mock_ovs_vsctl.ovs_cmd.side_effect = Exception
self.assertRaises(agent_exc.PatchPortNotFound,
self.assertRaises(agent_exc.PortNotFound,
ovs_utils.get_ovs_patch_port_ofport, patch)
expected_calls = [
@ -121,7 +121,7 @@ class TestOVS(test_base.TestCase):
ofport = ['[]']
self.mock_ovs_vsctl.ovs_cmd.return_value = ofport
self.assertRaises(agent_exc.PatchPortNotFound,
self.assertRaises(agent_exc.PortNotFound,
ovs_utils.get_ovs_patch_port_ofport, patch)
expected_calls = [