Remove six library
The tooz project doesn't support Python 2 anymore, using the six library should not be necessary. Change-Id: I9886cabcd13cbc615065ceb372efbf037dff1aeb
This commit is contained in:
parent
80f379bfa2
commit
5ac72fcb3d
@ -1,14 +1,12 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
|
|
||||||
coordinator = coordination.get_coordinator('zake://', b'host-1')
|
coordinator = coordination.get_coordinator('zake://', b'host-1')
|
||||||
coordinator.start()
|
coordinator.start()
|
||||||
|
|
||||||
# Create a group
|
# Create a group
|
||||||
group = six.binary_type(six.text_type(uuid.uuid4()).encode('ascii'))
|
group = bytes(str(uuid.uuid4()).encode('ascii'))
|
||||||
request = coordinator.create_group(group)
|
request = coordinator.create_group(group)
|
||||||
request.get()
|
request.get()
|
||||||
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
|
|
||||||
coordinator = coordination.get_coordinator('zake://', b'host-1')
|
coordinator = coordination.get_coordinator('zake://', b'host-1')
|
||||||
coordinator.start()
|
coordinator.start()
|
||||||
|
|
||||||
# Create a group
|
# Create a group
|
||||||
group = six.binary_type(six.text_type(uuid.uuid4()).encode('ascii'))
|
group = bytes(str(uuid.uuid4()).encode('ascii'))
|
||||||
request = coordinator.create_group(group)
|
request = coordinator.create_group(group)
|
||||||
request.get()
|
request.get()
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
|
|
||||||
ALIVE_TIME = 1
|
ALIVE_TIME = 1
|
||||||
@ -10,7 +8,7 @@ coordinator = coordination.get_coordinator('zake://', b'host-1')
|
|||||||
coordinator.start()
|
coordinator.start()
|
||||||
|
|
||||||
# Create a group
|
# Create a group
|
||||||
group = six.binary_type(six.text_type(uuid.uuid4()).encode('ascii'))
|
group = bytes(str(uuid.uuid4()).encode('ascii'))
|
||||||
request = coordinator.create_group(group)
|
request = coordinator.create_group(group)
|
||||||
request.get()
|
request.get()
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
# process, which may cause wedges in the gate later.
|
# process, which may cause wedges in the gate later.
|
||||||
pbr>=1.6 # Apache-2.0
|
pbr>=1.6 # Apache-2.0
|
||||||
stevedore>=1.16.0 # Apache-2.0
|
stevedore>=1.16.0 # Apache-2.0
|
||||||
six>=1.9.0 # MIT
|
|
||||||
voluptuous>=0.8.9 # BSD License
|
voluptuous>=0.8.9 # BSD License
|
||||||
msgpack>=0.4.0 # Apache-2.0
|
msgpack>=0.4.0 # Apache-2.0
|
||||||
fasteners>=0.7 # Apache-2.0
|
fasteners>=0.7 # Apache-2.0
|
||||||
|
@ -21,11 +21,11 @@ from concurrent import futures
|
|||||||
import enum
|
import enum
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
import urllib
|
||||||
|
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import netutils
|
from oslo_utils import netutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import six
|
|
||||||
from stevedore import driver
|
from stevedore import driver
|
||||||
import tenacity
|
import tenacity
|
||||||
|
|
||||||
@ -629,8 +629,7 @@ class CoordinationDriver(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class CoordAsyncResult(object, metaclass=abc.ABCMeta):
|
||||||
class CoordAsyncResult(object):
|
|
||||||
"""Representation of an asynchronous task.
|
"""Representation of an asynchronous task.
|
||||||
|
|
||||||
Every call API returns an CoordAsyncResult object on which the result or
|
Every call API returns an CoordAsyncResult object on which the result or
|
||||||
@ -786,12 +785,12 @@ def get_coordinator(backend_url, member_id,
|
|||||||
arguments query string)
|
arguments query string)
|
||||||
"""
|
"""
|
||||||
parsed_url = netutils.urlsplit(backend_url)
|
parsed_url = netutils.urlsplit(backend_url)
|
||||||
parsed_qs = six.moves.urllib.parse.parse_qs(parsed_url.query)
|
parsed_qs = urllib.parse.parse_qs(parsed_url.query)
|
||||||
if kwargs:
|
if kwargs:
|
||||||
options = {}
|
options = {}
|
||||||
for (k, v) in six.iteritems(kwargs):
|
for (k, v) in kwargs.items():
|
||||||
options[k] = [v]
|
options[k] = [v]
|
||||||
for (k, v) in six.iteritems(parsed_qs):
|
for (k, v) in parsed_qs.items():
|
||||||
if k not in options:
|
if k not in options:
|
||||||
options[k] = v
|
options[k] = v
|
||||||
else:
|
else:
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
@ -19,7 +20,6 @@ import fasteners
|
|||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import requests
|
import requests
|
||||||
import six
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
@ -33,7 +33,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
def _translate_failures(func):
|
def _translate_failures(func):
|
||||||
"""Translates common requests exceptions into tooz exceptions."""
|
"""Translates common requests exceptions into tooz exceptions."""
|
||||||
|
|
||||||
@six.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
@ -18,7 +18,6 @@ import threading
|
|||||||
import etcd3
|
import etcd3
|
||||||
from etcd3 import exceptions as etcd3_exc
|
from etcd3 import exceptions as etcd3_exc
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
import six
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
from tooz import _retry
|
from tooz import _retry
|
||||||
@ -48,7 +47,7 @@ def _failure_translator():
|
|||||||
|
|
||||||
def _translate_failures(func):
|
def _translate_failures(func):
|
||||||
|
|
||||||
@six.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
with _failure_translator():
|
with _failure_translator():
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
@ -11,14 +11,15 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import functools
|
||||||
import threading
|
import threading
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import etcd3gw
|
import etcd3gw
|
||||||
from etcd3gw import exceptions as etcd3_exc
|
from etcd3gw import exceptions as etcd3_exc
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
import six
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
from tooz import _retry
|
from tooz import _retry
|
||||||
@ -35,7 +36,7 @@ def _encode(data):
|
|||||||
def _translate_failures(func):
|
def _translate_failures(func):
|
||||||
"""Translates common requests exceptions into tooz exceptions."""
|
"""Translates common requests exceptions into tooz exceptions."""
|
||||||
|
|
||||||
@six.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
@ -32,7 +32,6 @@ import fasteners
|
|||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import fileutils
|
from oslo_utils import fileutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import six
|
|
||||||
import voluptuous
|
import voluptuous
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
@ -74,7 +73,7 @@ def _convert_from_old_format(data):
|
|||||||
# example of potential old python3 payload:
|
# example of potential old python3 payload:
|
||||||
# {u"member_id": b"member"}
|
# {u"member_id": b"member"}
|
||||||
# {u"member_id": u"member"}
|
# {u"member_id": u"member"}
|
||||||
if six.PY3 and b"member_id" in data or b"group_id" in data:
|
if b"member_id" in data or b"group_id" in data:
|
||||||
data = dict((k.decode("utf8"), v) for k, v in data.items())
|
data = dict((k.decode("utf8"), v) for k, v in data.items())
|
||||||
# About member_id and group_id valuse if the file have been written
|
# About member_id and group_id valuse if the file have been written
|
||||||
# with python2 and in the old format, we can't known with python3
|
# with python2 and in the old format, we can't known with python3
|
||||||
@ -91,7 +90,7 @@ def _lock_me(lock):
|
|||||||
|
|
||||||
def wrapper(func):
|
def wrapper(func):
|
||||||
|
|
||||||
@six.wraps(func)
|
@functools.wraps(func)
|
||||||
def decorator(*args, **kwargs):
|
def decorator(*args, **kwargs):
|
||||||
with lock:
|
with lock:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
@ -361,14 +360,12 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
|
|
||||||
_SCHEMAS = {
|
_SCHEMAS = {
|
||||||
'group': voluptuous.Schema({
|
'group': voluptuous.Schema({
|
||||||
voluptuous.Required('group_id'): voluptuous.Any(six.text_type,
|
voluptuous.Required('group_id'): voluptuous.Any(str, bytes),
|
||||||
six.binary_type),
|
|
||||||
# NOTE(sileht): tooz <1.36 was creating file without this
|
# NOTE(sileht): tooz <1.36 was creating file without this
|
||||||
voluptuous.Optional('encoded'): bool,
|
voluptuous.Optional('encoded'): bool,
|
||||||
}),
|
}),
|
||||||
'member': voluptuous.Schema({
|
'member': voluptuous.Schema({
|
||||||
voluptuous.Required('member_id'): voluptuous.Any(six.text_type,
|
voluptuous.Required('member_id'): voluptuous.Any(str, bytes),
|
||||||
six.binary_type),
|
|
||||||
voluptuous.Required('joined_on'): datetime.datetime,
|
voluptuous.Required('joined_on'): datetime.datetime,
|
||||||
# NOTE(sileht): tooz <1.36 was creating file without this
|
# NOTE(sileht): tooz <1.36 was creating file without this
|
||||||
voluptuous.Optional('encoded'): bool,
|
voluptuous.Optional('encoded'): bool,
|
||||||
|
@ -19,7 +19,6 @@ import struct
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import msgpack
|
import msgpack
|
||||||
import six
|
|
||||||
import sysv_ipc
|
import sysv_ipc
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
@ -37,10 +36,10 @@ def ftok(name, project):
|
|||||||
# Similar to ftok & http://semanchuk.com/philip/sysv_ipc/#ftok_weakness
|
# Similar to ftok & http://semanchuk.com/philip/sysv_ipc/#ftok_weakness
|
||||||
# but hopefully without as many weaknesses...
|
# but hopefully without as many weaknesses...
|
||||||
h = hashlib.md5()
|
h = hashlib.md5()
|
||||||
if not isinstance(project, six.binary_type):
|
if not isinstance(project, bytes):
|
||||||
project = project.encode('ascii')
|
project = project.encode('ascii')
|
||||||
h.update(project)
|
h.update(project)
|
||||||
if not isinstance(name, six.binary_type):
|
if not isinstance(name, bytes):
|
||||||
name = name.encode('ascii')
|
name = name.encode('ascii')
|
||||||
h.update(name)
|
h.update(name)
|
||||||
return (int(h.hexdigest(), 16) % _KEY_RANGE) + sysv_ipc.KEY_MIN
|
return (int(h.hexdigest(), 16) % _KEY_RANGE) + sysv_ipc.KEY_MIN
|
||||||
|
@ -22,7 +22,6 @@ import socket
|
|||||||
|
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from pymemcache import client as pymemcache_client
|
from pymemcache import client as pymemcache_client
|
||||||
import six
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
from tooz import _retry
|
from tooz import _retry
|
||||||
@ -65,7 +64,7 @@ def _failure_translator():
|
|||||||
|
|
||||||
def _translate_failures(func):
|
def _translate_failures(func):
|
||||||
|
|
||||||
@six.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
with _failure_translator():
|
with _failure_translator():
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
@ -266,7 +265,7 @@ class MemcachedDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _msgpack_serializer(key, value):
|
def _msgpack_serializer(key, value):
|
||||||
if isinstance(value, six.binary_type):
|
if isinstance(value, bytes):
|
||||||
return value, 1
|
return value, 1
|
||||||
return utils.dumps(value), 2
|
return utils.dumps(value), 2
|
||||||
|
|
||||||
@ -435,7 +434,7 @@ class MemcachedDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
if group_members is None:
|
if group_members is None:
|
||||||
raise coordination.GroupNotCreated(group_id)
|
raise coordination.GroupNotCreated(group_id)
|
||||||
actual_group_members = {}
|
actual_group_members = {}
|
||||||
for m, v in six.iteritems(group_members):
|
for m, v in group_members.items():
|
||||||
# Never kick self from the group, we know we're alive
|
# Never kick self from the group, we know we're alive
|
||||||
if (m == self._member_id or
|
if (m == self._member_id or
|
||||||
self.client.get(self._encode_member_id(m))):
|
self.client.get(self._encode_member_id(m))):
|
||||||
@ -512,7 +511,7 @@ class MemcachedDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
|
|
||||||
@_translate_failures
|
@_translate_failures
|
||||||
def run_elect_coordinator(self):
|
def run_elect_coordinator(self):
|
||||||
for group_id, hooks in six.iteritems(self._hooks_elected_leader):
|
for group_id, hooks in self._hooks_elected_leader.items():
|
||||||
# Try to grab the lock, if that fails, that means someone has it
|
# Try to grab the lock, if that fails, that means someone has it
|
||||||
# already.
|
# already.
|
||||||
leader_lock = self._get_leader_lock(group_id)
|
leader_lock = self._get_leader_lock(group_id)
|
||||||
|
@ -20,7 +20,6 @@ import logging
|
|||||||
|
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import six
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
from tooz import _retry
|
from tooz import _retry
|
||||||
@ -101,10 +100,7 @@ class PostgresLock(locking.Lock):
|
|||||||
self._options = options
|
self._options = options
|
||||||
h = hashlib.md5()
|
h = hashlib.md5()
|
||||||
h.update(name)
|
h.update(name)
|
||||||
if six.PY2:
|
self.key = h.digest()[0:2]
|
||||||
self.key = list(map(ord, h.digest()[0:2]))
|
|
||||||
else:
|
|
||||||
self.key = h.digest()[0:2]
|
|
||||||
|
|
||||||
def acquire(self, blocking=True, shared=False):
|
def acquire(self, blocking=True, shared=False):
|
||||||
|
|
||||||
|
@ -26,9 +26,6 @@ from oslo_utils import strutils
|
|||||||
import redis
|
import redis
|
||||||
from redis import exceptions
|
from redis import exceptions
|
||||||
from redis import sentinel
|
from redis import sentinel
|
||||||
import six
|
|
||||||
from six.moves import map as compat_map
|
|
||||||
from six.moves import zip as compat_zip
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
@ -55,7 +52,7 @@ def _translate_failures():
|
|||||||
|
|
||||||
class RedisLock(locking.Lock):
|
class RedisLock(locking.Lock):
|
||||||
def __init__(self, coord, client, name, timeout):
|
def __init__(self, coord, client, name, timeout):
|
||||||
name = "%s_%s_lock" % (coord.namespace, six.text_type(name))
|
name = "%s_%s_lock" % (coord.namespace, str(name))
|
||||||
super(RedisLock, self).__init__(name)
|
super(RedisLock, self).__init__(name)
|
||||||
# NOTE(jd) Make sure we don't release and heartbeat at the same time by
|
# NOTE(jd) Make sure we don't release and heartbeat at the same time by
|
||||||
# using a exclusive access lock (LP#1557593)
|
# using a exclusive access lock (LP#1557593)
|
||||||
@ -356,7 +353,7 @@ return 1
|
|||||||
self._scripts = {}
|
self._scripts = {}
|
||||||
|
|
||||||
def _check_fetch_redis_version(self, geq_version, not_existent=True):
|
def _check_fetch_redis_version(self, geq_version, not_existent=True):
|
||||||
if isinstance(geq_version, six.string_types):
|
if isinstance(geq_version, str):
|
||||||
desired_version = version.LooseVersion(geq_version)
|
desired_version = version.LooseVersion(geq_version)
|
||||||
elif isinstance(geq_version, version.LooseVersion):
|
elif isinstance(geq_version, version.LooseVersion):
|
||||||
desired_version = geq_version
|
desired_version = geq_version
|
||||||
@ -470,12 +467,12 @@ return 1
|
|||||||
# For py3.x ensure these are unicode since the string template
|
# For py3.x ensure these are unicode since the string template
|
||||||
# replacement will expect unicode (and we don't want b'' as a
|
# replacement will expect unicode (and we don't want b'' as a
|
||||||
# prefix which will happen in py3.x if this is not done).
|
# prefix which will happen in py3.x if this is not done).
|
||||||
for (k, v) in six.iteritems(tpl_params.copy()):
|
for (k, v) in tpl_params.copy().items():
|
||||||
if isinstance(v, six.binary_type):
|
if isinstance(v, bytes):
|
||||||
v = v.decode('ascii')
|
v = v.decode('ascii')
|
||||||
tpl_params[k] = v
|
tpl_params[k] = v
|
||||||
prepared_scripts = {}
|
prepared_scripts = {}
|
||||||
for name, raw_script_tpl in six.iteritems(self.SCRIPTS):
|
for name, raw_script_tpl in self.SCRIPTS.items():
|
||||||
script_tpl = string.Template(raw_script_tpl)
|
script_tpl = string.Template(raw_script_tpl)
|
||||||
script = script_tpl.substitute(**tpl_params)
|
script = script_tpl.substitute(**tpl_params)
|
||||||
prepared_scripts[name] = self._client.register_script(script)
|
prepared_scripts[name] = self._client.register_script(script)
|
||||||
@ -630,10 +627,10 @@ return 1
|
|||||||
return set()
|
return set()
|
||||||
# Ok now we need to see which members have passed away...
|
# Ok now we need to see which members have passed away...
|
||||||
gone_members = set()
|
gone_members = set()
|
||||||
member_values = p.mget(compat_map(self._encode_beat_id,
|
member_values = p.mget(map(self._encode_beat_id,
|
||||||
potential_members))
|
potential_members))
|
||||||
for (potential_member, value) in compat_zip(potential_members,
|
for (potential_member, value) in zip(potential_members,
|
||||||
member_values):
|
member_values):
|
||||||
# Always preserve self (just incase we haven't heartbeated
|
# Always preserve self (just incase we haven't heartbeated
|
||||||
# while this call/s was being made...), this does *not* prevent
|
# while this call/s was being made...), this does *not* prevent
|
||||||
# another client from removing this though...
|
# another client from removing this though...
|
||||||
@ -742,7 +739,7 @@ return 1
|
|||||||
return self.get_lock(name)
|
return self.get_lock(name)
|
||||||
|
|
||||||
def run_elect_coordinator(self):
|
def run_elect_coordinator(self):
|
||||||
for group_id, hooks in six.iteritems(self._hooks_elected_leader):
|
for group_id, hooks in self._hooks_elected_leader.items():
|
||||||
leader_lock = self._get_leader_lock(group_id)
|
leader_lock = self._get_leader_lock(group_id)
|
||||||
if leader_lock.acquire(blocking=False):
|
if leader_lock.acquire(blocking=False):
|
||||||
# We got the lock
|
# We got the lock
|
||||||
|
@ -25,8 +25,6 @@ from kazoo.handlers import threading as threading_handler
|
|||||||
from kazoo.protocol import paths
|
from kazoo.protocol import paths
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
import six
|
|
||||||
from six.moves import filter as compat_filter
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
@ -444,7 +442,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
|
|||||||
args.extend(more_args)
|
args.extend(more_args)
|
||||||
cleaned_args = []
|
cleaned_args = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if isinstance(arg, six.binary_type):
|
if isinstance(arg, bytes):
|
||||||
cleaned_args.append(arg.decode('ascii'))
|
cleaned_args.append(arg.decode('ascii'))
|
||||||
else:
|
else:
|
||||||
cleaned_args.append(arg)
|
cleaned_args.append(arg)
|
||||||
@ -467,7 +465,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
|
|||||||
auth_data = None
|
auth_data = None
|
||||||
|
|
||||||
maybe_hosts = [parsed_url.netloc] + list(options.get('hosts', []))
|
maybe_hosts = [parsed_url.netloc] + list(options.get('hosts', []))
|
||||||
hosts = list(compat_filter(None, maybe_hosts))
|
hosts = list(filter(None, maybe_hosts))
|
||||||
if not hosts:
|
if not hosts:
|
||||||
hosts = ['localhost:2181']
|
hosts = ['localhost:2181']
|
||||||
randomize_hosts = options.get('randomize_hosts', True)
|
randomize_hosts = options.get('randomize_hosts', True)
|
||||||
@ -520,7 +518,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
|
|||||||
return ZooKeeperLock(name, z_lock)
|
return ZooKeeperLock(name, z_lock)
|
||||||
|
|
||||||
def run_elect_coordinator(self):
|
def run_elect_coordinator(self):
|
||||||
for group_id in six.iterkeys(self._hooks_elected_leader):
|
for group_id in self._hooks_elected_leader.keys():
|
||||||
leader_lock = self._get_group_leader_lock(group_id)
|
leader_lock = self._get_group_leader_lock(group_id)
|
||||||
if leader_lock.is_acquired:
|
if leader_lock.is_acquired:
|
||||||
# Previously acquired/still leader, leave it be...
|
# Previously acquired/still leader, leave it be...
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
import bisect
|
import bisect
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
from tooz import utils
|
from tooz import utils
|
||||||
|
|
||||||
@ -71,7 +69,7 @@ class HashRing(object):
|
|||||||
for node in nodes:
|
for node in nodes:
|
||||||
key = utils.to_binary(node, 'utf-8')
|
key = utils.to_binary(node, 'utf-8')
|
||||||
key_hash = hashlib.md5(key)
|
key_hash = hashlib.md5(key)
|
||||||
for r in six.moves.range(self._partition_number * weight):
|
for r in range(self._partition_number * weight):
|
||||||
key_hash.update(key)
|
key_hash.update(key)
|
||||||
self._ring[self._hash2int(key_hash)] = node
|
self._ring[self._hash2int(key_hash)] = node
|
||||||
|
|
||||||
@ -93,7 +91,7 @@ class HashRing(object):
|
|||||||
|
|
||||||
key = utils.to_binary(node, 'utf-8')
|
key = utils.to_binary(node, 'utf-8')
|
||||||
key_hash = hashlib.md5(key)
|
key_hash = hashlib.md5(key)
|
||||||
for r in six.moves.range(self._partition_number * weight):
|
for r in range(self._partition_number * weight):
|
||||||
key_hash.update(key)
|
key_hash.update(key)
|
||||||
del self._ring[self._hash2int(key_hash)]
|
del self._ring[self._hash2int(key_hash)]
|
||||||
|
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
|
|
||||||
@ -34,8 +32,7 @@ class _LockProxy(object):
|
|||||||
self.lock.__exit__(exc_type, exc_val, exc_tb)
|
self.lock.__exit__(exc_type, exc_val, exc_tb)
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class Lock(object, metaclass=abc.ABCMeta):
|
||||||
class Lock(object):
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
if not name:
|
if not name:
|
||||||
raise ValueError("Locks must be provided a name")
|
raise ValueError("Locks must be provided a name")
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
import six
|
|
||||||
from tooz import hashring
|
from tooz import hashring
|
||||||
|
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class Partitioner(object):
|
|||||||
def _hash_object(obj):
|
def _hash_object(obj):
|
||||||
if hasattr(obj, "__tooz_hash__"):
|
if hasattr(obj, "__tooz_hash__"):
|
||||||
return obj.__tooz_hash__()
|
return obj.__tooz_hash__()
|
||||||
return six.text_type(obj).encode('utf8')
|
return str(obj).encode('utf8')
|
||||||
|
|
||||||
def members_for_object(self, obj, ignore_members=None, replicas=1):
|
def members_for_object(self, obj, ignore_members=None, replicas=1):
|
||||||
"""Return the members responsible for an object.
|
"""Return the members responsible for an object.
|
||||||
|
@ -19,7 +19,6 @@ import os
|
|||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
import six
|
|
||||||
from testtools import testcase
|
from testtools import testcase
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
@ -49,8 +48,7 @@ class SkipNotImplementedMeta(type):
|
|||||||
return type.__new__(cls, name, bases, local)
|
return type.__new__(cls, name, bases, local)
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(SkipNotImplementedMeta)
|
class TestWithCoordinator(testcase.TestCase, metaclass=SkipNotImplementedMeta):
|
||||||
class TestWithCoordinator(testcase.TestCase):
|
|
||||||
url = os.getenv("TOOZ_TEST_URL")
|
url = os.getenv("TOOZ_TEST_URL")
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
import urllib
|
||||||
|
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
from six.moves.urllib import parse
|
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
from testtools import testcase
|
from testtools import testcase
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ class TestAPI(tests.TestWithCoordinator):
|
|||||||
if (tooz.coordination.Characteristics.DISTRIBUTED_ACROSS_HOSTS
|
if (tooz.coordination.Characteristics.DISTRIBUTED_ACROSS_HOSTS
|
||||||
not in self._coord.CHARACTERISTICS):
|
not in self._coord.CHARACTERISTICS):
|
||||||
self.skipTest("This driver is not distributed across hosts")
|
self.skipTest("This driver is not distributed across hosts")
|
||||||
scheme = parse.urlparse(self.url).scheme
|
scheme = urllib.parse.urlparse(self.url).scheme
|
||||||
coord = tooz.coordination.get_coordinator(
|
coord = tooz.coordination.get_coordinator(
|
||||||
"%s://localhost:1/f00" % scheme,
|
"%s://localhost:1/f00" % scheme,
|
||||||
self.member_id)
|
self.member_id)
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
import six
|
|
||||||
|
|
||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
from tooz import tests
|
from tooz import tests
|
||||||
@ -32,7 +31,7 @@ class TestPartitioner(tests.TestWithCoordinator):
|
|||||||
|
|
||||||
def _add_members(self, number_of_members, weight=1):
|
def _add_members(self, number_of_members, weight=1):
|
||||||
groups = []
|
groups = []
|
||||||
for _ in six.moves.range(number_of_members):
|
for _ in range(number_of_members):
|
||||||
m = tests.get_random_uuid()
|
m = tests.get_random_uuid()
|
||||||
coord = coordination.get_coordinator(self.url, m)
|
coord = coordination.get_coordinator(self.url, m)
|
||||||
coord.start()
|
coord.start()
|
||||||
@ -43,7 +42,7 @@ class TestPartitioner(tests.TestWithCoordinator):
|
|||||||
return groups
|
return groups
|
||||||
|
|
||||||
def _remove_members(self, number_of_members):
|
def _remove_members(self, number_of_members):
|
||||||
for _ in six.moves.range(number_of_members):
|
for _ in range(number_of_members):
|
||||||
c = self._extra_coords.pop()
|
c = self._extra_coords.pop()
|
||||||
c.stop()
|
c.stop()
|
||||||
self._coord.run_watchers()
|
self._coord.run_watchers()
|
||||||
@ -80,7 +79,7 @@ class TestPartitioner(tests.TestWithCoordinator):
|
|||||||
def test_members_of_object_and_others(self):
|
def test_members_of_object_and_others(self):
|
||||||
p = self._coord.join_partitioned_group(self.group_id)
|
p = self._coord.join_partitioned_group(self.group_id)
|
||||||
self._add_members(3)
|
self._add_members(3)
|
||||||
o = six.text_type(u"чупакабра")
|
o = str(u"чупакабра")
|
||||||
m = p.members_for_object(o)
|
m = p.members_for_object(o)
|
||||||
self.assertEqual(1, len(m))
|
self.assertEqual(1, len(m))
|
||||||
m = m.pop()
|
m = m.pop()
|
||||||
|
@ -19,7 +19,6 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import futurist
|
import futurist
|
||||||
import six
|
|
||||||
from testtools import testcase
|
from testtools import testcase
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
@ -113,7 +112,7 @@ class TestUtilsCollapse(testcase.TestCase):
|
|||||||
'b': [2],
|
'b': [2],
|
||||||
'c': (1, 2, 3),
|
'c': (1, 2, 3),
|
||||||
}
|
}
|
||||||
c_ex = utils.collapse(ex, exclude=set(six.iterkeys(ex)))
|
c_ex = utils.collapse(ex, exclude=set(ex.keys()))
|
||||||
self.assertEqual(ex, c_ex)
|
self.assertEqual(ex, c_ex)
|
||||||
|
|
||||||
def test_custom_selector(self):
|
def test_custom_selector(self):
|
||||||
|
@ -24,7 +24,6 @@ import msgpack
|
|||||||
from oslo_serialization import msgpackutils
|
from oslo_serialization import msgpackutils
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
import six
|
|
||||||
|
|
||||||
import tooz
|
import tooz
|
||||||
|
|
||||||
@ -36,7 +35,7 @@ class Base64LockEncoder(object):
|
|||||||
self.keyspace_url += prefix
|
self.keyspace_url += prefix
|
||||||
|
|
||||||
def check_and_encode(self, name):
|
def check_and_encode(self, name):
|
||||||
if not isinstance(name, (six.text_type, six.binary_type)):
|
if not isinstance(name, (str, bytes)):
|
||||||
raise TypeError("Provided lock name is expected to be a string"
|
raise TypeError("Provided lock name is expected to be a string"
|
||||||
" or binary type and not %s" % type(name))
|
" or binary type and not %s" % type(name))
|
||||||
try:
|
try:
|
||||||
@ -47,7 +46,7 @@ class Base64LockEncoder(object):
|
|||||||
% encodeutils.exception_to_unicode(e))
|
% encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
def encode(self, name):
|
def encode(self, name):
|
||||||
if isinstance(name, six.text_type):
|
if isinstance(name, str):
|
||||||
name = name.encode("ascii")
|
name = name.encode("ascii")
|
||||||
enc_name = base64.urlsafe_b64encode(name)
|
enc_name = base64.urlsafe_b64encode(name)
|
||||||
return self.keyspace_url + "/" + enc_name.decode("ascii")
|
return self.keyspace_url + "/" + enc_name.decode("ascii")
|
||||||
@ -154,7 +153,7 @@ def collapse(config, exclude=None, item_selector=operator.itemgetter(-1)):
|
|||||||
if exclude is None:
|
if exclude is None:
|
||||||
exclude = set()
|
exclude = set()
|
||||||
collapsed = {}
|
collapsed = {}
|
||||||
for (k, v) in six.iteritems(config):
|
for (k, v) in config.items():
|
||||||
if isinstance(v, (tuple, list)):
|
if isinstance(v, (tuple, list)):
|
||||||
if k in exclude:
|
if k in exclude:
|
||||||
collapsed[k] = v
|
collapsed[k] = v
|
||||||
@ -168,7 +167,7 @@ def collapse(config, exclude=None, item_selector=operator.itemgetter(-1)):
|
|||||||
|
|
||||||
def to_binary(text, encoding='ascii'):
|
def to_binary(text, encoding='ascii'):
|
||||||
"""Return the binary representation of string (if not already binary)."""
|
"""Return the binary representation of string (if not already binary)."""
|
||||||
if not isinstance(text, six.binary_type):
|
if not isinstance(text, bytes):
|
||||||
text = text.encode(encoding)
|
text = text.encode(encoding)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user