Hi, For the python-etcd3gw package update.. Could we include this patch [0] to the 0.2.5-1 update?
The patch adds a description of the exception if one gets thrown. As well as an additional unit test. Just for clarification, the reason we went to v0.2.5 and not v0.2.6 was the commit "Make API path configurable"(20b4fca3640bb77b957cc57aef0d114e547e593b) breaks existing unit tests, and is not yet in a fixed release. Is that correct? [0] attached as 0001-Include-resp.text-as-detail-in-all-etcd-exceptions.patch Thank you, Heather Lemon -- Heather Lemon Associate Software Engineer (STS Engineering) P: +1-719-415-8858 MM: hlemon | hypothetical-lemon www.canonical.com | www.ubuntu.com
From 5a3157a122368c2314c7a961f61722e47355f981 Mon Sep 17 00:00:00 2001 From: Spike Curtis <sp...@tigera.io> Date: Wed, 12 Feb 2020 17:00:40 -0800 Subject: [PATCH] Include resp.text as detail in all etcd exceptions Signed-off-by: Spike Curtis <sp...@tigera.io> --- etcd3gw/client.py | 5 ++++- etcd3gw/tests/test_client.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/etcd3gw/client.py b/etcd3gw/client.py index 9f2901a..19cadcc 100644 --- a/etcd3gw/client.py +++ b/etcd3gw/client.py @@ -81,7 +81,10 @@ class Etcd3Client(object): try: resp = self.session.post(*args, **kwargs) if resp.status_code in _EXCEPTIONS_BY_CODE: - raise _EXCEPTIONS_BY_CODE[resp.status_code](resp.reason) + raise _EXCEPTIONS_BY_CODE[resp.status_code]( + resp.text, + resp.reason + ) if resp.status_code != requests.codes['ok']: raise exceptions.Etcd3Exception(resp.text, resp.reason) except requests.exceptions.Timeout as ex: diff --git a/etcd3gw/tests/test_client.py b/etcd3gw/tests/test_client.py index 5ebc840..9b0a145 100644 --- a/etcd3gw/tests/test_client.py +++ b/etcd3gw/tests/test_client.py @@ -14,6 +14,7 @@ import mock from etcd3gw.client import Etcd3Client from etcd3gw.exceptions import Etcd3Exception +from etcd3gw.exceptions import InternalServerError from etcd3gw.tests import base @@ -53,4 +54,23 @@ class TestEtcd3Gateway(base.TestCase): self.assertEqual(e.detail_text, '''{ "error": "etcdserver: mvcc: required revision has been compacted", "code": 11 +}''') + + def test_client_exceptions_by_code(self): + client = Etcd3Client(host="127.0.0.1") + with mock.patch.object(client, "session") as mock_session: + mock_response = mock.Mock() + mock_response.status_code = 500 + mock_response.reason = "Internal Server Error" + mock_response.text = '''{ +"error": "etcdserver: unable to reach quorum" +}''' + mock_session.post.return_value = mock_response + try: + client.status() + self.assertFalse(True) + except InternalServerError as e: + self.assertEqual(str(e), "Internal Server Error") + self.assertEqual(e.detail_text, '''{ +"error": "etcdserver: unable to reach quorum" }''') -- 2.25.1