Skip to content

Commit

Permalink
Merge pull request #72 from dulek/bug-1761507
Browse files Browse the repository at this point in the history
[release-4.2] Bug 1761507: Avoid controller crash upon unexpected neutron error handling ports
  • Loading branch information
openshift-merge-robot committed Oct 25, 2019
2 parents 39391bd + feb34ed commit 87d0a1b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 4 additions & 2 deletions kuryr_kubernetes/controller/drivers/nested_vlan_vif.py
Expand Up @@ -98,10 +98,12 @@ def request_vifs(self, pod, project_id, subnets, security_groups,
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):
Expand Down
7 changes: 6 additions & 1 deletion kuryr_kubernetes/controller/drivers/neutron_vif.py
Expand Up @@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from keystoneauth1 import exceptions as key_exc
from kuryr.lib import constants as kl_const
from neutronclient.common import exceptions as n_exc
from oslo_log import log as logging
Expand Down Expand Up @@ -87,7 +88,11 @@ def activate_vif(self, pod, vif):
return

neutron = clients.get_neutron_client()
port = neutron.show_port(vif.id).get('port')
try:
port = neutron.show_port(vif.id).get('port')
except (key_exc.ConnectionError, 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)
Expand Down
2 changes: 2 additions & 0 deletions kuryr_kubernetes/controller/drivers/vif_pool.py
Expand Up @@ -244,6 +244,8 @@ def _populate_pool(self, pool_key, pod, subnets, security_groups):
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=None):
Expand Down
Expand Up @@ -222,9 +222,8 @@ def test_request_vifs_trunk_subports_conflict(self):
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)
Expand Down Expand Up @@ -267,9 +266,8 @@ def test_request_vifs_trunk_subports_exception(self):
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)
Expand All @@ -279,7 +277,7 @@ def test_request_vifs_trunk_subports_exception(self):
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
Expand Down

0 comments on commit 87d0a1b

Please sign in to comment.