Merge "Extracted HTTP response codes to constants"

This commit is contained in:
Jenkins 2017-03-25 00:28:11 +00:00 committed by Gerrit Code Review
commit 5f66f158bf
8 changed files with 148 additions and 122 deletions

View File

@ -21,6 +21,7 @@ import ddt
import json
import mock
from simplejson import scanner
from six.moves import http_client
from cinder import exception
from cinder import test
@ -48,11 +49,13 @@ class NetAppEseriesClientDriverTestCase(test.TestCase):
self.my_client._endpoint = eseries_fake.FAKE_ENDPOINT_HTTP
fake_response = mock.Mock()
fake_response.status_code = 200
fake_response.status_code = http_client.OK
self.my_client.invoke_service = mock.Mock(return_value=fake_response)
self.my_client.api_version = '01.52.9000.1'
@ddt.data(200, 201, 203, 204)
@ddt.data(http_client.OK, http_client.CREATED,
http_client.NON_AUTHORITATIVE_INFORMATION,
http_client.NO_CONTENT)
def test_eval_response_success(self, status_code):
fake_resp = mock.Mock()
fake_resp.status_code = status_code
@ -76,7 +79,7 @@ class NetAppEseriesClientDriverTestCase(test.TestCase):
('unknown', None))
@ddt.unpack
def test_eval_response_422(self, ret_code, exc_regex):
status_code = 422
status_code = http_client.UNPROCESSABLE_ENTITY
fake_resp = mock.Mock()
fake_resp.text = "fakeError"
fake_resp.json = mock.Mock(return_value={'retcode': ret_code})
@ -89,7 +92,7 @@ class NetAppEseriesClientDriverTestCase(test.TestCase):
self.assertEqual(status_code, exc.status_code)
def test_eval_response_424(self):
status_code = 424
status_code = http_client.FAILED_DEPENDENCY
fake_resp = mock.Mock()
fake_resp.status_code = status_code
fake_resp.text = "Fake Error Message"
@ -567,7 +570,7 @@ class NetAppEseriesClientDriverTestCase(test.TestCase):
self.assertEqual(fake_volume, volume)
def test_list_volume_v2_not_found(self):
status_code = 404
status_code = http_client.NOT_FOUND
url = client.RestClient.RESOURCE_PATHS['ssc_volume']
self.my_client.features = mock.Mock()
self.my_client.features.SSC_API_V2 = na_utils.FeatureState(
@ -586,7 +589,7 @@ class NetAppEseriesClientDriverTestCase(test.TestCase):
mock.ANY})
def test_list_volume_v2_failure(self):
status_code = 422
status_code = http_client.UNPROCESSABLE_ENTITY
url = client.RestClient.RESOURCE_PATHS['ssc_volume']
self.my_client.features = mock.Mock()
self.my_client.features.SSC_API_V2 = na_utils.FeatureState(
@ -1145,7 +1148,7 @@ class NetAppEseriesClientDriverTestCase(test.TestCase):
fake_response = mock.Mock()
fake_response.json = mock.Mock(side_effect=scanner.JSONDecodeError(
'', '{}', 1))
fake_response.status_code = 424
fake_response.status_code = http_client.FAILED_DEPENDENCY
fake_response.text = "Fake Response"
self.mock_object(self.my_client, 'invoke_service',
return_value=fake_response)

View File

@ -23,6 +23,7 @@ from mock import patch
from oslo_serialization import jsonutils
import requests
from requests import adapters
from six.moves import http_client
from cinder import exception
from cinder import test
@ -33,7 +34,7 @@ USERNAME = 'user'
PASSWORD = 'pass'
def gen_response(code=200, json=None):
def gen_response(code=http_client.OK, json=None):
r = requests.Response()
r.headers['Content-Type'] = 'application/json'
r.encoding = 'utf8'
@ -80,7 +81,7 @@ class TestNexentaJSONProxyAuth(test.TestCase):
# an url is being requested for the second time
if self.counter == 1:
# make the fake backend respond 401
r = gen_response(401)
r = gen_response(http_client.UNAUTHORIZED)
r._content = ''
r.connection = mock.Mock()
r_ = gen_response(json={'data': []})
@ -147,31 +148,36 @@ class TestNexentaJSONProxy(test.TestCase):
def test_post(self):
random_dict = {'data': uuid.uuid4().hex}
rnd_url = 'some/random/url'
self._mount_adapter(rnd_url, self.gen_adapter(201, random_dict))
self._mount_adapter(rnd_url, self.gen_adapter(http_client.CREATED,
random_dict))
self.assertEqual(random_dict, self.nef.post(rnd_url))
def test_delete(self):
random_dict = {'data': uuid.uuid4().hex}
rnd_url = 'some/random/url'
self._mount_adapter(rnd_url, self.gen_adapter(201, random_dict))
self._mount_adapter(rnd_url, self.gen_adapter(http_client.CREATED,
random_dict))
self.assertEqual(random_dict, self.nef.delete(rnd_url))
def test_put(self):
random_dict = {'data': uuid.uuid4().hex}
rnd_url = 'some/random/url'
self._mount_adapter(rnd_url, self.gen_adapter(201, random_dict))
self._mount_adapter(rnd_url, self.gen_adapter(http_client.CREATED,
random_dict))
self.assertEqual(random_dict, self.nef.put(rnd_url))
def test_get_200(self):
random_dict = {'data': uuid.uuid4().hex}
rnd_url = 'some/random/url'
self._mount_adapter(rnd_url, self.gen_adapter(200, random_dict))
self._mount_adapter(rnd_url, self.gen_adapter(http_client.OK,
random_dict))
self.assertEqual(random_dict, self.nef.get(rnd_url))
def test_get_201(self):
random_dict = {'data': uuid.uuid4().hex}
rnd_url = 'some/random/url'
self._mount_adapter(rnd_url, self.gen_adapter(201, random_dict))
self._mount_adapter(rnd_url, self.gen_adapter(http_client.CREATED,
random_dict))
self.assertEqual(random_dict, self.nef.get(rnd_url))
def test_get_500(self):
@ -185,7 +191,7 @@ class TestNexentaJSONProxy(test.TestCase):
'code': 'NEF_ERROR',
'message': 'Some error'
}
r = gen_response(500, json)
r = gen_response(http_client.INTERNAL_SERVER_ERROR, json)
r.request = request
return r
@ -201,7 +207,7 @@ class TestNexentaJSONProxy(test.TestCase):
super(TestAdapter, self).__init__()
def send(self, request, *args, **kwargs):
r = gen_response(404)
r = gen_response(http_client.NOT_FOUND)
r._content = 'Page Not Found'
r.request = request
return r
@ -219,7 +225,7 @@ class TestNexentaJSONProxy(test.TestCase):
super(TestAdapter, self).__init__()
def send(self, request, *args, **kwargs):
r = gen_response(404)
r = gen_response(http_client.NOT_FOUND)
r.request = request
return r
@ -241,11 +247,12 @@ class TestNexentaJSONProxy(test.TestCase):
json = {
'links': [{'href': redirect_url}]
}
r = gen_response(202, json)
r = gen_response(http_client.ACCEPTED, json)
r.request = request
return r
rnd_url = 'some/random/url'
self._mount_adapter(rnd_url, RedirectTestAdapter())
self._mount_adapter(redirect_url, self.gen_adapter(201))
self._mount_adapter(redirect_url, self.gen_adapter(
http_client.CREATED))
self.assertIsNone(self.nef.get(rnd_url))

View File

@ -21,6 +21,7 @@ import math
import mock
from oslo_utils import units
import requests
from six.moves import http_client
from six import string_types
from cinder import context
@ -148,8 +149,8 @@ class MockResponse(object):
class SynoSessionTestCase(test.TestCase):
@mock.patch('requests.post', return_value=
MockResponse({'data': {'sid': 'sid'}, 'success': True}, 200))
@mock.patch('requests.post', return_value=MockResponse(
{'data': {'sid': 'sid'}, 'success': True}, http_client.OK))
def setUp(self, _mock_post):
super(SynoSessionTestCase, self).setUp()
@ -190,12 +191,12 @@ class SynoSessionTestCase(test.TestCase):
FAKE_API: out
},
'success': True
}, 200),
}, http_client.OK),
MockResponse({
'data': {
FAKE_API: out
}
}, 200),
}, http_client.OK),
])
result = self.session.query(FAKE_API)
@ -289,18 +290,21 @@ class SynoAPIRequestTestCase(test.TestCase):
self.request._encode_param = mock.Mock(side_effect=lambda x: x)
self.request.new_session = mock.Mock()
requests.post = mock.Mock(side_effect=[
MockResponse({'success': True}, 200),
MockResponse({'error': {'code': 101}, 'success': False}, 200),
MockResponse({'error': {'code': 101}}, 200),
MockResponse({}, 500)
MockResponse({'success': True}, http_client.OK),
MockResponse({'error': {'code': http_client.SWITCHING_PROTOCOLS},
'success': False}, http_client.OK),
MockResponse({'error': {'code': http_client.SWITCHING_PROTOCOLS}},
http_client.OK),
MockResponse({}, http_client.INTERNAL_SERVER_ERROR)
])
result = self.request.request(FAKE_API, FAKE_METHOD, version)
self.assertDictEqual({'success': True}, result)
result = self.request.request(FAKE_API, FAKE_METHOD, version)
self.assertDictEqual({'error': {'code': 101}, 'success': False},
result)
self.assertDictEqual(
{'error': {'code': http_client.SWITCHING_PROTOCOLS},
'success': False}, result)
self.assertRaises(exception.MalformedResponse,
self.request.request,
@ -309,7 +313,8 @@ class SynoAPIRequestTestCase(test.TestCase):
version)
result = self.request.request(FAKE_API, FAKE_METHOD, version)
self.assertDictEqual({'http_status': 500}, result)
self.assertDictEqual(
{'http_status': http_client.INTERNAL_SERVER_ERROR}, result)
@mock.patch.object(common.LOG, 'debug')
def test_request_auth_error(self, _log):
@ -322,7 +327,7 @@ class SynoAPIRequestTestCase(test.TestCase):
MockResponse({
'error': {'code': 105},
'success': False
}, 200))
}, http_client.OK))
self.assertRaises(exception.SynoAuthError,
self.request.request,
@ -1141,7 +1146,7 @@ class SynoCommonTestCase(test.TestCase):
version = 1
resp = {}
bad_resp = {
'http_status': 500
'http_status': http_client.INTERNAL_SERVER_ERROR
}
expected = copy.deepcopy(resp)
expected.update(api_info={'api': api,

View File

@ -76,7 +76,7 @@ def common_mocks(f):
inst.mock_response = mock.Mock()
inst.mock_response.read.return_value = '{}'
inst.mock_response.status = 200
inst.mock_response.status = http_client.OK
inst.mock_conn.request.return_value = True
inst.mock_conn.getresponse.return_value = inst.mock_response
@ -150,28 +150,28 @@ class BlockbridgeISCSIDriverTestCase(test.TestCase):
@common_mocks
def test_http_mock_success(self):
self.mock_response.read.return_value = '{}'
self.mock_response.status = 200
self.mock_response.status = http_client.OK
conn = http_client.HTTPSConnection('whatever', None)
conn.request('GET', '/blah', '{}', {})
rsp = conn.getresponse()
self.assertEqual('{}', rsp.read())
self.assertEqual(200, rsp.status)
self.assertEqual(http_client.OK, rsp.status)
@common_mocks
def test_http_mock_failure(self):
mock_body = '{"error": "no results matching query", "status": 413}'
self.mock_response.read.return_value = mock_body
self.mock_response.status = 413
self.mock_response.status = http_client.REQUEST_ENTITY_TOO_LARGE
conn = http_client.HTTPSConnection('whatever', None)
conn.request('GET', '/blah', '{}', {})
rsp = conn.getresponse()
self.assertEqual(mock_body, rsp.read())
self.assertEqual(413, rsp.status)
self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, rsp.status)
@common_mocks
def test_cfg_api_host(self):
@ -264,7 +264,7 @@ class BlockbridgeISCSIDriverTestCase(test.TestCase):
mock_body = '{"message": "no results matching query", "status": 413}'
self.mock_response.read.return_value = mock_body
self.mock_response.status = 413
self.mock_response.status = http_client.REQUEST_ENTITY_TOO_LARGE
self.assertRaisesRegex(exception.VolumeBackendAPIException,
"no results matching query",
@ -310,7 +310,7 @@ class BlockbridgeISCSIDriverTestCase(test.TestCase):
mock_body = '{"message": "over quota", "status": 413}'
self.mock_response.read.return_value = mock_body
self.mock_response.status = 413
self.mock_response.status = http_client.REQUEST_ENTITY_TOO_LARGE
self.assertRaisesRegex(exception.VolumeBackendAPIException,
"over quota",
@ -363,7 +363,7 @@ class BlockbridgeISCSIDriverTestCase(test.TestCase):
mock_body = '{"message": "over quota", "status": 413}'
self.mock_response.read.return_value = mock_body
self.mock_response.status = 413
self.mock_response.status = http_client.REQUEST_ENTITY_TOO_LARGE
src_vref = dict(
name='cloned_volume_source',
@ -409,7 +409,7 @@ class BlockbridgeISCSIDriverTestCase(test.TestCase):
def test_extend_volume_overquota(self):
mock_body = '{"message": "over quota", "status": 413}'
self.mock_response.read.return_value = mock_body
self.mock_response.status = 413
self.mock_response.status = http_client.REQUEST_ENTITY_TOO_LARGE
self.assertRaisesRegex(exception.VolumeBackendAPIException,
"over quota",
@ -459,7 +459,7 @@ class BlockbridgeISCSIDriverTestCase(test.TestCase):
def test_create_snapshot_overquota(self):
mock_body = '{"message": "over quota", "status": 413}'
self.mock_response.read.return_value = mock_body
self.mock_response.status = 413
self.mock_response.status = http_client.REQUEST_ENTITY_TOO_LARGE
self.assertRaisesRegex(exception.VolumeBackendAPIException,
"over quota",
@ -501,7 +501,7 @@ class BlockbridgeISCSIDriverTestCase(test.TestCase):
mock_generate_password.return_value = 'mock-password-abcdef123456'
self.mock_response.read.return_value = FIXTURE_VOL_EXPORT_OK
self.mock_response.status = 200
self.mock_response.status = http_client.OK
props = self.driver.initialize_connection(self.volume, self.connector)
@ -563,7 +563,7 @@ class BlockbridgeISCSIDriverTestCase(test.TestCase):
@common_mocks
def test_get_volume_stats_forbidden(self):
self.mock_response.status = 403
self.mock_response.status = http_client.FORBIDDEN
self.assertRaisesRegex(exception.NotAuthorized,
"Insufficient privileges",
self.driver.get_volume_stats,
@ -571,7 +571,7 @@ class BlockbridgeISCSIDriverTestCase(test.TestCase):
@common_mocks
def test_get_volume_stats_unauthorized(self):
self.mock_response.status = 401
self.mock_response.status = http_client.UNAUTHORIZED
self.assertRaisesRegex(exception.NotAuthorized,
"Invalid credentials",
self.driver.get_volume_stats,

View File

@ -21,6 +21,7 @@ import mock
from oslo_utils import units
import requests
import six
from six.moves import http_client
from cinder import exception
from cinder import test
@ -129,7 +130,7 @@ class InfiniboxDriverTestCase(test.TestCase):
response.status_code = result
response.raw = six.BytesIO(six.b(json.dumps(dict())))
else:
response.status_code = 200
response.status_code = http_client.OK
response.raw = six.BytesIO(six.b(json.dumps(dict(result=result))))
return response
@ -225,7 +226,8 @@ class InfiniboxDriverTestCase(test.TestCase):
self.driver.delete_volume(test_volume)
def test_delete_volume_doesnt_exist_on_delete(self):
self._responses["DELETE"][VOLUME_URL + APPROVAL] = 404
self._responses["DELETE"][VOLUME_URL + APPROVAL] = (
http_client.NOT_FOUND)
# due to a possible race condition (get+delete is not atomic) the
# GET may return the volume but it may still be deleted before
# the DELETE request
@ -309,7 +311,8 @@ class InfiniboxDriverTestCase(test.TestCase):
self.driver.delete_snapshot(test_snapshot)
def test_delete_snapshot_doesnt_exist_on_delete(self):
self._responses["DELETE"][SNAPSHOT_URL + APPROVAL] = 404
self._responses["DELETE"][SNAPSHOT_URL + APPROVAL] = (
http_client.NOT_FOUND)
# due to a possible race condition (get+delete is not atomic) the
# GET may return the snapshot but it may still be deleted before
# the DELETE request

View File

@ -15,6 +15,7 @@
import mock
from six.moves import http_client
import sys
from cinder import context
@ -215,7 +216,7 @@ class NimbleDriverBaseTestCase(test.TestCase):
configuration=configuration)
mock_login_response = mock_urllib2.post.return_value
mock_login_response = mock.MagicMock()
mock_login_response.status_code.return_value = 200
mock_login_response.status_code.return_value = http_client.OK
mock_login_response.json.return_value = (
FAKE_LOGIN_POST_RESPONSE)
self.driver.do_setup(context.get_admin_context())
@ -237,7 +238,7 @@ class NimbleDriverBaseTestCase(test.TestCase):
configuration=configuration)
mock_login_response = mock_urllib2.post.return_value
mock_login_response = mock.MagicMock()
mock_login_response.status_code.return_value = 200
mock_login_response.status_code.return_value = http_client.OK
mock_login_response.json.return_value = (
FAKE_LOGIN_POST_RESPONSE)
self.driver.do_setup(context.get_admin_context())

View File

@ -19,6 +19,7 @@ import sys
import ddt
import mock
from oslo_utils import units
from six.moves import http_client
from cinder import exception
from cinder import test
@ -790,7 +791,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.list_volume_private_connections.return_value = {}
self.array.destroy_volume.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Volume does not exist"
)
self.driver.delete_volume(VOLUME)
@ -805,8 +806,8 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.assert_has_calls(expected)
self.assertFalse(self.array.eradicate_volume.called)
self.array.destroy_volume.side_effect = (
self.purestorage_module.PureHTTPError(code=400, text="does not "
"exist"))
self.purestorage_module.PureHTTPError(code=http_client.BAD_REQUEST,
text="does not exist"))
self.driver.delete_volume(VOLUME)
self.array.destroy_volume.side_effect = None
self.assert_error_propagates([self.array.destroy_volume],
@ -864,7 +865,8 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.assert_has_calls(expected)
self.assertFalse(self.array.eradicate_volume.called)
self.array.destroy_volume.side_effect = (
self.purestorage_module.PureHTTPError(code=400, text=error_text))
self.purestorage_module.PureHTTPError(code=http_client.BAD_REQUEST,
text=error_text))
self.driver.delete_snapshot(SNAPSHOT)
self.array.destroy_volume.side_effect = None
self.assert_error_propagates([self.array.destroy_volume],
@ -917,7 +919,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
# Branch where connection is missing and the host is still deleted
self.array.reset_mock()
self.array.disconnect_host.side_effect = \
self.purestorage_module.PureHTTPError(code=400,
self.purestorage_module.PureHTTPError(code=http_client.BAD_REQUEST,
text="is not connected")
self.driver.terminate_connection(VOLUME, ISCSI_CONNECTOR)
self.array.disconnect_host.assert_called_with(PURE_HOST_NAME, vol_name)
@ -928,7 +930,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.reset_mock()
self.array.disconnect_host.side_effect = \
self.purestorage_module.PureHTTPError(
code=500,
code=http_client.INTERNAL_SERVER_ERROR,
text="Some other error"
)
self.assertRaises(self.purestorage_module.PureHTTPError,
@ -945,7 +947,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.reset_mock()
self.array.list_host_connections.return_value = []
self.array.delete_host.side_effect = \
self.purestorage_module.PureHTTPError(code=400,
self.purestorage_module.PureHTTPError(code=http_client.BAD_REQUEST,
text=error)
self.driver.terminate_connection(VOLUME, ISCSI_CONNECTOR)
self.array.disconnect_host.assert_called_with(PURE_HOST_NAME, vol_name)
@ -1145,7 +1147,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.destroy_pgroup.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Protection group has been destroyed."
)
self.driver.delete_consistencygroup(mock_context,
@ -1157,7 +1159,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.destroy_pgroup.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Protection group does not exist"
)
self.driver.delete_consistencygroup(mock_context,
@ -1169,7 +1171,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.destroy_pgroup.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Some other error"
)
self.assertRaises(self.purestorage_module.PureHTTPError,
@ -1180,7 +1182,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.destroy_pgroup.side_effect = \
self.purestorage_module.PureHTTPError(
code=500,
code=http_client.INTERNAL_SERVER_ERROR,
text="Another different error"
)
self.assertRaises(self.purestorage_module.PureHTTPError,
@ -1315,7 +1317,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.destroy_pgroup.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Protection group snapshot has been destroyed."
)
self.driver.delete_cgsnapshot(mock_context, mock_cgsnap, [mock_snap])
@ -1324,7 +1326,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.destroy_pgroup.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Protection group snapshot does not exist"
)
self.driver.delete_cgsnapshot(mock_context, mock_cgsnap, [mock_snap])
@ -1333,7 +1335,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.destroy_pgroup.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Some other error"
)
self.assertRaises(self.purestorage_module.PureHTTPError,
@ -1344,7 +1346,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.destroy_pgroup.side_effect = \
self.purestorage_module.PureHTTPError(
code=500,
code=http_client.INTERNAL_SERVER_ERROR,
text="Another different error"
)
self.assertRaises(self.purestorage_module.PureHTTPError,
@ -1411,7 +1413,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.get_volume.side_effect = \
self.purestorage_module.PureHTTPError(
text="Volume does not exist.",
code=400
code=http_client.BAD_REQUEST
)
self.assertRaises(exception.ManageExistingInvalidReference,
self.driver.manage_existing,
@ -1479,7 +1481,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.rename_volume.side_effect = \
self.purestorage_module.PureHTTPError(
text="Volume does not exist.",
code=400
code=http_client.BAD_REQUEST
)
self.driver.unmanage(VOLUME)
@ -1537,7 +1539,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.get_volume.side_effect = \
self.purestorage_module.PureHTTPError(
text="Volume does not exist.",
code=400
code=http_client.BAD_REQUEST
)
self.assertRaises(exception.ManageExistingInvalidReference,
self.driver.manage_existing_snapshot,
@ -1596,7 +1598,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.get_volume.side_effect = \
self.purestorage_module.PureHTTPError(
text="Volume does not exist.",
code=400
code=http_client.BAD_REQUEST
)
self.assertRaises(exception.ManageExistingInvalidReference,
self.driver.manage_existing_snapshot_get_size,
@ -1624,7 +1626,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self.array.rename_volume.side_effect = \
self.purestorage_module.PureHTTPError(
text="Snapshot does not exist.",
code=400
code=http_client.BAD_REQUEST
)
self.driver.unmanage_snapshot(SNAPSHOT)
@ -1853,7 +1855,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
def test_does_pgroup_exist_not_exists(self):
self.array.get_pgroup.side_effect = (
self.purestorage_module.PureHTTPError(code=400,
self.purestorage_module.PureHTTPError(code=http_client.BAD_REQUEST,
text="does not exist"))
exists = self.driver._does_pgroup_exist(self.array, "some_pgroup")
self.assertFalse(exists)
@ -2045,7 +2047,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
self, mock_get_volume_type):
mock_get_volume_type.return_value = REPLICATED_VOL_TYPE
self.array.set_pgroup.side_effect = FakePureStorageHTTPError(
code=400, text='already belongs to')
code=http_client.BAD_REQUEST, text='already belongs to')
self.driver._enable_replication_if_needed(self.array, VOLUME)
self.array.set_pgroup.assert_called_with(
self.driver._replication_pg_name,
@ -2148,7 +2150,7 @@ class PureBaseVolumeDriverTestCase(PureBaseSharedDriverTestCase):
def test_disable_replication_already_disabled(self):
self.array.set_pgroup.side_effect = FakePureStorageHTTPError(
code=400, text='could not be found')
code=http_client.BAD_REQUEST, text='could not be found')
self.driver._disable_replication(VOLUME)
self.array.set_pgroup.assert_called_with(
self.driver._replication_pg_name,
@ -2375,7 +2377,7 @@ class PureISCSIDriverTestCase(PureDriverTestCase):
[expected, {"host": "extra", "lun": 2}]
self.array.connect_host.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Connection already exists"
)
actual = self.driver._connect(VOLUME, ISCSI_CONNECTOR)
@ -2389,7 +2391,7 @@ class PureISCSIDriverTestCase(PureDriverTestCase):
self.array.list_volume_private_connections.return_value = {}
self.array.connect_host.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Connection already exists"
)
self.assertRaises(exception.PureDriverException, self.driver._connect,
@ -2401,10 +2403,11 @@ class PureISCSIDriverTestCase(PureDriverTestCase):
def test_connect_already_connected_list_hosts_exception(self, mock_host):
mock_host.return_value = PURE_HOST
self.array.list_volume_private_connections.side_effect = \
self.purestorage_module.PureHTTPError(code=400, text="")
self.purestorage_module.PureHTTPError(code=http_client.BAD_REQUEST,
text="")
self.array.connect_host.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Connection already exists"
)
self.assertRaises(self.purestorage_module.PureHTTPError,
@ -2422,7 +2425,7 @@ class PureISCSIDriverTestCase(PureDriverTestCase):
self.array.set_host.side_effect = (
self.purestorage_module.PureHTTPError(
code=400, text='Host does not exist.'))
code=http_client.BAD_REQUEST, text='Host does not exist.'))
# Because we mocked out retry make sure we are raising the right
# exception to allow for retries to happen.
@ -2436,7 +2439,8 @@ class PureISCSIDriverTestCase(PureDriverTestCase):
self.array.create_host.side_effect = (
self.purestorage_module.PureHTTPError(
code=400, text='The specified IQN is already in use.'))
code=http_client.BAD_REQUEST,
text='The specified IQN is already in use.'))
# Because we mocked out retry make sure we are raising the right
# exception to allow for retries to happen.
@ -2450,7 +2454,7 @@ class PureISCSIDriverTestCase(PureDriverTestCase):
self.array.create_host.side_effect = (
self.purestorage_module.PureHTTPError(
code=400, text='Host already exists.'))
code=http_client.BAD_REQUEST, text='Host already exists.'))
# Because we mocked out retry make sure we are raising the right
# exception to allow for retries to happen.
@ -2578,7 +2582,7 @@ class PureFCDriverTestCase(PureDriverTestCase):
[expected, {"host": "extra", "lun": 2}]
self.array.connect_host.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Connection already exists"
)
actual = self.driver._connect(VOLUME, FC_CONNECTOR)
@ -2592,7 +2596,7 @@ class PureFCDriverTestCase(PureDriverTestCase):
self.array.list_volume_private_connections.return_value = {}
self.array.connect_host.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Connection already exists"
)
self.assertRaises(exception.PureDriverException, self.driver._connect,
@ -2604,10 +2608,11 @@ class PureFCDriverTestCase(PureDriverTestCase):
def test_connect_already_connected_list_hosts_exception(self, mock_host):
mock_host.return_value = PURE_HOST
self.array.list_volume_private_connections.side_effect = \
self.purestorage_module.PureHTTPError(code=400, text="")
self.purestorage_module.PureHTTPError(code=http_client.BAD_REQUEST,
text="")
self.array.connect_host.side_effect = \
self.purestorage_module.PureHTTPError(
code=400,
code=http_client.BAD_REQUEST,
text="Connection already exists"
)
self.assertRaises(self.purestorage_module.PureHTTPError,
@ -2621,7 +2626,8 @@ class PureFCDriverTestCase(PureDriverTestCase):
self.array.create_host.side_effect = (
self.purestorage_module.PureHTTPError(
code=400, text='The specified WWN is already in use.'))
code=http_client.BAD_REQUEST,
text='The specified WWN is already in use.'))
# Because we mocked out retry make sure we are raising the right
# exception to allow for retries to happen.

View File

@ -14,6 +14,7 @@
# under the License.
import mock
from six.moves import http_client
from cinder import context
from cinder import exception
@ -119,7 +120,7 @@ ISE_GET_QUERY_XML =\
</array>""" % (ISE_IP1, ISE_IP2)
ISE_GET_QUERY_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_QUERY_XML.split())}
@ -139,7 +140,7 @@ ISE_GET_QUERY_NO_CAP_XML =\
</array>""" % (ISE_IP1, ISE_IP2)
ISE_GET_QUERY_NO_CAP_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_QUERY_NO_CAP_XML.split())}
@ -158,7 +159,7 @@ ISE_GET_QUERY_NO_CTRL_XML =\
</array>"""
ISE_GET_QUERY_NO_CTRL_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_QUERY_NO_CTRL_XML.split())}
@ -187,7 +188,7 @@ ISE_GET_QUERY_NO_IP_XML =\
</array>"""
ISE_GET_QUERY_NO_IP_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_QUERY_NO_IP_XML.split())}
@ -213,7 +214,7 @@ ISE_GET_QUERY_NO_GID_XML =\
</array>""" % (ISE_IP1, ISE_IP2)
ISE_GET_QUERY_NO_GID_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_QUERY_NO_GID_XML.split())}
@ -239,7 +240,7 @@ ISE_GET_QUERY_NO_CLONE_XML =\
</array>""" % (ISE_IP1, ISE_IP2)
ISE_GET_QUERY_NO_CLONE_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_QUERY_NO_CLONE_XML.split())}
@ -287,7 +288,7 @@ ISE_GET_STORAGE_POOLS_XML =\
"""
ISE_GET_STORAGE_POOLS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': 'Pool location',
'content': " ".join(ISE_GET_STORAGE_POOLS_XML.split())}
@ -295,7 +296,7 @@ ISE_GET_VOL_STATUS_NO_VOL_NODE_XML =\
"""<volumes></volumes>"""
ISE_GET_VOL_STATUS_NO_VOL_NODE_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': 'u%s' % ISE_VOLUME1_LOCATION_URL,
'content': " ".join(ISE_GET_VOL_STATUS_NO_VOL_NODE_XML.split())}
@ -306,7 +307,7 @@ ISE_GET_VOL_STATUS_NO_STATUS_XML =\
</volumes>""" % (ISE_VOLUME1_LOCATION_URL)
ISE_GET_VOL_STATUS_NO_STATUS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': 'u%s' % ISE_VOLUME1_LOCATION_URL,
'content': " ".join(ISE_GET_VOL_STATUS_NO_STATUS_XML.split())}
@ -323,7 +324,7 @@ ISE_GET_VOL1_STATUS_XML =\
</volumes>""" % (ISE_VOLUME1_LOCATION_URL)
ISE_GET_VOL1_STATUS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': 'u%s' % ISE_VOLUME1_LOCATION_URL,
'content': " ".join(ISE_GET_VOL1_STATUS_XML.split())}
@ -339,7 +340,7 @@ ISE_GET_VOL2_STATUS_XML =\
</volumes>""" % (ISE_VOLUME2_LOCATION_URL)
ISE_GET_VOL2_STATUS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': 'u%s' % ISE_VOLUME2_LOCATION_URL,
'content': " ".join(ISE_GET_VOL2_STATUS_XML.split())}
@ -355,7 +356,7 @@ ISE_GET_VOL3_STATUS_XML =\
</volumes>""" % (ISE_VOLUME3_LOCATION_URL)
ISE_GET_VOL3_STATUS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': 'u%s' % ISE_VOLUME3_LOCATION_URL,
'content': " ".join(ISE_GET_VOL3_STATUS_XML.split())}
@ -371,7 +372,7 @@ ISE_GET_SNAP1_STATUS_XML =\
</volumes>""" % (ISE_SNAPSHOT_LOCATION_URL)
ISE_GET_SNAP1_STATUS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': 'u%s' % ISE_SNAPSHOT_LOCATION_URL,
'content': " ".join(ISE_GET_SNAP1_STATUS_XML.split())}
@ -387,14 +388,14 @@ ISE_GET_CLONE1_STATUS_XML =\
</volumes>""" % (ISE_CLONE_LOCATION_URL)
ISE_GET_CLONE1_STATUS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': 'u%s' % ISE_CLONE_LOCATION_URL,
'content': " ".join(ISE_GET_CLONE1_STATUS_XML.split())}
ISE_CREATE_VOLUME_XML = """<volume/>"""
ISE_CREATE_VOLUME_RESP =\
{'status': 201,
{'status': http_client.CREATED,
'location': ISE_VOLUME1_LOCATION_URL,
'content': " ".join(ISE_CREATE_VOLUME_XML.split())}
@ -411,7 +412,7 @@ ISE_GET_IONETWORKS_XML =\
</chap>"""
ISE_GET_IONETWORKS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_IONETWORKS_XML.split())}
@ -428,14 +429,14 @@ ISE_GET_IONETWORKS_CHAP_XML =\
</chap>"""
ISE_GET_IONETWORKS_CHAP_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_IONETWORKS_CHAP_XML.split())}
ISE_DELETE_VOLUME_XML = """<volumes/>"""
ISE_DELETE_VOLUME_RESP =\
{'status': 204,
{'status': http_client.NO_CONTENT,
'location': '',
'content': " ".join(ISE_DELETE_VOLUME_XML.split())}
@ -454,7 +455,7 @@ ISE_GET_ALLOC_WITH_EP_XML =\
(ISE_ALLOCATION_LOCATION_URL, VOLUME1['name'], HOST1)
ISE_GET_ALLOC_WITH_EP_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': ISE_ALLOCATION_LOCATION_URL,
'content': " ".join(ISE_GET_ALLOC_WITH_EP_XML.split())}
@ -462,14 +463,14 @@ ISE_GET_ALLOC_WITH_NO_ALLOC_XML =\
"""<allocations self="%s"/>""" % ISE_ALLOCATION_LOCATION_URL
ISE_GET_ALLOC_WITH_NO_ALLOC_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': ISE_ALLOCATION_LOCATION_URL,
'content': " ".join(ISE_GET_ALLOC_WITH_NO_ALLOC_XML.split())}
ISE_DELETE_ALLOC_XML = """<allocations/>"""
ISE_DELETE_ALLOC_RESP =\
{'status': 204,
{'status': http_client.NO_CONTENT,
'location': '',
'content': " ".join(ISE_DELETE_ALLOC_XML.split())}
@ -477,7 +478,7 @@ ISE_GET_HOSTS_NOHOST_XML =\
"""<hosts self="http://ip/storage/hosts"/>"""
ISE_GET_HOSTS_NOHOST_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_HOSTS_NOHOST_XML.split())}
@ -502,7 +503,7 @@ ISE_GET_HOSTS_HOST1_XML =\
</hosts>""" % HOST1
ISE_GET_HOSTS_HOST1_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_HOSTS_HOST1_XML.split())}
@ -527,7 +528,7 @@ ISE_GET_HOSTS_HOST1_HOST_TYPE_XML =\
</hosts>""" % HOST1
ISE_GET_HOSTS_HOST1_HOST_TYPE_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_HOSTS_HOST1_HOST_TYPE_XML.split())}
@ -551,7 +552,7 @@ ISE_GET_HOSTS_HOST2_XML =\
</hosts>""" % HOST2
ISE_GET_HOSTS_HOST2_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_HOSTS_HOST2_XML.split())}
@ -559,7 +560,7 @@ ISE_CREATE_HOST_XML =\
"""<hosts self="http://ip/storage/hosts"/>"""
ISE_CREATE_HOST_RESP =\
{'status': 201,
{'status': http_client.CREATED,
'location': 'http://ip/storage/hosts/host1',
'content': " ".join(ISE_CREATE_HOST_XML.split())}
@ -567,7 +568,7 @@ ISE_CREATE_ALLOC_XML =\
"""<allocations self="http://ip/storage/allocations"/>"""
ISE_CREATE_ALLOC_RESP =\
{'status': 201,
{'status': http_client.CREATED,
'location': ISE_ALLOCATION_LOCATION_URL,
'content': " ".join(ISE_CREATE_ALLOC_XML.split())}
@ -607,7 +608,7 @@ ISE_GET_ENDPOINTS_XML =\
ISE_ALLOCATION_LOCATION_URL)
ISE_GET_ENDPOINTS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_ENDPOINTS_XML.split())}
@ -659,35 +660,35 @@ ISE_GET_CONTROLLERS_XML =\
ISE_ISCSI_IP2, ISE_WWN3, ISE_WWN4)
ISE_GET_CONTROLLERS_RESP =\
{'status': 200,
{'status': http_client.OK,
'location': '',
'content': " ".join(ISE_GET_CONTROLLERS_XML.split())}
ISE_CREATE_SNAPSHOT_XML = """<snapshot/>"""
ISE_CREATE_SNAPSHOT_RESP =\
{'status': 201,
{'status': http_client.CREATED,
'location': ISE_SNAPSHOT_LOCATION_URL,
'content': " ".join(ISE_CREATE_SNAPSHOT_XML.split())}
ISE_PREP_SNAPSHOT_XML = """<snapshot/>"""
ISE_PREP_SNAPSHOT_RESP =\
{'status': 202,
{'status': http_client.ACCEPTED,
'location': ISE_SNAPSHOT_LOCATION_URL,
'content': " ".join(ISE_PREP_SNAPSHOT_XML.split())}
ISE_MODIFY_VOLUME_XML = """<volume/>"""
ISE_MODIFY_VOLUME_RESP =\
{'status': 201,
{'status': http_client.CREATED,
'location': ISE_VOLUME1_LOCATION_URL,
'content': " ".join(ISE_MODIFY_VOLUME_XML.split())}
ISE_MODIFY_HOST_XML = """<host/>"""
ISE_MODIFY_HOST_RESP =\
{'status': 201,
{'status': http_client.CREATED,
'location': ISE_HOST_LOCATION_URL,
'content': " ".join(ISE_MODIFY_HOST_XML.split())}
@ -697,7 +698,7 @@ ISE_BAD_CONNECTION_RESP =\
'content': " "}
ISE_400_RESP =\
{'status': 400,
{'status': http_client.BAD_REQUEST,
'location': '',
'content': ""}
@ -705,7 +706,7 @@ ISE_GET_VOL_STATUS_404_XML = \
"""<response value="404" index="3">VOLUME not found.</response>"""
ISE_GET_VOL_STATUS_404_RESP =\
{'status': 404,
{'status': http_client.NOT_FOUND,
'location': '',
'content': " ".join(ISE_GET_VOL_STATUS_404_XML.split())}
@ -713,7 +714,7 @@ ISE_400_INVALID_STATE_XML = \
"""<response value="400">Not in a valid state.</response>"""
ISE_400_INVALID_STATE_RESP =\
{'status': 400,
{'status': http_client.BAD_REQUEST,
'location': '',
'content': " ".join(ISE_400_INVALID_STATE_XML.split())}
@ -721,7 +722,7 @@ ISE_409_CONFLICT_XML = \
"""<response value="409">Conflict</response>"""
ISE_409_CONFLICT_RESP =\
{'status': 409,
{'status': http_client.CONFLICT,
'location': '',
'content': " ".join(ISE_409_CONFLICT_XML.split())}