Clean up Neutron Ports by ID

While parallelizing the Ports deletion, the clean up should handle
the list of Ports ID, instead of expect Ports objects. This commit fixes
that by directly calling Neutron port deletion, also it retries the
Ports removal from Trunk in case an error occured.

Closes-bug: #1983027
Change-Id: I50fa4e3cdeffba2413dd9c8c327673ba12706570
This commit is contained in:
Maysa Macedo 2022-07-28 15:11:43 +02:00
parent cf2cf599d6
commit 9300fb495f
2 changed files with 16 additions and 7 deletions

View File

@ -1138,6 +1138,7 @@ class NestedVIFPool(BaseVIFPool):
"pools.")
raise exceptions.ResourceNotReady(net_id)
epool = eventlet.GreenPool(constants.LEFTOVER_RM_POOL_SIZE)
ports_to_remove = []
# NOTE(ltomasbo): Note the pods should already be deleted, but their
@ -1160,7 +1161,7 @@ class NestedVIFPool(BaseVIFPool):
except (os_exc.SDKException, os_exc.HttpException):
LOG.exception('Error removing subports from trunk: %s',
trunk_id)
continue
raise exceptions.ResourceNotReady(net_id)
for port_id in ports_id:
try:
@ -1178,9 +1179,14 @@ class NestedVIFPool(BaseVIFPool):
except KeyError:
pass
if not c_utils.delete_ports(ports_to_remove):
LOG.error('Some ports failed to be deleted.')
raise exceptions.ResourceNotReady(net_id)
# Parallelize Ports deletion. At this point the Ports
# should have been detatched from Trunk and if not operation
# will be retried
for result in epool.imap(c_utils.delete_neutron_port, ports_to_remove):
if result:
LOG.error('During Neutron port deletion an error occured: %s',
result)
raise exceptions.ResourceNotReady(net_id)
class MultiVIFPool(base.VIFPoolDriver):

View File

@ -1757,7 +1757,8 @@ class NestedVIFPool(test_base.TestCase):
m_driver._drv_vif._remove_subports.assert_called_once_with(trunk_id,
[port_id])
m_driver._drv_vif._release_vlan_id.assert_called_once_with(vlan_id)
m_pool.imap.assert_called_once_with(utils.delete_port, [port_id])
m_pool.imap.assert_called_once_with(utils.delete_neutron_port,
[port_id])
def test_delete_network_pools_not_ready(self):
cls = vif_pool.NestedVIFPool
@ -1804,7 +1805,8 @@ class NestedVIFPool(test_base.TestCase):
m_driver._get_pool_key_net.return_value = net_id
m_driver._drv_vif._remove_subports.side_effect = os_exc.SDKException
cls.delete_network_pools(m_driver, net_id)
self.assertRaises(exceptions.ResourceNotReady,
cls.delete_network_pools, m_driver, net_id)
m_driver._trigger_return_to_pool.assert_called_once()
m_driver._get_pool_key_net.assert_called_once()
@ -1850,4 +1852,5 @@ class NestedVIFPool(test_base.TestCase):
m_driver._drv_vif._remove_subports.assert_called_once_with(trunk_id,
[port_id])
m_driver._drv_vif._release_vlan_id.assert_not_called()
m_pool.imap.assert_called_once_with(utils.delete_port, [port_id])
m_pool.imap.assert_called_once_with(utils.delete_neutron_port,
[port_id])