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
This commit is contained in:
John Eckersberg 2023-01-30 16:10:59 -05:00
parent 2a7f392a80
commit 714d366b97
2 changed files with 8 additions and 4 deletions

View File

@ -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):

View File

@ -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):