Merge "Fix Load balancer remains on PENDING_CREATE" into stable/train

This commit is contained in:
Zuul 2022-06-03 11:03:46 +00:00 committed by Gerrit Code Review
commit eacab77be7
2 changed files with 49 additions and 18 deletions
networking_ovn
octavia
tests/unit/octavia

@ -1045,27 +1045,47 @@ class OvnProviderHelper(object):
def lb_create(self, loadbalancer, protocol=None):
port = None
subnet = {}
network_driver = get_network_driver()
if loadbalancer.get('vip_port_id'):
# In case we don't have vip_network_id
port = network_driver.neutron_client.show_port(
loadbalancer['vip_port_id'])['port']
for ip in port['fixed_ips']:
if ip['ip_address'] == loadbalancer[constants.VIP_ADDRESS]:
subnet = network_driver.neutron_client.show_subnet(
ip['subnet_id'])['subnet']
break
elif (loadbalancer.get('vip_network_id') and
loadbalancer.get('vip_address')):
ports = network_driver.neutron_client.list_ports(
network_id=loadbalancer['vip_network_id'])
for p in ports['ports']:
for ip in p['fixed_ips']:
if ip['ip_address'] == loadbalancer['vip_address']:
port = p
try:
network_driver = get_network_driver()
if loadbalancer.get('vip_port_id'):
# In case we don't have vip_network_id
port = network_driver.neutron_client.show_port(
loadbalancer['vip_port_id'])['port']
for ip in port['fixed_ips']:
if ip['ip_address'] == loadbalancer[constants.VIP_ADDRESS]:
subnet = network_driver.neutron_client.show_subnet(
ip['subnet_id'])['subnet']
break
elif (loadbalancer.get('vip_network_id') and
loadbalancer.get('vip_address')):
ports = network_driver.neutron_client.list_ports(
network_id=loadbalancer['vip_network_id'])
for p in ports['ports']:
for ip in p['fixed_ips']:
if ip['ip_address'] == loadbalancer['vip_address']:
port = p
subnet = network_driver.neutron_client.show_subnet(
ip['subnet_id'])['subnet']
break
except Exception:
LOG.error('Cannot get info from neutron client')
LOG.exception(EXCEPTION_MSG, "creation of loadbalancer")
# Any Exception set the status to ERROR
if isinstance(port, dict):
try:
self.delete_vip_port(port.get('id'))
LOG.warning("Deleting the VIP port %s since LB went into "
"ERROR state", str(port.get('id')))
except Exception:
LOG.exception("Error deleting the VIP port %s upon "
"loadbalancer %s creation failure",
str(port.get('id')),
str(loadbalancer[constants.ID]))
status = {
'loadbalancers': [{"id": loadbalancer['id'],
"provisioning_status": constants.ERROR,
"operating_status": constants.ERROR}]}
return status
# If protocol set make sure its lowercase
protocol = protocol.lower() if protocol else []

@ -1508,6 +1508,17 @@ class TestOvnProviderHelper(TestOvnOctaviaBase):
mock.call(self.ovn_lb, associate=True, network_id='foo',
update_ls_ref=True)])
@mock.patch('networking_ovn.octavia.ovn_driver.get_network_driver')
def test_lb_create_neutron_client_exception(self, net_dr):
net_dr.return_value.neutron_client.list_ports.return_value = self.ports
net_dr.return_value.neutron_client.show_subnet.side_effect = [
n_exc.NotFound]
status = self.helper.lb_create(self.lb)
self.assertEqual(status['loadbalancers'][0]['provisioning_status'],
constants.ERROR)
self.assertEqual(status['loadbalancers'][0]['operating_status'],
constants.ERROR)
@mock.patch('networking_ovn.octavia.ovn_driver.get_network_driver')
@mock.patch.object(ovn_driver.OvnProviderHelper, 'delete_vip_port')
def test_lb_create_exception(self, del_port, net_dr):