Merge "Avoid controller crash upon unexpected neutron error handling ports"

This commit is contained in:
Zuul 2019-10-16 23:01:06 +00:00 committed by Gerrit Code Review
commit 643c8261c1
4 changed files with 17 additions and 10 deletions

View File

@ -98,10 +98,12 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
LOG.error("vlan ids already in use on trunk")
for port in ports:
neutron.delete_port(port['id'])
raise
return []
except n_exc.NeutronClientException:
LOG.exception("Error happened during subport addition to trunk")
raise
for port in ports:
neutron.delete_port(port['id'])
return []
vifs = []
for index, port in enumerate(ports):

View File

@ -15,6 +15,7 @@
from kuryr.lib import constants as kl_const
from neutronclient.common import exceptions as n_exc
from oslo_log import log as logging
from kuryr_kubernetes import clients
@ -87,7 +88,11 @@ class NeutronPodVIFDriver(base.PodVIFDriver):
return
neutron = clients.get_neutron_client()
port = neutron.show_port(vif.id).get('port')
try:
port = neutron.show_port(vif.id).get('port')
except n_exc.ConnectionFailed:
LOG.debug("Unable to obtain port information, retrying.")
raise k_exc.ResourceNotReady(vif)
if port['status'] != kl_const.PORT_STATUS_ACTIVE:
raise k_exc.ResourceNotReady(vif)

View File

@ -244,6 +244,8 @@ class BaseVIFPool(base.VIFPoolDriver):
self._available_ports_pools.setdefault(
pool_key, {}).setdefault(
security_groups, []).append(vif.id)
if not vifs:
self._last_update[pool_key] = {security_groups: last_update}
def release_vif(self, pod, vif, project_id, security_groups):
host_addr = self._get_host_addr(pod)

View File

@ -222,9 +222,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
neutron.create_port.return_value = {'ports': [port, port]}
neutron.trunk_add_subports.side_effect = n_exc.Conflict
self.assertRaises(n_exc.Conflict, cls.request_vifs,
m_driver, pod, project_id, subnets,
security_groups, num_ports)
self.assertEqual([], cls.request_vifs(m_driver, pod, project_id,
subnets, security_groups, num_ports))
m_driver._get_parent_port.assert_called_once_with(neutron, pod)
m_driver._get_trunk_id.assert_called_once_with(parent_port)
@ -267,9 +266,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
neutron.create_port.return_value = {'ports': [port, port]}
neutron.trunk_add_subports.side_effect = n_exc.NeutronClientException
self.assertRaises(n_exc.NeutronClientException, cls.request_vifs,
m_driver, pod, project_id, subnets,
security_groups, num_ports)
self.assertEqual([], cls.request_vifs(m_driver, pod, project_id,
subnets, security_groups, num_ports))
m_driver._get_parent_port.assert_called_once_with(neutron, pod)
m_driver._get_trunk_id.assert_called_once_with(parent_port)
@ -279,7 +277,7 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
neutron.create_port.assert_called_once_with(bulk_rq)
neutron.trunk_add_subports.assert_called_once_with(
trunk_id, {'sub_ports': subports_info})
neutron.delete_port.assert_not_called()
neutron.delete_port.assert_called_with(port['id'])
def test_release_vif(self):
cls = nested_vlan_vif.NestedVlanPodVIFDriver