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.
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
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
from stevedore import driver
import tooz
from tooz.openstack.common import network_utils
TOOZ_BACKENDS_NAMESPACE = "tooz.backends"
@ -75,7 +76,7 @@ class CoordinationDriver(object):
@staticmethod
def run_watchers():
"""Run the watchers callback."""
raise NotImplementedError
raise tooz.NotImplemented
@abc.abstractmethod
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
"""
raise NotImplementedError
raise tooz.NotImplemented
def start(self):
"""Start the service engine.
@ -192,7 +193,7 @@ class CoordinationDriver(object):
:returns: None
:rtype: CoordAsyncResult
"""
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def get_groups():
@ -201,7 +202,7 @@ class CoordinationDriver(object):
:returns: the list of all created group ids
:rtype: CoordAsyncResult
"""
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def join_group(group_id, capabilities=b""):
@ -214,7 +215,7 @@ class CoordinationDriver(object):
:returns: None
:rtype: CoordAsyncResult
"""
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def leave_group(group_id):
@ -225,7 +226,7 @@ class CoordinationDriver(object):
:returns: None
:rtype: CoordAsyncResult
"""
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def get_members(group_id):
@ -235,7 +236,7 @@ class CoordinationDriver(object):
:returns: list of all created group ids
:rtype: CoordAsyncResult
"""
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def get_member_capabilities(group_id, member_id):
@ -248,7 +249,7 @@ class CoordinationDriver(object):
:returns: capabilities of a member
:rtype: CoordAsyncResult
"""
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def update_capabilities(group_id, capabilities):
@ -262,7 +263,7 @@ class CoordinationDriver(object):
:returns: None
:rtype: CoordAsyncResult
"""
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def get_leader(group_id):
@ -272,7 +273,7 @@ class CoordinationDriver(object):
:returns: the leader
:rtype: CoordAsyncResult
"""
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def get_lock(name):
@ -282,7 +283,7 @@ class CoordinationDriver(object):
nodes.
"""
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def heartbeat():

View File

@ -17,6 +17,7 @@
# under the License.
import posix_ipc
import tooz
from tooz import coordination
from tooz import locking
from tooz.openstack.common import lockutils
@ -62,24 +63,24 @@ class IPCDriver(coordination.CoordinationDriver):
@staticmethod
def watch_join_group(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def unwatch_join_group(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def watch_leave_group(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def unwatch_leave_group(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def watch_elected_as_leader(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
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_storage
import tooz
from tooz.drivers import zookeeper
@ -35,28 +36,28 @@ class ZakeDriver(zookeeper.BaseZooKeeperDriver):
@staticmethod
def watch_join_group(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def unwatch_join_group(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def watch_leave_group(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def unwatch_leave_group(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def watch_elected_as_leader(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def unwatch_elected_as_leader(group_id, callback):
raise NotImplementedError
raise tooz.NotImplemented
@staticmethod
def run_watchers():
raise NotImplementedError
raise tooz.NotImplemented

View File

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