summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Erdfelt <johannes.erdfelt@rackspace.com>2013-07-26 15:16:13 +0000
committerJohannes Erdfelt <johannes.erdfelt@rackspace.com>2013-07-26 20:20:25 +0000
commitdf3f2bafbe76d78d017d40e7dc08909fee7dbe34 (patch)
tree839406bbf4f76adb436ff04162b459a6b916273b
parentd4d81262ff74ff54e51db4065192fd9a0119ec34 (diff)
BaseException.message is deprecated since Python 2.6
PEP 352 deprecated the message attribute of the BaseException class. Using the message attribute will result in warnings like this: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 Using unicode(exc) is the suggested replacement. Change-Id: Ibf3c56e4baa6ad83e2b95a948787e9d02cf074d4
-rw-r--r--openstack/common/db/sqlalchemy/session.py10
-rw-r--r--openstack/common/excutils.py7
-rw-r--r--openstack/common/timeutils.py4
-rw-r--r--tests/unit/test_processutils.py16
4 files changed, 24 insertions, 13 deletions
diff --git a/openstack/common/db/sqlalchemy/session.py b/openstack/common/db/sqlalchemy/session.py
index 59bcb90..e83009c 100644
--- a/openstack/common/db/sqlalchemy/session.py
+++ b/openstack/common/db/sqlalchemy/session.py
@@ -478,6 +478,11 @@ def _raise_if_duplicate_entry_error(integrity_error, engine_name):
if engine_name not in ["mysql", "sqlite", "postgresql"]:
return
+ # FIXME(johannes): The usage of the .message attribute has been
+ # deprecated since Python 2.6. However, the exceptions raised by
+ # SQLAlchemy can differ when using unicode() and accessing .message.
+ # An audit across all three supported engines will be necessary to
+ # ensure there are no regressions.
m = _DUP_KEY_RE_DB[engine_name].match(integrity_error.message)
if not m:
return
@@ -510,6 +515,11 @@ def _raise_if_deadlock_error(operational_error, engine_name):
re = _DEADLOCK_RE_DB.get(engine_name)
if re is None:
return
+ # FIXME(johannes): The usage of the .message attribute has been
+ # deprecated since Python 2.6. However, the exceptions raised by
+ # SQLAlchemy can differ when using unicode() and accessing .message.
+ # An audit across all three supported engines will be necessary to
+ # ensure there are no regressions.
m = re.match(operational_error.message)
if not m:
return
diff --git a/openstack/common/excutils.py b/openstack/common/excutils.py
index abe6f87..664b2e4 100644
--- a/openstack/common/excutils.py
+++ b/openstack/common/excutils.py
@@ -77,7 +77,8 @@ def forever_retry_uncaught_exceptions(infunc):
try:
return infunc(*args, **kwargs)
except Exception as exc:
- if exc.message == last_exc_message:
+ this_exc_message = unicode(exc)
+ if this_exc_message == last_exc_message:
exc_count += 1
else:
exc_count = 1
@@ -85,12 +86,12 @@ def forever_retry_uncaught_exceptions(infunc):
# the exception message changes
cur_time = int(time.time())
if (cur_time - last_log_time > 60 or
- exc.message != last_exc_message):
+ this_exc_message != last_exc_message):
logging.exception(
_('Unexpected exception occurred %d time(s)... '
'retrying.') % exc_count)
last_log_time = cur_time
- last_exc_message = exc.message
+ last_exc_message = this_exc_message
exc_count = 0
# This should be a very rare event. In case it isn't, do
# a sleep.
diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py
index bd60489..aa9f708 100644
--- a/openstack/common/timeutils.py
+++ b/openstack/common/timeutils.py
@@ -49,9 +49,9 @@ def parse_isotime(timestr):
try:
return iso8601.parse_date(timestr)
except iso8601.ParseError as e:
- raise ValueError(e.message)
+ raise ValueError(unicode(e))
except TypeError as e:
- raise ValueError(e.message)
+ raise ValueError(unicode(e))
def strtime(at=None, fmt=PERFECT_TIME_FORMAT):
diff --git a/tests/unit/test_processutils.py b/tests/unit/test_processutils.py
index 7c6e11c..8a14eaf 100644
--- a/tests/unit/test_processutils.py
+++ b/tests/unit/test_processutils.py
@@ -41,23 +41,23 @@ class ProcessExecutionErrorTest(utils.BaseTestCase):
def test_defaults(self):
err = processutils.ProcessExecutionError()
- self.assertTrue('None\n' in err.message)
- self.assertTrue('code: -\n' in err.message)
+ self.assertTrue('None\n' in unicode(err))
+ self.assertTrue('code: -\n' in unicode(err))
def test_with_description(self):
description = 'The Narwhal Bacons at Midnight'
err = processutils.ProcessExecutionError(description=description)
- self.assertTrue(description in err.message)
+ self.assertTrue(description in unicode(err))
def test_with_exit_code(self):
exit_code = 0
err = processutils.ProcessExecutionError(exit_code=exit_code)
- self.assertTrue(str(exit_code) in err.message)
+ self.assertTrue(str(exit_code) in unicode(err))
def test_with_cmd(self):
cmd = 'telinit'
err = processutils.ProcessExecutionError(cmd=cmd)
- self.assertTrue(cmd in err.message)
+ self.assertTrue(cmd in unicode(err))
def test_with_stdout(self):
stdout = """
@@ -80,13 +80,13 @@ class ProcessExecutionErrorTest(utils.BaseTestCase):
the Wielder of Wonder, with world's renown.
""".strip()
err = processutils.ProcessExecutionError(stdout=stdout)
- print(err.message)
- self.assertTrue('people-kings' in err.message)
+ print(unicode(err))
+ self.assertTrue('people-kings' in unicode(err))
def test_with_stderr(self):
stderr = 'Cottonian library'
err = processutils.ProcessExecutionError(stderr=stderr)
- self.assertTrue(stderr in str(err.message))
+ self.assertTrue(stderr in unicode(err))
def test_retry_on_failure(self):
fd, tmpfilename = tempfile.mkstemp()