diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-06-25 17:16:20 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-06-25 17:16:20 +0000 |
commit | c096afa8193f37112ed5a547a88904c9d6686ce0 (patch) | |
tree | a2585e19b1c53ef7bc5fa46c13e1fc332f7c6cef | |
parent | 31662cad4e2297b0aa681baac2b7a20eb2efb079 (diff) | |
parent | b48f9feb47894549f2d2cdffb8149d1e9eef85a7 (diff) | |
download | tempest-lib-c096afa8193f37112ed5a547a88904c9d6686ce0.tar.gz |
Merge "Categorize rest client exceptions"
-rw-r--r-- | tempest_lib/common/rest_client.py | 8 | ||||
-rw-r--r-- | tempest_lib/exceptions.py | 52 | ||||
-rw-r--r-- | tempest_lib/tests/test_rest_client.py | 2 |
3 files changed, 39 insertions, 23 deletions
diff --git a/tempest_lib/common/rest_client.py b/tempest_lib/common/rest_client.py index 062cc8e..6ae2348 100644 --- a/tempest_lib/common/rest_client.py +++ b/tempest_lib/common/rest_client.py @@ -583,9 +583,8 @@ class RestClient(object): :rtype: tuple :return: a tuple with the first entry containing the response headers and the second the response body - :raises InvalidContentType: If the content-type of the response isn't - an expect type or a 415 response code is - received + :raises UnexpectedContentType: If the content-type of the response + isn't an expect type :raises Unauthorized: If a 401 response code is received :raises Forbidden: If a 403 response code is received :raises NotFound: If a 404 response code is received @@ -595,6 +594,7 @@ class RestClient(object): not in the response body :raises RateLimitExceeded: If a 413 response code is received and over_limit is in the response body + :raises InvalidContentType: If a 415 response code is received :raises UnprocessableEntity: If a 422 response code is received :raises InvalidHTTPResponseBody: The response body wasn't valid JSON and couldn't be parsed @@ -670,7 +670,7 @@ class RestClient(object): elif ctype.lower() in TXT_ENC: parse_resp = False else: - raise exceptions.InvalidContentType(str(resp.status)) + raise exceptions.UnexpectedContentType(str(resp.status)) if resp.status == 401: if parse_resp: diff --git a/tempest_lib/exceptions.py b/tempest_lib/exceptions.py index 887c9b0..ba51622 100644 --- a/tempest_lib/exceptions.py +++ b/tempest_lib/exceptions.py @@ -53,77 +53,93 @@ class RestClientException(TempestException, super(RestClientException, self).__init__(message, *args, **kwargs) -class InvalidHttpSuccessCode(RestClientException): +class OtherRestClientException(RestClientException): + pass + + +class ServerRestClientException(RestClientException): + pass + + +class ClientRestClientException(RestClientException): + pass + + +class InvalidHttpSuccessCode(OtherRestClientException): message = "The success code is different than the expected one" -class NotFound(RestClientException): +class NotFound(ClientRestClientException): message = "Object not found" -class Unauthorized(RestClientException): +class Unauthorized(ClientRestClientException): message = 'Unauthorized' -class Forbidden(RestClientException): +class Forbidden(ClientRestClientException): message = "Forbidden" -class TimeoutException(RestClientException): +class TimeoutException(OtherRestClientException): message = "Request timed out" -class BadRequest(RestClientException): +class BadRequest(ClientRestClientException): message = "Bad request" -class UnprocessableEntity(RestClientException): +class UnprocessableEntity(ClientRestClientException): message = "Unprocessable entity" -class RateLimitExceeded(RestClientException): +class RateLimitExceeded(ClientRestClientException): message = "Rate limit exceeded" -class OverLimit(RestClientException): +class OverLimit(ClientRestClientException): message = "Quota exceeded" -class ServerFault(RestClientException): +class ServerFault(ServerRestClientException): message = "Got server fault" -class NotImplemented(RestClientException): +class NotImplemented(ServerRestClientException): message = "Got NotImplemented error" -class Conflict(RestClientException): +class Conflict(ClientRestClientException): message = "An object with that identifier already exists" -class ResponseWithNonEmptyBody(RestClientException): +class ResponseWithNonEmptyBody(OtherRestClientException): message = ("RFC Violation! Response with %(status)d HTTP Status Code " "MUST NOT have a body") -class ResponseWithEntity(RestClientException): +class ResponseWithEntity(OtherRestClientException): message = ("RFC Violation! Response with 205 HTTP Status Code " "MUST NOT have an entity") -class InvalidHTTPResponseBody(RestClientException): +class InvalidHTTPResponseBody(OtherRestClientException): message = "HTTP response body is invalid json or xml" -class InvalidHTTPResponseHeader(RestClientException): +class InvalidHTTPResponseHeader(OtherRestClientException): message = "HTTP response header is invalid" -class InvalidContentType(RestClientException): +class InvalidContentType(ClientRestClientException): message = "Invalid content type provided" -class UnexpectedResponseCode(RestClientException): +class UnexpectedContentType(OtherRestClientException): + message = "Unexpected content type provided" + + +class UnexpectedResponseCode(OtherRestClientException): message = "Unexpected response code received" diff --git a/tempest_lib/tests/test_rest_client.py b/tempest_lib/tests/test_rest_client.py index 5deee3f..b71555c 100644 --- a/tempest_lib/tests/test_rest_client.py +++ b/tempest_lib/tests/test_rest_client.py @@ -464,7 +464,7 @@ class TestRestClientErrorCheckerTEXT(TestRestClientErrorCheckerJSON): # This test is required only in one exemplar # Any response code, that bigger than 400, and not in # (401, 403, 404, 409, 413, 422, 500, 501) - self.assertRaises(exceptions.InvalidContentType, + self.assertRaises(exceptions.UnexpectedContentType, self.rest_client._error_checker, **self.set_data("405", enc="fake_enc")) |