summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-02-12 18:08:02 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-02-12 18:11:02 -0800
commit60bf3af5879e5f5df1a6be69f98e714ed9c17212 (patch)
tree6b7da3ac00a8eea3434903c464e3aba8f1c2d304
parent5edf2b3db33a42b646fe923580debff6b58a1122 (diff)
downloadtooz-60bf3af5879e5f5df1a6be69f98e714ed9c17212.tar.gz
Allow coordinator non-string options and use them
To allow the zake driver to use a pre-existing storage backend (for example, shared with a taskflow test that also uses zake) we need a way to provide non-query-string options and to get those options to the zake driver for usage. This approach allows the `get_coordinator` function to take **kwargs and have those take precedence over the options found with the same name in the urls query string (and merge those together to form the coordinators option dictionary that exists already). Change-Id: Ibc745927eccac050992227410cca393d956f8c44
-rw-r--r--tooz/coordination.py16
-rw-r--r--tooz/drivers/zake.py6
2 files changed, 19 insertions, 3 deletions
diff --git a/tooz/coordination.py b/tooz/coordination.py
index 0cdbef1..41ac223 100644
--- a/tooz/coordination.py
+++ b/tooz/coordination.py
@@ -340,21 +340,33 @@ class CoordAsyncResult(object):
"""Returns True if the task is done, False otherwise."""
-def get_coordinator(backend_url, member_id):
+def get_coordinator(backend_url, member_id, **kwargs):
"""Initialize and load the backend.
:param backend_url: the backend URL to use
:type backend: str
:param member_id: the id of the member
:type member_id: str
+ :param kwargs: additional coordinator options (these take precedence over
+ options of the **same** name found in the ``backend_url``
+ arguments query string)
"""
parsed_url = netutils.urlsplit(backend_url)
parsed_qs = six.moves.urllib.parse.parse_qs(parsed_url.query)
+ if kwargs:
+ options = {}
+ for (k, v) in six.iteritems(kwargs):
+ options[k] = [v]
+ for (k, v) in six.iteritems(parsed_qs):
+ if k not in options:
+ options[k] = v
+ else:
+ options = parsed_qs
return driver.DriverManager(
namespace=TOOZ_BACKENDS_NAMESPACE,
name=parsed_url.scheme,
invoke_on_load=True,
- invoke_args=(member_id, parsed_url, parsed_qs)).driver
+ invoke_args=(member_id, parsed_url, options)).driver
class ToozError(Exception):
diff --git a/tooz/drivers/zake.py b/tooz/drivers/zake.py
index 1909a43..e10f365 100644
--- a/tooz/drivers/zake.py
+++ b/tooz/drivers/zake.py
@@ -35,4 +35,8 @@ class ZakeDriver(zookeeper.KazooDriver):
@classmethod
def _make_client(cls, parsed_url, options):
- return fake_client.FakeClient(storage=cls.fake_storage)
+ if 'storage' in options:
+ storage = options['storage'][-1]
+ else:
+ storage = cls.fake_storage
+ return fake_client.FakeClient(storage=storage)