Move Zake driver code to separated Python module

That is needed to prevent Zake driver load in real-life Zookeeper
usage - currently we had the situation when even if you want to use
just KaZoo, you needed to install partially test-requierements
(zake package).

Change-Id: I9664fda2d6e76a6e48776b4a6d92af4c4baf1425
This commit is contained in:
Dina Belova 2014-08-26 12:18:49 +04:00 committed by Joshua Harlow
parent 54dd719079
commit faaeb41721
3 changed files with 63 additions and 44 deletions

View File

@ -25,7 +25,7 @@ packages =
[entry_points]
tooz.backends =
kazoo = tooz.drivers.zookeeper:KazooDriver
zake = tooz.drivers.zookeeper:ZakeDriver
zake = tooz.drivers.zake:ZakeDriver
memcached = tooz.drivers.memcached:MemcachedDriver
ipc = tooz.drivers.ipc:IPCDriver

62
tooz/drivers/zake.py Normal file
View File

@ -0,0 +1,62 @@
# Copyright (c) 2013-2014 Mirantis 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.
from __future__ import absolute_import
from zake import fake_client
from zake import fake_storage
from tooz.drivers import zookeeper
class ZakeDriver(zookeeper.BaseZooKeeperDriver):
"""The driver using the Zake client which mimic a fake Kazoo client
without the need of real ZooKeeper servers.
"""
# here we need to pass *threading handler* as an argument
fake_storage = fake_storage.FakeStorage(
fake_client.k_threading.SequentialThreadingHandler())
def __init__(self, member_id, parsed_url, options):
super(ZakeDriver, self).__init__(member_id, parsed_url, options)
self._coord = fake_client.FakeClient(storage=self.fake_storage)
@staticmethod
def watch_join_group(group_id, callback):
raise NotImplementedError
@staticmethod
def unwatch_join_group(group_id, callback):
raise NotImplementedError
@staticmethod
def watch_leave_group(group_id, callback):
raise NotImplementedError
@staticmethod
def unwatch_leave_group(group_id, callback):
raise NotImplementedError
@staticmethod
def watch_elected_as_leader(group_id, callback):
raise NotImplementedError
@staticmethod
def unwatch_elected_as_leader(group_id, callback):
raise NotImplementedError
@staticmethod
def run_watchers():
raise NotImplementedError

View File

@ -21,8 +21,6 @@ from kazoo import client
from kazoo import exceptions
from kazoo.protocol import paths
import six
import zake.fake_client
import zake.fake_storage
from tooz import coordination
from tooz import locking
@ -352,47 +350,6 @@ class KazooDriver(BaseZooKeeperDriver):
return ret
class ZakeDriver(BaseZooKeeperDriver):
"""The driver using the Zake client which mimic a fake Kazoo client
without the need of real ZooKeeper servers.
"""
fake_storage = zake.fake_storage.FakeStorage(
zake.fake_client.k_threading.SequentialThreadingHandler())
def __init__(self, member_id, parsed_url, options):
super(ZakeDriver, self).__init__(member_id, parsed_url, options)
self._coord = zake.fake_client.FakeClient(storage=self.fake_storage)
@staticmethod
def watch_join_group(group_id, callback):
raise NotImplementedError
@staticmethod
def unwatch_join_group(group_id, callback):
raise NotImplementedError
@staticmethod
def watch_leave_group(group_id, callback):
raise NotImplementedError
@staticmethod
def unwatch_leave_group(group_id, callback):
raise NotImplementedError
@staticmethod
def watch_elected_as_leader(group_id, callback):
raise NotImplementedError
@staticmethod
def unwatch_elected_as_leader(group_id, callback):
raise NotImplementedError
@staticmethod
def run_watchers():
raise NotImplementedError
class ZooAsyncResult(coordination.CoordAsyncResult):
def __init__(self, kazooAsyncResult, handler, **kwargs):