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
This commit is contained in:
poojajadhav 2017-01-23 21:05:34 +05:30
parent 35738c47ab
commit 90fed35450
14 changed files with 156 additions and 126 deletions

View File

@ -15,6 +15,7 @@
from oslo_serialization import jsonutils
from oslo_utils import netutils
import requests
from six.moves import http_client
from six.moves import urllib
from cinder.i18n import _
@ -113,7 +114,7 @@ class TestOpenStackClient(object):
http_status = response.status_code
if http_status == 401:
if http_status == http_client.UNAUTHORIZED:
raise OpenStackApiException401(response=response)
self.auth_result = response.headers
@ -160,7 +161,7 @@ class TestOpenStackClient(object):
return ""
def api_get(self, relative_uri, **kwargs):
kwargs.setdefault('check_response_status', [200])
kwargs.setdefault('check_response_status', [http_client.OK])
response = self.api_request(relative_uri, **kwargs)
return self._decode_json(response)
@ -171,7 +172,8 @@ class TestOpenStackClient(object):
headers['Content-Type'] = 'application/json'
kwargs['body'] = jsonutils.dumps(body)
kwargs.setdefault('check_response_status', [200, 202])
kwargs.setdefault('check_response_status', [http_client.OK,
http_client.ACCEPTED])
response = self.api_request(relative_uri, **kwargs)
return self._decode_json(response)
@ -182,13 +184,17 @@ class TestOpenStackClient(object):
headers['Content-Type'] = 'application/json'
kwargs['body'] = jsonutils.dumps(body)
kwargs.setdefault('check_response_status', [200, 202, 204])
kwargs.setdefault('check_response_status', [http_client.OK,
http_client.ACCEPTED,
http_client.NO_CONTENT])
response = self.api_request(relative_uri, **kwargs)
return self._decode_json(response)
def api_delete(self, relative_uri, **kwargs):
kwargs['method'] = 'DELETE'
kwargs.setdefault('check_response_status', [200, 202, 204])
kwargs.setdefault('check_response_status', [http_client.OK,
http_client.ACCEPTED,
http_client.NO_CONTENT])
return self.api_request(relative_uri, **kwargs)
def get_volume(self, volume_id):

View File

@ -17,6 +17,7 @@
import iso8601
from oslo_config import cfg
from oslo_serialization import jsonutils
from six.moves import http_client
import webob
from cinder.api import extensions
@ -56,7 +57,7 @@ class ExtensionControllerTest(ExtensionTestCase):
app = router.APIRouter()
request = webob.Request.blank("/fake/extensions")
response = request.get_response(app)
self.assertEqual(200, response.status_int)
self.assertEqual(http_client.OK, response.status_int)
# Make sure we have all the extensions, extra extensions being OK.
data = jsonutils.loads(response.body)
@ -91,7 +92,7 @@ class ExtensionControllerTest(ExtensionTestCase):
app = router.APIRouter()
request = webob.Request.blank("/fake/extensions/FOXNSOX")
response = request.get_response(app)
self.assertEqual(200, response.status_int)
self.assertEqual(http_client.OK, response.status_int)
data = jsonutils.loads(response.body)
self.assertEqual(
@ -105,7 +106,7 @@ class ExtensionControllerTest(ExtensionTestCase):
app = router.APIRouter()
request = webob.Request.blank("/fake/extensions/4")
response = request.get_response(app)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
class StubExtensionManager(object):

View File

@ -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):

View File

@ -16,6 +16,7 @@ import uuid
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from six.moves import http_client
import webob
from cinder.api.contrib import volume_image_metadata
@ -148,14 +149,14 @@ class VolumeImageMetadataTest(test.TestCase):
self._create_volume_and_glance_metadata()
res = self._make_request('/v2/%s/volumes/%s' % (
fake.PROJECT_ID, self.UUID))
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(fake_image_metadata,
self._get_image_metadata(res.body))
def test_list_detail_volumes(self):
self._create_volume_and_glance_metadata()
res = self._make_request('/v2/%s/volumes/detail' % fake.PROJECT_ID)
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(fake_image_metadata,
self._get_image_metadata_list(res.body)[0])
@ -169,7 +170,7 @@ class VolumeImageMetadataTest(test.TestCase):
fake_volume_get_all_empty)
res = self._make_request('/v2/%s/volumes/detail' % fake.PROJECT_ID)
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertFalse(fake_dont_call_this.called)
def test_list_detail_volumes_with_limit(self):
@ -183,7 +184,7 @@ class VolumeImageMetadataTest(test.TestCase):
'key2', 'value2')
res = self._make_request('/v2/%s/volumes/detail?limit=1'
% fake.PROJECT_ID)
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual({'key1': 'value1', 'key2': 'value2'},
self._get_image_metadata_list(res.body)[0])
@ -202,7 +203,7 @@ class VolumeImageMetadataTest(test.TestCase):
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.user_ctxt))
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(fake_image_metadata,
jsonutils.loads(res.body)["metadata"])
@ -233,7 +234,7 @@ class VolumeImageMetadataTest(test.TestCase):
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.user_ctxt))
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(fake_image_metadata,
jsonutils.loads(res.body)["metadata"])
@ -308,7 +309,7 @@ class VolumeImageMetadataTest(test.TestCase):
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.user_ctxt))
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
def test_delete_meta_not_found(self):
data = {"os-unset_image_metadata": {
@ -349,6 +350,6 @@ class VolumeImageMetadataTest(test.TestCase):
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.user_ctxt))
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(fake_image_metadata,
jsonutils.loads(res.body)["metadata"])

View File

@ -18,6 +18,7 @@ import mock
from oslo_config import cfg
import oslo_messaging as messaging
from oslo_serialization import jsonutils
from six.moves import http_client
from six.moves.urllib.parse import urlencode
import webob
@ -215,7 +216,7 @@ class VolumeManageTest(test.TestCase):
if cluster:
body['volume']['cluster'] = 'cluster'
res = self._get_resp_post(body)
self.assertEqual(202, res.status_int)
self.assertEqual(http_client.ACCEPTED, res.status_int)
# Check that the manage API was called with the correct arguments.
self.assertEqual(1, mock_api_manage.call_count)
@ -267,7 +268,7 @@ class VolumeManageTest(test.TestCase):
"""Test correct failure when host is not specified."""
body = {'volume': {'ref': 'fake_ref'}}
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int)
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
@mock.patch('cinder.objects.Service.get_by_args')
def test_manage_volume_service_not_found_on_host(self, mock_service):
@ -278,13 +279,13 @@ class VolumeManageTest(test.TestCase):
service_id='cinder-volume',
host='host_ok')
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int)
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
def test_manage_volume_missing_ref(self):
"""Test correct failure when the ref is not specified."""
body = {'volume': {'host': 'host_ok'}}
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int)
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
def test_manage_volume_with_invalid_bootable(self):
"""Test correct failure when invalid bool value is specified."""
@ -292,7 +293,7 @@ class VolumeManageTest(test.TestCase):
'ref': 'fake_ref',
'bootable': 'InvalidBool'}}
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int)
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
@mock.patch('cinder.objects.service.Service.is_up', return_value=True,
new_callable=mock.PropertyMock)
@ -300,7 +301,7 @@ class VolumeManageTest(test.TestCase):
"""Test manage volume failure due to disabled service."""
body = {'volume': {'host': 'host_disabled', 'ref': 'fake_ref'}}
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int, res)
self.assertEqual(http_client.BAD_REQUEST, res.status_int, res)
self.assertEqual(exception.ServiceUnavailable.message,
res.json['badRequest']['message'])
mock_is_up.assert_not_called()
@ -311,7 +312,7 @@ class VolumeManageTest(test.TestCase):
"""Test manage volume failure due to down service."""
body = {'volume': {'host': 'host_ok', 'ref': 'fake_ref'}}
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int, res)
self.assertEqual(http_client.BAD_REQUEST, res.status_int, res)
self.assertEqual(exception.ServiceUnavailable.message,
res.json['badRequest']['message'])
self.assertTrue(mock_is_up.called)
@ -330,7 +331,7 @@ class VolumeManageTest(test.TestCase):
'volume_type': fake.VOLUME_TYPE_ID,
'bootable': True}}
res = self._get_resp_post(body)
self.assertEqual(202, res.status_int)
self.assertEqual(http_client.ACCEPTED, res.status_int)
self.assertTrue(mock_validate.called)
@mock.patch('cinder.volume.api.API.manage_existing', api_manage)
@ -346,7 +347,7 @@ class VolumeManageTest(test.TestCase):
'ref': 'fake_ref',
'volume_type': 'good_fakevt'}}
res = self._get_resp_post(body)
self.assertEqual(202, res.status_int)
self.assertEqual(http_client.ACCEPTED, res.status_int)
self.assertTrue(mock_validate.called)
def test_manage_volume_bad_volume_type_by_uuid(self):
@ -355,7 +356,7 @@ class VolumeManageTest(test.TestCase):
'ref': 'fake_ref',
'volume_type': fake.WILL_NOT_BE_FOUND_ID}}
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int)
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
def test_manage_volume_bad_volume_type_by_name(self):
"""Test failure on nonexistent volume type specified by name."""
@ -363,7 +364,7 @@ class VolumeManageTest(test.TestCase):
'ref': 'fake_ref',
'volume_type': 'bad_fakevt'}}
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int)
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
def _get_resp_get(self, host, detailed, paging, admin=True):
"""Helper to execute a GET os-volume-manage API call."""
@ -389,10 +390,10 @@ class VolumeManageTest(test.TestCase):
wraps=api_get_manageable_volumes)
def test_get_manageable_volumes_non_admin(self, mock_api_manageable):
res = self._get_resp_get('fakehost', False, False, admin=False)
self.assertEqual(403, res.status_int)
self.assertEqual(http_client.FORBIDDEN, res.status_int)
mock_api_manageable.assert_not_called()
res = self._get_resp_get('fakehost', True, False, admin=False)
self.assertEqual(403, res.status_int)
self.assertEqual(http_client.FORBIDDEN, res.status_int)
mock_api_manageable.assert_not_called()
@mock.patch('cinder.volume.api.API.get_manageable_volumes',
@ -406,7 +407,7 @@ class VolumeManageTest(test.TestCase):
'size': 4, 'safe_to_manage': False},
{'reference': {'source-name': 'myvol'},
'size': 5, 'safe_to_manage': True}]}
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(exp, jsonutils.loads(res.body))
mock_api_manageable.assert_called_once_with(
self._admin_ctxt, 'fakehost', None, limit=10, marker='1234',
@ -433,7 +434,7 @@ class VolumeManageTest(test.TestCase):
{'reference': {'source-name': 'myvol'}, 'cinder_id': None,
'size': 5, 'reason_not_safe': None, 'safe_to_manage': True,
'extra_info': 'qos_setting:low'}]}
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(exp, jsonutils.loads(res.body))
mock_api_manageable.assert_called_once_with(
self._admin_ctxt, 'fakehost', None, limit=CONF.osapi_max_limit,
@ -458,13 +459,13 @@ class VolumeManageTest(test.TestCase):
'ref': 'fake_ref',
"metadata": value}}
res = self._get_resp_post(body)
self.assertEqual(400, res.status_int)
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
@mock.patch('cinder.objects.service.Service.is_up', return_value=True,
new_callable=mock.PropertyMock)
def test_get_manageable_volumes_disabled(self, mock_is_up):
res = self._get_resp_get('host_disabled', False, True)
self.assertEqual(400, res.status_int, res)
self.assertEqual(http_client.BAD_REQUEST, res.status_int, res)
self.assertEqual(exception.ServiceUnavailable.message,
res.json['badRequest']['message'])
mock_is_up.assert_not_called()
@ -473,7 +474,7 @@ class VolumeManageTest(test.TestCase):
new_callable=mock.PropertyMock)
def test_get_manageable_volumes_is_down(self, mock_is_up):
res = self._get_resp_get('host_ok', False, True)
self.assertEqual(400, res.status_int, res)
self.assertEqual(http_client.BAD_REQUEST, res.status_int, res)
self.assertEqual(exception.ServiceUnavailable.message,
res.json['badRequest']['message'])
self.assertTrue(mock_is_up.called)
@ -484,7 +485,7 @@ class VolumeManageTest(test.TestCase):
body = {'volume': {'host': 'host_ok',
'ref': 'fake_ref'}}
res = self._get_resp_post_v3(body, '3.15')
self.assertEqual(202, res.status_int)
self.assertEqual(http_client.ACCEPTED, res.status_int)
self.assertEqual(1, mock_api_manage.call_count)
self.assertEqual('creating',
jsonutils.loads(res.body)['volume']['status'])
@ -496,7 +497,7 @@ class VolumeManageTest(test.TestCase):
body = {'volume': {'host': 'host_ok',
'ref': 'fake_ref'}}
res = self._get_resp_post(body)
self.assertEqual(202, res.status_int)
self.assertEqual(http_client.ACCEPTED, res.status_int)
self.assertEqual(1, mock_api_manage.call_count)
self.assertEqual('creating',
jsonutils.loads(res.body)['volume']['status'])

View File

@ -20,6 +20,7 @@ Tests for volume transfer code.
import mock
from oslo_serialization import jsonutils
from six.moves import http_client
import webob
from cinder.api.contrib import volume_transfer
@ -80,7 +81,7 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual('test_transfer', res_dict['transfer']['name'])
self.assertEqual(transfer['id'], res_dict['transfer']['id'])
self.assertEqual(volume_id, res_dict['transfer']['volume_id'])
@ -97,8 +98,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual(http_client.NOT_FOUND, res.status_int)
self.assertEqual(http_client.NOT_FOUND,
res_dict['itemNotFound']['code'])
self.assertEqual('Transfer %s could not be found.' %
fake.WILL_NOT_BE_FOUND_ID,
res_dict['itemNotFound']['message'])
@ -117,7 +119,7 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(4, len(res_dict['transfers'][0]))
self.assertEqual(transfer1['id'], res_dict['transfers'][0]['id'])
self.assertEqual('test_transfer', res_dict['transfers'][0]['name'])
@ -144,7 +146,7 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(200, res.status_int)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(5, len(res_dict['transfers'][0]))
self.assertEqual('test_transfer',
res_dict['transfers'][0]['name'])
@ -201,7 +203,7 @@ class VolumeTransferAPITestCase(test.TestCase):
res_dict = jsonutils.loads(res.body)
self.assertEqual(202, res.status_int)
self.assertEqual(http_client.ACCEPTED, res.status_int)
self.assertIn('id', res_dict['transfer'])
self.assertIn('auth_key', res_dict['transfer'])
self.assertIn('created_at', res_dict['transfer'])
@ -222,8 +224,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
self.assertEqual(http_client.BAD_REQUEST,
res_dict['badRequest']['code'])
self.assertEqual("Missing required element 'transfer' in "
"request body.",
res_dict['badRequest']['message'])
@ -239,8 +242,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
self.assertEqual(http_client.BAD_REQUEST,
res_dict['badRequest']['code'])
self.assertEqual('Incorrect request body format',
res_dict['badRequest']['message'])
@ -257,8 +261,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual(http_client.NOT_FOUND, res.status_int)
self.assertEqual(http_client.NOT_FOUND,
res_dict['itemNotFound']['code'])
self.assertEqual('Volume 1234 could not be found.',
res_dict['itemNotFound']['message'])
@ -275,8 +280,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
self.assertEqual(http_client.BAD_REQUEST,
res_dict['badRequest']['code'])
self.assertEqual('Invalid volume: status must be available',
res_dict['badRequest']['message'])
@ -292,7 +298,7 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.user_ctxt))
self.assertEqual(202, res.status_int)
self.assertEqual(http_client.ACCEPTED, res.status_int)
# verify transfer has been deleted
req = webob.Request.blank('/v2/%s/os-volume-transfer/%s' % (
@ -303,8 +309,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual(http_client.NOT_FOUND, res.status_int)
self.assertEqual(http_client.NOT_FOUND,
res_dict['itemNotFound']['code'])
self.assertEqual('Transfer %s could not be found.' % transfer['id'],
res_dict['itemNotFound']['message'])
self.assertEqual(db.volume_get(context.get_admin_context(),
@ -321,8 +328,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual(http_client.NOT_FOUND, res.status_int)
self.assertEqual(http_client.NOT_FOUND,
res_dict['itemNotFound']['code'])
self.assertEqual('Transfer %s could not be found.' %
fake.WILL_NOT_BE_FOUND_ID,
res_dict['itemNotFound']['message'])
@ -343,7 +351,7 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(202, res.status_int)
self.assertEqual(http_client.ACCEPTED, res.status_int)
self.assertEqual(transfer['id'], res_dict['transfer']['id'])
self.assertEqual(volume_id, res_dict['transfer']['volume_id'])
# cleanup
@ -363,8 +371,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
self.assertEqual(http_client.BAD_REQUEST,
res_dict['badRequest']['code'])
self.assertEqual("Missing required element 'accept' in request body.",
res_dict['badRequest']['message'])
@ -386,8 +395,9 @@ class VolumeTransferAPITestCase(test.TestCase):
res_dict = jsonutils.loads(res.body)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
self.assertEqual(http_client.BAD_REQUEST,
res_dict['badRequest']['code'])
self.assertEqual("Missing required element 'accept' in request body.",
res_dict['badRequest']['message'])
@ -406,8 +416,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual(http_client.BAD_REQUEST, res.status_int)
self.assertEqual(http_client.BAD_REQUEST,
res_dict['badRequest']['code'])
self.assertEqual(res_dict['badRequest']['message'],
'Invalid auth key: Attempt to transfer %s with '
'invalid auth key.' % transfer['id'])
@ -430,8 +441,9 @@ class VolumeTransferAPITestCase(test.TestCase):
fake_auth_context=self.user_ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual(http_client.NOT_FOUND, res.status_int)
self.assertEqual(http_client.NOT_FOUND,
res_dict['itemNotFound']['code'])
self.assertEqual('Transfer %s could not be found.' %
fake.WILL_NOT_BE_FOUND_ID,
res_dict['itemNotFound']['message'])

View File

@ -13,6 +13,7 @@
import datetime
from six.moves import http_client
import webob
from cinder.api.contrib import volume_type_access as type_access
@ -297,7 +298,7 @@ class VolumeTypeAccessTest(test.TestCase):
use_admin_context=True)
result = self.type_action_controller._addProjectAccess(
req, fake.VOLUME_TYPE4_ID, body)
self.assertEqual(202, result.status_code)
self.assertEqual(http_client.ACCEPTED, result.status_code)
def test_add_project_access_with_no_admin_user(self):
req = fakes.HTTPRequest.blank('/v2/%s/types/%s/action' % (

View File

@ -16,6 +16,7 @@
import mock
from oslo_serialization import jsonutils
from six.moves import http_client
import webob
from cinder import context
@ -88,7 +89,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
self._create_type_and_encryption(volume_type)
res = self._get_response(volume_type)
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
res_dict = jsonutils.loads(res.body)
expected = fake_volume_type_encryption()
@ -99,12 +100,12 @@ class VolumeTypeEncryptionTest(test.TestCase):
def test_index_invalid_type(self):
volume_type = self._default_volume_type
res = self._get_response(volume_type)
self.assertEqual(404, res.status_code)
self.assertEqual(http_client.NOT_FOUND, res.status_code)
res_dict = jsonutils.loads(res.body)
expected = {
'itemNotFound': {
'code': 404,
'code': http_client.NOT_FOUND,
'message': ('Volume type %s could not be found.'
% volume_type['id'])
}
@ -118,7 +119,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
url='/v2/%s/types/%s/encryption/key_size')
res_dict = jsonutils.loads(res.body)
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
self.assertEqual(256, res_dict['key_size'])
db.volume_type_destroy(context.get_admin_context(), volume_type['id'])
@ -131,7 +132,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
url='/v2/%s/types/%s/encryption/provider')
res_dict = jsonutils.loads(res.body)
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
self.assertEqual('fake_provider', res_dict['provider'])
db.volume_type_destroy(context.get_admin_context(), volume_type['id'])
@ -143,10 +144,10 @@ class VolumeTypeEncryptionTest(test.TestCase):
url='/v2/%s/types/%s/encryption/fake')
res_dict = jsonutils.loads(res.body)
self.assertEqual(404, res.status_code)
self.assertEqual(http_client.NOT_FOUND, res.status_code)
expected = {
'itemNotFound': {
'code': 404,
'code': http_client.NOT_FOUND,
'message': ('Volume type encryption for type %s does not '
'exist.' % volume_type['id'])
}
@ -167,7 +168,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
self.assertEqual(0, len(self.notifier.notifications))
res = self._get_response(volume_type)
res_dict = jsonutils.loads(res.body)
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
# Confirm that volume type has no encryption information
# before create.
self.assertEqual(b'{}', res.body)
@ -220,11 +221,11 @@ class VolumeTypeEncryptionTest(test.TestCase):
res_dict = jsonutils.loads(res.body)
self.assertEqual(0, len(self.notifier.notifications))
self.assertEqual(404, res.status_code)
self.assertEqual(http_client.NOT_FOUND, res.status_code)
expected = {
'itemNotFound': {
'code': 404,
'code': http_client.NOT_FOUND,
'message': ('Volume type %s could not be found.'
% volume_type['id'])
}
@ -245,7 +246,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
expected = {
'badRequest': {
'code': 400,
'code': http_client.BAD_REQUEST,
'message': ('Volume type encryption for type '
'%s already exists.' % fake.VOLUME_TYPE_ID)
}
@ -281,7 +282,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
expected = {
'badRequest': {
'code': 400,
'code': http_client.BAD_REQUEST,
'message': ('Cannot create encryption specs. '
'Volume type in use.')
}
@ -303,7 +304,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
expected = {
'badRequest': {
'code': 400,
'code': http_client.BAD_REQUEST,
'message': (msg)
}
}
@ -351,7 +352,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
# Test that before create, there's nothing with a get
res = self._get_response(volume_type)
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
res_dict = jsonutils.loads(res.body)
self.assertEqual({}, res_dict)
@ -370,7 +371,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
res = self._get_response(volume_type, req_method='GET',
req_headers='application/json',
url='/v2/%s/types/%s/encryption')
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
res_dict = jsonutils.loads(res.body)
self.assertEqual(volume_type['id'], res_dict['volume_type_id'])
@ -378,12 +379,12 @@ class VolumeTypeEncryptionTest(test.TestCase):
res = self._get_response(volume_type, req_method='DELETE',
req_headers='application/json',
url='/v2/%s/types/%s/encryption/provider')
self.assertEqual(202, res.status_code)
self.assertEqual(http_client.ACCEPTED, res.status_code)
self.assertEqual(0, len(res.body))
res = self._get_response(volume_type, req_method='GET',
req_headers='application/json',
url='/v2/%s/types/%s/encryption')
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
res_dict = jsonutils.loads(res.body)
self.assertEqual({}, res_dict)
@ -407,7 +408,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
res = self._get_response(volume_type, req_method='GET',
req_headers='application/json',
url='/v2/%s/types/%s/encryption')
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
res_dict = jsonutils.loads(res.body)
self.assertEqual(volume_type['id'], res_dict['volume_type_id'])
@ -434,11 +435,11 @@ class VolumeTypeEncryptionTest(test.TestCase):
res = self._get_response(volume_type, req_method='DELETE',
req_headers='application/json',
url='/v2/%s/types/%s/encryption/provider')
self.assertEqual(400, res.status_code)
self.assertEqual(http_client.BAD_REQUEST, res.status_code)
res_dict = jsonutils.loads(res.body)
expected = {
'badRequest': {
'code': 400,
'code': http_client.BAD_REQUEST,
'message': 'Cannot delete encryption specs. '
'Volume type in use.'
}
@ -453,12 +454,12 @@ class VolumeTypeEncryptionTest(test.TestCase):
res = self._get_response(volume_type, req_method='DELETE',
req_headers='application/json',
url='/v2/%s/types/%s/encryption/provider')
self.assertEqual(202, res.status_code)
self.assertEqual(http_client.ACCEPTED, res.status_code)
self.assertEqual(0, len(res.body))
res = self._get_response(volume_type, req_method='GET',
req_headers='application/json',
url='/v2/%s/types/%s/encryption')
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
res_dict = jsonutils.loads(res.body)
self.assertEqual({}, res_dict)
@ -474,12 +475,12 @@ class VolumeTypeEncryptionTest(test.TestCase):
res = self._get_response(volume_type, req_method='DELETE',
req_headers='application/json',
url='/v2/%s/types/%s/encryption/provider')
self.assertEqual(404, res.status_code)
self.assertEqual(http_client.NOT_FOUND, res.status_code)
expected = {
"itemNotFound": {
"message": "Volume type encryption for type "
"%s does not exist." % fake.VOLUME_TYPE_ID,
"code": 404
"code": http_client.NOT_FOUND
}
}
self.assertEqual(expected, jsonutils.loads(res.body))
@ -540,7 +541,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
expected = {
'badRequest': {
'code': 400,
'code': http_client.BAD_REQUEST,
'message': (msg)
}
}
@ -592,7 +593,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
# Get the Encryption
res = self._get_response(volume_type)
self.assertEqual(200, res.status_code)
self.assertEqual(http_client.OK, res.status_code)
res_dict = jsonutils.loads(res.body)
self.assertEqual(volume_type['id'], res_dict['volume_type_id'])
@ -605,11 +606,11 @@ class VolumeTypeEncryptionTest(test.TestCase):
req_headers='application/json',
url='/v2/%s/types/%s/encryption/' +
fake.ENCRYPTION_KEY_ID)
self.assertEqual(400, res.status_code)
self.assertEqual(http_client.BAD_REQUEST, res.status_code)
res_dict = jsonutils.loads(res.body)
expected = {
'badRequest': {
'code': 400,
'code': http_client.BAD_REQUEST,
'message': 'Cannot update encryption specs. '
'Volume type in use.'
}

View File

@ -14,6 +14,7 @@
import mock
from oslo_serialization import jsonutils
from six.moves import http_client
import webob
from cinder import context
@ -65,7 +66,7 @@ class VolumeUnmanageTest(test.TestCase):
"""Return success for valid and unattached volume."""
vol = utils.create_volume(self.ctxt)
res = self._get_resp(vol.id)
self.assertEqual(202, res.status_int, res)
self.assertEqual(http_client.ACCEPTED, res.status_int, res)
mock_rpcapi.assert_called_once_with(self.ctxt, mock.ANY, True, False)
vol = objects.volume.Volume.get_by_id(self.ctxt, vol.id)
@ -75,7 +76,7 @@ class VolumeUnmanageTest(test.TestCase):
def test_unmanage_volume_bad_volume_id(self):
"""Return 404 if the volume does not exist."""
res = self._get_resp(fake.WILL_NOT_BE_FOUND_ID)
self.assertEqual(404, res.status_int, res)
self.assertEqual(http_client.NOT_FOUND, res.status_int, res)
def test_unmanage_volume_attached(self):
"""Return 400 if the volume exists but is attached."""
@ -83,7 +84,7 @@ class VolumeUnmanageTest(test.TestCase):
self.ctxt, status='in-use',
attach_status=fields.VolumeAttachStatus.ATTACHED)
res = self._get_resp(vol.id)
self.assertEqual(400, res.status_int, res)
self.assertEqual(http_client.BAD_REQUEST, res.status_int, res)
db.volume_destroy(self.ctxt, vol.id)
def test_unmanage_volume_with_snapshots(self):
@ -91,6 +92,6 @@ class VolumeUnmanageTest(test.TestCase):
vol = utils.create_volume(self.ctxt)
snap = utils.create_snapshot(self.ctxt, vol.id)
res = self._get_resp(vol.id)
self.assertEqual(400, res.status_int, res)
self.assertEqual(http_client.BAD_REQUEST, res.status_int, res)
db.volume_destroy(self.ctxt, vol.id)
db.snapshot_destroy(self.ctxt, snap.id)

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_middleware import request_id
from six.moves import http_client
import webob
import cinder.api.middleware.auth
@ -38,32 +39,32 @@ class TestCinderKeystoneContextMiddleware(test.TestCase):
def test_no_user_or_user_id(self):
response = self.request.get_response(self.middleware)
self.assertEqual('401 Unauthorized', response.status)
self.assertEqual(http_client.UNAUTHORIZED, response.status_int)
def test_user_only(self):
self.request.headers['X_USER'] = 'testuser'
response = self.request.get_response(self.middleware)
self.assertEqual('200 OK', response.status)
self.assertEqual(http_client.OK, response.status_int)
self.assertEqual('testuser', self.context.user_id)
def test_user_id_only(self):
self.request.headers['X_USER_ID'] = 'testuserid'
response = self.request.get_response(self.middleware)
self.assertEqual('200 OK', response.status)
self.assertEqual(http_client.OK, response.status_int)
self.assertEqual('testuserid', self.context.user_id)
def test_user_id_trumps_user(self):
self.request.headers['X_USER_ID'] = 'testuserid'
self.request.headers['X_USER'] = 'testuser'
response = self.request.get_response(self.middleware)
self.assertEqual('200 OK', response.status)
self.assertEqual(http_client.OK, response.status_int)
self.assertEqual('testuserid', self.context.user_id)
def test_tenant_id_name(self):
self.request.headers['X_USER_ID'] = 'testuserid'
self.request.headers['X_TENANT_NAME'] = 'testtenantname'
response = self.request.get_response(self.middleware)
self.assertEqual('200 OK', response.status)
self.assertEqual(http_client.OK, response.status_int)
self.assertEqual('testtenantid', self.context.project_id)
self.assertEqual('testtenantname', self.context.project_name)

View File

@ -14,6 +14,7 @@
# under the License.
from oslo_i18n import fixture as i18n_fixture
from oslo_serialization import jsonutils
from six.moves import http_client
import webob.dec
from cinder.api.openstack import wsgi
@ -41,7 +42,7 @@ class TestFaults(test.TestCase):
expected = {
"badRequest": {
"message": "scram",
"code": 400,
"code": http_client.BAD_REQUEST,
},
}
actual = jsonutils.loads(response.body)
@ -65,7 +66,7 @@ class TestFaults(test.TestCase):
expected = {
"overLimit": {
"message": "sorry",
"code": 413,
"code": http_client.REQUEST_ENTITY_TOO_LARGE,
"retryAfter": "4",
},
}
@ -77,4 +78,4 @@ class TestFaults(test.TestCase):
def test_fault_has_status_int(self):
"""Ensure the status_int is set correctly on faults."""
fault = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='what?'))
self.assertEqual(400, fault.status_int)
self.assertEqual(http_client.BAD_REQUEST, fault.status_int)

View File

@ -15,6 +15,7 @@ import inspect
import mock
from oslo_utils import encodeutils
from six.moves import http_client
import webob
from cinder.api.openstack import wsgi
@ -233,7 +234,7 @@ class ResourceTest(test.TestCase):
app = fakes.TestRouter(Controller())
response = req.get_response(app)
self.assertEqual(b'off', response.body)
self.assertEqual(200, response.status_int)
self.assertEqual(http_client.OK, response.status_int)
def test_resource_not_authorized(self):
class Controller(object):
@ -243,7 +244,7 @@ class ResourceTest(test.TestCase):
req = webob.Request.blank('/tests')
app = fakes.TestRouter(Controller())
response = req.get_response(app)
self.assertEqual(403, response.status_int)
self.assertEqual(http_client.FORBIDDEN, response.status_int)
def test_dispatch(self):
class Controller(object):
@ -777,21 +778,21 @@ class ResourceTest(test.TestCase):
class ResponseObjectTest(test.TestCase):
def test_default_code(self):
robj = wsgi.ResponseObject({})
self.assertEqual(200, robj.code)
self.assertEqual(http_client.OK, robj.code)
def test_modified_code(self):
robj = wsgi.ResponseObject({})
robj._default_code = 202
self.assertEqual(202, robj.code)
robj._default_code = http_client.ACCEPTED
self.assertEqual(http_client.ACCEPTED, robj.code)
def test_override_default_code(self):
robj = wsgi.ResponseObject({}, code=404)
self.assertEqual(404, robj.code)
robj = wsgi.ResponseObject({}, code=http_client.NOT_FOUND)
self.assertEqual(http_client.NOT_FOUND, robj.code)
def test_override_modified_code(self):
robj = wsgi.ResponseObject({}, code=404)
robj._default_code = 202
self.assertEqual(404, robj.code)
robj = wsgi.ResponseObject({}, code=http_client.NOT_FOUND)
robj._default_code = http_client.ACCEPTED
self.assertEqual(http_client.NOT_FOUND, robj.code)
def test_set_header(self):
robj = wsgi.ResponseObject({})

View File

@ -16,6 +16,7 @@
import ddt
import mock
from oslo_config import cfg
from six.moves import http_client
from six.moves.urllib import parse as urllib
import webob
@ -280,7 +281,7 @@ class SnapshotApiTest(test.TestCase):
snapshot_id = UUID
req = fakes.HTTPRequest.blank('/v1/snapshots/%s' % snapshot_id)
resp = self.controller.delete(req, snapshot_id)
self.assertEqual(202, resp.status_int)
self.assertEqual(http_client.ACCEPTED, resp.status_int)
def test_snapshot_delete_invalid_id(self):
self.mock_object(volume.api.API, "delete_snapshot",

View File

@ -20,6 +20,7 @@ import iso8601
import ddt
import mock
from oslo_config import cfg
from six.moves import http_client
from six.moves import range
import webob
@ -731,7 +732,7 @@ class VolumeApiTest(test.TestCase):
def test_volume_delete(self):
req = fakes.HTTPRequest.blank('/v1/volumes/%s' % fake.VOLUME_ID)
resp = self.controller.delete(req, fake.VOLUME_ID)
self.assertEqual(202, resp.status_int)
self.assertEqual(http_client.ACCEPTED, resp.status_int)
def test_volume_delete_no_volume(self):
self.mock_object(volume_api.API, "get",