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
This commit is contained in:
parent
5edf2b3db3
commit
60bf3af587
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue