Switch to a custom NotImplemented error

Some code in the drivers might actually raise the standard
NotImplemented error, and that would be a bug to skip a test if that was
the case. In that case we want the test to fail.

So let's switch to a custom exception that is used to skip the test if
it's raised.

Change-Id: Ideafee0b1f008ff32724fb98d6a477bd3976104d
This commit is contained in:
Julien Danjou 2014-09-12 11:19:09 +02:00
parent 9b81673302
commit 3981a3a300
6 changed files with 50 additions and 26 deletions

View File

@ -12,7 +12,7 @@ driver you want it to use. Different drivers may provide different set of
capabilities. capabilities.
If a driver does not support a feature, it will raise a If a driver does not support a feature, it will raise a
:class:`~NotImplementedError` exception. :class:`~tooz.NotImplemented` exception.
This example program loads a basic coordinataor using the ZooKeeper based This example program loads a basic coordinataor using the ZooKeeper based
driver. driver.

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 eNovance Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
class NotImplemented(NotImplementedError):
pass

View File

@ -20,6 +20,7 @@ import collections
import six import six
from stevedore import driver from stevedore import driver
import tooz
from tooz.openstack.common import network_utils from tooz.openstack.common import network_utils
TOOZ_BACKENDS_NAMESPACE = "tooz.backends" TOOZ_BACKENDS_NAMESPACE = "tooz.backends"
@ -75,7 +76,7 @@ class CoordinationDriver(object):
@staticmethod @staticmethod
def run_watchers(): def run_watchers():
"""Run the watchers callback.""" """Run the watchers callback."""
raise NotImplementedError raise tooz.NotImplemented
@abc.abstractmethod @abc.abstractmethod
def watch_join_group(self, group_id, callback): def watch_join_group(self, group_id, callback):
@ -166,7 +167,7 @@ class CoordinationDriver(object):
:param group_id: The group where we don't want to be a leader anymore :param group_id: The group where we don't want to be a leader anymore
""" """
raise NotImplementedError raise tooz.NotImplemented
def start(self): def start(self):
"""Start the service engine. """Start the service engine.
@ -192,7 +193,7 @@ class CoordinationDriver(object):
:returns: None :returns: None
:rtype: CoordAsyncResult :rtype: CoordAsyncResult
""" """
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def get_groups(): def get_groups():
@ -201,7 +202,7 @@ class CoordinationDriver(object):
:returns: the list of all created group ids :returns: the list of all created group ids
:rtype: CoordAsyncResult :rtype: CoordAsyncResult
""" """
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def join_group(group_id, capabilities=b""): def join_group(group_id, capabilities=b""):
@ -214,7 +215,7 @@ class CoordinationDriver(object):
:returns: None :returns: None
:rtype: CoordAsyncResult :rtype: CoordAsyncResult
""" """
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def leave_group(group_id): def leave_group(group_id):
@ -225,7 +226,7 @@ class CoordinationDriver(object):
:returns: None :returns: None
:rtype: CoordAsyncResult :rtype: CoordAsyncResult
""" """
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def get_members(group_id): def get_members(group_id):
@ -235,7 +236,7 @@ class CoordinationDriver(object):
:returns: list of all created group ids :returns: list of all created group ids
:rtype: CoordAsyncResult :rtype: CoordAsyncResult
""" """
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def get_member_capabilities(group_id, member_id): def get_member_capabilities(group_id, member_id):
@ -248,7 +249,7 @@ class CoordinationDriver(object):
:returns: capabilities of a member :returns: capabilities of a member
:rtype: CoordAsyncResult :rtype: CoordAsyncResult
""" """
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def update_capabilities(group_id, capabilities): def update_capabilities(group_id, capabilities):
@ -262,7 +263,7 @@ class CoordinationDriver(object):
:returns: None :returns: None
:rtype: CoordAsyncResult :rtype: CoordAsyncResult
""" """
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def get_leader(group_id): def get_leader(group_id):
@ -272,7 +273,7 @@ class CoordinationDriver(object):
:returns: the leader :returns: the leader
:rtype: CoordAsyncResult :rtype: CoordAsyncResult
""" """
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def get_lock(name): def get_lock(name):
@ -282,7 +283,7 @@ class CoordinationDriver(object):
nodes. nodes.
""" """
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def heartbeat(): def heartbeat():

View File

@ -17,6 +17,7 @@
# under the License. # under the License.
import posix_ipc import posix_ipc
import tooz
from tooz import coordination from tooz import coordination
from tooz import locking from tooz import locking
from tooz.openstack.common import lockutils from tooz.openstack.common import lockutils
@ -62,24 +63,24 @@ class IPCDriver(coordination.CoordinationDriver):
@staticmethod @staticmethod
def watch_join_group(group_id, callback): def watch_join_group(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def unwatch_join_group(group_id, callback): def unwatch_join_group(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def watch_leave_group(group_id, callback): def watch_leave_group(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def unwatch_leave_group(group_id, callback): def unwatch_leave_group(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def watch_elected_as_leader(group_id, callback): def watch_elected_as_leader(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def unwatch_elected_as_leader(group_id, callback): def unwatch_elected_as_leader(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented

View File

@ -17,6 +17,7 @@ from __future__ import absolute_import
from zake import fake_client from zake import fake_client
from zake import fake_storage from zake import fake_storage
import tooz
from tooz.drivers import zookeeper from tooz.drivers import zookeeper
@ -35,28 +36,28 @@ class ZakeDriver(zookeeper.BaseZooKeeperDriver):
@staticmethod @staticmethod
def watch_join_group(group_id, callback): def watch_join_group(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def unwatch_join_group(group_id, callback): def unwatch_join_group(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def watch_leave_group(group_id, callback): def watch_leave_group(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def unwatch_leave_group(group_id, callback): def unwatch_leave_group(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def watch_elected_as_leader(group_id, callback): def watch_elected_as_leader(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def unwatch_elected_as_leader(group_id, callback): def unwatch_elected_as_leader(group_id, callback):
raise NotImplementedError raise tooz.NotImplemented
@staticmethod @staticmethod
def run_watchers(): def run_watchers():
raise NotImplementedError raise tooz.NotImplemented

View File

@ -19,13 +19,15 @@ import functools
import six import six
from testtools import testcase from testtools import testcase
import tooz
def _skip_decorator(func): def _skip_decorator(func):
@functools.wraps(func) @functools.wraps(func)
def skip_if_not_implemented(*args, **kwargs): def skip_if_not_implemented(*args, **kwargs):
try: try:
return func(*args, **kwargs) return func(*args, **kwargs)
except NotImplementedError as e: except tooz.NotImplemented as e:
raise testcase.TestSkipped(str(e)) raise testcase.TestSkipped(str(e))
return skip_if_not_implemented return skip_if_not_implemented