From fd55a4e1d049748634e6d802ca124cb67596cd52 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Wed, 5 Jun 2013 22:44:35 +0000 Subject: Improve Keypair error messages in osapi The KeypairAPI code provides useful error messages that weren't being percolated back through the OpenStack API. This patch addresses this by using the original `message` when crafting the HTTPException objects. References bug 1187952 Change-Id: I786a225010d912d7bfea5c01838ddcf43fd90d53 --- nova/api/openstack/compute/contrib/keypairs.py | 10 ++++------ nova/api/openstack/compute/plugins/v3/keypairs.py | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/keypairs.py b/nova/api/openstack/compute/contrib/keypairs.py index a79b39aae..4245355e5 100644 --- a/nova/api/openstack/compute/contrib/keypairs.py +++ b/nova/api/openstack/compute/contrib/keypairs.py @@ -94,12 +94,10 @@ class KeypairController(object): raise webob.exc.HTTPRequestEntityTooLarge( explanation=msg, headers={'Retry-After': 0}) - except exception.InvalidKeypair: - msg = _("Keypair data is invalid") - raise webob.exc.HTTPBadRequest(explanation=msg) - except exception.KeyPairExists: - msg = _("Key pair '%s' already exists.") % name - raise webob.exc.HTTPConflict(explanation=msg) + except exception.InvalidKeypair as exc: + raise webob.exc.HTTPBadRequest(explanation=exc.format_message()) + except exception.KeyPairExists as exc: + raise webob.exc.HTTPConflict(explanation=exc.format_message()) def delete(self, req, id): """ diff --git a/nova/api/openstack/compute/plugins/v3/keypairs.py b/nova/api/openstack/compute/plugins/v3/keypairs.py index 4051a3497..bf740641e 100644 --- a/nova/api/openstack/compute/plugins/v3/keypairs.py +++ b/nova/api/openstack/compute/plugins/v3/keypairs.py @@ -95,12 +95,10 @@ class KeypairController(object): raise webob.exc.HTTPRequestEntityTooLarge( explanation=msg, headers={'Retry-After': 0}) - except exception.InvalidKeypair: - msg = _("Keypair data is invalid") - raise webob.exc.HTTPBadRequest(explanation=msg) - except exception.KeyPairExists: - msg = _("Key pair '%s' already exists.") % name - raise webob.exc.HTTPConflict(explanation=msg) + except exception.InvalidKeypair as exc: + raise webob.exc.HTTPBadRequest(explanation=exc.format_message()) + except exception.KeyPairExists as exc: + raise webob.exc.HTTPConflict(explanation=exc.format_message()) def delete(self, req, id): """ -- cgit