summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Ryzhenkin <vryzhenkin@mirantis.com>2015-11-17 00:59:20 +0300
committerVictor Ryzhenkin <vryzhenkin@mirantis.com>2015-11-17 01:01:10 +0300
commitf20a9c24f50bbae4261a74fa117d826a2899dd98 (patch)
tree9be00fe89ebf9b4fb1259ea88c08c582928d2c23
parent588e675e8b3ca192cc1aff11737cf297954a1de0 (diff)
downloadtempest-lib-f20a9c24f50bbae4261a74fa117d826a2899dd98.tar.gz
Add 410 error code handling to REST client
- Add Gone exception which will raised if REST client hits error code 410. - Add unit tests for this exception. Change-Id: I543fa80875d6de00845d5dc26bc07da2c1a7cd09
-rw-r--r--tempest_lib/common/rest_client.py6
-rw-r--r--tempest_lib/exceptions.py4
-rw-r--r--tempest_lib/tests/test_rest_client.py22
3 files changed, 32 insertions, 0 deletions
diff --git a/tempest_lib/common/rest_client.py b/tempest_lib/common/rest_client.py
index f3fa839..d833d5f 100644
--- a/tempest_lib/common/rest_client.py
+++ b/tempest_lib/common/rest_client.py
@@ -592,6 +592,7 @@ class RestClient(object):
:raises Forbidden: If a 403 response code is received
:raises NotFound: If a 404 response code is received
:raises BadRequest: If a 400 response code is received
+ :raises Gone: If a 410 response code is received
:raises Conflict: If a 409 response code is received
:raises OverLimit: If a 413 response code is received and over_limit is
not in the response body
@@ -696,6 +697,11 @@ class RestClient(object):
resp_body = self._parse_resp(resp_body)
raise exceptions.BadRequest(resp_body, resp=resp)
+ if resp.status == 410:
+ if parse_resp:
+ resp_body = self._parse_resp(resp_body)
+ raise exceptions.Gone(resp_body, resp=resp)
+
if resp.status == 409:
if parse_resp:
resp_body = self._parse_resp(resp_body)
diff --git a/tempest_lib/exceptions.py b/tempest_lib/exceptions.py
index 5873b4a..2bf7cdd 100644
--- a/tempest_lib/exceptions.py
+++ b/tempest_lib/exceptions.py
@@ -115,6 +115,10 @@ class Conflict(ClientRestClientException):
message = "An object with that identifier already exists"
+class Gone(ClientRestClientException):
+ message = "The requested resource is no longer available"
+
+
class ResponseWithNonEmptyBody(OtherRestClientException):
message = ("RFC Violation! Response with %(status)d HTTP Status Code "
"MUST NOT have a body")
diff --git a/tempest_lib/tests/test_rest_client.py b/tempest_lib/tests/test_rest_client.py
index f356ecd..0875092 100644
--- a/tempest_lib/tests/test_rest_client.py
+++ b/tempest_lib/tests/test_rest_client.py
@@ -330,6 +330,9 @@ class TestRestClientErrorCheckerJSON(base.TestCase):
def test_response_409(self):
self._test_error_checker(exceptions.Conflict, self.set_data("409"))
+ def test_response_410(self):
+ self._test_error_checker(exceptions.Gone, self.set_data("410"))
+
def test_response_413(self):
self._test_error_checker(exceptions.OverLimit, self.set_data("413"))
@@ -405,6 +408,25 @@ class TestRestClientErrorCheckerJSON(base.TestCase):
expected = r_body
self.assertEqual(expected, e.resp_body)
+ def test_response_410_with_dict(self):
+ r_body = '{"resp_body": {"err": "fake_resp_body"}}'
+ e = self._test_error_checker(exceptions.Gone,
+ self.set_data("410", r_body=r_body))
+
+ if self.c_type == 'application/json':
+ expected = {"err": "fake_resp_body"}
+ else:
+ expected = r_body
+ self.assertEqual(expected, e.resp_body)
+
+ def test_response_410_with_invalid_dict(self):
+ r_body = '{"foo": "bar"]'
+ e = self._test_error_checker(exceptions.Gone,
+ self.set_data("410", r_body=r_body))
+
+ expected = r_body
+ self.assertEqual(expected, e.resp_body)
+
def test_response_409_with_dict(self):
r_body = '{"resp_body": {"err": "fake_resp_body"}}'
e = self._test_error_checker(exceptions.Conflict,