Return empty lists for resources if neutron doesn't exist

It's the general design of the cloud layer to return empty resources
rather than throw exceptions when a user tries to fetch a non-existent
resource.

Change-Id: I1c6ce28af767f466f349b51a47abe27c0dcdd3fb
This commit is contained in:
Monty Taylor 2019-07-09 09:19:02 -04:00
parent 7935cf00a1
commit 983cc997ff
3 changed files with 21 additions and 20 deletions

View File

@ -123,6 +123,9 @@ class NetworkCloudMixin(_normalize.Normalizer):
:returns: A list of ``munch.Munch`` containing network info.
"""
# If the cloud is running nova-network, just return an empty list.
if not self.has_service('network'):
return []
# Translate None from search interface to empty {} for kwargs below
if not filters:
filters = {}
@ -136,6 +139,9 @@ class NetworkCloudMixin(_normalize.Normalizer):
:returns: A list of router ``munch.Munch``.
"""
# If the cloud is running nova-network, just return an empty list.
if not self.has_service('network'):
return []
# Translate None from search interface to empty {} for kwargs below
if not filters:
filters = {}
@ -152,6 +158,9 @@ class NetworkCloudMixin(_normalize.Normalizer):
:returns: A list of subnet ``munch.Munch``.
"""
# If the cloud is running nova-network, just return an empty list.
if not self.has_service('network'):
return []
# Translate None from search interface to empty {} for kwargs below
if not filters:
filters = {}
@ -192,6 +201,9 @@ class NetworkCloudMixin(_normalize.Normalizer):
return _utils._filter_list(self._ports, None, filters or {})
def _list_ports(self, filters):
# If the cloud is running nova-network, just return an empty list.
if not self.has_service('network'):
return []
resp = self.network.get("/ports.json", params=filters)
data = proxy._json_response(
resp,

View File

@ -122,26 +122,10 @@ class TestShade(base.TestCase):
self.assert_calls()
def test__neutron_exceptions_resource_not_found(self):
self.register_uris([
dict(method='GET',
uri=self.get_mock_url(
'network', 'public', append=['v2.0', 'networks.json']),
status_code=404)
])
self.assertRaises(exc.OpenStackCloudResourceNotFound,
self.cloud.list_networks)
self.assert_calls()
def test__neutron_exceptions_url_not_found(self):
self.register_uris([
dict(method='GET',
uri=self.get_mock_url(
'network', 'public', append=['v2.0', 'networks.json']),
status_code=404)
])
self.assertRaises(exc.OpenStackCloudURINotFound,
self.cloud.list_networks)
def test_neutron_not_found(self):
self.use_nothing()
self.cloud.has_service = mock.Mock(return_value=False)
self.assertEqual([], self.cloud.list_networks())
self.assert_calls()
def test_list_servers(self):

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Basic networking list calls in the cloud layer been fixed to return
an empty list if neutron is not running.