From e4bf6a631f6b8e3020f24f560d5e4600303266f2 Mon Sep 17 00:00:00 2001 From: Vu Cong Tuan Date: Tue, 20 Jun 2017 17:07:42 +0700 Subject: [PATCH] Stop using deprecated 'message' attribute in Exception The 'message' attribute has been deprecated and removed from Python3. For more details, please check: https://www.python.org/dev/peps/pep-0352/ Change-Id: If69389968f92b2b32f876c10ce9b4a00306c4d2a --- mogan/api/controllers/v1/flavors.py | 7 ++++--- mogan/api/controllers/v1/servers.py | 21 +++++++++++---------- mogan/engine/baremetal/ironic/driver.py | 8 ++++---- mogan/engine/manager.py | 4 ++-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/mogan/api/controllers/v1/flavors.py b/mogan/api/controllers/v1/flavors.py index 9ced72f5..1a7d4d3a 100644 --- a/mogan/api/controllers/v1/flavors.py +++ b/mogan/api/controllers/v1/flavors.py @@ -15,6 +15,7 @@ import pecan from pecan import rest +import six from six.moves import http_client import wsme from wsme import types as wtypes @@ -157,10 +158,10 @@ class FlavorAccessController(rest.RestController): flavor.save() except exception.FlavorNotFound as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.NOT_FOUND) + six.text_type(e), status_code=http_client.NOT_FOUND) except exception.FlavorAccessExists as err: raise wsme.exc.ClientSideError( - err.message, status_code=http_client.CONFLICT) + six.text_type(err), status_code=http_client.CONFLICT) @policy.authorize_wsgi("mogan:flavor_access", "remove_tenant_access") @expose.expose(None, types.uuid, types.uuid, @@ -181,7 +182,7 @@ class FlavorAccessController(rest.RestController): except (exception.FlavorAccessNotFound, exception.FlavorNotFound) as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.NOT_FOUND) + six.text_type(e), status_code=http_client.NOT_FOUND) class FlavorsController(rest.RestController): diff --git a/mogan/api/controllers/v1/servers.py b/mogan/api/controllers/v1/servers.py index 1b69a9e0..6af2278e 100644 --- a/mogan/api/controllers/v1/servers.py +++ b/mogan/api/controllers/v1/servers.py @@ -19,6 +19,7 @@ from oslo_log import log from oslo_utils import netutils import pecan from pecan import rest +import six from six.moves import http_client from webob import exc import wsme @@ -262,10 +263,10 @@ class FloatingIPController(ServerControllerBase): port_id=nic.port_id, fixed_address=fixed_address) except exception.FloatingIpNotFoundForAddress as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.NOT_FOUND) + six.text_type(e), status_code=http_client.NOT_FOUND) except exception.Forbidden as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.FORBIDDEN) + six.text_type(e), status_code=http_client.FORBIDDEN) except Exception as e: msg = _('Unable to associate floating IP %(address)s to ' 'fixed IP %(fixed_address)s for server %(id)s. ' @@ -305,10 +306,10 @@ class FloatingIPController(ServerControllerBase): pecan.request.context, address) except exception.FloatingIpNotFoundForAddress as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.NOT_FOUND) + six.text_type(e), status_code=http_client.NOT_FOUND) except exception.FloatingIpMultipleFoundForAddress as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.CONFLICT) + six.text_type(e), status_code=http_client.CONFLICT) # disassociate if associated if (floating_ip.get('port_id') and server_id == server_uuid): @@ -317,7 +318,7 @@ class FloatingIPController(ServerControllerBase): pecan.request.context, address) except exception.Forbidden as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.FORBIDDEN) + six.text_type(e), status_code=http_client.FORBIDDEN) except exception.CannotDisassociateAutoAssignedFloatingIP: msg = _('Cannot disassociate auto assigned floating IP') raise wsme.exc.ClientSideError( @@ -363,10 +364,10 @@ class InterfaceController(ServerControllerBase): exception.ComputePortNotAvailable, exception.NetworkNotFound) as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.BAD_REQUEST) + six.text_type(e), status_code=http_client.BAD_REQUEST) except exception.InterfaceAttachFailed as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.CONFLICT) + six.text_type(e), status_code=http_client.CONFLICT) class ServerNetworks(base.APIBase): @@ -671,7 +672,7 @@ class ServerController(ServerControllerBase): msg, status_code=http_client.BAD_REQUEST) except exception.PortLimitExceeded as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.FORBIDDEN) + six.text_type(e), status_code=http_client.FORBIDDEN) except exception.AZNotFound: msg = _('The requested availability zone is not available') raise wsme.exc.ClientSideError( @@ -684,10 +685,10 @@ class ServerController(ServerControllerBase): exception.NetworkNotFound, exception.PortRequiresFixedIP) as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.BAD_REQUEST) + six.text_type(e), status_code=http_client.BAD_REQUEST) except exception.PortInUse as e: raise wsme.exc.ClientSideError( - e.message, status_code=http_client.CONFLICT) + six.text_type(e), status_code=http_client.CONFLICT) # Set the HTTP Location Header for the first server. pecan.response.location = link.build_url('server', servers[0].uuid) diff --git a/mogan/engine/baremetal/ironic/driver.py b/mogan/engine/baremetal/ironic/driver.py index 84987734..7fc6d968 100644 --- a/mogan/engine/baremetal/ironic/driver.py +++ b/mogan/engine/baremetal/ironic/driver.py @@ -451,7 +451,7 @@ class IronicDriver(base_driver.BaseEngineDriver): node_list = self.ironicclient.call("node.list", **params) except client_e.ClientException as e: LOG.exception("Could not get nodes from ironic. Reason: " - "%(detail)s", {'detail': e.message}) + "%(detail)s", {'detail': six.text_type(e)}) node_list = [] # Retrive ports @@ -464,7 +464,7 @@ class IronicDriver(base_driver.BaseEngineDriver): port_list = self.ironicclient.call("port.list", **params) except client_e.ClientException as e: LOG.exception("Could not get ports from ironic. Reason: " - "%(detail)s", {'detail': e.message}) + "%(detail)s", {'detail': six.text_type(e)}) port_list = [] # TODO(zhenguo): Add portgroups resources @@ -493,7 +493,7 @@ class IronicDriver(base_driver.BaseEngineDriver): node_list = self.ironicclient.call("node.list", **params) except client_e.ClientException as e: LOG.exception("Could not get nodes from ironic. Reason: " - "%(detail)s", {'detail': e.message}) + "%(detail)s", {'detail': six.text_type(e)}) node_list = [] return node_list @@ -515,7 +515,7 @@ class IronicDriver(base_driver.BaseEngineDriver): node_list = self.ironicclient.call("node.list", **params) except client_e.ClientException as e: LOG.exception("Could not get nodes from ironic. Reason: " - "%(detail)s", {'detail': e.message}) + "%(detail)s", {'detail': six.text_type(e)}) node_list = [] return node_list diff --git a/mogan/engine/manager.py b/mogan/engine/manager.py index b135db58..a942bebd 100644 --- a/mogan/engine/manager.py +++ b/mogan/engine/manager.py @@ -594,7 +594,7 @@ class EngineManager(base_manager.BaseEngineManager): return pif # if no available compute ports, raise exception - message = "Node %s has no available pysical ports." % node + message = "Node %s has no available physical ports." % node LOG.error(message) raise exception.ComputePortNotAvailable(message=message) @@ -618,4 +618,4 @@ class EngineManager(base_manager.BaseEngineManager): server.nics = nics_obj server.save() except Exception as e: - raise exception.InterfaceAttachFailed(message=e.message) + raise exception.InterfaceAttachFailed(message=six.text_type(e))