Handle PortNotFoundClient exception when getting ports
There could be a race between deleting an instance and retrieving its port groups from Neutron. In this case PortNotFoundClient is raised and it can be safely ignored. Change-Id: I31c9ea8628c6f3985f8e9118d9687bbfb8789b68 Closes-Bug: #1767058
This commit is contained in:
@@ -332,7 +332,13 @@ class SecurityGroupAPI(security_group_base.SecurityGroupBase):
|
|||||||
ports = []
|
ports = []
|
||||||
for ids in _chunk_by_ids(servers, MAX_SEARCH_IDS):
|
for ids in _chunk_by_ids(servers, MAX_SEARCH_IDS):
|
||||||
search_opts = {'device_id': ids}
|
search_opts = {'device_id': ids}
|
||||||
|
try:
|
||||||
ports.extend(neutron.list_ports(**search_opts).get('ports'))
|
ports.extend(neutron.list_ports(**search_opts).get('ports'))
|
||||||
|
except n_exc.PortNotFoundClient:
|
||||||
|
# There could be a race between deleting an instance and
|
||||||
|
# retrieving its port groups from Neutron. In this case
|
||||||
|
# PortNotFoundClient is raised and it can be safely ignored
|
||||||
|
LOG.debug("Port not found for device with id %s", ids)
|
||||||
|
|
||||||
return ports
|
return ports
|
||||||
|
|
||||||
|
@@ -305,6 +305,19 @@ class TestNeutronDriver(test.NoDBTestCase):
|
|||||||
self.assertEqual(sorted([sg1_id, sg2_id]),
|
self.assertEqual(sorted([sg1_id, sg2_id]),
|
||||||
sorted(self.mocked_client.list_security_groups.call_args[1]['id']))
|
sorted(self.mocked_client.list_security_groups.call_args[1]['id']))
|
||||||
|
|
||||||
|
def test_instances_security_group_bindings_port_not_found(self):
|
||||||
|
server_id = 'c5a20e8d-c4b0-47cf-9dca-ebe4f758acb1'
|
||||||
|
servers = [{'id': server_id}]
|
||||||
|
|
||||||
|
self.mocked_client.list_ports.side_effect = n_exc.PortNotFoundClient()
|
||||||
|
|
||||||
|
sg_api = neutron_driver.SecurityGroupAPI()
|
||||||
|
result = sg_api.get_instances_security_groups_bindings(
|
||||||
|
self.context, servers)
|
||||||
|
self.mocked_client.list_ports.assert_called_once_with(
|
||||||
|
device_id=[server_id])
|
||||||
|
self.assertEqual({}, result)
|
||||||
|
|
||||||
def _test_instances_security_group_bindings_scale(self, num_servers):
|
def _test_instances_security_group_bindings_scale(self, num_servers):
|
||||||
max_query = 150
|
max_query = 150
|
||||||
sg1_id = '2f7ce969-1a73-4ef9-bbd6-c9a91780ecd4'
|
sg1_id = '2f7ce969-1a73-4ef9-bbd6-c9a91780ecd4'
|
||||||
|
Reference in New Issue
Block a user