Support etcd3gw api version

since etcd3 3.5 dropped support for v3alpha and v3beta api, replacing
those with v3.

etcd3gw library supports passing api_path (v3alpha by default), but tooz
lacks such possibility and thus can not work with etcd3 3.5.

This patch adds handling of "api_version" in the options to
"ectd3+https" connection URLs (defaults to v3alpha as it is today and
corresponds to etcd3 version shipped in major LTS distros at the
moment).

Closes-Bug: #1983668
Depends-On: I49c480f573a4ba8294627a3ce730b816ded10aed
Change-Id: Ib30c1e003f261cd7e1ac6fed87167f9974bf8542
This commit is contained in:
Pavlo Shchelokovskyy 2022-02-02 15:06:27 +02:00 committed by Alan Bishop
parent e88e601f92
commit b64623daeb
2 changed files with 12 additions and 1 deletions

View File

@ -177,6 +177,7 @@ class Etcd3Driver(coordination.CoordinationDriverWithExecutor):
================== =======
Name Default
================== =======
api_version v3alpha
ca_cert None
cert_key None
cert_cert None
@ -195,6 +196,9 @@ class Etcd3Driver(coordination.CoordinationDriverWithExecutor):
#: Default port used if none provided (4001 or 2379 are the common ones).
DEFAULT_PORT = 2379
#: Default api version if none provided
DEFAULT_API_VERSION = "v3alpha"
GROUP_PREFIX = b"tooz/groups/"
def __init__(self, member_id, parsed_url, options):
@ -207,12 +211,14 @@ class Etcd3Driver(coordination.CoordinationDriverWithExecutor):
cert_key = options.get('cert_key')
cert_cert = options.get('cert_cert')
timeout = int(options.get('timeout', self.DEFAULT_TIMEOUT))
api_version = options.get("api_version", self.DEFAULT_API_VERSION)
self.client = etcd3gw.client(host=host,
port=port,
protocol=protocol,
ca_cert=ca_cert,
cert_key=cert_key,
cert_cert=cert_cert,
api_path="/" + api_version + "/",
timeout=timeout)
self.lock_timeout = int(options.get('lock_timeout', timeout))
self.membership_timeout = int(options.get(

View File

@ -34,16 +34,19 @@ class TestEtcd3Gw(testcase.TestCase):
'ca_cert': None,
'cert_key': None,
'cert_cert': None,
'api_path': (
"/" + etcd3gw_driver.Etcd3Driver.DEFAULT_API_VERSION + "/"),
'timeout': etcd3gw_driver.Etcd3Driver.DEFAULT_TIMEOUT},
{'coord_url': ('etcd3+https://my_host:666?ca_cert=/my/ca_cert&'
'cert_key=/my/cert_key&cert_cert=/my/cert_cert&'
'timeout=42'),
'timeout=42&api_version=v3'),
'protocol': 'https',
'host': 'my_host',
'port': 666,
'ca_cert': '/my/ca_cert',
'cert_key': '/my/cert_key',
'cert_cert': '/my/cert_cert',
'api_path': '/v3/',
'timeout': 42})
@ddt.unpack
@mock.patch('etcd3gw.client')
@ -56,6 +59,7 @@ class TestEtcd3Gw(testcase.TestCase):
ca_cert,
cert_key,
cert_cert,
api_path,
timeout):
tooz.coordination.get_coordinator(coord_url, self.FAKE_MEMBER_ID)
mock_etcd3gw_client.assert_called_with(host=host,
@ -64,4 +68,5 @@ class TestEtcd3Gw(testcase.TestCase):
ca_cert=ca_cert,
cert_key=cert_key,
cert_cert=cert_cert,
api_path=api_path,
timeout=timeout)