From 3981a3a3003b1d7df380f39c9ac1451e716a0c18 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 12 Sep 2014 11:19:09 +0200 Subject: [PATCH] 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 --- doc/source/tutorial/coordinator.rst | 2 +- tooz/__init__.py | 19 +++++++++++++++++++ tooz/coordination.py | 23 ++++++++++++----------- tooz/drivers/ipc.py | 13 +++++++------ tooz/drivers/zake.py | 15 ++++++++------- tooz/tests/__init__.py | 4 +++- 6 files changed, 50 insertions(+), 26 deletions(-) diff --git a/doc/source/tutorial/coordinator.rst b/doc/source/tutorial/coordinator.rst index 23d39cc6..37128463 100644 --- a/doc/source/tutorial/coordinator.rst +++ b/doc/source/tutorial/coordinator.rst @@ -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. diff --git a/tooz/__init__.py b/tooz/__init__.py index e69de29b..1de10ab1 100644 --- a/tooz/__init__.py +++ b/tooz/__init__.py @@ -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 diff --git a/tooz/coordination.py b/tooz/coordination.py index 98daabed..9d5d0547 100644 --- a/tooz/coordination.py +++ b/tooz/coordination.py @@ -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(): diff --git a/tooz/drivers/ipc.py b/tooz/drivers/ipc.py index 50cbbdad..0e2a0136 100644 --- a/tooz/drivers/ipc.py +++ b/tooz/drivers/ipc.py @@ -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 diff --git a/tooz/drivers/zake.py b/tooz/drivers/zake.py index 4e43ae11..5ca244e4 100644 --- a/tooz/drivers/zake.py +++ b/tooz/drivers/zake.py @@ -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 diff --git a/tooz/tests/__init__.py b/tooz/tests/__init__.py index 76e27a52..dde33f3b 100644 --- a/tooz/tests/__init__.py +++ b/tooz/tests/__init__.py @@ -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