Handle a NeutronClientException 404 Error for floating ips

I9229d882712df1ad57afbda7477fa4d72f4fd83c introduced _safe_get_floating_ips
which returns an empty list of floating ips in cases where neutron returns
a 404. It also switched a check for NeutronClientException with NotFound.
The NotFound Exception isn't used by neutron client so allow for both cases.

Closes-bug: #1513879
Change-Id: I1d37a0dadd4c9055ba545906535bb3e40e70a0f0
This commit is contained in:
Derek Higgins 2015-11-05 16:36:55 +00:00
parent e52d236a3f
commit cbbbaa93ae
2 changed files with 9 additions and 2 deletions

View File

@ -1468,7 +1468,11 @@ class API(base_api.NetworkAPI):
# list_floatingips will be raised.
except neutron_client_exc.NotFound:
return []
except neutron_client_exc.NeutronClientException:
except neutron_client_exc.NeutronClientException as e:
# bug/1513879 neutron client is currently using
# NeutronClientException when there is no L3 API
if e.status_code == 404:
return []
with excutils.save_and_reraise_exception():
LOG.exception(_LE('Unable to access floating IP for %s'),
', '.join(['%s %s' % (k, v)

View File

@ -3585,7 +3585,10 @@ class TestNeutronv2WithMock(test.TestCase):
def test_get_floating_ips_by_project_not_found(self, mock_ntrn):
mock_nc = mock.Mock()
mock_ntrn.return_value = mock_nc
mock_nc.list_floatingips.side_effect = exceptions.NotFound()
# neutronclient doesn't raise NotFound in this scenario, it raises a
# NeutronClientException with status_code=404
notfound = exceptions.NeutronClientException(status_code=404)
mock_nc.list_floatingips.side_effect = notfound
fips = self.api.get_floating_ips_by_project(self.context)
self.assertEqual([], fips)