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
poojajadhav
9 years ago
| 16 | 16 | import time |
| 17 | 17 | |
| 18 | 18 | from oslo_serialization import jsonutils as json |
| 19 | from six.moves import http_client | |
| 19 | 20 | from tempest import exceptions |
| 20 | 21 | from tempest.lib.common import rest_client |
| 21 | 22 | from tempest.lib import exceptions as lib_exc |
| 40 | 41 | post_body = json.dumps({'consistencygroup': post_body}) |
| 41 | 42 | resp, body = self.post('consistencygroups', post_body) |
| 42 | 43 | body = json.loads(body) |
| 43 | self.expected_success(202, resp.status) | |
| 44 | self.expected_success(http_client.ACCEPTED, resp.status) | |
| 44 | 45 | return rest_client.ResponseBody(resp, body) |
| 45 | 46 | |
| 46 | 47 | def create_consistencygroup_from_src(self, **kwargs): |
| 57 | 58 | post_body = json.dumps({'consistencygroup-from-src': post_body}) |
| 58 | 59 | resp, body = self.post('consistencygroups/create_from_src', post_body) |
| 59 | 60 | body = json.loads(body) |
| 60 | self.expected_success(202, resp.status) | |
| 61 | self.expected_success(http_client.ACCEPTED, resp.status) | |
| 61 | 62 | return rest_client.ResponseBody(resp, body) |
| 62 | 63 | |
| 63 | 64 | def delete_consistencygroup(self, cg_id): |
| 66 | 67 | post_body = json.dumps({'consistencygroup': post_body}) |
| 67 | 68 | resp, body = self.post('consistencygroups/%s/delete' % cg_id, |
| 68 | 69 | post_body) |
| 69 | self.expected_success(202, resp.status) | |
| 70 | self.expected_success(http_client.ACCEPTED, resp.status) | |
| 70 | 71 | return rest_client.ResponseBody(resp, body) |
| 71 | 72 | |
| 72 | 73 | def show_consistencygroup(self, cg_id): |
| 74 | 75 | url = "consistencygroups/%s" % str(cg_id) |
| 75 | 76 | resp, body = self.get(url) |
| 76 | 77 | body = json.loads(body) |
| 77 | self.expected_success(200, resp.status) | |
| 78 | self.expected_success(http_client.OK, resp.status) | |
| 78 | 79 | return rest_client.ResponseBody(resp, body) |
| 79 | 80 | |
| 80 | 81 | def list_consistencygroups(self, detail=False): |
| 84 | 85 | url += "/detail" |
| 85 | 86 | resp, body = self.get(url) |
| 86 | 87 | body = json.loads(body) |
| 87 | self.expected_success(200, resp.status) | |
| 88 | self.expected_success(http_client.OK, resp.status) | |
| 88 | 89 | return rest_client.ResponseBody(resp, body) |
| 89 | 90 | |
| 90 | 91 | def create_cgsnapshot(self, consistencygroup_id, **kwargs): |
| 97 | 98 | post_body = json.dumps({'cgsnapshot': post_body}) |
| 98 | 99 | resp, body = self.post('cgsnapshots', post_body) |
| 99 | 100 | body = json.loads(body) |
| 100 | self.expected_success(202, resp.status) | |
| 101 | self.expected_success(http_client.ACCEPTED, resp.status) | |
| 101 | 102 | return rest_client.ResponseBody(resp, body) |
| 102 | 103 | |
| 103 | 104 | def delete_cgsnapshot(self, cgsnapshot_id): |
| 104 | 105 | """Delete a consistency group snapshot.""" |
| 105 | 106 | resp, body = self.delete('cgsnapshots/%s' % (str(cgsnapshot_id))) |
| 106 | self.expected_success(202, resp.status) | |
| 107 | self.expected_success(http_client.ACCEPTED, resp.status) | |
| 107 | 108 | return rest_client.ResponseBody(resp, body) |
| 108 | 109 | |
| 109 | 110 | def show_cgsnapshot(self, cgsnapshot_id): |
| 111 | 112 | url = "cgsnapshots/%s" % str(cgsnapshot_id) |
| 112 | 113 | resp, body = self.get(url) |
| 113 | 114 | body = json.loads(body) |
| 114 | self.expected_success(200, resp.status) | |
| 115 | self.expected_success(http_client.OK, resp.status) | |
| 115 | 116 | return rest_client.ResponseBody(resp, body) |
| 116 | 117 | |
| 117 | 118 | def list_cgsnapshots(self, detail=False): |
| 121 | 122 | url += "/detail" |
| 122 | 123 | resp, body = self.get(url) |
| 123 | 124 | body = json.loads(body) |
| 124 | self.expected_success(200, resp.status) | |
| 125 | self.expected_success(http_client.OK, resp.status) | |
| 125 | 126 | return rest_client.ResponseBody(resp, body) |
| 126 | 127 | |
| 127 | 128 | def wait_for_consistencygroup_status(self, cg_id, status): |