From 714d366b97312d72494fbf03a1746eccc7911065 Mon Sep 17 00:00:00 2001 From: John Eckersberg Date: Mon, 30 Jan 2023 16:10:59 -0500 Subject: [PATCH] Allow override of api path via ETCD3GW_API_PATH envvar Per https://etcd.io/docs/v3.5/dev-guide/api_grpc_gateway/: etcd v3.5 or later uses only [CLIENT-URL]/v3/*. Due to this, running the tests against etcd >= 3.5 will fail, since we use /v3alpha/ by default for backward compatibility. This change allows running the tests successfully against a newer etcd by passing the environment through tox like so: $ ETCD3GW_API_PATH=/v3/ TOX_TESTENV_PASSENV=ETCD3GW_API_PATH tox -epy311 [snip] py311: commands succeeded congratulations :) Change-Id: If0bbe5bb9dd3dd3f3e1ed79e354be582568950ce --- etcd3gw/client.py | 3 ++- etcd3gw/tests/test_client.py | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/etcd3gw/client.py b/etcd3gw/client.py index 0f43ea4..43690ce 100644 --- a/etcd3gw/client.py +++ b/etcd3gw/client.py @@ -11,6 +11,7 @@ # under the License. import json +import os import queue import threading import uuid @@ -37,7 +38,7 @@ _EXCEPTIONS_BY_CODE = { requests.codes['precondition_failed']: exceptions.PreconditionFailedError, } -DEFAULT_API_PATH = '/v3alpha/' +DEFAULT_API_PATH = os.getenv('ETCD3GW_API_PATH', '/v3alpha/') class Etcd3Client(object): diff --git a/etcd3gw/tests/test_client.py b/etcd3gw/tests/test_client.py index 39a6df3..7c36c94 100644 --- a/etcd3gw/tests/test_client.py +++ b/etcd3gw/tests/test_client.py @@ -22,17 +22,20 @@ class TestEtcd3Gateway(base.TestCase): def test_client_default(self): client = Etcd3Client() - self.assertEqual("http://localhost:2379/v3alpha/lease/grant", + self.assertEqual("http://localhost:2379%slease/grant" % + client.api_path, client.get_url("/lease/grant")) def test_client_ipv4(self): client = Etcd3Client(host="127.0.0.1") - self.assertEqual("http://127.0.0.1:2379/v3alpha/lease/grant", + self.assertEqual("http://127.0.0.1:2379%slease/grant" % + client.api_path, client.get_url("/lease/grant")) def test_client_ipv6(self): client = Etcd3Client(host="::1") - self.assertEqual("http://[::1]:2379/v3alpha/lease/grant", + self.assertEqual("http://[::1]:2379%slease/grant" % + client.api_path, client.get_url("/lease/grant")) def test_client_bad_request(self):