From f180411f42b77f85123e44983f0799e688a21044 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Fri, 17 Nov 2023 23:38:08 +0900 Subject: [PATCH] etcd3gw: Discover API version automatically etcd changed API version from v3beta to v3alpha, then v3, and because of transition available api versions are different according to the etcd server available. This change implements the mechanism to detect the current api version according to the etcd version obtained via the version API. So that the url without api version works regardless of the etcd server used. Closes-Bug: #2043810 Depends-on: https://review.opendev.org/c/openstack/etcd3gw/+/901244 Change-Id: Ib81390eb73feafe08d007db1ced4d0ceb3bde212 --- ...d3gw-api-version-discovery-3e9943c73fae48d4.yaml | 11 +++++++++++ setup.cfg | 2 +- tooz/drivers/etcd3gw.py | 13 +++++++------ tooz/tests/drivers/test_etcd3gw.py | 3 +-- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/etcd3gw-api-version-discovery-3e9943c73fae48d4.yaml diff --git a/releasenotes/notes/etcd3gw-api-version-discovery-3e9943c73fae48d4.yaml b/releasenotes/notes/etcd3gw-api-version-discovery-3e9943c73fae48d4.yaml new file mode 100644 index 00000000..eaeff153 --- /dev/null +++ b/releasenotes/notes/etcd3gw-api-version-discovery-3e9943c73fae48d4.yaml @@ -0,0 +1,11 @@ +--- +features: + - | + The ``etcd3gw`` driver now automatically discovers available etcd API + version and determines the api path. The driver detects the appropriate api + path before sending its first request, and the path is reused for its + subsequent requests. Services may need to be restarted after its backend + etcd server is upgraded, so that the new api path is detected. + The detection is skipped if the coordination backend url contains + the ``api_version`` query parameter or the ``ETCD3GW_API_PATH`` + environment is set. diff --git a/setup.cfg b/setup.cfg index e5740fcd..62700ea6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -53,7 +53,7 @@ etcd3 = grpcio>=1.18.0 protobuf<4.0 # BSD License (3 clause) etcd3gw = - etcd3gw!=0.2.6,>=0.1.0 # Apache-2.0 + etcd3gw!=0.2.6,>=2.3.0 # Apache-2.0 zake = zake>=0.1.6 # Apache-2.0 redis = diff --git a/tooz/drivers/etcd3gw.py b/tooz/drivers/etcd3gw.py index 5d058dee..21634f1b 100644 --- a/tooz/drivers/etcd3gw.py +++ b/tooz/drivers/etcd3gw.py @@ -181,7 +181,7 @@ class Etcd3Driver(coordination.CoordinationDriverCachedRunWatchers, ================== ======= Name Default ================== ======= - api_version v3 + api_version None ca_cert None cert_key None cert_cert None @@ -200,9 +200,6 @@ class Etcd3Driver(coordination.CoordinationDriverCachedRunWatchers, #: 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 = "v3" - GROUP_PREFIX = b"tooz/groups/" def __init__(self, member_id, parsed_url, options): @@ -215,14 +212,18 @@ class Etcd3Driver(coordination.CoordinationDriverCachedRunWatchers, 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) + api_version = options.get("api_version") + if api_version: + api_path = "/" + api_version + "/" + else: + api_path = None 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 + "/", + api_path=api_path, timeout=timeout) self.lock_timeout = int(options.get('lock_timeout', timeout)) self.membership_timeout = int(options.get( diff --git a/tooz/tests/drivers/test_etcd3gw.py b/tooz/tests/drivers/test_etcd3gw.py index ea417895..483f5d91 100644 --- a/tooz/tests/drivers/test_etcd3gw.py +++ b/tooz/tests/drivers/test_etcd3gw.py @@ -34,8 +34,7 @@ class TestEtcd3Gw(testcase.TestCase): 'ca_cert': None, 'cert_key': None, 'cert_cert': None, - 'api_path': ( - "/" + etcd3gw_driver.Etcd3Driver.DEFAULT_API_VERSION + "/"), + 'api_path': None, '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&'