Move ToozError to root module

Change-Id: I73b1c5a37b75991f79d8a5fb383c605689503333
This commit is contained in:
Julien Danjou 2016-12-02 13:43:33 +01:00
parent bb20e9f8a8
commit 04866ab9c3
17 changed files with 100 additions and 86 deletions

View File

@ -71,7 +71,7 @@ Zookeeper
Exceptions Exceptions
---------- ----------
.. autoclass:: tooz.coordination.ToozError .. autoclass:: tooz.ToozError
.. autoclass:: tooz.coordination.ToozConnectionError .. autoclass:: tooz.coordination.ToozConnectionError
.. autoclass:: tooz.coordination.OperationTimedOut .. autoclass:: tooz.coordination.OperationTimedOut
.. autoclass:: tooz.coordination.GroupNotCreated .. autoclass:: tooz.coordination.GroupNotCreated

View File

@ -15,5 +15,22 @@
# under the License. # under the License.
class NotImplemented(NotImplementedError): class ToozError(Exception):
"""Exception raised when an internal error occurs.
Raised for instance in case of server internal error.
:ivar cause: the cause of the exception being raised, when not none this
will itself be an exception instance, this is useful for
creating a chain of exceptions for versions of python where
this is not yet implemented/supported natively.
"""
def __init__(self, message, cause=None):
super(ToozError, self).__init__(message)
self.cause = cause
class NotImplemented(NotImplementedError, ToozError):
pass pass

View File

@ -21,6 +21,7 @@ import enum
import logging import logging
import threading import threading
from debtcollector import moves
from oslo_utils import excutils from oslo_utils import excutils
from oslo_utils import netutils from oslo_utils import netutils
from oslo_utils import timeutils from oslo_utils import timeutils
@ -385,7 +386,7 @@ class CoordinationDriver(object):
is initiated. is initiated.
""" """
if self._started: if self._started:
raise ToozError( raise tooz.ToozError(
"Can not start a driver which has not been stopped") "Can not start a driver which has not been stopped")
self._start() self._start()
if self.requires_beating and start_heart: if self.requires_beating and start_heart:
@ -404,7 +405,8 @@ class CoordinationDriver(object):
disappear from all joined groups. disappear from all joined groups.
""" """
if not self._started: if not self._started:
raise ToozError("Can not stop a driver which has not been started") raise tooz.ToozError(
"Can not stop a driver which has not been started")
if self.heart.is_alive(): if self.heart.is_alive():
self.heart.stop() self.heart.stop()
self.heart.wait() self.heart.wait()
@ -415,7 +417,7 @@ class CoordinationDriver(object):
for fut in leaving: for fut in leaving:
try: try:
fut.get() fut.get()
except ToozError: except tooz.ToozError:
# Whatever happens, ignore. Maybe we got booted out/never # Whatever happens, ignore. Maybe we got booted out/never
# existed in the first place, or something is down, but we just # existed in the first place, or something is down, but we just
# want to call _stop after whatever happens to not leak any # want to call _stop after whatever happens to not leak any
@ -734,40 +736,28 @@ def get_coordinator(backend_url, member_id,
return d return d
class ToozError(Exception): @moves.moved_class(tooz.ToozError, "ToozError", "tooz.coordination")
"""Exception raised when an internal error occurs. class ToozError(tooz.ToozError):
pass
Raised for instance in case of server internal error.
:ivar cause: the cause of the exception being raised, when not none this
will itself be an exception instance, this is useful for
creating a chain of exceptions for versions of python where
this is not yet implemented/supported natively.
"""
def __init__(self, message, cause=None):
super(ToozError, self).__init__(message)
self.cause = cause
class ToozDriverChosenPoorly(ToozError): class ToozDriverChosenPoorly(tooz.ToozError):
"""Raised when a driver does not match desired characteristics.""" """Raised when a driver does not match desired characteristics."""
class ToozConnectionError(ToozError): class ToozConnectionError(tooz.ToozError):
"""Exception raised when the client cannot connect to the server.""" """Exception raised when the client cannot connect to the server."""
class OperationTimedOut(ToozError): class OperationTimedOut(tooz.ToozError):
"""Exception raised when an operation times out.""" """Exception raised when an operation times out."""
class LockAcquireFailed(ToozError): class LockAcquireFailed(tooz.ToozError):
"""Exception raised when a lock acquire fails in a context manager.""" """Exception raised when a lock acquire fails in a context manager."""
class GroupNotCreated(ToozError): class GroupNotCreated(tooz.ToozError):
"""Exception raised when the caller request an nonexistent group.""" """Exception raised when the caller request an nonexistent group."""
def __init__(self, group_id): def __init__(self, group_id):
self.group_id = group_id self.group_id = group_id
@ -775,7 +765,7 @@ class GroupNotCreated(ToozError):
"Group %s does not exist" % group_id) "Group %s does not exist" % group_id)
class GroupAlreadyExist(ToozError): class GroupAlreadyExist(tooz.ToozError):
"""Exception raised trying to create an already existing group.""" """Exception raised trying to create an already existing group."""
def __init__(self, group_id): def __init__(self, group_id):
self.group_id = group_id self.group_id = group_id
@ -783,7 +773,7 @@ class GroupAlreadyExist(ToozError):
"Group %s already exists" % group_id) "Group %s already exists" % group_id)
class MemberAlreadyExist(ToozError): class MemberAlreadyExist(tooz.ToozError):
"""Exception raised trying to join a group already joined.""" """Exception raised trying to join a group already joined."""
def __init__(self, group_id, member_id): def __init__(self, group_id, member_id):
self.group_id = group_id self.group_id = group_id
@ -793,7 +783,7 @@ class MemberAlreadyExist(ToozError):
(member_id, group_id)) (member_id, group_id))
class MemberNotJoined(ToozError): class MemberNotJoined(tooz.ToozError):
"""Exception raised trying to access a member not in a group.""" """Exception raised trying to access a member not in a group."""
def __init__(self, group_id, member_id): def __init__(self, group_id, member_id):
self.group_id = group_id self.group_id = group_id
@ -802,14 +792,14 @@ class MemberNotJoined(ToozError):
(member_id, group_id)) (member_id, group_id))
class GroupNotEmpty(ToozError): class GroupNotEmpty(tooz.ToozError):
"Exception raised when the caller try to delete a group with members." "Exception raised when the caller try to delete a group with members."
def __init__(self, group_id): def __init__(self, group_id):
self.group_id = group_id self.group_id = group_id
super(GroupNotEmpty, self).__init__("Group %s is not empty" % group_id) super(GroupNotEmpty, self).__init__("Group %s is not empty" % group_id)
class WatchCallbackNotFound(ToozError): class WatchCallbackNotFound(tooz.ToozError):
"""Exception raised when unwatching a group. """Exception raised when unwatching a group.
Raised when the caller tries to unwatch a group with a callback that Raised when the caller tries to unwatch a group with a callback that
@ -824,7 +814,7 @@ class WatchCallbackNotFound(ToozError):
(callback.__name__, group_id)) (callback.__name__, group_id))
class SerializationError(ToozError): class SerializationError(tooz.ToozError):
"Exception raised when serialization or deserialization breaks." "Exception raised when serialization or deserialization breaks."
@ -837,8 +827,7 @@ def raise_with_cause(exc_cls, message, *args, **kwargs):
:pep:`3134`) we should try to raise the desired exception with the given :pep:`3134`) we should try to raise the desired exception with the given
*cause*. *cause*.
:param exc_cls: the :py:class:`~tooz.coordination.ToozError` class :param exc_cls: the :py:class:`~tooz.ToozError` class to raise.
to raise.
:param message: the text/str message that will be passed to :param message: the text/str message that will be passed to
the exceptions constructor as its first positional the exceptions constructor as its first positional
argument. argument.
@ -847,6 +836,6 @@ def raise_with_cause(exc_cls, message, *args, **kwargs):
:param kwargs: any additional keyword arguments to pass to the :param kwargs: any additional keyword arguments to pass to the
exceptions constructor. exceptions constructor.
""" """
if not issubclass(exc_cls, ToozError): if not issubclass(exc_cls, tooz.ToozError):
raise ValueError("Subclass of tooz error is required") raise ValueError("Subclass of tooz error is required")
excutils.raise_with_cause(exc_cls, message, *args, **kwargs) excutils.raise_with_cause(exc_cls, message, *args, **kwargs)

View File

@ -21,6 +21,7 @@ from oslo_utils import timeutils
import requests import requests
import six import six
import tooz
from tooz import coordination from tooz import coordination
from tooz import locking from tooz import locking
from tooz import utils from tooz import utils
@ -38,7 +39,7 @@ def _translate_failures(func):
return func(*args, **kwargs) return func(*args, **kwargs)
except ValueError as e: except ValueError as e:
# Typically json decoding failed for some reason. # Typically json decoding failed for some reason.
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:

View File

@ -55,7 +55,7 @@ def _translate_failures():
try: try:
yield yield
except (EnvironmentError, voluptuous.Invalid) as e: except (EnvironmentError, voluptuous.Invalid) as e:
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
@ -445,7 +445,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers):
if len(entries) > 1: if len(entries) > 1:
raise coordination.GroupNotEmpty(group_id) raise coordination.GroupNotEmpty(group_id)
elif len(entries) == 1 and entries != ['.metadata']: elif len(entries) == 1 and entries != ['.metadata']:
raise coordination.ToozError( raise tooz.ToozError(
"Unexpected path '%s' found in" "Unexpected path '%s' found in"
" group directory '%s' (expected to only find" " group directory '%s' (expected to only find"
" a '.metadata' path)" % (entries[0], group_dir)) " a '.metadata' path)" % (entries[0], group_dir))

View File

@ -196,7 +196,7 @@ class IPCDriver(coordination.CoordinationDriver):
def _write_group_list(self, group_list): def _write_group_list(self, group_list):
data = msgpack.dumps(list(group_list)) data = msgpack.dumps(list(group_list))
if len(data) >= self._SEGMENT_SIZE - 2: if len(data) >= self._SEGMENT_SIZE - 2:
raise coordination.ToozError("Group list is too big") raise tooz.ToozError("Group list is too big")
self._group_list.write(struct.pack('H', len(data))) self._group_list.write(struct.pack('H', len(data)))
self._group_list.write(data, offset=2) self._group_list.write(data, offset=2)

View File

@ -23,6 +23,7 @@ from oslo_utils import encodeutils
from pymemcache import client as pymemcache_client from pymemcache import client as pymemcache_client
import six import six
import tooz
from tooz import _retry from tooz import _retry
from tooz import coordination from tooz import coordination
from tooz import locking from tooz import locking
@ -58,7 +59,7 @@ def _translate_failures(func):
coordination.raise_with_cause(coordination.ToozConnectionError, coordination.raise_with_cause(coordination.ToozConnectionError,
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(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)

View File

@ -64,7 +64,7 @@ class MySQLLock(locking.Lock):
return True return True
except pymysql.MySQLError as e: except pymysql.MySQLError as e:
coordination.raise_with_cause( coordination.raise_with_cause(
coordination.ToozError, tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
@ -84,7 +84,7 @@ class MySQLLock(locking.Lock):
self.acquired = False self.acquired = False
return True return True
except pymysql.MySQLError as e: except pymysql.MySQLError as e:
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)

View File

@ -85,7 +85,7 @@ def _translating_cursor(conn):
with conn.cursor() as cur: with conn.cursor() as cur:
yield cur yield cur
except psycopg2.Error as e: except psycopg2.Error as e:
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
_format_exception(e), _format_exception(e),
cause=e) cause=e)

View File

@ -49,7 +49,7 @@ def _translate_failures():
encodeutils.exception_to_unicode(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(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
@ -501,7 +501,7 @@ return 1
for lock in self._acquired_locks.copy(): for lock in self._acquired_locks.copy():
try: try:
lock.heartbeat() lock.heartbeat()
except coordination.ToozError: except tooz.ToozError:
LOG.warning("Unable to heartbeat lock '%s'", lock, LOG.warning("Unable to heartbeat lock '%s'", lock,
exc_info=True) exc_info=True)
return min(self.lock_timeout, self.membership_timeout) return min(self.lock_timeout, self.membership_timeout)
@ -511,7 +511,7 @@ return 1
lock = self._acquired_locks.pop() lock = self._acquired_locks.pop()
try: try:
lock.release() lock.release()
except coordination.ToozError: except tooz.ToozError:
LOG.warning("Unable to release lock '%s'", lock, exc_info=True) LOG.warning("Unable to release lock '%s'", lock, exc_info=True)
self._executor.stop() self._executor.stop()
if self._client is not None: if self._client is not None:
@ -522,7 +522,7 @@ return 1
# exist in the first place, which is fine/expected/desired... # exist in the first place, which is fine/expected/desired...
with _translate_failures(): with _translate_failures():
self._client.delete(beat_id) self._client.delete(beat_id)
except coordination.ToozError: except tooz.ToozError:
LOG.warning("Unable to delete heartbeat key '%s'", beat_id, LOG.warning("Unable to delete heartbeat key '%s'", beat_id,
exc_info=True) exc_info=True)
self._client = None self._client = None
@ -532,14 +532,14 @@ return 1
def _submit(self, cb, *args, **kwargs): def _submit(self, cb, *args, **kwargs):
if not self._started: if not self._started:
raise coordination.ToozError("Redis driver has not been started") raise tooz.ToozError("Redis driver has not been started")
return self._executor.submit(cb, *args, **kwargs) return self._executor.submit(cb, *args, **kwargs)
def _get_script(self, script_key): def _get_script(self, script_key):
try: try:
return self._scripts[script_key] return self._scripts[script_key]
except KeyError: except KeyError:
raise coordination.ToozError("Redis driver has not been started") raise tooz.ToozError("Redis driver has not been started")
def create_group(self, group_id): def create_group(self, group_id):
script = self._get_script('create_group') script = self._get_script('create_group')
@ -696,11 +696,11 @@ return 1
if result == -3: if result == -3:
raise coordination.GroupNotEmpty(group_id) raise coordination.GroupNotEmpty(group_id)
if result == -4: if result == -4:
raise coordination.ToozError("Unable to remove '%s' key" raise tooz.ToozError("Unable to remove '%s' key"
" from set located at '%s'" " from set located at '%s'"
% (args[0], keys[-1])) % (args[0], keys[-1]))
if result != 1: if result != 1:
raise coordination.ToozError("Internal error, unable" raise tooz.ToozError("Internal error, unable"
" to complete group '%s' removal" " to complete group '%s' removal"
% (group_id)) % (group_id))

View File

@ -30,6 +30,7 @@ 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
import tooz
from tooz import coordination from tooz import coordination
from tooz import locking from tooz import locking
from tooz import utils from tooz import utils
@ -54,7 +55,7 @@ class ZooKeeperLock(locking.Lock):
exceptions.NoNodeError): exceptions.NoNodeError):
return False return False
except exceptions.KazooException as e: except exceptions.KazooException as e:
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
"operation error: %s" % (e), "operation error: %s" % (e),
cause=e) cause=e)
@ -154,7 +155,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
self._coord.ensure_path(self._paths_join("/", self._namespace)) self._coord.ensure_path(self._paths_join("/", self._namespace))
except exceptions.KazooException as e: except exceptions.KazooException as e:
e_msg = encodeutils.exception_to_unicode(e) e_msg = encodeutils.exception_to_unicode(e)
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
"Operational error: %s" % e_msg, "Operational error: %s" % e_msg,
cause=e) cause=e)
self._watchers = collections.deque() self._watchers = collections.deque()
@ -182,12 +183,12 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
except exceptions.NodeExistsError: except exceptions.NodeExistsError:
raise coordination.GroupAlreadyExist(group_id) raise coordination.GroupAlreadyExist(group_id)
except exceptions.NoNodeError as e: except exceptions.NoNodeError as e:
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
"Tooz namespace '%s' has not" "Tooz namespace '%s' has not"
" been created" % self._namespace, " been created" % self._namespace,
cause=e) cause=e)
except exceptions.ZookeeperError as e: except exceptions.ZookeeperError as e:
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
@ -212,7 +213,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
except exceptions.NotEmptyError: except exceptions.NotEmptyError:
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(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
@ -237,7 +238,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
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(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
@ -263,7 +264,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
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(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
@ -281,7 +282,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
except exceptions.NoNodeError: except exceptions.NoNodeError:
pass pass
except exceptions.ZookeeperError as e: except exceptions.ZookeeperError as e:
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
return self.timeout return self.timeout
@ -305,7 +306,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
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(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
else: else:
@ -330,7 +331,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
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(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
@ -355,7 +356,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
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(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
else: else:
@ -383,7 +384,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
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(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
else: else:
@ -410,12 +411,12 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
except exceptions.NoNodeError as e: except exceptions.NoNodeError as e:
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
"Tooz namespace '%s' has not" "Tooz namespace '%s' has not"
" been created" % self._namespace, " been created" % self._namespace,
cause=e) cause=e)
except exceptions.ZookeeperError as e: except exceptions.ZookeeperError as e:
coordination.raise_with_cause(coordination.ToozError, coordination.raise_with_cause(tooz.ToozError,
encodeutils.exception_to_unicode(e), encodeutils.exception_to_unicode(e),
cause=e) cause=e)
else: else:

View File

@ -21,6 +21,7 @@ import fixtures
import mock import mock
from testtools import testcase from testtools import testcase
import tooz
from tooz import coordination from tooz import coordination
from tooz import tests from tooz import tests
@ -52,7 +53,7 @@ class TestFileDriver(testcase.TestCase):
pass pass
os.unlink(os.path.join(file_path, 'groups', os.unlink(os.path.join(file_path, 'groups',
safe_group_id, '.metadata')) safe_group_id, '.metadata'))
self.assertRaises(coordination.ToozError, self.assertRaises(tooz.ToozError,
coord.delete_group(b"my_group").get) coord.delete_group(b"my_group").get)
@mock.patch('os.path.normpath', lambda x: x.replace('/', '\\')) @mock.patch('os.path.normpath', lambda x: x.replace('/', '\\'))

View File

@ -25,6 +25,7 @@ from six.moves.urllib import parse
from testtools import matchers from testtools import matchers
from testtools import testcase from testtools import testcase
import tooz
import tooz.coordination import tooz.coordination
from tooz import tests from tooz import tests
@ -78,7 +79,7 @@ class TestAPI(tests.TestCaseSkipNotImplemented):
def test_stop_first(self): def test_stop_first(self):
c = tooz.coordination.get_coordinator(self.url, c = tooz.coordination.get_coordinator(self.url,
self.member_id) self.member_id)
self.assertRaises(tooz.coordination.ToozError, self.assertRaises(tooz.ToozError,
c.stop) c.stop)
def test_create_group(self): def test_create_group(self):

View File

@ -18,6 +18,7 @@
from oslo_utils import encodeutils from oslo_utils import encodeutils
from testtools import testcase from testtools import testcase
import tooz
from tooz import coordination from tooz import coordination
from tooz import tests from tooz import tests
@ -29,7 +30,7 @@ class TestMySQLDriver(testcase.TestCase):
def _safe_stop(coord): def _safe_stop(coord):
try: try:
coord.stop() coord.stop()
except coordination.ToozError as e: except tooz.ToozError as e:
message = encodeutils.exception_to_unicode(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'):

View File

@ -24,6 +24,7 @@ from oslo_utils import encodeutils
import testtools import testtools
from testtools import testcase from testtools import testcase
import tooz
from tooz import coordination from tooz import coordination
from tooz import tests from tooz import tests
@ -47,7 +48,7 @@ class TestPostgreSQLFailures(testcase.TestCase):
def _safe_stop(coord): def _safe_stop(coord):
try: try:
coord.stop() coord.stop()
except coordination.ToozError as e: except tooz.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 = encodeutils.exception_to_unicode(e) message = encodeutils.exception_to_unicode(e)
@ -88,7 +89,7 @@ class TestPostgreSQLFailures(testcase.TestCase):
c = self._create_coordinator() c = self._create_coordinator()
c.start() c.start()
test_lock = c.get_lock(b'test-lock') test_lock = c.get_lock(b'test-lock')
self.assertRaises(coordination.ToozError, test_lock.acquire) self.assertRaises(tooz.ToozError, test_lock.acquire)
@mock.patch("tooz.drivers.pgsql.psycopg2.connect") @mock.patch("tooz.drivers.pgsql.psycopg2.connect")
def test_failure_release_lock(self, psycopg2_connector): def test_failure_release_lock(self, psycopg2_connector):
@ -110,4 +111,4 @@ class TestPostgreSQLFailures(testcase.TestCase):
c.start() c.start()
test_lock = c.get_lock(b'test-lock') test_lock = c.get_lock(b'test-lock')
self.assertTrue(test_lock.acquire()) self.assertTrue(test_lock.acquire())
self.assertRaises(coordination.ToozError, test_lock.release) self.assertRaises(tooz.ToozError, test_lock.release)

View File

@ -22,7 +22,7 @@ import futurist
import six import six
from testtools import testcase from testtools import testcase
from tooz import coordination import tooz
from tooz import utils from tooz import utils
@ -54,13 +54,13 @@ class TestProxyExecutor(testcase.TestCase):
def test_fetch_unknown_executor(self): def test_fetch_unknown_executor(self):
options = {'executor': 'huh'} options = {'executor': 'huh'}
self.assertRaises(coordination.ToozError, self.assertRaises(tooz.ToozError,
utils.ProxyExecutor.build, 'test', utils.ProxyExecutor.build, 'test',
options) options)
def test_no_submit_stopped(self): def test_no_submit_stopped(self):
executor = utils.ProxyExecutor.build("test", {}) executor = utils.ProxyExecutor.build("test", {})
self.assertRaises(coordination.ToozError, self.assertRaises(tooz.ToozError,
executor.submit, lambda: None) executor.submit, lambda: None)

View File

@ -25,6 +25,7 @@ from oslo_serialization import msgpackutils
from oslo_utils import encodeutils from oslo_utils import encodeutils
import six import six
import tooz
from tooz import coordination from tooz import coordination
@ -82,7 +83,7 @@ class ProxyExecutor(object):
default_executor_fact = cls.KIND_TO_FACTORY[executor_kind] default_executor_fact = cls.KIND_TO_FACTORY[executor_kind]
except KeyError: except KeyError:
executors_known = sorted(list(cls.KIND_TO_FACTORY)) executors_known = sorted(list(cls.KIND_TO_FACTORY))
raise coordination.ToozError("Unknown executor" raise tooz.ToozError("Unknown executor"
" '%s' provided, accepted values" " '%s' provided, accepted values"
" are %s" % (executor_kind, " are %s" % (executor_kind,
executors_known)) executors_known))
@ -103,13 +104,13 @@ class ProxyExecutor(object):
def submit(self, cb, *args, **kwargs): def submit(self, cb, *args, **kwargs):
if not self.started: if not self.started:
raise coordination.ToozError("%s driver asynchronous executor" raise tooz.ToozError("%s driver asynchronous executor"
" has not been started" " has not been started"
% self.driver_name) % self.driver_name)
try: try:
return self.executor.submit(cb, *args, **kwargs) return self.executor.submit(cb, *args, **kwargs)
except RuntimeError: except RuntimeError:
raise coordination.ToozError("%s driver asynchronous executor has" raise tooz.ToozError("%s driver asynchronous executor has"
" been shutdown" % self.driver_name) " been shutdown" % self.driver_name)