"""Create a new backup."""
LOG.debug(_('Creating new backup %s'), body)
if not self.is_valid_body(body, 'backup'):
- raise exc.HTTPUnprocessableEntity()
+ raise exc.HTTPBadRequest()
context = req.environ['cinder.context']
backup_id = id
LOG.debug(_('Restoring backup %(backup_id)s (%(body)s)') % locals())
if not self.is_valid_body(body, 'restore'):
- raise exc.HTTPUnprocessableEntity()
+ raise exc.HTTPBadRequest()
context = req.environ['cinder.context']
host = body['host']
service = body['service']
except (TypeError, KeyError):
- raise webob.exc.HTTPUnprocessableEntity()
+ raise webob.exc.HTTPBadRequest()
try:
svc = db.service_get_by_args(context, host, service)
authorize(context)
if not self.is_valid_body(body, 'volume_type'):
- raise webob.exc.HTTPUnprocessableEntity()
+ raise webob.exc.HTTPBadRequest()
vol_type = body['volume_type']
name = vol_type.get('name', None)
specs = vol_type.get('extra_specs', {})
if name is None or name == "":
- raise webob.exc.HTTPUnprocessableEntity()
+ raise webob.exc.HTTPBadRequest()
try:
volume_types.create(context, name, specs)
context = req.environ['cinder.context']
if not self.is_valid_body(body, 'snapshot'):
- raise exc.HTTPUnprocessableEntity()
+ raise exc.HTTPBadRequest()
snapshot = body['snapshot']
kwargs['metadata'] = snapshot.get('metadata', None)
context = req.environ['cinder.context']
if not body:
- raise exc.HTTPUnprocessableEntity()
+ raise exc.HTTPBadRequest()
if 'snapshot' not in body:
- raise exc.HTTPUnprocessableEntity()
+ raise exc.HTTPBadRequest()
snapshot = body['snapshot']
update_dict = {}
def create(self, req, body):
"""Creates a new volume."""
if not self.is_valid_body(body, 'volume'):
- raise exc.HTTPUnprocessableEntity()
+ raise exc.HTTPBadRequest()
context = req.environ['cinder.context']
volume = body['volume']
context = req.environ['cinder.context']
if not body:
- raise exc.HTTPUnprocessableEntity()
+ raise exc.HTTPBadRequest()
if 'volume' not in body:
- raise exc.HTTPUnprocessableEntity()
+ raise exc.HTTPBadRequest()
volume = body['volume']
update_dict = {}
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
- self.assertEqual(res.status_int, 422)
- self.assertEqual(res_dict['computeFault']['code'], 422)
- self.assertEqual(res_dict['computeFault']['message'],
- 'Unable to process the contained instructions')
+ self.assertEqual(res.status_int, 400)
+ self.assertEqual(res_dict['badRequest']['code'], 400)
+ self.assertEqual(res_dict['badRequest']['message'],
+ 'The server could not comply with the request since'
+ ' it is either malformed or otherwise incorrect.')
def test_create_backup_with_body_KeyError(self):
# omit volume_id from body
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
- self.assertEqual(res.status_int, 422)
- self.assertEqual(res_dict['computeFault']['code'], 422)
- self.assertEqual(res_dict['computeFault']['message'],
- 'Unable to process the contained instructions')
+ self.assertEqual(res.status_int, 400)
+ self.assertEqual(res_dict['badRequest']['code'], 400)
+ self.assertEqual(res_dict['badRequest']['message'],
+ 'The server could not comply with the request since'
+ ' it is either malformed or otherwise incorrect.')
db.backup_destroy(context.get_admin_context(), backup_id)
res_dict = json.loads(res.body)
- self.assertEqual(res.status_int, 422)
- self.assertEqual(res_dict['computeFault']['code'], 422)
- self.assertEqual(res_dict['computeFault']['message'],
- 'Unable to process the contained instructions')
+ self.assertEqual(res.status_int, 400)
+ self.assertEqual(res_dict['badRequest']['code'], 400)
+ self.assertEqual(res_dict['badRequest']['message'],
+ 'The server could not comply with the request since'
+ ' it is either malformed or otherwise incorrect.')
def test_restore_backup_volume_id_unspecified(self):
self.assertEqual(1, len(res_dict))
self.assertEqual('vol_type_1', res_dict['volume_type']['name'])
-
-class VolumeTypesUnprocessableEntityTestCase(test.TestCase):
-
- """
- Tests of places we throw 422 Unprocessable Entity from
- """
-
- def setUp(self):
- super(VolumeTypesUnprocessableEntityTestCase, self).setUp()
- self.controller = types_manage.VolumeTypesManageController()
-
- def _unprocessable_volume_type_create(self, body):
+ def _create_volume_type_bad_body(self, body):
req = fakes.HTTPRequest.blank('/v2/fake/types')
req.method = 'POST'
-
- self.assertRaises(webob.exc.HTTPUnprocessableEntity,
+ self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._create, req, body)
def test_create_no_body(self):
- self._unprocessable_volume_type_create(body=None)
+ self._create_volume_type_bad_body(body=None)
def test_create_missing_volume(self):
body = {'foo': {'a': 'b'}}
- self._unprocessable_volume_type_create(body=body)
+ self._create_volume_type_bad_body(body=body)
def test_create_malformed_entity(self):
body = {'volume_type': 'string'}
- self._unprocessable_volume_type_create(body=body)
+ self._create_volume_type_bad_body(body=body)
def test_snapshot_update_missing_body(self):
body = {}
req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % UUID)
- self.assertRaises(webob.exc.HTTPUnprocessableEntity,
+ self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update, req, UUID, body)
def test_snapshot_update_invalid_body(self):
body = {'name': 'missing top level snapshot key'}
req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % UUID)
- self.assertRaises(webob.exc.HTTPUnprocessableEntity,
+ self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update, req, UUID, body)
def test_snapshot_update_not_found(self):
self.assertTrue('snapshots' in res)
self.assertEqual(1, len(res['snapshots']))
+ def _create_snapshot_bad_body(self, body):
+ req = fakes.HTTPRequest.blank('/v2/fake/snapshots')
+ req.method = 'POST'
+
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ self.controller.create, req, body)
+
+ def test_create_no_body(self):
+ self._create_snapshot_bad_body(body=None)
+
+ def test_create_missing_snapshot(self):
+ body = {'foo': {'a': 'b'}}
+ self._create_snapshot_bad_body(body=body)
+
+ def test_create_malformed_entity(self):
+ body = {'snapshot': 'string'}
+ self._create_snapshot_bad_body(body=body)
+
class SnapshotSerializerTest(test.TestCase):
def _verify_snapshot(self, snap, tree):
self.assertEqual(len(raw_snapshots), len(tree))
for idx, child in enumerate(tree):
self._verify_snapshot(raw_snapshots[idx], child)
-
-
-class SnapshotsUnprocessableEntityTestCase(test.TestCase):
-
- """
- Tests of places we throw 422 Unprocessable Entity from
- """
-
- def setUp(self):
- super(SnapshotsUnprocessableEntityTestCase, self).setUp()
- self.controller = snapshots.SnapshotsController()
-
- def _unprocessable_snapshot_create(self, body):
- req = fakes.HTTPRequest.blank('/v2/fake/snapshots')
- req.method = 'POST'
-
- self.assertRaises(webob.exc.HTTPUnprocessableEntity,
- self.controller.create, req, body)
-
- def test_create_no_body(self):
- self._unprocessable_snapshot_create(body=None)
-
- def test_create_missing_snapshot(self):
- body = {'foo': {'a': 'b'}}
- self._unprocessable_snapshot_create(body=body)
-
- def test_create_malformed_entity(self):
- body = {'snapshot': 'string'}
- self._unprocessable_snapshot_create(body=body)
def test_update_empty_body(self):
body = {}
req = fakes.HTTPRequest.blank('/v2/volumes/1')
- self.assertRaises(webob.exc.HTTPUnprocessableEntity,
+ self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update,
req, '1', body)
'name': 'missing top level volume key'
}
req = fakes.HTTPRequest.blank('/v2/volumes/1')
- self.assertRaises(webob.exc.HTTPUnprocessableEntity,
+ self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update,
req, '1', body)
self.assertTrue('volumes' in res)
self.assertEqual(1, len(res['volumes']))
+ def _create_volume_bad_request(self, body):
+ req = fakes.HTTPRequest.blank('/v2/fake/volumes')
+ req.method = 'POST'
+
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ self.controller.create, req, body)
+
+ def test_create_no_body(self):
+ self._create_volume_bad_request(body=None)
+
+ def test_create_missing_volume(self):
+ body = {'foo': {'a': 'b'}}
+ self._create_volume_bad_request(body=body)
+
+ def test_create_malformed_entity(self):
+ body = {'volume': 'string'}
+ self._create_volume_bad_request(body=body)
+
class VolumeSerializerTest(test.TestCase):
def _verify_volume_attachment(self, attach, tree):
},
}
self.assertEquals(request['body'], expected)
-
-
-class VolumesUnprocessableEntityTestCase(test.TestCase):
-
- """
- Tests of places we throw 422 Unprocessable Entity from
- """
-
- def setUp(self):
- super(VolumesUnprocessableEntityTestCase, self).setUp()
- self.ext_mgr = extensions.ExtensionManager()
- self.ext_mgr.extensions = {}
- self.controller = volumes.VolumeController(self.ext_mgr)
-
- def _unprocessable_volume_create(self, body):
- req = fakes.HTTPRequest.blank('/v2/fake/volumes')
- req.method = 'POST'
-
- self.assertRaises(webob.exc.HTTPUnprocessableEntity,
- self.controller.create, req, body)
-
- def test_create_no_body(self):
- self._unprocessable_volume_create(body=None)
-
- def test_create_missing_volume(self):
- body = {'foo': {'a': 'b'}}
- self._unprocessable_volume_create(body=body)
-
- def test_create_malformed_entity(self):
- body = {'volume': 'string'}
- self._unprocessable_volume_create(body=body)