diff options
| author | Alex Meade <alex.meade@rackspace.com> | 2011-07-01 15:07:08 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-07-01 15:07:08 +0000 |
| commit | b69eaefcccc682a270a66ce33b9083ba40a1a71f (patch) | |
| tree | 7f9c567ab0b28dcadc605cef2d12da20729f3b2a | |
| parent | 7d544631f0c767727c5a48627617d995f8890ae6 (diff) | |
| parent | 73a4b0496e1973d3d8af699d0d0d50829ef026c3 (diff) | |
| download | nova-b69eaefcccc682a270a66ce33b9083ba40a1a71f.tar.gz nova-b69eaefcccc682a270a66ce33b9083ba40a1a71f.tar.xz nova-b69eaefcccc682a270a66ce33b9083ba40a1a71f.zip | |
Fixed the case where an exception was thrown when trying to get a list of flavors via the api yet there were no flavors to list.
hand tested :)
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 6 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_flavors.py | 26 |
2 files changed, 28 insertions, 4 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index c08d3dbb5..ffd009513 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -2944,13 +2944,11 @@ def instance_type_get_all(context, inactive=False): filter_by(deleted=False).\ order_by("name").\ all() + inst_dict = {} if inst_types: - inst_dict = {} for i in inst_types: inst_dict[i['name']] = _dict_with_extra_specs(i) - return inst_dict - else: - raise exception.NoInstanceTypesFound() + return inst_dict @require_context diff --git a/nova/tests/api/openstack/test_flavors.py b/nova/tests/api/openstack/test_flavors.py index d1c62e454..fba4d593a 100644 --- a/nova/tests/api/openstack/test_flavors.py +++ b/nova/tests/api/openstack/test_flavors.py @@ -87,6 +87,19 @@ class FlavorsTest(test.TestCase): ] self.assertEqual(flavors, expected) + def test_get_empty_flavor_list_v1_0(self): + def _return_empty(self): + return {} + self.stubs.Set(nova.db.api, "instance_type_get_all", + _return_empty) + + req = webob.Request.blank('/v1.0/flavors') + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 200) + flavors = json.loads(res.body)["flavors"] + expected = [] + self.assertEqual(flavors, expected) + def test_get_flavor_list_detail_v1_0(self): req = webob.Request.blank('/v1.0/flavors/detail') res = req.get_response(fakes.wsgi_app()) @@ -261,3 +274,16 @@ class FlavorsTest(test.TestCase): }, ] self.assertEqual(flavor, expected) + + def test_get_empty_flavor_list_v1_1(self): + def _return_empty(self): + return {} + self.stubs.Set(nova.db.api, "instance_type_get_all", + _return_empty) + + req = webob.Request.blank('/v1.1/flavors') + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 200) + flavors = json.loads(res.body)["flavors"] + expected = [] + self.assertEqual(flavors, expected) |
