Merge "Avoid LB ERROR status on delete when LS/LR are already deleted"

This commit is contained in:
Zuul 2022-09-27 17:32:51 +00:00 committed by Gerrit Code Review
commit bfb8f89ceb
2 changed files with 48 additions and 3 deletions

View File

@ -1169,9 +1169,30 @@ class OvnProviderHelper():
if_exists=True))
commands.append(self.ovn_nbdb_api.lb_del(ovn_lb.uuid))
# TODO(froyo): atomic process to execute all commands in a transaction
# if any of them fails the transaction is aborted
self._execute_commands(commands)
try:
self._execute_commands(commands)
except idlutils.RowNotFound:
# NOTE(froyo): If any of the Ls or Lr had been deleted between
# time to list and time to execute txn, we will received a
# RowNotFound exception, if this case we will run every command
# one by one passing exception in case the command is related to
# deletion of Ls or Lr already deleted. Any other case will raise
# exception and upper function will report the LB in ERROR status
for command in commands:
try:
command.execute(check_error=True)
except idlutils.RowNotFound:
if isinstance(command, (cmd.LsLbDelCommand)):
LOG.warning('delete lb from ls fail because ls '
'%s is not found, keep going on...',
getattr(command, 'switch', ''))
elif isinstance(command, (cmd.LrLbDelCommand)):
LOG.warning('delete lb to lr fail because lr '
'%s is not found, keep going on...',
getattr(command, 'router', ''))
else:
raise
return status
def lb_update(self, loadbalancer):

View File

@ -778,6 +778,30 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase):
self.ovn_lb.uuid)
del_port.assert_not_called()
@mock.patch.object(ovn_helper.OvnProviderHelper, 'delete_vip_port')
def test_lb_delete_step_by_step(self, del_port):
self.helper.ovn_nbdb_api.lr_lb_del.side_effect = [idlutils.RowNotFound]
status = self.helper.lb_delete(self.lb)
self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
constants.DELETED)
self.assertEqual(status['loadbalancers'][0]['operating_status'],
constants.OFFLINE)
self.helper.ovn_nbdb_api.lb_del.assert_called_once_with(
self.ovn_lb.uuid)
del_port.assert_called_once_with('foo_port')
@mock.patch.object(ovn_helper.OvnProviderHelper, 'delete_vip_port')
def test_lb_delete_step_by_step_exception(self, del_port):
self.helper.ovn_nbdb_api.lb_del.side_effect = [idlutils.RowNotFound]
status = self.helper.lb_delete(self.lb)
self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
constants.ERROR)
self.assertEqual(status['loadbalancers'][0]['operating_status'],
constants.ERROR)
self.helper.ovn_nbdb_api.lb_del.assert_called_once_with(
self.ovn_lb.uuid)
del_port.assert_not_called()
@mock.patch('ovn_octavia_provider.common.clients.get_neutron_client')
@mock.patch.object(ovn_helper.OvnProviderHelper, 'delete_vip_port')
def test_lb_delete_port_not_found(self, del_port, net_cli):