Add PreconditionFailed exception for HTTP 412 errors
This will be an expected error code from Neutron API tests
when testing the compare-and-swap update capabilities being
added in I7d97d6044378eb59cb2c7bdc788dc6c174783299.
Otherwise the tests need to catch UnexpectedResponseCode and
extract the error number from the body, which looks ugly.
Change-Id: Ic2576438228ea1e15de01779735f7c3ca048c4e5
diff --git a/tempest/lib/common/rest_client.py b/tempest/lib/common/rest_client.py
index d0e21ff..f5bff20 100644
--- a/tempest/lib/common/rest_client.py
+++ b/tempest/lib/common/rest_client.py
@@ -617,6 +617,7 @@
: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 PreconditionFailed: If a 412 response code is received
:raises OverLimit: If a 413 response code is received and over_limit is
not in the response body
:raises RateLimitExceeded: If a 413 response code is received and
@@ -775,6 +776,11 @@
resp_body = self._parse_resp(resp_body)
raise exceptions.Conflict(resp_body, resp=resp)
+ if resp.status == 412:
+ if parse_resp:
+ resp_body = self._parse_resp(resp_body)
+ raise exceptions.PreconditionFailed(resp_body, resp=resp)
+
if resp.status == 413:
if parse_resp:
resp_body = self._parse_resp(resp_body)
diff --git a/tempest/lib/exceptions.py b/tempest/lib/exceptions.py
index 108ba70..af3acbf 100644
--- a/tempest/lib/exceptions.py
+++ b/tempest/lib/exceptions.py
@@ -101,6 +101,11 @@
message = "The requested resource is no longer available"
+class PreconditionFailed(ClientRestClientException):
+ status_code = 412
+ message = "Precondition Failed"
+
+
class RateLimitExceeded(ClientRestClientException):
status_code = 413
message = "Rate limit exceeded"
diff --git a/tempest/tests/lib/test_rest_client.py b/tempest/tests/lib/test_rest_client.py
index e6cf047..4a83631 100644
--- a/tempest/tests/lib/test_rest_client.py
+++ b/tempest/tests/lib/test_rest_client.py
@@ -337,6 +337,10 @@
def test_response_410(self):
self._test_error_checker(exceptions.Gone, self.set_data("410"))
+ def test_response_412(self):
+ self._test_error_checker(exceptions.PreconditionFailed,
+ self.set_data("412"))
+
def test_response_413(self):
self._test_error_checker(exceptions.OverLimit, self.set_data("413"))
@@ -460,7 +464,7 @@
def test_response_bigger_than_400(self):
# Any response code, that bigger than 400, and not in
- # (401, 403, 404, 409, 413, 422, 500, 501)
+ # (401, 403, 404, 409, 412, 413, 422, 500, 501)
self._test_error_checker(exceptions.UnexpectedResponseCode,
self.set_data("402"))