Fix exception message issues with Python3

Partially implements: blueprint python-3
Change-Id: I56cec793798c33f176bdb2dc9c8d98ffe487521a
This commit is contained in:
Hiroaki Kobayashi 2018-01-12 11:51:07 +09:00
parent f4c000da92
commit 9c3ce9a707
10 changed files with 20 additions and 22 deletions

View File

@ -247,9 +247,9 @@ def bad_request(error):
LOG.debug("Validation Error occurred: error_code=%(code)s, "
"error_message=%(msg)s, error_name=%(name)s",
{'code': error.code, 'msg': error.message, 'name': error.code})
{'code': error.code, 'msg': str(error), 'name': error.code})
return render_error_message(error.code, error.message, error.code)
return render_error_message(error.code, str(error), error.code)
def not_found(error):
@ -259,6 +259,6 @@ def not_found(error):
LOG.debug("Not Found exception occurred: error_code=%(code)s, "
"error_message=%(msg)s, error_name=%(name)s",
{'code': error.code, 'msg': error.message, 'name': error.code})
{'code': error.code, 'msg': str(error), 'name': error.code})
return render_error_message(error.code, error.message, error.code)
return render_error_message(error.code, str(error), error.code)

View File

@ -250,7 +250,7 @@ class ManagerService(service_utils.RPCServer):
self._check_date_within_lease_limits(before_end_date,
lease_values)
except common_ex.BlazarException as e:
LOG.error("Invalid before_end_date param. %s", e.message)
LOG.error("Invalid before_end_date param. %s", str(e))
raise e
elif CONF.manager.minutes_before_end_lease > 0:
delta = datetime.timedelta(
@ -373,7 +373,7 @@ class ManagerService(service_utils.RPCServer):
self._check_date_within_lease_limits(before_end_date,
values)
except common_ex.BlazarException as e:
LOG.error("Invalid before_end_date param. %s", e.message)
LOG.error("Invalid before_end_date param. %s", str(e))
raise e
# TODO(frossigneux) rollback if an exception is raised

View File

@ -44,7 +44,7 @@ class BaseMonitor(object):
reservation_flags = callback(*args, **kwargs)
except Exception as e:
LOG.exception('Caught an exception while executing a callback. '
'%s', e.message)
'%s', str(e))
# TODO(hiro-kobayashi): update statuses of related leases and
# reservations. Depends on the state-machine blueprint.

View File

@ -39,7 +39,7 @@ class NotificationMonitor(base.BaseMonitor):
LOG.debug('Notification listener is successfully created.')
except Exception as e:
LOG.exception('Failed to create a notification listener. (%s)',
e.message)
str(e))
def start_monitoring(self):
"""Start subscribing notifications."""
@ -48,7 +48,7 @@ class NotificationMonitor(base.BaseMonitor):
self.listener.start()
except Exception as e:
LOG.exception('Failed to start a notification monitor. (%s)',
e.message)
str(e))
def stop_monitoring(self):
"""Stop subscribing notifications."""
@ -57,7 +57,7 @@ class NotificationMonitor(base.BaseMonitor):
self.listener.stop()
except Exception as e:
LOG.exception('Failed to stop a notification monitor. (%s)',
e.message)
str(e))
def _get_targets(self, monitor_plugins):
"""Get a list of targets to subscribe.

View File

@ -39,7 +39,7 @@ class PollingMonitor(base.BaseMonitor):
self.update_statuses, 0, plugin.poll)
except Exception as e:
LOG.exception('Failed to start a polling monitor. (%s)',
e.message)
str(e))
def stop_monitoring(self):
"""Stop polling."""
@ -47,4 +47,4 @@ class PollingMonitor(base.BaseMonitor):
try:
self.tg.stop()
except Exception as e:
LOG.exception('Failed to stop a polling monitor. (%s)', e.message)
LOG.exception('Failed to stop a polling monitor. (%s)', str(e))

View File

@ -364,9 +364,7 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
except db_ex.BlazarDBException as e:
# Nothing so bad, but we need to alert admins
# they have to rerun
raise manager_ex.CantDeleteHost(
host=host_id,
msg=e.message)
raise manager_ex.CantDeleteHost(host=host_id, msg=str(e))
def _matching_hosts(self, hypervisor_properties, resource_properties,
count_range, start_date, end_date):

View File

@ -204,7 +204,7 @@ class LeaseStatus(BaseStatus):
result = func(*args, **kwargs)
except Exception as e:
LOG.error('Lease %s went into ERROR status. %s',
lease_id, e.message)
lease_id, str(e))
db_api.lease_update(lease_id,
{'status': cls.ERROR})
raise e

View File

@ -19,10 +19,10 @@ from blazar.api.v1 import utils
from blazar import tests
class Error:
class Error(Exception):
def __init__(self, message=None, code=None):
self.message = message
self.code = code
super(Error, self).__init__(message)
class UtilsTestCase(tests.TestCase):

View File

@ -37,7 +37,7 @@ class BlazarExceptionTestCase(tests.TestCase):
exc = FakeBlazarException(code=500)
self.assertEqual(six.text_type(exc), 'default message: 500')
self.assertEqual(exc.message, 'default message: 500')
self.assertEqual(str(exc), 'default message: 500')
def test_error_msg_exception_with_kwargs(self):
class FakeBlazarException(exceptions.BlazarException):
@ -45,7 +45,7 @@ class BlazarExceptionTestCase(tests.TestCase):
exc = FakeBlazarException(code=500, mispelled_code='blah')
self.assertEqual(six.text_type(exc), 'default message: blah')
self.assertEqual(exc.message, 'default message: blah')
self.assertEqual(str(exc), 'default message: blah')
def test_default_error_code(self):
class FakeBlazarException(exceptions.BlazarException):
@ -63,6 +63,6 @@ class BlazarExceptionTestCase(tests.TestCase):
def test_policynotauthorized_exception(self):
exc = exceptions.PolicyNotAuthorized(action='foo')
self.assertEqual(six.text_type(exc.message),
self.assertEqual(six.text_type(exc),
"Policy doesn't allow foo to be performed")
self.assertEqual(exc.kwargs['code'], 403)

View File

@ -265,7 +265,7 @@ class ReservationPool(NovaClientWrapper):
project_id = ctx.project_id
except RuntimeError:
e = manager_exceptions.ProjectIdNotFound()
LOG.error(e.message)
LOG.error(str(e))
raise e
if metadata: