diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-02-03 18:37:28 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-02-03 18:37:28 +0000 |
commit | 75d6a844a23aba3316e426793ee09ae8870f3b83 (patch) | |
tree | 8b4bd4fd708d293096a6ac40e3fd32ae1b5ce3ed | |
parent | 8ac1b20fef00f58bbbe45ac7bdb37a0c1f4bd47d (diff) | |
parent | 07d74aa916ee2798f717ae5d298f8ca51e883770 (diff) | |
download | nova-75d6a844a23aba3316e426793ee09ae8870f3b83.tar.gz nova-75d6a844a23aba3316e426793ee09ae8870f3b83.tar.xz nova-75d6a844a23aba3316e426793ee09ae8870f3b83.zip |
Merge "Raise ApiError in response to InstanceTypeNotFound"
-rw-r--r-- | Authors | 1 | ||||
-rw-r--r-- | nova/compute/instance_types.py | 23 | ||||
-rw-r--r-- | nova/tests/test_instance_types.py | 8 |
3 files changed, 16 insertions, 16 deletions
@@ -107,6 +107,7 @@ Lvov Maxim <usrleon@gmail.com> Mandell Degerness <mdegerne@gmail.com> Mark McLoughlin <markmc@redhat.com> Mark Washenberger <mark.washenberger@rackspace.com> +Maru Newby <mnewby@internap.com> Masanori Itoh <itoumsn@nttdata.co.jp> Matt Dietz <matt.dietz@rackspace.com> Matthew Hooker <matt@cloudscaling.com> diff --git a/nova/compute/instance_types.py b/nova/compute/instance_types.py index 583b2da4e..e6a6d4a88 100644 --- a/nova/compute/instance_types.py +++ b/nova/compute/instance_types.py @@ -118,8 +118,8 @@ def get_default_instance_type(): name = FLAGS.default_instance_type try: return get_instance_type_by_name(name) - except exception.DBError: - raise exception.ApiError(_("Unknown instance type: %s") % name) + except exception.InstanceTypeNotFound as e: + raise exception.ApiError(e) def get_instance_type(instance_type_id): @@ -130,9 +130,8 @@ def get_instance_type(instance_type_id): ctxt = context.get_admin_context() try: return db.instance_type_get(ctxt, instance_type_id) - except exception.DBError: - msg = _("Unknown instance type: %s") % instance_type_id - raise exception.ApiError(msg) + except exception.InstanceTypeNotFound as e: + raise exception.ApiError(e) def get_instance_type_by_name(name): @@ -144,16 +143,16 @@ def get_instance_type_by_name(name): try: return db.instance_type_get_by_name(ctxt, name) - except exception.DBError: - raise exception.ApiError(_("Unknown instance type: %s") % name) + except exception.InstanceTypeNotFound as e: + raise exception.ApiError(e) # TODO(termie): flavor-specific code should probably be in the API that uses # flavors. def get_instance_type_by_flavor_id(flavorid): - """Retrieve instance type by flavorid.""" + """Retrieve instance type by flavorid. + + :raises: FlavorNotFound + """ ctxt = context.get_admin_context() - try: - return db.instance_type_get_by_flavor_id(ctxt, flavorid) - except exception.DBError: - raise exception.ApiError(_("Unknown instance type: %s") % flavorid) + return db.instance_type_get_by_flavor_id(ctxt, flavorid) diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index b0613c757..29b812a2b 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -174,7 +174,7 @@ class InstanceTypeTestCase(test.TestCase): def test_will_not_get_bad_default_instance_type(self): """ensures error raised on bad default instance type""" FLAGS.default_instance_type = 'unknown_flavor' - self.assertRaises(exception.InstanceTypeNotFoundByName, + self.assertRaises(exception.ApiError, instance_types.get_default_instance_type) def test_will_get_instance_type_by_id(self): @@ -185,12 +185,12 @@ class InstanceTypeTestCase(test.TestCase): def test_will_not_get_instance_type_by_unknown_id(self): """Ensure get by name returns default flavor with no name""" - self.assertRaises(exception.InstanceTypeNotFound, + self.assertRaises(exception.ApiError, instance_types.get_instance_type, 10000) def test_will_not_get_instance_type_with_bad_id(self): """Ensure get by name returns default flavor with bad name""" - self.assertRaises(exception.InstanceTypeNotFound, + self.assertRaises(exception.ApiError, instance_types.get_instance_type, 'asdf') def test_instance_type_get_by_None_name_returns_default(self): @@ -201,7 +201,7 @@ class InstanceTypeTestCase(test.TestCase): def test_will_not_get_instance_type_with_bad_name(self): """Ensure get by name returns default flavor with bad name""" - self.assertRaises(exception.InstanceTypeNotFoundByName, + self.assertRaises(exception.ApiError, instance_types.get_instance_type_by_name, 10000) def test_will_not_get_instance_by_unknown_flavor_id(self): |