Merge "Remove wait_for_image_resp_code"
diff --git a/tempest/api/compute/images/test_image_metadata.py b/tempest/api/compute/images/test_image_metadata.py
index a769744..6ecd62a 100644
--- a/tempest/api/compute/images/test_image_metadata.py
+++ b/tempest/api/compute/images/test_image_metadata.py
@@ -42,7 +42,6 @@
resp, _ = cls.client.create_image(cls.server_id, name, {})
cls.image_id = resp['location'].rsplit('/', 1)[1]
- cls.client.wait_for_image_resp_code(cls.image_id, 200)
cls.client.wait_for_image_status(cls.image_id, 'ACTIVE')
@classmethod
diff --git a/tempest/api/compute/images/test_images.py b/tempest/api/compute/images/test_images.py
index 97fbd8b..820aeaf 100644
--- a/tempest/api/compute/images/test_images.py
+++ b/tempest/api/compute/images/test_images.py
@@ -59,7 +59,6 @@
def __create_image__(self, server_id, name, meta=None):
resp, body = self.client.create_image(server_id, name, meta)
image_id = parse_image_id(resp['location'])
- self.client.wait_for_image_resp_code(image_id, 200)
self.client.wait_for_image_status(image_id, 'ACTIVE')
self.image_ids.append(image_id)
return resp, body
diff --git a/tempest/api/compute/images/test_images_oneserver.py b/tempest/api/compute/images/test_images_oneserver.py
index 06e9ab2..ede54c8 100644
--- a/tempest/api/compute/images/test_images_oneserver.py
+++ b/tempest/api/compute/images/test_images_oneserver.py
@@ -104,7 +104,6 @@
resp, body = self.client.create_image(self.server['id'], name, meta)
self.assertEqual(202, resp.status)
image_id = parse_image_id(resp['location'])
- self.client.wait_for_image_resp_code(image_id, 200)
self.client.wait_for_image_status(image_id, 'ACTIVE')
# Verify the image was created correctly
diff --git a/tempest/api/compute/images/test_list_image_filters.py b/tempest/api/compute/images/test_list_image_filters.py
index e700278..dff8cc4 100644
--- a/tempest/api/compute/images/test_list_image_filters.py
+++ b/tempest/api/compute/images/test_list_image_filters.py
@@ -47,7 +47,6 @@
# Create images to be used in the filter tests
resp, body = cls.create_image_from_server(cls.server1['id'])
cls.image1_id = parse_image_id(resp['location'])
- cls.client.wait_for_image_resp_code(cls.image1_id, 200)
cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE')
resp, cls.image1 = cls.client.get_image(cls.image1_id)
@@ -56,13 +55,11 @@
# server will sometimes cause failures
resp, body = cls.create_image_from_server(cls.server2['id'])
cls.image3_id = parse_image_id(resp['location'])
- cls.client.wait_for_image_resp_code(cls.image3_id, 200)
cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE')
resp, cls.image3 = cls.client.get_image(cls.image3_id)
resp, body = cls.create_image_from_server(cls.server1['id'])
cls.image2_id = parse_image_id(resp['location'])
- cls.client.wait_for_image_resp_code(cls.image2_id, 200)
cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE')
resp, cls.image2 = cls.client.get_image(cls.image2_id)
diff --git a/tempest/api/compute/test_authorization.py b/tempest/api/compute/test_authorization.py
index efdadb0..5997f9f 100644
--- a/tempest/api/compute/test_authorization.py
+++ b/tempest/api/compute/test_authorization.py
@@ -65,7 +65,6 @@
name = rand_name('image')
resp, body = cls.client.create_image(server['id'], name)
image_id = parse_image_id(resp['location'])
- cls.images_client.wait_for_image_resp_code(image_id, 200)
cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
resp, cls.image = cls.images_client.get_image(image_id)
diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py
index 81393a9..d0d5e84 100644
--- a/tempest/common/rest_client.py
+++ b/tempest/common/rest_client.py
@@ -32,6 +32,9 @@
MAX_RECURSION_DEPTH = 2
TOKEN_CHARS_RE = re.compile('^[-A-Za-z0-9+/=]*$')
+# All the successful HTTP status codes from RFC 2616
+HTTP_SUCCESS = (200, 201, 202, 203, 204, 205, 206)
+
class RestClient(object):
TYPE = "json"
@@ -266,6 +269,20 @@
raise exceptions.AuthenticationFailure(user=user,
password=password)
+ def expected_success(self, expected_code, read_code):
+ assert_msg = ("This function only allowed to use for HTTP status"
+ "codes which explicitly defined in the RFC 2616. {0}"
+ " is not a defined Success Code!").format(expected_code)
+ assert expected_code in HTTP_SUCCESS, assert_msg
+
+ # NOTE(afazekas): the http status code above 400 is processed by
+ # the _error_checker method
+ if read_code < 400 and read_code != expected_code:
+ pattern = """Unexpected http success status code {0},
+ The expected status code is {1}"""
+ details = pattern.format(read_code, expected_code)
+ raise exceptions.InvalidHttpSuccessCode(details)
+
def post(self, url, body, headers):
return self.request('POST', url, headers, body)
diff --git a/tempest/exceptions.py b/tempest/exceptions.py
index 924ebc9..8c97312 100644
--- a/tempest/exceptions.py
+++ b/tempest/exceptions.py
@@ -57,6 +57,10 @@
pass
+class InvalidHttpSuccessCode(RestClientException):
+ message = "The success code is different than the expected one"
+
+
class NotFound(RestClientException):
message = "Object not found"
diff --git a/tempest/services/compute/json/images_client.py b/tempest/services/compute/json/images_client.py
index b13d0f1..0850158 100644
--- a/tempest/services/compute/json/images_client.py
+++ b/tempest/services/compute/json/images_client.py
@@ -72,6 +72,7 @@
def get_image(self, image_id):
"""Returns the details of a single image."""
resp, body = self.get("images/%s" % str(image_id))
+ self.expected_success(200, resp)
body = json.loads(body)
return resp, body['image']
@@ -79,21 +80,6 @@
"""Deletes the provided image."""
return self.delete("images/%s" % str(image_id))
- def wait_for_image_resp_code(self, image_id, code):
- """
- Waits until the HTTP response code for the request matches the
- expected value
- """
- resp, body = self.get("images/%s" % str(image_id))
- start = int(time.time())
-
- while resp.status != code:
- time.sleep(self.build_interval)
- resp, body = self.get("images/%s" % str(image_id))
-
- if int(time.time()) - start >= self.build_timeout:
- raise exceptions.TimeoutException
-
def wait_for_image_status(self, image_id, status):
"""Waits for an image to reach a given status."""
resp, image = self.get_image(image_id)
diff --git a/tempest/services/compute/xml/images_client.py b/tempest/services/compute/xml/images_client.py
index cc13aa1..b17ae78 100644
--- a/tempest/services/compute/xml/images_client.py
+++ b/tempest/services/compute/xml/images_client.py
@@ -130,6 +130,7 @@
def get_image(self, image_id):
"""Returns the details of a single image."""
resp, body = self.get("images/%s" % str(image_id), self.headers)
+ self.expected_success(200, resp)
body = self._parse_image(etree.fromstring(body))
return resp, body
@@ -137,21 +138,6 @@
"""Deletes the provided image."""
return self.delete("images/%s" % str(image_id), self.headers)
- def wait_for_image_resp_code(self, image_id, code):
- """
- Waits until the HTTP response code for the request matches the
- expected value
- """
- resp, body = self.get("images/%s" % str(image_id), self.headers)
- start = int(time.time())
-
- while resp.status != code:
- time.sleep(self.build_interval)
- resp, body = self.get("images/%s" % str(image_id), self.headers)
-
- if int(time.time()) - start >= self.build_timeout:
- raise exceptions.TimeoutException
-
def wait_for_image_status(self, image_id, status):
"""Waits for an image to reach a given status."""
resp, image = self.get_image(image_id)