summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikola Dipanov <ndipanov@redhat.com>2013-03-26 14:38:09 +0100
committerNikola Dipanov <ndipanov@redhat.com>2013-03-27 17:45:12 +0100
commit86031940b313532606449c400bca64707be1797a (patch)
tree0598a39889cfac4c0991c2e1e04cc3ef89495721
parentb936df8c1ec47300540403ebb6833f0fbf5f195f (diff)
downloadnova-86031940b313532606449c400bca64707be1797a.tar.gz
nova-86031940b313532606449c400bca64707be1797a.tar.xz
nova-86031940b313532606449c400bca64707be1797a.zip
Use format_message on exceptions instead of str()
This patch changes all usages of unicode() and str() in the API layer (and most other reasonable places) into a new format_message method. This is done in order to avoid leaking the stack trace back to the user through the Remote excepitons. This patch deliberately avoids the EC2 api as the way how the EC2 API handles responses is being worked on as part of another blueprint. Fixes bug 1159755 Change-Id: I04a74682c4fac9a66ba25b52fd5c7af5e10e81e8
-rw-r--r--nova/api/openstack/compute/contrib/admin_actions.py2
-rw-r--r--nova/api/openstack/compute/contrib/agents.py4
-rw-r--r--nova/api/openstack/compute/contrib/console_output.py2
-rw-r--r--nova/api/openstack/compute/contrib/consoles.py6
-rw-r--r--nova/api/openstack/compute/contrib/deferred_delete.py4
-rw-r--r--nova/api/openstack/compute/contrib/fixed_ips.py2
-rw-r--r--nova/api/openstack/compute/contrib/flavor_access.py4
-rw-r--r--nova/api/openstack/compute/contrib/flavorextraspecs.py4
-rw-r--r--nova/api/openstack/compute/contrib/flavormanage.py4
-rw-r--r--nova/api/openstack/compute/contrib/floating_ip_dns.py4
-rw-r--r--nova/api/openstack/compute/contrib/floating_ips_bulk.py6
-rw-r--r--nova/api/openstack/compute/contrib/hosts.py8
-rw-r--r--nova/api/openstack/compute/contrib/rescue.py3
-rw-r--r--nova/api/openstack/compute/contrib/security_groups.py8
-rw-r--r--nova/api/openstack/compute/contrib/server_password.py2
-rw-r--r--nova/api/openstack/compute/contrib/server_start_stop.py4
-rw-r--r--nova/api/openstack/compute/server_metadata.py10
-rw-r--r--nova/api/openstack/compute/servers.py32
-rw-r--r--nova/compute/api.py2
19 files changed, 59 insertions, 52 deletions
diff --git a/nova/api/openstack/compute/contrib/admin_actions.py b/nova/api/openstack/compute/contrib/admin_actions.py
index 951bc0c11..ff595fad6 100644
--- a/nova/api/openstack/compute/contrib/admin_actions.py
+++ b/nova/api/openstack/compute/contrib/admin_actions.py
@@ -286,7 +286,7 @@ class AdminActionsController(wsgi.Controller):
exception.InvalidHypervisorType,
exception.UnableToMigrateToSelf,
exception.DestinationHypervisorTooOld) as ex:
- raise exc.HTTPBadRequest(explanation=str(ex))
+ raise exc.HTTPBadRequest(explanation=ex.format_message())
except Exception:
if host is None:
msg = _("Live migration of instance %(id)s to another host"
diff --git a/nova/api/openstack/compute/contrib/agents.py b/nova/api/openstack/compute/contrib/agents.py
index 1ea92b4de..7756187f3 100644
--- a/nova/api/openstack/compute/contrib/agents.py
+++ b/nova/api/openstack/compute/contrib/agents.py
@@ -109,7 +109,7 @@ class AgentController(object):
'url': url,
'md5hash': md5hash})
except exception.AgentBuildNotFound as ex:
- raise webob.exc.HTTPNotFound(explanation=str(ex))
+ raise webob.exc.HTTPNotFound(explanation=ex.format_message())
return {"agent": {'agent_id': id, 'version': version,
'url': url, 'md5hash': md5hash}}
@@ -122,7 +122,7 @@ class AgentController(object):
try:
db.agent_build_destroy(context, id)
except exception.AgentBuildNotFound as ex:
- raise webob.exc.HTTPNotFound(explanation=str(ex))
+ raise webob.exc.HTTPNotFound(explanation=ex.format_message())
def create(self, req, body):
"""Creates a new agent build."""
diff --git a/nova/api/openstack/compute/contrib/console_output.py b/nova/api/openstack/compute/contrib/console_output.py
index 2cfa6e447..b3588d344 100644
--- a/nova/api/openstack/compute/contrib/console_output.py
+++ b/nova/api/openstack/compute/contrib/console_output.py
@@ -66,7 +66,7 @@ class ConsoleOutputController(wsgi.Controller):
except exception.NotFound:
raise webob.exc.HTTPNotFound(_('Unable to get console'))
except exception.InstanceNotReady as e:
- raise webob.exc.HTTPConflict(explanation=unicode(e))
+ raise webob.exc.HTTPConflict(explanation=e.format_message())
# XML output is not correctly escaped, so remove invalid characters
remove_re = re.compile('[\x00-\x08\x0B-\x0C\x0E-\x1F-\x0D]')
diff --git a/nova/api/openstack/compute/contrib/consoles.py b/nova/api/openstack/compute/contrib/consoles.py
index 0431a0694..ade5261b2 100644
--- a/nova/api/openstack/compute/contrib/consoles.py
+++ b/nova/api/openstack/compute/contrib/consoles.py
@@ -47,7 +47,7 @@ class ConsolesController(wsgi.Controller):
instance,
console_type)
except exception.InstanceNotFound as e:
- raise webob.exc.HTTPNotFound(explanation=unicode(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(
explanation=_('Instance not yet ready'))
@@ -69,9 +69,9 @@ class ConsolesController(wsgi.Controller):
instance,
console_type)
except exception.InstanceNotFound as e:
- raise webob.exc.HTTPNotFound(explanation=unicode(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceNotReady as e:
- raise webob.exc.HTTPConflict(explanation=unicode(e))
+ raise webob.exc.HTTPConflict(explanation=e.format_message())
return {'console': {'type': console_type, 'url': output['url']}}
diff --git a/nova/api/openstack/compute/contrib/deferred_delete.py b/nova/api/openstack/compute/contrib/deferred_delete.py
index 122fc7035..30358b376 100644
--- a/nova/api/openstack/compute/contrib/deferred_delete.py
+++ b/nova/api/openstack/compute/contrib/deferred_delete.py
@@ -44,8 +44,8 @@ class DeferredDeleteController(wsgi.Controller):
self.compute_api.restore(context, instance)
except exception.QuotaError as error:
raise webob.exc.HTTPRequestEntityTooLarge(
- explanation=unicode(error),
- headers={'Retry-After': 0})
+ explanation=error.format_message(),
+ headers={'Retry-After': 0})
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'restore')
diff --git a/nova/api/openstack/compute/contrib/fixed_ips.py b/nova/api/openstack/compute/contrib/fixed_ips.py
index 6f0a36888..e88038f3f 100644
--- a/nova/api/openstack/compute/contrib/fixed_ips.py
+++ b/nova/api/openstack/compute/contrib/fixed_ips.py
@@ -34,7 +34,7 @@ class FixedIPController(object):
try:
fixed_ip = db.fixed_ip_get_by_address_detailed(context, id)
except exception.FixedIpNotFoundForAddress as ex:
- raise webob.exc.HTTPNotFound(explanation=str(ex))
+ raise webob.exc.HTTPNotFound(explanation=ex.format_message())
fixed_ip_info = {"fixed_ip": {}}
if fixed_ip[1] is None:
diff --git a/nova/api/openstack/compute/contrib/flavor_access.py b/nova/api/openstack/compute/contrib/flavor_access.py
index ec5937094..39220ee4a 100644
--- a/nova/api/openstack/compute/contrib/flavor_access.py
+++ b/nova/api/openstack/compute/contrib/flavor_access.py
@@ -175,7 +175,7 @@ class FlavorActionController(wsgi.Controller):
try:
instance_types.add_instance_type_access(id, tenant, context)
except exception.FlavorAccessExists as err:
- raise webob.exc.HTTPConflict(explanation=str(err))
+ raise webob.exc.HTTPConflict(explanation=err.format_message())
return _marshall_flavor_access(id)
@@ -192,7 +192,7 @@ class FlavorActionController(wsgi.Controller):
try:
instance_types.remove_instance_type_access(id, tenant, context)
except exception.FlavorAccessNotFound, e:
- raise webob.exc.HTTPNotFound(explanation=str(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
return _marshall_flavor_access(id)
diff --git a/nova/api/openstack/compute/contrib/flavorextraspecs.py b/nova/api/openstack/compute/contrib/flavorextraspecs.py
index 1349abe78..de68eb7d6 100644
--- a/nova/api/openstack/compute/contrib/flavorextraspecs.py
+++ b/nova/api/openstack/compute/contrib/flavorextraspecs.py
@@ -76,7 +76,7 @@ class FlavorExtraSpecsController(object):
flavor_id,
specs)
except exception.MetadataLimitExceeded as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
return body
@wsgi.serializers(xml=ExtraSpecTemplate)
@@ -95,7 +95,7 @@ class FlavorExtraSpecsController(object):
flavor_id,
body)
except exception.MetadataLimitExceeded as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
return body
@wsgi.serializers(xml=ExtraSpecTemplate)
diff --git a/nova/api/openstack/compute/contrib/flavormanage.py b/nova/api/openstack/compute/contrib/flavormanage.py
index e8ac4d522..7cff7f4b8 100644
--- a/nova/api/openstack/compute/contrib/flavormanage.py
+++ b/nova/api/openstack/compute/contrib/flavormanage.py
@@ -45,7 +45,7 @@ class FlavorManageController(wsgi.Controller):
flavor = instance_types.get_instance_type_by_flavor_id(
id, read_deleted="no")
except exception.NotFound, e:
- raise webob.exc.HTTPNotFound(explanation=str(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
instance_types.destroy(flavor['name'])
@@ -75,7 +75,7 @@ class FlavorManageController(wsgi.Controller):
req.cache_db_flavor(flavor)
except (exception.InstanceTypeExists,
exception.InstanceTypeIdExists) as err:
- raise webob.exc.HTTPConflict(explanation=str(err))
+ raise webob.exc.HTTPConflict(explanation=err.format_message())
return self._view_builder.show(req, flavor)
diff --git a/nova/api/openstack/compute/contrib/floating_ip_dns.py b/nova/api/openstack/compute/contrib/floating_ip_dns.py
index 5caea9ffa..62eb0d08f 100644
--- a/nova/api/openstack/compute/contrib/floating_ip_dns.py
+++ b/nova/api/openstack/compute/contrib/floating_ip_dns.py
@@ -189,7 +189,7 @@ class FloatingIPDNSDomainController(object):
try:
self.network_api.delete_dns_domain(context, domain)
except exception.NotFound as e:
- raise webob.exc.HTTPNotFound(explanation=unicode(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
return webob.Response(status_int=202)
@@ -274,7 +274,7 @@ class FloatingIPDNSEntryController(object):
try:
self.network_api.delete_dns_entry(context, name, domain)
except exception.NotFound as e:
- raise webob.exc.HTTPNotFound(explanation=unicode(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
return webob.Response(status_int=202)
diff --git a/nova/api/openstack/compute/contrib/floating_ips_bulk.py b/nova/api/openstack/compute/contrib/floating_ips_bulk.py
index e6a7fecee..1baf474c2 100644
--- a/nova/api/openstack/compute/contrib/floating_ips_bulk.py
+++ b/nova/api/openstack/compute/contrib/floating_ips_bulk.py
@@ -98,12 +98,12 @@ class FloatingIPBulkController(object):
'interface': interface}
for address in self._address_to_hosts(ip_range))
except exception.InvalidInput as exc:
- raise webob.exc.HTTPBadRequest(explanation=str(exc))
+ raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
try:
db.floating_ip_bulk_create(context, ips)
except exception.FloatingIpExists as exc:
- raise webob.exc.HTTPBadRequest(explanation=str(exc))
+ raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
return {"floating_ips_bulk_create": {"ip_range": ip_range,
"pool": pool,
@@ -126,7 +126,7 @@ class FloatingIPBulkController(object):
ips = ({'address': str(address)}
for address in self._address_to_hosts(ip_range))
except exception.InvalidInput as exc:
- raise webob.exc.HTTPBadRequest(explanation=str(exc))
+ raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
db.floating_ip_bulk_destroy(context, ips)
return {"floating_ips_bulk_delete": ip_range}
diff --git a/nova/api/openstack/compute/contrib/hosts.py b/nova/api/openstack/compute/contrib/hosts.py
index 0c910bb8a..a896678f0 100644
--- a/nova/api/openstack/compute/contrib/hosts.py
+++ b/nova/api/openstack/compute/contrib/hosts.py
@@ -210,7 +210,7 @@ class HostController(object):
msg = _("Virt driver does not implement host maintenance mode.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
except exception.NotFound as e:
- raise webob.exc.HTTPNotFound(explanation=unicode(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
if result not in ("on_maintenance", "off_maintenance"):
raise webob.exc.HTTPBadRequest(explanation=result)
return result
@@ -230,7 +230,7 @@ class HostController(object):
msg = _("Virt driver does not implement host disabled status.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
except exception.NotFound as e:
- raise webob.exc.HTTPNotFound(explanation=unicode(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
if result not in ("enabled", "disabled"):
raise webob.exc.HTTPBadRequest(explanation=result)
return result
@@ -246,7 +246,7 @@ class HostController(object):
msg = _("Virt driver does not implement host power management.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
except exception.NotFound as e:
- raise webob.exc.HTTPNotFound(explanation=unicode(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
return {"host": host_name, "power_action": result}
@wsgi.serializers(xml=HostActionTemplate)
@@ -327,7 +327,7 @@ class HostController(object):
try:
service = self.api.service_get_by_compute_host(context, host_name)
except exception.NotFound as e:
- raise webob.exc.HTTPNotFound(explanation=unicode(e))
+ raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.AdminRequired:
msg = _("Describe-resource is admin only functionality")
raise webob.exc.HTTPForbidden(explanation=msg)
diff --git a/nova/api/openstack/compute/contrib/rescue.py b/nova/api/openstack/compute/contrib/rescue.py
index d8699e0e0..87d838bdf 100644
--- a/nova/api/openstack/compute/contrib/rescue.py
+++ b/nova/api/openstack/compute/contrib/rescue.py
@@ -64,7 +64,8 @@ class RescueController(wsgi.Controller):
common.raise_http_conflict_for_instance_invalid_state(state_error,
'rescue')
except exception.InstanceNotRescuable as non_rescuable:
- raise exc.HTTPBadRequest(explanation=unicode(non_rescuable))
+ raise exc.HTTPBadRequest(
+ explanation=non_rescuable.format_message())
return {'adminPass': password}
diff --git a/nova/api/openstack/compute/contrib/security_groups.py b/nova/api/openstack/compute/contrib/security_groups.py
index 615bf9764..354fab647 100644
--- a/nova/api/openstack/compute/contrib/security_groups.py
+++ b/nova/api/openstack/compute/contrib/security_groups.py
@@ -387,7 +387,7 @@ class ServerSecurityGroupController(SecurityGroupControllerBase):
try:
instance = self.compute_api.get(context, server_id)
except exception.InstanceNotFound as exp:
- raise exc.HTTPNotFound(explanation=unicode(exp))
+ raise exc.HTTPNotFound(explanation=exp.format_message())
groups = self.security_group_api.get_instance_security_groups(
req, instance['id'], instance['uuid'], True)
@@ -429,11 +429,11 @@ class SecurityGroupActionController(wsgi.Controller):
instance = self.compute_api.get(context, id)
method(context, instance, group_name)
except exception.SecurityGroupNotFound as exp:
- raise exc.HTTPNotFound(explanation=unicode(exp))
+ raise exc.HTTPNotFound(explanation=exp.format_message())
except exception.InstanceNotFound as exp:
- raise exc.HTTPNotFound(explanation=unicode(exp))
+ raise exc.HTTPNotFound(explanation=exp.format_message())
except exception.Invalid as exp:
- raise exc.HTTPBadRequest(explanation=unicode(exp))
+ raise exc.HTTPBadRequest(explanation=exp.format_message())
return webob.Response(status_int=202)
diff --git a/nova/api/openstack/compute/contrib/server_password.py b/nova/api/openstack/compute/contrib/server_password.py
index 9436d354f..14ea91ef2 100644
--- a/nova/api/openstack/compute/contrib/server_password.py
+++ b/nova/api/openstack/compute/contrib/server_password.py
@@ -47,7 +47,7 @@ class ServerPasswordController(object):
try:
return self.compute_api.get(context, server_id)
except exception.InstanceNotFound as exp:
- raise webob.exc.HTTPNotFound(explanation=unicode(exp))
+ raise webob.exc.HTTPNotFound(explanation=exp.format_message())
@wsgi.serializers(xml=ServerPasswordTemplate)
def index(self, req, server_id):
diff --git a/nova/api/openstack/compute/contrib/server_start_stop.py b/nova/api/openstack/compute/contrib/server_start_stop.py
index a13aabb05..c4d0d5c9e 100644
--- a/nova/api/openstack/compute/contrib/server_start_stop.py
+++ b/nova/api/openstack/compute/contrib/server_start_stop.py
@@ -47,7 +47,7 @@ class ServerStartStopActionController(wsgi.Controller):
try:
self.compute_api.start(context, instance)
except exception.InstanceNotReady as e:
- raise webob.exc.HTTPConflict(explanation=unicode(e))
+ raise webob.exc.HTTPConflict(explanation=e.format_message())
return webob.Response(status_int=202)
@wsgi.action('os-stop')
@@ -59,7 +59,7 @@ class ServerStartStopActionController(wsgi.Controller):
try:
self.compute_api.stop(context, instance)
except exception.InstanceNotReady as e:
- raise webob.exc.HTTPConflict(explanation=unicode(e))
+ raise webob.exc.HTTPConflict(explanation=e.format_message())
return webob.Response(status_int=202)
diff --git a/nova/api/openstack/compute/server_metadata.py b/nova/api/openstack/compute/server_metadata.py
index 7dc6b0194..3f7915a84 100644
--- a/nova/api/openstack/compute/server_metadata.py
+++ b/nova/api/openstack/compute/server_metadata.py
@@ -127,14 +127,16 @@ class Controller(object):
raise exc.HTTPBadRequest(explanation=msg)
except exception.InvalidMetadata as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
except exception.InvalidMetadataSize as error:
- raise exc.HTTPRequestEntityTooLarge(explanation=unicode(error))
+ raise exc.HTTPRequestEntityTooLarge(
+ explanation=error.format_message())
except exception.QuotaError as error:
- raise exc.HTTPRequestEntityTooLarge(explanation=unicode(error),
- headers={'Retry-After': 0})
+ raise exc.HTTPRequestEntityTooLarge(
+ explanation=error.format_message(),
+ headers={'Retry-After': 0})
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index df8055b62..12efa5eb4 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -897,25 +897,27 @@ class Controller(wsgi.Controller):
auto_disk_config=auto_disk_config,
scheduler_hints=scheduler_hints)
except exception.QuotaError as error:
- raise exc.HTTPRequestEntityTooLarge(explanation=unicode(error),
- headers={'Retry-After': 0})
+ raise exc.HTTPRequestEntityTooLarge(
+ explanation=error.format_message(),
+ headers={'Retry-After': 0})
except exception.InstanceTypeMemoryTooSmall as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
except exception.InstanceTypeNotFound as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error)
except exception.InstanceTypeDiskTooSmall as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
except exception.InvalidMetadata as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
except exception.InvalidMetadataSize as error:
- raise exc.HTTPRequestEntityTooLarge(explanation=unicode(error))
+ raise exc.HTTPRequestEntityTooLarge(
+ explanation=error.format_message())
except exception.InvalidRequest as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
except exception.ImageNotFound as error:
msg = _("Can not find requested image")
raise exc.HTTPBadRequest(explanation=msg)
except exception.ImageNotActive as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
except exception.FlavorNotFound as error:
msg = _("Invalid flavorRef provided.")
raise exc.HTTPBadRequest(explanation=msg)
@@ -923,7 +925,7 @@ class Controller(wsgi.Controller):
msg = _("Invalid key_name provided.")
raise exc.HTTPBadRequest(explanation=msg)
except exception.SecurityGroupNotFound as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
except rpc_common.RemoteError as err:
msg = "%(err_type)s: %(err_msg)s" % {'err_type': err.exc_type,
'err_msg': err.value}
@@ -1288,16 +1290,18 @@ class Controller(wsgi.Controller):
msg = _("Instance could not be found")
raise exc.HTTPNotFound(explanation=msg)
except exception.InvalidMetadata as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(
+ explanation=error.format_message())
except exception.InvalidMetadataSize as error:
- raise exc.HTTPRequestEntityTooLarge(explanation=unicode(error))
+ raise exc.HTTPRequestEntityTooLarge(
+ explanation=error.format_message())
except exception.ImageNotFound:
msg = _("Cannot find image for rebuild")
raise exc.HTTPBadRequest(explanation=msg)
except exception.InstanceTypeMemoryTooSmall as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
except exception.InstanceTypeDiskTooSmall as error:
- raise exc.HTTPBadRequest(explanation=unicode(error))
+ raise exc.HTTPBadRequest(explanation=error.format_message())
instance = self._get_server(context, req, id)
diff --git a/nova/compute/api.py b/nova/compute/api.py
index b115772db..0d915bfc9 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -2888,7 +2888,7 @@ class SecurityGroupAPI(base.Base, security_group_base.SecurityGroupBase):
return self.db.security_group_get(context, id)
except exception.NotFound as exp:
if map_exception:
- msg = unicode(exp)
+ msg = exp.format_message()
self.raise_not_found(msg)
else:
raise