From 496ea7917f8d3b365400d0e5f856222b9307d953 Mon Sep 17 00:00:00 2001 From: poojajadhav Date: Mon, 23 Jan 2017 21:05:34 +0530 Subject: [PATCH] Extracted HTTP response codes to constants There are several places in the source code where HTTP response codes are used as numeric values. Status codes 200, 202, 204, 400, 403, 404, 405 and 413 under tests/functional, tests/tempest and tests/unit/api are replaced with symbolic constants from six.moves.http_client thus improves code readability. More patches will be submitted to address other status codes. Partial-Bug: #1520159 Change-Id: Idc4d3ee8469e7a41dda2d33f4e0629442bbbce4c --- .../services/consistencygroups_client.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cinder/tests/tempest/services/consistencygroups_client.py b/cinder/tests/tempest/services/consistencygroups_client.py index 28853ec..10415d4 100644 --- a/cinder/tests/tempest/services/consistencygroups_client.py +++ b/cinder/tests/tempest/services/consistencygroups_client.py @@ -17,6 +17,7 @@ import time from oslo_serialization import jsonutils as json +from six.moves import http_client from tempest import exceptions from tempest.lib.common import rest_client from tempest.lib import exceptions as lib_exc @@ -41,7 +42,7 @@ class ConsistencyGroupsClient(rest_client.RestClient): post_body = json.dumps({'consistencygroup': post_body}) resp, body = self.post('consistencygroups', post_body) body = json.loads(body) - self.expected_success(202, resp.status) + self.expected_success(http_client.ACCEPTED, resp.status) return rest_client.ResponseBody(resp, body) def create_consistencygroup_from_src(self, **kwargs): @@ -58,7 +59,7 @@ class ConsistencyGroupsClient(rest_client.RestClient): post_body = json.dumps({'consistencygroup-from-src': post_body}) resp, body = self.post('consistencygroups/create_from_src', post_body) body = json.loads(body) - self.expected_success(202, resp.status) + self.expected_success(http_client.ACCEPTED, resp.status) return rest_client.ResponseBody(resp, body) def delete_consistencygroup(self, cg_id): @@ -67,7 +68,7 @@ class ConsistencyGroupsClient(rest_client.RestClient): post_body = json.dumps({'consistencygroup': post_body}) resp, body = self.post('consistencygroups/%s/delete' % cg_id, post_body) - self.expected_success(202, resp.status) + self.expected_success(http_client.ACCEPTED, resp.status) return rest_client.ResponseBody(resp, body) def show_consistencygroup(self, cg_id): @@ -75,7 +76,7 @@ class ConsistencyGroupsClient(rest_client.RestClient): url = "consistencygroups/%s" % str(cg_id) resp, body = self.get(url) body = json.loads(body) - self.expected_success(200, resp.status) + self.expected_success(http_client.OK, resp.status) return rest_client.ResponseBody(resp, body) def list_consistencygroups(self, detail=False): @@ -85,7 +86,7 @@ class ConsistencyGroupsClient(rest_client.RestClient): url += "/detail" resp, body = self.get(url) body = json.loads(body) - self.expected_success(200, resp.status) + self.expected_success(http_client.OK, resp.status) return rest_client.ResponseBody(resp, body) def create_cgsnapshot(self, consistencygroup_id, **kwargs): @@ -98,13 +99,13 @@ class ConsistencyGroupsClient(rest_client.RestClient): post_body = json.dumps({'cgsnapshot': post_body}) resp, body = self.post('cgsnapshots', post_body) body = json.loads(body) - self.expected_success(202, resp.status) + self.expected_success(http_client.ACCEPTED, resp.status) return rest_client.ResponseBody(resp, body) def delete_cgsnapshot(self, cgsnapshot_id): """Delete a consistency group snapshot.""" resp, body = self.delete('cgsnapshots/%s' % (str(cgsnapshot_id))) - self.expected_success(202, resp.status) + self.expected_success(http_client.ACCEPTED, resp.status) return rest_client.ResponseBody(resp, body) def show_cgsnapshot(self, cgsnapshot_id): @@ -112,7 +113,7 @@ class ConsistencyGroupsClient(rest_client.RestClient): url = "cgsnapshots/%s" % str(cgsnapshot_id) resp, body = self.get(url) body = json.loads(body) - self.expected_success(200, resp.status) + self.expected_success(http_client.OK, resp.status) return rest_client.ResponseBody(resp, body) def list_cgsnapshots(self, detail=False): @@ -122,7 +123,7 @@ class ConsistencyGroupsClient(rest_client.RestClient): url += "/detail" resp, body = self.get(url) body = json.loads(body) - self.expected_success(200, resp.status) + self.expected_success(http_client.OK, resp.status) return rest_client.ResponseBody(resp, body) def wait_for_consistencygroup_status(self, cg_id, status):