From a0150a4d9e751ec222221558dfe89a66b0c118ab Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Wed, 21 Mar 2012 19:13:16 +0000 Subject: Add the serialization of exceptions for RPC calls. This change uses json to serialize an exception so that it can be sent through RPC calls to be reconstructed on the other side. The traceback is added to the exception message. If recreating the exception fails for whatever reason then a RemoteError is created containing all of the exception information. Adds flag 'allowed_rpc_exception_modules' to prevent dangerous modules from being accessed and allowing arbitrary code to be run. Fixes bug 920705 Fixes bug 940500 Change-Id: Ife3b64b19fe8abbc730184d4ee7d9fcabfd29db3 --- nova/api/ec2/cloud.py | 12 ++---------- nova/api/openstack/compute/contrib/floating_ips.py | 17 +++++------------ 2 files changed, 7 insertions(+), 22 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 2ff5b32c6..9346d107b 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -41,7 +41,6 @@ from nova import flags from nova.image import s3 from nova import log as logging from nova import network -from nova.rpc import common as rpc_common from nova import utils from nova import volume @@ -1253,15 +1252,8 @@ class CloudController(object): def allocate_address(self, context, **kwargs): LOG.audit(_("Allocate address"), context=context) - try: - public_ip = self.network_api.allocate_floating_ip(context) - return {'publicIp': public_ip} - except rpc_common.RemoteError as ex: - # NOTE(tr3buchet) - why does this block exist? - if ex.exc_type == 'NoMoreFloatingIps': - raise exception.NoMoreFloatingIps() - else: - raise + public_ip = self.network_api.allocate_floating_ip(context) + return {'publicIp': public_ip} def release_address(self, context, public_ip, **kwargs): LOG.audit(_("Release address %s"), public_ip, context=context) diff --git a/nova/api/openstack/compute/contrib/floating_ips.py b/nova/api/openstack/compute/contrib/floating_ips.py index 6b9e9e97c..4a5cec8d2 100644 --- a/nova/api/openstack/compute/contrib/floating_ips.py +++ b/nova/api/openstack/compute/contrib/floating_ips.py @@ -152,16 +152,12 @@ class FloatingIPController(object): try: address = self.network_api.allocate_floating_ip(context, pool) ip = self.network_api.get_floating_ip_by_address(context, address) - except rpc_common.RemoteError as ex: - # NOTE(tr3buchet) - why does this block exist? - if ex.exc_type == 'NoMoreFloatingIps': - if pool: - msg = _("No more floating ips in pool %s.") % pool - else: - msg = _("No more floating ips available.") - raise webob.exc.HTTPBadRequest(explanation=msg) + except exception.NoMoreFloatingIps: + if pool: + msg = _("No more floating ips in pool %s.") % pool else: - raise + msg = _("No more floating ips available.") + raise webob.exc.HTTPBadRequest(explanation=msg) return _translate_floating_ip_view(ip) @@ -212,9 +208,6 @@ class FloatingIPActionController(wsgi.Controller): except exception.FixedIpNotFoundForInstance: msg = _("No fixed ips associated to instance") raise webob.exc.HTTPBadRequest(explanation=msg) - except rpc_common.RemoteError: - msg = _("Associate floating ip failed") - raise webob.exc.HTTPInternalServerError(explanation=msg) return webob.Response(status_int=202) -- cgit