utils: replace exception_message by exception_to_unicode
This leverages directly oslo_utils.encodeutils. Change-Id: Id345f4c18cfe98e7359c8934b7148c97e2e1fd99
This commit is contained in:
parent
de9308e154
commit
8d6540f6a9
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import requests
|
import requests
|
||||||
import six
|
import six
|
||||||
|
@ -36,7 +37,7 @@ def _translate_failures(func):
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
coordination.raise_with_cause(coordination.ToozConnectionError,
|
coordination.raise_with_cause(coordination.ToozConnectionError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -175,7 +176,8 @@ class EtcdDriver(coordination.CoordinationDriver):
|
||||||
try:
|
try:
|
||||||
self.client.self_stats()
|
self.client.self_stats()
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.ConnectionError as e:
|
||||||
raise coordination.ToozConnectionError(utils.exception_message(e))
|
raise coordination.ToozConnectionError(
|
||||||
|
encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
def get_lock(self, name):
|
def get_lock(self, name):
|
||||||
return EtcdLock(name, self, self.client, self.lock_timeout)
|
return EtcdLock(name, self, self.client, self.lock_timeout)
|
||||||
|
|
|
@ -28,6 +28,7 @@ from concurrent import futures
|
||||||
|
|
||||||
import fasteners
|
import fasteners
|
||||||
import jsonschema
|
import jsonschema
|
||||||
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ def _translate_failures():
|
||||||
yield
|
yield
|
||||||
except (EnvironmentError, jsonschema.ValidationError) as e:
|
except (EnvironmentError, jsonschema.ValidationError) as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
|
|
||||||
|
@ -473,7 +474,7 @@ class FileFutureResult(coordination.CoordAsyncResult):
|
||||||
return self._fut.result(timeout=timeout)
|
return self._fut.result(timeout=timeout)
|
||||||
except futures.TimeoutError as e:
|
except futures.TimeoutError as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
def done(self):
|
def done(self):
|
||||||
|
|
|
@ -20,6 +20,7 @@ import time
|
||||||
|
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
import msgpack
|
import msgpack
|
||||||
|
from oslo_utils import encodeutils
|
||||||
import six
|
import six
|
||||||
import sysv_ipc
|
import sysv_ipc
|
||||||
|
|
||||||
|
@ -243,7 +244,7 @@ class IPCFutureResult(coordination.CoordAsyncResult):
|
||||||
return self._fut.result(timeout=timeout)
|
return self._fut.result(timeout=timeout)
|
||||||
except futures.TimeoutError as e:
|
except futures.TimeoutError as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
def done(self):
|
def done(self):
|
||||||
|
|
|
@ -20,6 +20,7 @@ import logging
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
|
from oslo_utils import encodeutils
|
||||||
from pymemcache import client as pymemcache_client
|
from pymemcache import client as pymemcache_client
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
@ -44,14 +45,14 @@ def _translate_failures(func):
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
except pymemcache_client.MemcacheUnexpectedCloseError as e:
|
except pymemcache_client.MemcacheUnexpectedCloseError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozConnectionError,
|
coordination.raise_with_cause(coordination.ToozConnectionError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except (socket.timeout, socket.error,
|
except (socket.timeout, socket.error,
|
||||||
socket.gaierror, socket.herror) as e:
|
socket.gaierror, socket.herror) as e:
|
||||||
# TODO(harlowja): get upstream pymemcache to produce a better
|
# TODO(harlowja): get upstream pymemcache to produce a better
|
||||||
# exception for these, using socket (vs. a memcache specific
|
# exception for these, using socket (vs. a memcache specific
|
||||||
# error) seems sorta not right and/or the best approach...
|
# error) seems sorta not right and/or the best approach...
|
||||||
msg = utils.exception_message(e)
|
msg = encodeutils.exception_to_unicode(e)
|
||||||
if e.errno is not None:
|
if e.errno is not None:
|
||||||
msg += " (with errno %s [%s])" % (errno.errorcode[e.errno],
|
msg += " (with errno %s [%s])" % (errno.errorcode[e.errno],
|
||||||
e.errno)
|
e.errno)
|
||||||
|
@ -59,7 +60,7 @@ def _translate_failures(func):
|
||||||
msg, cause=e)
|
msg, cause=e)
|
||||||
except pymemcache_client.MemcacheError as e:
|
except pymemcache_client.MemcacheError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -533,9 +534,10 @@ class MemcachedFutureResult(coordination.CoordAsyncResult):
|
||||||
try:
|
try:
|
||||||
return self._fut.result(timeout=timeout)
|
return self._fut.result(timeout=timeout)
|
||||||
except futures.TimeoutError as e:
|
except futures.TimeoutError as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(
|
||||||
utils.exception_message(e),
|
coordination.OperationTimedOut,
|
||||||
cause=e)
|
encodeutils.exception_to_unicode(e),
|
||||||
|
cause=e)
|
||||||
|
|
||||||
def done(self):
|
def done(self):
|
||||||
return self._fut.done()
|
return self._fut.done()
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from oslo_utils import encodeutils
|
||||||
import pymysql
|
import pymysql
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
|
@ -62,9 +63,10 @@ class MySQLLock(locking.Lock):
|
||||||
self.acquired = True
|
self.acquired = True
|
||||||
return True
|
return True
|
||||||
except pymysql.MySQLError as e:
|
except pymysql.MySQLError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(
|
||||||
utils.exception_message(e),
|
coordination.ToozError,
|
||||||
cause=e)
|
encodeutils.exception_to_unicode(e),
|
||||||
|
cause=e)
|
||||||
|
|
||||||
if blocking:
|
if blocking:
|
||||||
raise _retry.Retry
|
raise _retry.Retry
|
||||||
|
@ -83,7 +85,7 @@ class MySQLLock(locking.Lock):
|
||||||
return True
|
return True
|
||||||
except pymysql.MySQLError as e:
|
except pymysql.MySQLError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
@ -166,5 +168,5 @@ class MySQLDriver(coordination.CoordinationDriver):
|
||||||
database=dbname)
|
database=dbname)
|
||||||
except (pymysql.err.OperationalError, pymysql.err.InternalError) as e:
|
except (pymysql.err.OperationalError, pymysql.err.InternalError) as e:
|
||||||
coordination.raise_with_cause(coordination.ToozConnectionError,
|
coordination.raise_with_cause(coordination.ToozConnectionError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
|
@ -18,6 +18,7 @@ import contextlib
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from oslo_utils import encodeutils
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
@ -55,7 +56,8 @@ _DIAGNOSTICS_ATTRS = tuple([
|
||||||
|
|
||||||
def _format_exception(e):
|
def _format_exception(e):
|
||||||
lines = [
|
lines = [
|
||||||
"%s: %s" % (type(e).__name__, utils.exception_message(e).strip()),
|
"%s: %s" % (type(e).__name__,
|
||||||
|
encodeutils.exception_to_unicode(e).strip()),
|
||||||
]
|
]
|
||||||
if hasattr(e, 'pgcode') and e.pgcode is not None:
|
if hasattr(e, 'pgcode') and e.pgcode is not None:
|
||||||
lines.append("Error code: %s" % e.pgcode)
|
lines.append("Error code: %s" % e.pgcode)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import logging
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
import redis
|
import redis
|
||||||
from redis import exceptions
|
from redis import exceptions
|
||||||
|
@ -46,11 +47,11 @@ def _translate_failures():
|
||||||
yield
|
yield
|
||||||
except (exceptions.ConnectionError, exceptions.TimeoutError) as e:
|
except (exceptions.ConnectionError, exceptions.TimeoutError) as e:
|
||||||
coordination.raise_with_cause(coordination.ToozConnectionError,
|
coordination.raise_with_cause(coordination.ToozConnectionError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.RedisError as e:
|
except exceptions.RedisError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
|
|
||||||
|
@ -415,7 +416,7 @@ return 1
|
||||||
self.timeout)
|
self.timeout)
|
||||||
except exceptions.RedisError as e:
|
except exceptions.RedisError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozConnectionError,
|
coordination.raise_with_cause(coordination.ToozConnectionError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
else:
|
else:
|
||||||
# Ensure that the server is alive and not dead, this does not
|
# Ensure that the server is alive and not dead, this does not
|
||||||
|
@ -779,7 +780,7 @@ class RedisFutureResult(coordination.CoordAsyncResult):
|
||||||
return self._fut.result(timeout=timeout)
|
return self._fut.result(timeout=timeout)
|
||||||
except futures.TimeoutError as e:
|
except futures.TimeoutError as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
def done(self):
|
def done(self):
|
||||||
|
|
|
@ -22,6 +22,7 @@ from kazoo import exceptions
|
||||||
from kazoo.handlers import eventlet as eventlet_handler
|
from kazoo.handlers import eventlet as eventlet_handler
|
||||||
from kazoo.handlers import threading as threading_handler
|
from kazoo.handlers import threading as threading_handler
|
||||||
from kazoo.protocol import paths
|
from kazoo.protocol import paths
|
||||||
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
import six
|
import six
|
||||||
from six.moves import filter as compat_filter
|
from six.moves import filter as compat_filter
|
||||||
|
@ -124,7 +125,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
async_result.get(block=True, timeout=timeout)
|
async_result.get(block=True, timeout=timeout)
|
||||||
except timeout_exception as e:
|
except timeout_exception as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.NodeExistsError:
|
except exceptions.NodeExistsError:
|
||||||
raise coordination.GroupAlreadyExist(group_id)
|
raise coordination.GroupAlreadyExist(group_id)
|
||||||
|
@ -132,7 +133,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
raise coordination.ToozError("tooz namespace has not been created")
|
raise coordination.ToozError("tooz namespace has not been created")
|
||||||
except exceptions.ZookeeperError as e:
|
except exceptions.ZookeeperError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
def create_group(self, group_id):
|
def create_group(self, group_id):
|
||||||
|
@ -149,7 +150,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
async_result.get(block=True, timeout=timeout)
|
async_result.get(block=True, timeout=timeout)
|
||||||
except timeout_exception as e:
|
except timeout_exception as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.NoNodeError:
|
except exceptions.NoNodeError:
|
||||||
raise coordination.GroupNotCreated(group_id)
|
raise coordination.GroupNotCreated(group_id)
|
||||||
|
@ -157,7 +158,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
raise coordination.GroupNotEmpty(group_id)
|
raise coordination.GroupNotEmpty(group_id)
|
||||||
except exceptions.ZookeeperError as e:
|
except exceptions.ZookeeperError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
def delete_group(self, group_id):
|
def delete_group(self, group_id):
|
||||||
|
@ -174,7 +175,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
async_result.get(block=True, timeout=timeout)
|
async_result.get(block=True, timeout=timeout)
|
||||||
except timeout_exception as e:
|
except timeout_exception as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.NodeExistsError:
|
except exceptions.NodeExistsError:
|
||||||
raise coordination.MemberAlreadyExist(group_id, member_id)
|
raise coordination.MemberAlreadyExist(group_id, member_id)
|
||||||
|
@ -182,7 +183,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
raise coordination.GroupNotCreated(group_id)
|
raise coordination.GroupNotCreated(group_id)
|
||||||
except exceptions.ZookeeperError as e:
|
except exceptions.ZookeeperError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
def join_group(self, group_id, capabilities=b""):
|
def join_group(self, group_id, capabilities=b""):
|
||||||
|
@ -202,13 +203,13 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
async_result.get(block=True, timeout=timeout)
|
async_result.get(block=True, timeout=timeout)
|
||||||
except timeout_exception as e:
|
except timeout_exception as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.NoNodeError:
|
except exceptions.NoNodeError:
|
||||||
raise coordination.MemberNotJoined(group_id, member_id)
|
raise coordination.MemberNotJoined(group_id, member_id)
|
||||||
except exceptions.ZookeeperError as e:
|
except exceptions.ZookeeperError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
def leave_group(self, group_id):
|
def leave_group(self, group_id):
|
||||||
|
@ -225,13 +226,13 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
members_ids = async_result.get(block=True, timeout=timeout)
|
members_ids = async_result.get(block=True, timeout=timeout)
|
||||||
except timeout_exception as e:
|
except timeout_exception as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.NoNodeError:
|
except exceptions.NoNodeError:
|
||||||
raise coordination.GroupNotCreated(group_id)
|
raise coordination.GroupNotCreated(group_id)
|
||||||
except exceptions.ZookeeperError as e:
|
except exceptions.ZookeeperError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
else:
|
else:
|
||||||
return set(m.encode('ascii') for m in members_ids)
|
return set(m.encode('ascii') for m in members_ids)
|
||||||
|
@ -250,13 +251,13 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
async_result.get(block=True, timeout=timeout)
|
async_result.get(block=True, timeout=timeout)
|
||||||
except timeout_exception as e:
|
except timeout_exception as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.NoNodeError:
|
except exceptions.NoNodeError:
|
||||||
raise coordination.MemberNotJoined(group_id, member_id)
|
raise coordination.MemberNotJoined(group_id, member_id)
|
||||||
except exceptions.ZookeeperError as e:
|
except exceptions.ZookeeperError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
def update_capabilities(self, group_id, capabilities):
|
def update_capabilities(self, group_id, capabilities):
|
||||||
|
@ -275,13 +276,13 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
capabilities = async_result.get(block=True, timeout=timeout)[0]
|
capabilities = async_result.get(block=True, timeout=timeout)[0]
|
||||||
except timeout_exception as e:
|
except timeout_exception as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.NoNodeError:
|
except exceptions.NoNodeError:
|
||||||
raise coordination.MemberNotJoined(group_id, member_id)
|
raise coordination.MemberNotJoined(group_id, member_id)
|
||||||
except exceptions.ZookeeperError as e:
|
except exceptions.ZookeeperError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
else:
|
else:
|
||||||
return cls._loads(capabilities)
|
return cls._loads(capabilities)
|
||||||
|
@ -303,13 +304,13 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
timeout=timeout)
|
timeout=timeout)
|
||||||
except timeout_exception as e:
|
except timeout_exception as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.NoNodeError:
|
except exceptions.NoNodeError:
|
||||||
raise coordination.MemberNotJoined(group_id, member_id)
|
raise coordination.MemberNotJoined(group_id, member_id)
|
||||||
except exceptions.ZookeeperError as e:
|
except exceptions.ZookeeperError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
else:
|
else:
|
||||||
member_info = {
|
member_info = {
|
||||||
|
@ -333,13 +334,13 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||||
group_ids = async_result.get(block=True, timeout=timeout)
|
group_ids = async_result.get(block=True, timeout=timeout)
|
||||||
except timeout_exception as e:
|
except timeout_exception as e:
|
||||||
coordination.raise_with_cause(coordination.OperationTimedOut,
|
coordination.raise_with_cause(coordination.OperationTimedOut,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except exceptions.NoNodeError:
|
except exceptions.NoNodeError:
|
||||||
raise coordination.ToozError("tooz namespace has not been created")
|
raise coordination.ToozError("tooz namespace has not been created")
|
||||||
except exceptions.ZookeeperError as e:
|
except exceptions.ZookeeperError as e:
|
||||||
coordination.raise_with_cause(coordination.ToozError,
|
coordination.raise_with_cause(coordination.ToozError,
|
||||||
utils.exception_message(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
else:
|
else:
|
||||||
return set(g.encode('ascii') for g in group_ids)
|
return set(g.encode('ascii') for g in group_ids)
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from oslo_utils import encodeutils
|
||||||
import testtools
|
import testtools
|
||||||
from testtools import testcase
|
from testtools import testcase
|
||||||
|
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
from tooz import utils
|
|
||||||
|
|
||||||
|
|
||||||
@testtools.skipUnless(os.getenv("TOOZ_TEST_MYSQL_URL"),
|
@testtools.skipUnless(os.getenv("TOOZ_TEST_MYSQL_URL"),
|
||||||
|
@ -37,7 +37,7 @@ class TestMYSQLDriver(testcase.TestCase):
|
||||||
try:
|
try:
|
||||||
coord.stop()
|
coord.stop()
|
||||||
except coordination.ToozError as e:
|
except coordination.ToozError as e:
|
||||||
message = utils.exception_message(e)
|
message = encodeutils.exception_to_unicode(e)
|
||||||
if (message != 'Can not stop a driver which has not'
|
if (message != 'Can not stop a driver which has not'
|
||||||
' been started'):
|
' been started'):
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -22,11 +22,11 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
from oslo_utils import encodeutils
|
||||||
import testtools
|
import testtools
|
||||||
from testtools import testcase
|
from testtools import testcase
|
||||||
|
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
from tooz import utils
|
|
||||||
|
|
||||||
# Handle the case gracefully where the driver is not installed.
|
# Handle the case gracefully where the driver is not installed.
|
||||||
try:
|
try:
|
||||||
|
@ -51,7 +51,7 @@ class TestPostgreSQLFailures(testcase.TestCase):
|
||||||
except coordination.ToozError as e:
|
except coordination.ToozError as e:
|
||||||
# TODO(harlowja): make this better, so that we don't have to
|
# TODO(harlowja): make this better, so that we don't have to
|
||||||
# do string checking...
|
# do string checking...
|
||||||
message = utils.exception_message(e)
|
message = encodeutils.exception_to_unicode(e)
|
||||||
if (message != 'Can not stop a driver which has not'
|
if (message != 'Can not stop a driver which has not'
|
||||||
' been started'):
|
' been started'):
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -157,11 +157,6 @@ def collapse(config, exclude=None, item_selector=None):
|
||||||
return collapsed
|
return collapsed
|
||||||
|
|
||||||
|
|
||||||
# TODO(harlowja): get rid of this...
|
|
||||||
#: Return the string (unicode) representation of an exception.
|
|
||||||
exception_message = encodeutils.exception_to_unicode
|
|
||||||
|
|
||||||
|
|
||||||
def to_binary(text, encoding='ascii'):
|
def to_binary(text, encoding='ascii'):
|
||||||
"""Return the binary representation of string (if not already binary)."""
|
"""Return the binary representation of string (if not already binary)."""
|
||||||
if not isinstance(text, six.binary_type):
|
if not isinstance(text, six.binary_type):
|
||||||
|
@ -174,7 +169,8 @@ def dumps(data, excp_cls=coordination.SerializationError):
|
||||||
try:
|
try:
|
||||||
return msgpackutils.dumps(data)
|
return msgpackutils.dumps(data)
|
||||||
except (msgpack.PackException, ValueError) as e:
|
except (msgpack.PackException, ValueError) as e:
|
||||||
coordination.raise_with_cause(excp_cls, exception_message(e),
|
coordination.raise_with_cause(excp_cls,
|
||||||
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
|
|
||||||
|
@ -183,7 +179,8 @@ def loads(blob, excp_cls=coordination.SerializationError):
|
||||||
try:
|
try:
|
||||||
return msgpackutils.loads(blob)
|
return msgpackutils.loads(blob)
|
||||||
except (msgpack.UnpackException, ValueError) as e:
|
except (msgpack.UnpackException, ValueError) as e:
|
||||||
coordination.raise_with_cause(excp_cls, exception_message(e),
|
coordination.raise_with_cause(excp_cls,
|
||||||
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue