Run pyupgrade to clean up Python 2 syntaxes
Update all .py source files by $ pyupgrade --py3-only $(git ls-files | grep ".py$") to modernize the code according to Python 3 syntaxes. pep8 errors are fixed by $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \ --in-place tooz Also add the pyupgrade hook to pre-commit to avoid merging additional Python 2 syntaxes. Change-Id: I18b9e51964afe739ddabd3d074431c27a09a8508
This commit is contained in:
parent
53b085b20e
commit
9c7dbf8fd0
@ -1,6 +1,6 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.5.0
|
rev: v5.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
# Replaces or checks mixed line ending
|
# Replaces or checks mixed line ending
|
||||||
@ -19,12 +19,17 @@ repos:
|
|||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
files: .*\.(yaml|yml)$
|
files: .*\.(yaml|yml)$
|
||||||
- repo: https://opendev.org/openstack/hacking
|
- repo: https://opendev.org/openstack/hacking
|
||||||
rev: 6.1.0
|
rev: 7.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: hacking
|
- id: hacking
|
||||||
additional_dependencies: []
|
additional_dependencies: []
|
||||||
exclude: '^(doc|releasenotes|tools)/.*$'
|
exclude: '^(doc|releasenotes|tools)/.*$'
|
||||||
- repo: https://github.com/PyCQA/doc8
|
- repo: https://github.com/PyCQA/doc8
|
||||||
rev: v1.1.1
|
rev: v1.1.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: doc8
|
- id: doc8
|
||||||
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
|
rev: v3.18.0
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args: [--py3-only]
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (C) 2020 Red Hat, Inc.
|
# Copyright (C) 2020 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -80,8 +79,8 @@ latex_elements = {}
|
|||||||
# (source start file, target name, title, author,
|
# (source start file, target name, title, author,
|
||||||
# documentclass [howto/manual]).
|
# documentclass [howto/manual]).
|
||||||
latex_documents = [
|
latex_documents = [
|
||||||
('index', 'tooz.tex', u'tooz Documentation',
|
('index', 'tooz.tex', 'tooz Documentation',
|
||||||
u'eNovance', 'manual'),
|
'eNovance', 'manual'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Grouping the document tree into Texinfo files. List of tuples
|
# Grouping the document tree into Texinfo files. List of tuples
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (C) 2020 Red Hat, Inc.
|
# Copyright (C) 2020 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -60,8 +59,8 @@ source_suffix = '.rst'
|
|||||||
master_doc = 'index'
|
master_doc = 'index'
|
||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = u'tooz Release Notes'
|
project = 'tooz Release Notes'
|
||||||
copyright = u'2016, tooz Developers'
|
copyright = '2016, tooz Developers'
|
||||||
|
|
||||||
# Release do not need a version number in the title, they
|
# Release do not need a version number in the title, they
|
||||||
# cover multiple versions.
|
# cover multiple versions.
|
||||||
@ -208,8 +207,8 @@ latex_elements = {
|
|||||||
# author, documentclass [howto, manual, or own class]).
|
# author, documentclass [howto, manual, or own class]).
|
||||||
latex_documents = [
|
latex_documents = [
|
||||||
('index', 'toozReleaseNotes.tex',
|
('index', 'toozReleaseNotes.tex',
|
||||||
u'tooz Release Notes Documentation',
|
'tooz Release Notes Documentation',
|
||||||
u'tooz Developers', 'manual'),
|
'tooz Developers', 'manual'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# The name of an image file (relative to this directory) to place at the top of
|
# The name of an image file (relative to this directory) to place at the top of
|
||||||
@ -239,8 +238,8 @@ latex_documents = [
|
|||||||
# (source start file, name, description, authors, manual section).
|
# (source start file, name, description, authors, manual section).
|
||||||
man_pages = [
|
man_pages = [
|
||||||
('index', 'toozReleaseNotes',
|
('index', 'toozReleaseNotes',
|
||||||
u'tooz Release Notes Documentation',
|
'tooz Release Notes Documentation',
|
||||||
[u'tooz Developers'], 1)
|
['tooz Developers'], 1)
|
||||||
]
|
]
|
||||||
|
|
||||||
# If true, show URL addresses after external links.
|
# If true, show URL addresses after external links.
|
||||||
@ -254,8 +253,8 @@ man_pages = [
|
|||||||
# dir menu entry, description, category)
|
# dir menu entry, description, category)
|
||||||
texinfo_documents = [
|
texinfo_documents = [
|
||||||
('index', 'toozReleaseNotes',
|
('index', 'toozReleaseNotes',
|
||||||
u'tooz Release Notes Documentation',
|
'tooz Release Notes Documentation',
|
||||||
u'tooz Developers', 'toozReleaseNotes',
|
'tooz Developers', 'toozReleaseNotes',
|
||||||
'One line description of project.',
|
'One line description of project.',
|
||||||
'Miscellaneous'),
|
'Miscellaneous'),
|
||||||
]
|
]
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (C) 2015 Yahoo! Inc. All Rights Reserved.
|
# Copyright (C) 2015 Yahoo! Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014 eNovance Inc. All Rights Reserved.
|
# Copyright (C) 2014 eNovance Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
@ -28,7 +27,7 @@ class ToozError(Exception):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, message, cause=None):
|
def __init__(self, message, cause=None):
|
||||||
super(ToozError, self).__init__(message)
|
super().__init__(message)
|
||||||
self.cause = cause
|
self.cause = cause
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright © 2016 Red Hat, Inc.
|
# Copyright © 2016 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2016 Red Hat, Inc.
|
# Copyright (C) 2016 Red Hat, Inc.
|
||||||
# Copyright (C) 2013-2014 eNovance Inc. All Rights Reserved.
|
# Copyright (C) 2013-2014 eNovance Inc. All Rights Reserved.
|
||||||
@ -120,7 +119,7 @@ class Hooks(list):
|
|||||||
return list(map(lambda cb: cb(*args, **kwargs), self))
|
return list(map(lambda cb: cb(*args, **kwargs), self))
|
||||||
|
|
||||||
|
|
||||||
class Event(object):
|
class Event:
|
||||||
"""Base class for events."""
|
"""Base class for events."""
|
||||||
|
|
||||||
|
|
||||||
@ -132,9 +131,9 @@ class MemberJoinedGroup(Event):
|
|||||||
self.member_id = member_id
|
self.member_id = member_id
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: group %s: +member %s>" % (self.__class__.__name__,
|
return "<{}: group {}: +member {}>".format(self.__class__.__name__,
|
||||||
self.group_id,
|
self.group_id,
|
||||||
self.member_id)
|
self.member_id)
|
||||||
|
|
||||||
|
|
||||||
class MemberLeftGroup(Event):
|
class MemberLeftGroup(Event):
|
||||||
@ -145,9 +144,9 @@ class MemberLeftGroup(Event):
|
|||||||
self.member_id = member_id
|
self.member_id = member_id
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: group %s: -member %s>" % (self.__class__.__name__,
|
return "<{}: group {}: -member {}>".format(self.__class__.__name__,
|
||||||
self.group_id,
|
self.group_id,
|
||||||
self.member_id)
|
self.member_id)
|
||||||
|
|
||||||
|
|
||||||
class LeaderElected(Event):
|
class LeaderElected(Event):
|
||||||
@ -158,7 +157,7 @@ class LeaderElected(Event):
|
|||||||
self.member_id = member_id
|
self.member_id = member_id
|
||||||
|
|
||||||
|
|
||||||
class Heart(object):
|
class Heart:
|
||||||
"""Coordination drivers main liveness pump (its heart)."""
|
"""Coordination drivers main liveness pump (its heart)."""
|
||||||
|
|
||||||
def __init__(self, driver, thread_cls=threading.Thread,
|
def __init__(self, driver, thread_cls=threading.Thread,
|
||||||
@ -228,7 +227,7 @@ class Heart(object):
|
|||||||
return self._runner.is_alive()
|
return self._runner.is_alive()
|
||||||
|
|
||||||
|
|
||||||
class CoordinationDriver(object):
|
class CoordinationDriver:
|
||||||
|
|
||||||
requires_beating = False
|
requires_beating = False
|
||||||
"""
|
"""
|
||||||
@ -245,7 +244,7 @@ class CoordinationDriver(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
super(CoordinationDriver, self).__init__()
|
super().__init__()
|
||||||
self._member_id = member_id
|
self._member_id = member_id
|
||||||
self._started = False
|
self._started = False
|
||||||
self._hooks_join_group = collections.defaultdict(Hooks)
|
self._hooks_join_group = collections.defaultdict(Hooks)
|
||||||
@ -629,7 +628,7 @@ class CoordinationDriver(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CoordAsyncResult(object, metaclass=abc.ABCMeta):
|
class CoordAsyncResult(metaclass=abc.ABCMeta):
|
||||||
"""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
|
||||||
@ -681,15 +680,15 @@ class CoordinationDriverWithExecutor(CoordinationDriver):
|
|||||||
self._options = utils.collapse(options, exclude=self.EXCLUDE_OPTIONS)
|
self._options = utils.collapse(options, exclude=self.EXCLUDE_OPTIONS)
|
||||||
self._executor = utils.ProxyExecutor.build(
|
self._executor = utils.ProxyExecutor.build(
|
||||||
self.__class__.__name__, self._options)
|
self.__class__.__name__, self._options)
|
||||||
super(CoordinationDriverWithExecutor, self).__init__(
|
super().__init__(
|
||||||
member_id, parsed_url, options)
|
member_id, parsed_url, options)
|
||||||
|
|
||||||
def start(self, start_heart=False):
|
def start(self, start_heart=False):
|
||||||
self._executor.start()
|
self._executor.start()
|
||||||
super(CoordinationDriverWithExecutor, self).start(start_heart)
|
super().start(start_heart)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
super(CoordinationDriverWithExecutor, self).stop()
|
super().stop()
|
||||||
self._executor.stop()
|
self._executor.stop()
|
||||||
|
|
||||||
|
|
||||||
@ -703,7 +702,7 @@ class CoordinationDriverCachedRunWatchers(CoordinationDriver):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
super(CoordinationDriverCachedRunWatchers, self).__init__(
|
super().__init__(
|
||||||
member_id, parsed_url, options)
|
member_id, parsed_url, options)
|
||||||
# A cache for group members
|
# A cache for group members
|
||||||
self._group_members = collections.defaultdict(set)
|
self._group_members = collections.defaultdict(set)
|
||||||
@ -716,11 +715,11 @@ class CoordinationDriverCachedRunWatchers(CoordinationDriver):
|
|||||||
|
|
||||||
def watch_join_group(self, group_id, callback):
|
def watch_join_group(self, group_id, callback):
|
||||||
self._init_watch_group(group_id)
|
self._init_watch_group(group_id)
|
||||||
super(CoordinationDriverCachedRunWatchers, self).watch_join_group(
|
super().watch_join_group(
|
||||||
group_id, callback)
|
group_id, callback)
|
||||||
|
|
||||||
def unwatch_join_group(self, group_id, callback):
|
def unwatch_join_group(self, group_id, callback):
|
||||||
super(CoordinationDriverCachedRunWatchers, self).unwatch_join_group(
|
super().unwatch_join_group(
|
||||||
group_id, callback)
|
group_id, callback)
|
||||||
|
|
||||||
if (not self._has_hooks_for_group(group_id) and
|
if (not self._has_hooks_for_group(group_id) and
|
||||||
@ -729,11 +728,11 @@ class CoordinationDriverCachedRunWatchers(CoordinationDriver):
|
|||||||
|
|
||||||
def watch_leave_group(self, group_id, callback):
|
def watch_leave_group(self, group_id, callback):
|
||||||
self._init_watch_group(group_id)
|
self._init_watch_group(group_id)
|
||||||
super(CoordinationDriverCachedRunWatchers, self).watch_leave_group(
|
super().watch_leave_group(
|
||||||
group_id, callback)
|
group_id, callback)
|
||||||
|
|
||||||
def unwatch_leave_group(self, group_id, callback):
|
def unwatch_leave_group(self, group_id, callback):
|
||||||
super(CoordinationDriverCachedRunWatchers, self).unwatch_leave_group(
|
super().unwatch_leave_group(
|
||||||
group_id, callback)
|
group_id, callback)
|
||||||
|
|
||||||
if (not self._has_hooks_for_group(group_id) and
|
if (not self._has_hooks_for_group(group_id) and
|
||||||
@ -840,7 +839,7 @@ class GroupNotCreated(tooz.ToozError):
|
|||||||
"""Exception raised when the caller request an nonexistent group."""
|
"""Exception raised when the caller request an nonexistent group."""
|
||||||
def __init__(self, group_id):
|
def __init__(self, group_id):
|
||||||
self.group_id = group_id
|
self.group_id = group_id
|
||||||
super(GroupNotCreated, self).__init__(
|
super().__init__(
|
||||||
"Group %s does not exist" % group_id)
|
"Group %s does not exist" % group_id)
|
||||||
|
|
||||||
|
|
||||||
@ -848,7 +847,7 @@ class GroupAlreadyExist(tooz.ToozError):
|
|||||||
"""Exception raised trying to create an already existing group."""
|
"""Exception raised trying to create an already existing group."""
|
||||||
def __init__(self, group_id):
|
def __init__(self, group_id):
|
||||||
self.group_id = group_id
|
self.group_id = group_id
|
||||||
super(GroupAlreadyExist, self).__init__(
|
super().__init__(
|
||||||
"Group %s already exists" % group_id)
|
"Group %s already exists" % group_id)
|
||||||
|
|
||||||
|
|
||||||
@ -857,7 +856,7 @@ class MemberAlreadyExist(tooz.ToozError):
|
|||||||
def __init__(self, group_id, member_id):
|
def __init__(self, group_id, member_id):
|
||||||
self.group_id = group_id
|
self.group_id = group_id
|
||||||
self.member_id = member_id
|
self.member_id = member_id
|
||||||
super(MemberAlreadyExist, self).__init__(
|
super().__init__(
|
||||||
"Member %s has already joined %s" %
|
"Member %s has already joined %s" %
|
||||||
(member_id, group_id))
|
(member_id, group_id))
|
||||||
|
|
||||||
@ -867,15 +866,15 @@ class MemberNotJoined(tooz.ToozError):
|
|||||||
def __init__(self, group_id, member_id):
|
def __init__(self, group_id, member_id):
|
||||||
self.group_id = group_id
|
self.group_id = group_id
|
||||||
self.member_id = member_id
|
self.member_id = member_id
|
||||||
super(MemberNotJoined, self).__init__("Member %s has not joined %s" %
|
super().__init__("Member %s has not joined %s" %
|
||||||
(member_id, group_id))
|
(member_id, group_id))
|
||||||
|
|
||||||
|
|
||||||
class GroupNotEmpty(tooz.ToozError):
|
class GroupNotEmpty(tooz.ToozError):
|
||||||
"Exception raised when the caller try to delete a group with members."
|
"Exception raised when the caller try to delete a group with members."
|
||||||
def __init__(self, group_id):
|
def __init__(self, group_id):
|
||||||
self.group_id = group_id
|
self.group_id = group_id
|
||||||
super(GroupNotEmpty, self).__init__("Group %s is not empty" % group_id)
|
super().__init__("Group %s is not empty" % group_id)
|
||||||
|
|
||||||
|
|
||||||
class WatchCallbackNotFound(tooz.ToozError):
|
class WatchCallbackNotFound(tooz.ToozError):
|
||||||
@ -888,7 +887,7 @@ class WatchCallbackNotFound(tooz.ToozError):
|
|||||||
def __init__(self, group_id, callback):
|
def __init__(self, group_id, callback):
|
||||||
self.group_id = group_id
|
self.group_id = group_id
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
super(WatchCallbackNotFound, self).__init__(
|
super().__init__(
|
||||||
'Callback %s is not registered on group %s' %
|
'Callback %s is not registered on group %s' %
|
||||||
(callback.__name__, group_id))
|
(callback.__name__, group_id))
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright © 2015 Yahoo! Inc.
|
# Copyright © 2015 Yahoo! Inc.
|
||||||
#
|
#
|
||||||
@ -57,7 +56,7 @@ def _translate_failures(func):
|
|||||||
|
|
||||||
class ConsulLock(locking.Lock):
|
class ConsulLock(locking.Lock):
|
||||||
def __init__(self, name, node, address, session_id, client, token=None):
|
def __init__(self, name, node, address, session_id, client, token=None):
|
||||||
super(ConsulLock, self).__init__(name)
|
super().__init__(name)
|
||||||
self._name = name
|
self._name = name
|
||||||
self._node = node
|
self._node = node
|
||||||
self._address = address
|
self._address = address
|
||||||
@ -218,7 +217,7 @@ class ConsulDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
super(ConsulDriver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
options = utils.collapse(options)
|
options = utils.collapse(options)
|
||||||
self._host = parsed_url.hostname
|
self._host = parsed_url.hostname
|
||||||
self._port = parsed_url.port or self.DEFAULT_PORT
|
self._port = parsed_url.port or self.DEFAULT_PORT
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
@ -50,7 +49,7 @@ def _translate_failures(func):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class _Client(object):
|
class _Client:
|
||||||
def __init__(self, host, port, protocol):
|
def __init__(self, host, port, protocol):
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
@ -88,7 +87,7 @@ class EtcdLock(locking.Lock):
|
|||||||
_TOOZ_LOCK_PREFIX = "tooz_locks"
|
_TOOZ_LOCK_PREFIX = "tooz_locks"
|
||||||
|
|
||||||
def __init__(self, lock_url, name, coord, client, ttl=60):
|
def __init__(self, lock_url, name, coord, client, ttl=60):
|
||||||
super(EtcdLock, self).__init__(name)
|
super().__init__(name)
|
||||||
self.client = client
|
self.client = client
|
||||||
self.coord = coord
|
self.coord = coord
|
||||||
self.ttl = ttl
|
self.ttl = ttl
|
||||||
@ -242,7 +241,7 @@ class EtcdDriver(coordination.CoordinationDriver):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
super(EtcdDriver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
host = parsed_url.hostname or self.DEFAULT_HOST
|
host = parsed_url.hostname or self.DEFAULT_HOST
|
||||||
port = parsed_url.port or self.DEFAULT_PORT
|
port = parsed_url.port or self.DEFAULT_PORT
|
||||||
options = utils.collapse(options)
|
options = utils.collapse(options)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
@ -69,7 +68,7 @@ class Etcd3Lock(locking.Lock):
|
|||||||
LOCK_PREFIX = b"/tooz/locks"
|
LOCK_PREFIX = b"/tooz/locks"
|
||||||
|
|
||||||
def __init__(self, coord, name, timeout):
|
def __init__(self, coord, name, timeout):
|
||||||
super(Etcd3Lock, self).__init__(name)
|
super().__init__(name)
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
self._coord = coord
|
self._coord = coord
|
||||||
self._key = self.LOCK_PREFIX + name
|
self._key = self.LOCK_PREFIX + name
|
||||||
@ -214,7 +213,7 @@ class Etcd3Driver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
super(Etcd3Driver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
protocol = 'https' if parsed_url.scheme.endswith('https') else 'http'
|
protocol = 'https' if parsed_url.scheme.endswith('https') else 'http'
|
||||||
host = parsed_url.hostname or self.DEFAULT_HOST
|
host = parsed_url.hostname or self.DEFAULT_HOST
|
||||||
port = parsed_url.port or self.DEFAULT_PORT
|
port = parsed_url.port or self.DEFAULT_PORT
|
||||||
@ -243,7 +242,7 @@ class Etcd3Driver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
self._membership_lease = None
|
self._membership_lease = None
|
||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
super(Etcd3Driver, self)._start()
|
super()._start()
|
||||||
self._membership_lease = self.client.lease(self.membership_timeout)
|
self._membership_lease = self.client.lease(self.membership_timeout)
|
||||||
|
|
||||||
def get_lock(self, name):
|
def get_lock(self, name):
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright © 2015 eNovance
|
# Copyright © 2015 eNovance
|
||||||
#
|
#
|
||||||
@ -42,7 +41,7 @@ from tooz import utils
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class _Barrier(object):
|
class _Barrier:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cond = threading.Condition()
|
self.cond = threading.Condition()
|
||||||
self.owner = None
|
self.owner = None
|
||||||
@ -54,7 +53,7 @@ class _Barrier(object):
|
|||||||
def _translate_failures():
|
def _translate_failures():
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
except (EnvironmentError, voluptuous.Invalid) as e:
|
except (OSError, voluptuous.Invalid) as e:
|
||||||
utils.raise_with_cause(tooz.ToozError,
|
utils.raise_with_cause(tooz.ToozError,
|
||||||
encodeutils.exception_to_unicode(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
@ -74,7 +73,7 @@ def _convert_from_old_format(data):
|
|||||||
# {u"member_id": b"member"}
|
# {u"member_id": b"member"}
|
||||||
# {u"member_id": u"member"}
|
# {u"member_id": u"member"}
|
||||||
if 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 = {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
|
||||||
# if we need to decode the value or not. Python3 see bytes blob
|
# if we need to decode the value or not. Python3 see bytes blob
|
||||||
@ -104,7 +103,7 @@ class FileLock(locking.Lock):
|
|||||||
"""A file based lock."""
|
"""A file based lock."""
|
||||||
|
|
||||||
def __init__(self, path, barrier, member_id):
|
def __init__(self, path, barrier, member_id):
|
||||||
super(FileLock, self).__init__(path)
|
super().__init__(path)
|
||||||
self.acquired = False
|
self.acquired = False
|
||||||
self._lock = fasteners.InterProcessLock(path)
|
self._lock = fasteners.InterProcessLock(path)
|
||||||
self._barrier = barrier
|
self._barrier = barrier
|
||||||
@ -226,7 +225,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
"""Initialize the file driver."""
|
"""Initialize the file driver."""
|
||||||
super(FileDriver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
self._dir = self._normalize_path(parsed_url.path)
|
self._dir = self._normalize_path(parsed_url.path)
|
||||||
self._group_dir = os.path.join(self._dir, 'groups')
|
self._group_dir = os.path.join(self._dir, 'groups')
|
||||||
self._tmpdir = os.path.join(self._dir, 'tmp')
|
self._tmpdir = os.path.join(self._dir, 'tmp')
|
||||||
@ -271,7 +270,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
return hashlib.new(cls.HASH_ROUTINE, item).hexdigest()
|
return hashlib.new(cls.HASH_ROUTINE, item).hexdigest()
|
||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
super(FileDriver, self)._start()
|
super()._start()
|
||||||
for a_dir in self._reserved_dirs:
|
for a_dir in self._reserved_dirs:
|
||||||
try:
|
try:
|
||||||
fileutils.ensure_tree(a_dir)
|
fileutils.ensure_tree(a_dir)
|
||||||
@ -280,9 +279,9 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
|
|
||||||
def _update_group_metadata(self, path, group_id):
|
def _update_group_metadata(self, path, group_id):
|
||||||
details = {
|
details = {
|
||||||
u'group_id': utils.to_binary(group_id, encoding="utf8")
|
'group_id': utils.to_binary(group_id, encoding="utf8")
|
||||||
}
|
}
|
||||||
details[u'encoded'] = details[u"group_id"] != group_id
|
details['encoded'] = details["group_id"] != group_id
|
||||||
details_blob = utils.dumps(details)
|
details_blob = utils.dumps(details)
|
||||||
fd, name = tempfile.mkstemp("tooz", dir=self._tmpdir)
|
fd, name = tempfile.mkstemp("tooz", dir=self._tmpdir)
|
||||||
with os.fdopen(fd, "wb") as fh:
|
with os.fdopen(fd, "wb") as fh:
|
||||||
@ -321,12 +320,12 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
raise coordination.MemberAlreadyExist(group_id,
|
raise coordination.MemberAlreadyExist(group_id,
|
||||||
self._member_id)
|
self._member_id)
|
||||||
details = {
|
details = {
|
||||||
u'capabilities': capabilities,
|
'capabilities': capabilities,
|
||||||
u'joined_on': datetime.datetime.now(),
|
'joined_on': datetime.datetime.now(),
|
||||||
u'member_id': utils.to_binary(self._member_id,
|
'member_id': utils.to_binary(self._member_id,
|
||||||
encoding="utf-8")
|
encoding="utf-8")
|
||||||
}
|
}
|
||||||
details[u'encoded'] = details[u"member_id"] != self._member_id
|
details['encoded'] = details["member_id"] != self._member_id
|
||||||
details_blob = utils.dumps(details)
|
details_blob = utils.dumps(details)
|
||||||
with open(me_path, "wb") as fh:
|
with open(me_path, "wb") as fh:
|
||||||
fh.write(details_blob)
|
fh.write(details_blob)
|
||||||
@ -346,7 +345,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
raise coordination.GroupNotCreated(group_id)
|
raise coordination.GroupNotCreated(group_id)
|
||||||
try:
|
try:
|
||||||
os.unlink(me_path)
|
os.unlink(me_path)
|
||||||
except EnvironmentError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
@ -382,8 +381,8 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
with open(path, 'rb') as fh:
|
with open(path, 'rb') as fh:
|
||||||
details = self._load_and_validate(fh.read(), 'member')
|
details = self._load_and_validate(fh.read(), 'member')
|
||||||
if details.get("encoded"):
|
if details.get("encoded"):
|
||||||
return details[u'member_id'].decode("utf-8")
|
return details['member_id'].decode("utf-8")
|
||||||
return details[u'member_id']
|
return details['member_id']
|
||||||
|
|
||||||
def get_members(self, group_id):
|
def get_members(self, group_id):
|
||||||
safe_group_id = self._make_filesystem_safe(group_id)
|
safe_group_id = self._make_filesystem_safe(group_id)
|
||||||
@ -396,7 +395,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
members = set()
|
members = set()
|
||||||
try:
|
try:
|
||||||
entries = os.listdir(group_dir)
|
entries = os.listdir(group_dir)
|
||||||
except EnvironmentError as e:
|
except OSError as e:
|
||||||
# Did someone manage to remove it before we got here...
|
# Did someone manage to remove it before we got here...
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
@ -415,7 +414,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
member_id = self._read_member_id(entry_path)
|
member_id = self._read_member_id(entry_path)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
except EnvironmentError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
@ -436,7 +435,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
try:
|
try:
|
||||||
with open(member_path, "rb") as fh:
|
with open(member_path, "rb") as fh:
|
||||||
contents = fh.read()
|
contents = fh.read()
|
||||||
except EnvironmentError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
if not os.path.isdir(group_dir):
|
if not os.path.isdir(group_dir):
|
||||||
raise coordination.GroupNotCreated(group_id)
|
raise coordination.GroupNotCreated(group_id)
|
||||||
@ -447,7 +446,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
details = self._load_and_validate(contents, 'member')
|
details = self._load_and_validate(contents, 'member')
|
||||||
return details.get(u"capabilities")
|
return details.get("capabilities")
|
||||||
|
|
||||||
fut = self._executor.submit(_do_get_member_capabilities)
|
fut = self._executor.submit(_do_get_member_capabilities)
|
||||||
return FileFutureResult(fut)
|
return FileFutureResult(fut)
|
||||||
@ -460,7 +459,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
def _do_delete_group():
|
def _do_delete_group():
|
||||||
try:
|
try:
|
||||||
entries = os.listdir(group_dir)
|
entries = os.listdir(group_dir)
|
||||||
except EnvironmentError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise coordination.GroupNotCreated(group_id)
|
raise coordination.GroupNotCreated(group_id)
|
||||||
else:
|
else:
|
||||||
@ -476,7 +475,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(group_dir)
|
shutil.rmtree(group_dir)
|
||||||
except EnvironmentError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -487,8 +486,8 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
with open(path, 'rb') as fh:
|
with open(path, 'rb') as fh:
|
||||||
details = self._load_and_validate(fh.read(), 'group')
|
details = self._load_and_validate(fh.read(), 'group')
|
||||||
if details.get("encoded"):
|
if details.get("encoded"):
|
||||||
return details[u'group_id'].decode("utf-8")
|
return details['group_id'].decode("utf-8")
|
||||||
return details[u'group_id']
|
return details['group_id']
|
||||||
|
|
||||||
def get_groups(self):
|
def get_groups(self):
|
||||||
|
|
||||||
@ -498,7 +497,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
path = os.path.join(self._group_dir, entry, '.metadata')
|
path = os.path.join(self._group_dir, entry, '.metadata')
|
||||||
try:
|
try:
|
||||||
groups.append(self._read_group_id(path))
|
groups.append(self._read_group_id(path))
|
||||||
except EnvironmentError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
return groups
|
return groups
|
||||||
@ -517,7 +516,7 @@ class FileDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
def _do_heartbeat():
|
def _do_heartbeat():
|
||||||
try:
|
try:
|
||||||
os.utime(member_path, None)
|
os.utime(member_path, None)
|
||||||
except EnvironmentError as err:
|
except OSError as err:
|
||||||
if err.errno != errno.ENOENT:
|
if err.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
_do_heartbeat()
|
_do_heartbeat()
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright © 2014 eNovance
|
# Copyright © 2014 eNovance
|
||||||
#
|
#
|
||||||
@ -58,7 +57,7 @@ class IPCLock(locking.Lock):
|
|||||||
_LOCK_PROJECT = b'__TOOZ_LOCK_'
|
_LOCK_PROJECT = b'__TOOZ_LOCK_'
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
super(IPCLock, self).__init__(name)
|
super().__init__(name)
|
||||||
self.key = ftok(name, self._LOCK_PROJECT)
|
self.key = ftok(name, self._LOCK_PROJECT)
|
||||||
self._lock = None
|
self._lock = None
|
||||||
|
|
||||||
@ -173,7 +172,7 @@ class IPCDriver(coordination.CoordinationDriverWithExecutor):
|
|||||||
_INTERNAL_LOCK_NAME = "TOOZ_INTERNAL_LOCK"
|
_INTERNAL_LOCK_NAME = "TOOZ_INTERNAL_LOCK"
|
||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
super(IPCDriver, self)._start()
|
super()._start()
|
||||||
self._group_list = sysv_ipc.SharedMemory(
|
self._group_list = sysv_ipc.SharedMemory(
|
||||||
ftok(self._GROUP_LIST_KEY, self._GROUP_PROJECT),
|
ftok(self._GROUP_LIST_KEY, self._GROUP_PROJECT),
|
||||||
sysv_ipc.IPC_CREAT,
|
sysv_ipc.IPC_CREAT,
|
||||||
@ -181,7 +180,7 @@ class IPCDriver(coordination.CoordinationDriverWithExecutor):
|
|||||||
self._lock = self.get_lock(self._INTERNAL_LOCK_NAME)
|
self._lock = self.get_lock(self._INTERNAL_LOCK_NAME)
|
||||||
|
|
||||||
def _stop(self):
|
def _stop(self):
|
||||||
super(IPCDriver, self)._stop()
|
super()._stop()
|
||||||
try:
|
try:
|
||||||
self._group_list.detach()
|
self._group_list.detach()
|
||||||
self._group_list.remove()
|
self._group_list.remove()
|
||||||
@ -230,12 +229,12 @@ class IPCDriver(coordination.CoordinationDriverWithExecutor):
|
|||||||
def watch_join_group(self, group_id, callback):
|
def watch_join_group(self, group_id, callback):
|
||||||
# Check the group exist
|
# Check the group exist
|
||||||
self.get_members(group_id).get()
|
self.get_members(group_id).get()
|
||||||
super(IPCDriver, self).watch_join_group(group_id, callback)
|
super().watch_join_group(group_id, callback)
|
||||||
|
|
||||||
def watch_leave_group(self, group_id, callback):
|
def watch_leave_group(self, group_id, callback):
|
||||||
# Check the group exist
|
# Check the group exist
|
||||||
self.get_members(group_id).get()
|
self.get_members(group_id).get()
|
||||||
super(IPCDriver, self).watch_leave_group(group_id, callback)
|
super().watch_leave_group(group_id, callback)
|
||||||
|
|
||||||
def _get_groups_handler(self):
|
def _get_groups_handler(self):
|
||||||
with self._lock:
|
with self._lock:
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright © 2014 eNovance
|
# Copyright © 2014 eNovance
|
||||||
#
|
#
|
||||||
@ -45,15 +44,14 @@ def _failure_translator():
|
|||||||
utils.raise_with_cause(coordination.ToozConnectionError,
|
utils.raise_with_cause(coordination.ToozConnectionError,
|
||||||
encodeutils.exception_to_unicode(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
except (socket.timeout, socket.error,
|
except (socket.timeout, OSError, socket.gaierror, socket.herror) as e:
|
||||||
socket.gaierror, socket.herror) as e:
|
|
||||||
# TODO(harlowja): get upstream pymemcache to produce a better
|
# TODO(harlowja): get upstream pymemcache to produce a better
|
||||||
# exception for these, using socket (vs. a memcache specific
|
# exception for these, using socket (vs. a memcache specific
|
||||||
# error) seems sorta not right and/or the best approach...
|
# error) seems sorta not right and/or the best approach...
|
||||||
msg = encodeutils.exception_to_unicode(e)
|
msg = encodeutils.exception_to_unicode(e)
|
||||||
if e.errno is not None:
|
if e.errno is not None:
|
||||||
msg += " (with errno %s [%s])" % (errno.errorcode[e.errno],
|
msg += " (with errno {} [{}])".format(errno.errorcode[e.errno],
|
||||||
e.errno)
|
e.errno)
|
||||||
utils.raise_with_cause(coordination.ToozConnectionError,
|
utils.raise_with_cause(coordination.ToozConnectionError,
|
||||||
msg, cause=e)
|
msg, cause=e)
|
||||||
except pymemcache_client.MemcacheError as e:
|
except pymemcache_client.MemcacheError as e:
|
||||||
@ -76,7 +74,7 @@ class MemcachedLock(locking.Lock):
|
|||||||
_LOCK_PREFIX = b'__TOOZ_LOCK_'
|
_LOCK_PREFIX = b'__TOOZ_LOCK_'
|
||||||
|
|
||||||
def __init__(self, coord, name, timeout):
|
def __init__(self, coord, name, timeout):
|
||||||
super(MemcachedLock, self).__init__(self._LOCK_PREFIX + name)
|
super().__init__(self._LOCK_PREFIX + name)
|
||||||
self.coord = coord
|
self.coord = coord
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
@ -252,7 +250,7 @@ class MemcachedDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
STILL_ALIVE = b"It's alive!"
|
STILL_ALIVE = b"It's alive!"
|
||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
super(MemcachedDriver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
self.host = (parsed_url.hostname or "localhost",
|
self.host = (parsed_url.hostname or "localhost",
|
||||||
parsed_url.port or 11211)
|
parsed_url.port or 11211)
|
||||||
default_timeout = self._options.get('timeout', self.DEFAULT_TIMEOUT)
|
default_timeout = self._options.get('timeout', self.DEFAULT_TIMEOUT)
|
||||||
@ -287,7 +285,7 @@ class MemcachedDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
|
|
||||||
@_translate_failures
|
@_translate_failures
|
||||||
def _start(self):
|
def _start(self):
|
||||||
super(MemcachedDriver, self)._start()
|
super()._start()
|
||||||
self.client = pymemcache_client.PooledClient(
|
self.client = pymemcache_client.PooledClient(
|
||||||
self.host,
|
self.host,
|
||||||
serializer=self._msgpack_serializer,
|
serializer=self._msgpack_serializer,
|
||||||
@ -301,7 +299,7 @@ class MemcachedDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
|
|
||||||
@_translate_failures
|
@_translate_failures
|
||||||
def _stop(self):
|
def _stop(self):
|
||||||
super(MemcachedDriver, self)._stop()
|
super()._stop()
|
||||||
for lock in list(self._acquired_locks):
|
for lock in list(self._acquired_locks):
|
||||||
lock.release()
|
lock.release()
|
||||||
self.client.delete(self._encode_member_id(self._member_id))
|
self.client.delete(self._encode_member_id(self._member_id))
|
||||||
@ -529,7 +527,7 @@ class MemcachedDriver(coordination.CoordinationDriverCachedRunWatchers,
|
|||||||
self._member_id))
|
self._member_id))
|
||||||
|
|
||||||
def run_watchers(self, timeout=None):
|
def run_watchers(self, timeout=None):
|
||||||
result = super(MemcachedDriver, self).run_watchers(timeout=timeout)
|
result = super().run_watchers(timeout=timeout)
|
||||||
self.run_elect_coordinator()
|
self.run_elect_coordinator()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright © 2014 eNovance
|
# Copyright © 2014 eNovance
|
||||||
#
|
#
|
||||||
@ -34,7 +33,7 @@ class MySQLLock(locking.Lock):
|
|||||||
MYSQL_DEFAULT_PORT = 3306
|
MYSQL_DEFAULT_PORT = 3306
|
||||||
|
|
||||||
def __init__(self, name, parsed_url, options):
|
def __init__(self, name, parsed_url, options):
|
||||||
super(MySQLLock, self).__init__(name)
|
super().__init__(name)
|
||||||
self.acquired = False
|
self.acquired = False
|
||||||
self._conn = MySQLDriver.get_connection(parsed_url, options, True)
|
self._conn = MySQLDriver.get_connection(parsed_url, options, True)
|
||||||
|
|
||||||
@ -156,7 +155,7 @@ class MySQLDriver(coordination.CoordinationDriver):
|
|||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
"""Initialize the MySQL driver."""
|
"""Initialize the MySQL driver."""
|
||||||
super(MySQLDriver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
self._parsed_url = parsed_url
|
self._parsed_url = parsed_url
|
||||||
self._options = utils.collapse(options)
|
self._options = utils.collapse(options)
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright © 2014 eNovance
|
# Copyright © 2014 eNovance
|
||||||
#
|
#
|
||||||
@ -55,8 +54,8 @@ _DIAGNOSTICS_ATTRS = tuple([
|
|||||||
|
|
||||||
def _format_exception(e):
|
def _format_exception(e):
|
||||||
lines = [
|
lines = [
|
||||||
"%s: %s" % (type(e).__name__,
|
"{}: {}".format(type(e).__name__,
|
||||||
encodeutils.exception_to_unicode(e).strip()),
|
encodeutils.exception_to_unicode(e).strip()),
|
||||||
]
|
]
|
||||||
if hasattr(e, 'pgcode') and e.pgcode is not None:
|
if hasattr(e, 'pgcode') and e.pgcode is not None:
|
||||||
lines.append("Error code: %s" % e.pgcode)
|
lines.append("Error code: %s" % e.pgcode)
|
||||||
@ -71,7 +70,7 @@ def _format_exception(e):
|
|||||||
attr_value = getattr(e.diag, attr_name)
|
attr_value = getattr(e.diag, attr_name)
|
||||||
if attr_value is None:
|
if attr_value is None:
|
||||||
continue
|
continue
|
||||||
diagnostic_lines.append(" %s = %s" % (attr_name, attr_value))
|
diagnostic_lines.append(" {} = {}".format(attr_name, attr_value))
|
||||||
if diagnostic_lines:
|
if diagnostic_lines:
|
||||||
lines.append('Diagnostics:')
|
lines.append('Diagnostics:')
|
||||||
lines.extend(diagnostic_lines)
|
lines.extend(diagnostic_lines)
|
||||||
@ -93,7 +92,7 @@ class PostgresLock(locking.Lock):
|
|||||||
"""A PostgreSQL based lock."""
|
"""A PostgreSQL based lock."""
|
||||||
|
|
||||||
def __init__(self, name, parsed_url, options):
|
def __init__(self, name, parsed_url, options):
|
||||||
super(PostgresLock, self).__init__(name)
|
super().__init__(name)
|
||||||
self.acquired = False
|
self.acquired = False
|
||||||
self._conn = None
|
self._conn = None
|
||||||
self._parsed_url = parsed_url
|
self._parsed_url = parsed_url
|
||||||
@ -192,7 +191,7 @@ class PostgresDriver(coordination.CoordinationDriver):
|
|||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
"""Initialize the PostgreSQL driver."""
|
"""Initialize the PostgreSQL driver."""
|
||||||
super(PostgresDriver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
self._parsed_url = parsed_url
|
self._parsed_url = parsed_url
|
||||||
self._options = utils.collapse(options)
|
self._options = utils.collapse(options)
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
|
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
@ -79,8 +77,8 @@ def _handle_failures(n_tries=15):
|
|||||||
|
|
||||||
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, str(name))
|
name = "{}_{}_lock".format(coord.namespace, str(name))
|
||||||
super(RedisLock, self).__init__(name)
|
super().__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)
|
||||||
self._exclusive_access = threading.Lock()
|
self._exclusive_access = threading.Lock()
|
||||||
@ -373,7 +371,7 @@ return 1
|
|||||||
EXCLUDE_OPTIONS = CLIENT_LIST_ARGS
|
EXCLUDE_OPTIONS = CLIENT_LIST_ARGS
|
||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
super(RedisDriver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
self._parsed_url = parsed_url
|
self._parsed_url = parsed_url
|
||||||
self._encoding = self._options.get('encoding', self.DEFAULT_ENCODING)
|
self._encoding = self._options.get('encoding', self.DEFAULT_ENCODING)
|
||||||
timeout = self._options.get('timeout', self.CLIENT_DEFAULT_SOCKET_TO)
|
timeout = self._options.get('timeout', self.CLIENT_DEFAULT_SOCKET_TO)
|
||||||
@ -492,7 +490,7 @@ return 1
|
|||||||
|
|
||||||
@_handle_failures()
|
@_handle_failures()
|
||||||
def _start(self):
|
def _start(self):
|
||||||
super(RedisDriver, self)._start()
|
super()._start()
|
||||||
try:
|
try:
|
||||||
self._client = self._make_client(self._parsed_url, self._options,
|
self._client = self._make_client(self._parsed_url, self._options,
|
||||||
self.timeout)
|
self.timeout)
|
||||||
@ -586,7 +584,7 @@ return 1
|
|||||||
lock.release()
|
lock.release()
|
||||||
except tooz.ToozError:
|
except tooz.ToozError:
|
||||||
LOG.warning("Unable to release lock '%s'", lock, exc_info=True)
|
LOG.warning("Unable to release lock '%s'", lock, exc_info=True)
|
||||||
super(RedisDriver, self)._stop()
|
super()._stop()
|
||||||
if self._client is not None:
|
if self._client is not None:
|
||||||
# Make sure we no longer exist...
|
# Make sure we no longer exist...
|
||||||
beat_id = self._encode_beat_id(self._member_id)
|
beat_id = self._encode_beat_id(self._member_id)
|
||||||
@ -703,8 +701,8 @@ return 1
|
|||||||
for m in gone_members)
|
for m in gone_members)
|
||||||
p.hdel(encoded_group, *encoded_gone_members)
|
p.hdel(encoded_group, *encoded_gone_members)
|
||||||
p.execute()
|
p.execute()
|
||||||
return set(m for m in potential_members
|
return {m for m in potential_members
|
||||||
if m not in gone_members)
|
if m not in gone_members}
|
||||||
return potential_members
|
return potential_members
|
||||||
|
|
||||||
return RedisFutureResult(self._submit(self._client.transaction,
|
return RedisFutureResult(self._submit(self._client.transaction,
|
||||||
@ -805,7 +803,7 @@ return 1
|
|||||||
self._member_id))
|
self._member_id))
|
||||||
|
|
||||||
def run_watchers(self, timeout=None):
|
def run_watchers(self, timeout=None):
|
||||||
result = super(RedisDriver, self).run_watchers(timeout=timeout)
|
result = super().run_watchers(timeout=timeout)
|
||||||
self.run_elect_coordinator()
|
self.run_elect_coordinator()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class ZakeDriver(zookeeper.KazooDriver):
|
|||||||
fake_client.k_threading.SequentialThreadingHandler())
|
fake_client.k_threading.SequentialThreadingHandler())
|
||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
super(ZakeDriver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"The zake driver is deprecated, and will be removed in "
|
"The zake driver is deprecated, and will be removed in "
|
||||||
"a future release."
|
"a future release."
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2013-2014 eNovance Inc. All Rights Reserved.
|
# Copyright (C) 2013-2014 eNovance Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
@ -34,7 +33,7 @@ from tooz import utils
|
|||||||
|
|
||||||
class ZooKeeperLock(locking.Lock):
|
class ZooKeeperLock(locking.Lock):
|
||||||
def __init__(self, name, lock):
|
def __init__(self, name, lock):
|
||||||
super(ZooKeeperLock, self).__init__(name)
|
super().__init__(name)
|
||||||
self._lock = lock
|
self._lock = lock
|
||||||
self._client = lock.client
|
self._client = lock.client
|
||||||
|
|
||||||
@ -144,7 +143,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, member_id, parsed_url, options):
|
def __init__(self, member_id, parsed_url, options):
|
||||||
super(KazooDriver, self).__init__(member_id, parsed_url, options)
|
super().__init__(member_id, parsed_url, options)
|
||||||
options = utils.collapse(options, exclude=['hosts'])
|
options = utils.collapse(options, exclude=['hosts'])
|
||||||
self.timeout = int(options.get('timeout', '10'))
|
self.timeout = int(options.get('timeout', '10'))
|
||||||
self._namespace = options.get('namespace', self.TOOZ_NAMESPACE)
|
self._namespace = options.get('namespace', self.TOOZ_NAMESPACE)
|
||||||
@ -317,7 +316,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
|
|||||||
encodeutils.exception_to_unicode(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
else:
|
else:
|
||||||
return set(m.encode('ascii') for m in members_ids)
|
return {m.encode('ascii') for m in members_ids}
|
||||||
|
|
||||||
def get_members(self, group_id):
|
def get_members(self, group_id):
|
||||||
group_path = self._paths_join("/", self._namespace, group_id)
|
group_path = self._paths_join("/", self._namespace, group_id)
|
||||||
@ -427,7 +426,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
|
|||||||
encodeutils.exception_to_unicode(e),
|
encodeutils.exception_to_unicode(e),
|
||||||
cause=e)
|
cause=e)
|
||||||
else:
|
else:
|
||||||
return set(g.encode('ascii') for g in group_ids)
|
return {g.encode('ascii') for g in group_ids}
|
||||||
|
|
||||||
def get_groups(self):
|
def get_groups(self):
|
||||||
tooz_namespace = self._paths_join("/", self._namespace)
|
tooz_namespace = self._paths_join("/", self._namespace)
|
||||||
@ -464,7 +463,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
|
|||||||
username = parsed_url.username
|
username = parsed_url.username
|
||||||
password = parsed_url.password
|
password = parsed_url.password
|
||||||
|
|
||||||
digest_auth = "%s:%s" % (username, password)
|
digest_auth = "{}:{}".format(username, password)
|
||||||
digest_acl = security.make_digest_acl(username, password, all=True)
|
digest_acl = security.make_digest_acl(username, password, all=True)
|
||||||
default_acl = (digest_acl,)
|
default_acl = (digest_acl,)
|
||||||
auth_data = [('digest', digest_auth)]
|
auth_data = [('digest', digest_auth)]
|
||||||
@ -547,7 +546,7 @@ class KazooDriver(coordination.CoordinationDriverCachedRunWatchers):
|
|||||||
self._member_id))
|
self._member_id))
|
||||||
|
|
||||||
def run_watchers(self, timeout=None):
|
def run_watchers(self, timeout=None):
|
||||||
results = super(KazooDriver, self).run_watchers(timeout)
|
results = super().run_watchers(timeout)
|
||||||
self.run_elect_coordinator()
|
self.run_elect_coordinator()
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2016 Red Hat, Inc.
|
# Copyright (C) 2016 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
@ -25,11 +24,11 @@ from tooz import utils
|
|||||||
class UnknownNode(tooz.ToozError):
|
class UnknownNode(tooz.ToozError):
|
||||||
"""Node is unknown."""
|
"""Node is unknown."""
|
||||||
def __init__(self, node):
|
def __init__(self, node):
|
||||||
super(UnknownNode, self).__init__("Unknown node `%s'" % node)
|
super().__init__("Unknown node `%s'" % node)
|
||||||
self.node = node
|
self.node = node
|
||||||
|
|
||||||
|
|
||||||
class HashRing(object):
|
class HashRing:
|
||||||
"""Map objects onto nodes based on their consistent hash."""
|
"""Map objects onto nodes based on their consistent hash."""
|
||||||
|
|
||||||
DEFAULT_PARTITION_NUMBER = 2**5
|
DEFAULT_PARTITION_NUMBER = 2**5
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014 eNovance Inc. All Rights Reserved.
|
# Copyright (C) 2014 eNovance Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
@ -19,7 +18,7 @@ import tooz
|
|||||||
from tooz import coordination
|
from tooz import coordination
|
||||||
|
|
||||||
|
|
||||||
class _LockProxy(object):
|
class _LockProxy:
|
||||||
def __init__(self, lock, *args, **kwargs):
|
def __init__(self, lock, *args, **kwargs):
|
||||||
self.lock = lock
|
self.lock = lock
|
||||||
self.args = args
|
self.args = args
|
||||||
@ -32,7 +31,7 @@ class _LockProxy(object):
|
|||||||
self.lock.__exit__(exc_type, exc_val, exc_tb)
|
self.lock.__exit__(exc_type, exc_val, exc_tb)
|
||||||
|
|
||||||
|
|
||||||
class Lock(object, metaclass=abc.ABCMeta):
|
class Lock(metaclass=abc.ABCMeta):
|
||||||
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")
|
||||||
@ -48,7 +47,7 @@ class Lock(object, metaclass=abc.ABCMeta):
|
|||||||
def __enter__(self, *args, **kwargs):
|
def __enter__(self, *args, **kwargs):
|
||||||
acquired = self.acquire(*args, **kwargs)
|
acquired = self.acquire(*args, **kwargs)
|
||||||
if not acquired:
|
if not acquired:
|
||||||
msg = u'Acquiring lock %s failed' % self.name
|
msg = 'Acquiring lock %s failed' % self.name
|
||||||
raise coordination.LockAcquireFailed(msg)
|
raise coordination.LockAcquireFailed(msg)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2016 Red Hat, Inc.
|
# Copyright (C) 2016 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
@ -17,7 +16,7 @@
|
|||||||
from tooz import hashring
|
from tooz import hashring
|
||||||
|
|
||||||
|
|
||||||
class Partitioner(object):
|
class Partitioner:
|
||||||
"""Partition set of objects across several members.
|
"""Partition set of objects across several members.
|
||||||
|
|
||||||
Objects to be partitioned should implement the __tooz_hash__ method to
|
Objects to be partitioned should implement the __tooz_hash__ method to
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014 eNovance Inc. All Rights Reserved.
|
# Copyright (C) 2014 eNovance Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
@ -53,7 +52,7 @@ class TestWithCoordinator(testcase.TestCase, metaclass=SkipNotImplementedMeta):
|
|||||||
url = os.getenv("TOOZ_TEST_URL")
|
url = os.getenv("TOOZ_TEST_URL")
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestWithCoordinator, self).setUp()
|
super().setUp()
|
||||||
if self.url is None:
|
if self.url is None:
|
||||||
raise RuntimeError("No URL set for this driver")
|
raise RuntimeError("No URL set for this driver")
|
||||||
if os.getenv("TOOZ_TEST_ETCD3GW"):
|
if os.getenv("TOOZ_TEST_ETCD3GW"):
|
||||||
@ -72,4 +71,4 @@ class TestWithCoordinator(testcase.TestCase, metaclass=SkipNotImplementedMeta):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self._coord.stop()
|
self._coord.stop()
|
||||||
super(TestWithCoordinator, self).tearDown()
|
super().tearDown()
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright 2016 Red Hat, Inc.
|
# Copyright 2016 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
@ -26,7 +25,7 @@ class TestEtcd(testcase.TestCase):
|
|||||||
FAKE_MEMBER_ID = "mocked-not-really-member"
|
FAKE_MEMBER_ID = "mocked-not-really-member"
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestEtcd, self).setUp()
|
super().setUp()
|
||||||
self._coord = tooz.coordination.get_coordinator(self.FAKE_URL,
|
self._coord = tooz.coordination.get_coordinator(self.FAKE_URL,
|
||||||
self.FAKE_MEMBER_ID)
|
self.FAKE_MEMBER_ID)
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright 2020 Red Hat, Inc.
|
# Copyright 2020 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright 2016 Cloudbase Solutions Srl
|
# Copyright 2016 Cloudbase Solutions Srl
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (c) 2015 OpenStack Foundation
|
# Copyright (c) 2015 OpenStack Foundation
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (c) 2015 OpenStack Foundation
|
# Copyright (c) 2015 OpenStack Foundation
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
|
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright © 2013-2015 eNovance Inc. All Rights Reserved.
|
# Copyright © 2013-2015 eNovance Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
@ -988,7 +987,7 @@ class TestAPI(tests.TestWithCoordinator):
|
|||||||
|
|
||||||
class TestHook(testcase.TestCase):
|
class TestHook(testcase.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestHook, self).setUp()
|
super().setUp()
|
||||||
self.hooks = tooz.coordination.Hooks()
|
self.hooks = tooz.coordination.Hooks()
|
||||||
self.triggered = False
|
self.triggered = False
|
||||||
|
|
||||||
|
@ -92,8 +92,8 @@ class HashRingTestCase(testcase.TestCase):
|
|||||||
ring = hashring.HashRing(nodes)
|
ring = hashring.HashRing(nodes)
|
||||||
self.assertEqual(nodes, set(ring.nodes.keys()))
|
self.assertEqual(nodes, set(ring.nodes.keys()))
|
||||||
self.assertEqual(2 ** 5 * len(nodes), len(ring))
|
self.assertEqual(2 ** 5 * len(nodes), len(ring))
|
||||||
nodes.add(u'\u0634\u0628\u06a9\u0647')
|
nodes.add('\u0634\u0628\u06a9\u0647')
|
||||||
ring.add_node(u'\u0634\u0628\u06a9\u0647')
|
ring.add_node('\u0634\u0628\u06a9\u0647')
|
||||||
self.assertEqual(nodes, set(ring.nodes.keys()))
|
self.assertEqual(nodes, set(ring.nodes.keys()))
|
||||||
self.assertEqual(2 ** 5 * len(nodes), len(ring))
|
self.assertEqual(2 ** 5 * len(nodes), len(ring))
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class HashRingTestCase(testcase.TestCase):
|
|||||||
self.assertEqual(2 ** 5 * len(nodes), len(ring))
|
self.assertEqual(2 ** 5 * len(nodes), len(ring))
|
||||||
nodes.add('baz')
|
nodes.add('baz')
|
||||||
nodes.add('baz2')
|
nodes.add('baz2')
|
||||||
ring.add_nodes(set(['baz', 'baz2']), weight=10)
|
ring.add_nodes({'baz', 'baz2'}, weight=10)
|
||||||
self.assertEqual(nodes, set(ring.nodes.keys()))
|
self.assertEqual(nodes, set(ring.nodes.keys()))
|
||||||
self.assertEqual(2 ** 5 * 22, len(ring))
|
self.assertEqual(2 ** 5 * 22, len(ring))
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Copyright © 2016 Red Hat, Inc.
|
# Copyright © 2016 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
@ -21,13 +20,13 @@ from tooz import tests
|
|||||||
class TestPartitioner(tests.TestWithCoordinator):
|
class TestPartitioner(tests.TestWithCoordinator):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPartitioner, self).setUp()
|
super().setUp()
|
||||||
self._extra_coords = []
|
self._extra_coords = []
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for c in self._extra_coords:
|
for c in self._extra_coords:
|
||||||
c.stop()
|
c.stop()
|
||||||
super(TestPartitioner, self).tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def _add_members(self, number_of_members, weight=1):
|
def _add_members(self, number_of_members, weight=1):
|
||||||
groups = []
|
groups = []
|
||||||
@ -66,8 +65,8 @@ class TestPartitioner(tests.TestWithCoordinator):
|
|||||||
p = self._coord.join_partitioned_group(self.group_id, weight=5)
|
p = self._coord.join_partitioned_group(self.group_id, weight=5)
|
||||||
self.assertEqual([5], list(p.ring.nodes.values()))
|
self.assertEqual([5], list(p.ring.nodes.values()))
|
||||||
p2 = self._add_members(1, weight=10)[0]
|
p2 = self._add_members(1, weight=10)[0]
|
||||||
self.assertEqual(set([5, 10]), set(p.ring.nodes.values()))
|
self.assertEqual({5, 10}, set(p.ring.nodes.values()))
|
||||||
self.assertEqual(set([5, 10]), set(p2.ring.nodes.values()))
|
self.assertEqual({5, 10}, set(p2.ring.nodes.values()))
|
||||||
p.stop()
|
p.stop()
|
||||||
|
|
||||||
def test_stop(self):
|
def test_stop(self):
|
||||||
@ -79,7 +78,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 = str(u"чупакабра")
|
o = "чупакабра"
|
||||||
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()
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (c) 2015 OpenStack Foundation
|
# Copyright (c) 2015 OpenStack Foundation
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
|
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
@ -28,7 +26,7 @@ from oslo_utils import excutils
|
|||||||
import tooz
|
import tooz
|
||||||
|
|
||||||
|
|
||||||
class Base64LockEncoder(object):
|
class Base64LockEncoder:
|
||||||
def __init__(self, keyspace_url, prefix=''):
|
def __init__(self, keyspace_url, prefix=''):
|
||||||
self.keyspace_url = keyspace_url
|
self.keyspace_url = keyspace_url
|
||||||
if prefix:
|
if prefix:
|
||||||
@ -52,7 +50,7 @@ class Base64LockEncoder(object):
|
|||||||
return self.keyspace_url + "/" + enc_name.decode("ascii")
|
return self.keyspace_url + "/" + enc_name.decode("ascii")
|
||||||
|
|
||||||
|
|
||||||
class ProxyExecutor(object):
|
class ProxyExecutor:
|
||||||
KIND_TO_FACTORY = {
|
KIND_TO_FACTORY = {
|
||||||
'threaded': (lambda:
|
'threaded': (lambda:
|
||||||
futurist.ThreadPoolExecutor(max_workers=1)),
|
futurist.ThreadPoolExecutor(max_workers=1)),
|
||||||
|
Loading…
Reference in New Issue
Block a user