Do not send status update in case of IpAddressAlreadyAllocated

If IpAddressAlreadyAllocated is raised and the created VIP with
the same IP address allocated is not owned by LB that we're trying
to create, we should raise DriverError instead passing the status
update to Octavia API.

Conflicts:
      ovn_octavia_provider/helper.py
      ovn_octavia_provider/tests/unit/test_helper.py

Change-Id: Id0dc8a478b903b80cf8afdfa3d2b23e90d22e112
Closes-Bug: 1882724
(cherry picked from commit ac4d0272a8)
This commit is contained in:
Maciej Jozefczyk 2020-06-09 13:13:47 +00:00
parent d87b7849bd
commit 2448c4925b
2 changed files with 12 additions and 15 deletions

View File

@ -1795,7 +1795,7 @@ class OvnProviderHelper(object):
neutron_client = get_neutron_client()
try:
return neutron_client.create_port(port)
except n_exc.IpAddressAlreadyAllocatedClient:
except n_exc.IpAddressAlreadyAllocatedClient as e:
# Sometimes the VIP is already created (race-conditions)
# Lets get the it from Neutron API.
ports = neutron_client.list_ports(
@ -1804,12 +1804,7 @@ class OvnProviderHelper(object):
if not ports['ports']:
LOG.error('Cannot create/get LoadBalancer VIP port with '
'fixed IP: %s', vip_d['vip_address'])
status = {'loadbalancers': [{
"id": lb_id,
"provisioning_status": constants.ERROR,
"operating_status": constants.ERROR}]}
self._update_status_to_octavia(status)
return
raise e
# there should only be one port returned
port = ports['ports'][0]
LOG.debug('VIP Port already exists, uuid: %s', port['id'])
@ -2267,5 +2262,10 @@ class OvnProviderDriver(driver_base.ProviderDriver):
vip_dict['vip_port_id'] = port['id']
vip_dict['vip_address'] = port['fixed_ips'][0]['ip_address']
except Exception as e:
raise driver_exceptions.DriverError(e)
kwargs = {}
if hasattr(e, 'message'):
kwargs = {'user_fault_string': e.message,
'operator_fault_string': e.message}
raise driver_exceptions.DriverError(
**kwargs)
return vip_dict

View File

@ -2908,22 +2908,19 @@ class TestOvnProviderHelper(TestOvnOctaviaBase):
net_cli.return_value.list_ports.return_value = {
'ports': []}
self.vip_dict['vip_address'] = '10.1.10.1'
ret = self.helper.create_vip_port(
self.assertRaises(
n_exc.IpAddressAlreadyAllocatedClient,
self.helper.create_vip_port,
self.project_id,
self.loadbalancer_id,
self.vip_dict)
self.assertIsNone(ret)
expected_call = [
mock.call().list_ports(
network_id='%s' % self.vip_dict['vip_network_id'],
name='%s%s' % (ovn_const.LB_VIP_PORT_PREFIX,
self.loadbalancer_id))]
net_cli.assert_has_calls(expected_call)
self.helper._update_status_to_octavia.assert_called_once_with(
{'loadbalancers':
[{'id': self.loadbalancer_id,
'provisioning_status': 'ERROR',
'operating_status': 'ERROR'}]})
self.helper._update_status_to_octavia.assert_not_called()
def test_get_pool_member_id(self):
ret = self.helper.get_pool_member_id(