]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Validate outermost request body element name consistently
authorAbhijeet Malawade <Abhijeet.Malawade@nttdata.com>
Fri, 22 May 2015 12:43:25 +0000 (05:43 -0700)
committerAbhijeet Malawade <Abhijeet.Malawade@nttdata.com>
Fri, 19 Jun 2015 06:16:48 +0000 (23:16 -0700)
1. Return useful error message instead of empty error message.
ex.- Return "Missing required element '<element name>' in request body"
     instead of "Bad Request"
2. Return consistent error message in case request body element
name is not present.
3. Added 'assert_valid_body' method to raise HTTPBadRequest exception
if request body is not valid. It is not possible to modify
'is_valid_body' method itself to raise exception because V1 and v2
api's return different error code when 'is_valid_body' returns False.

APIImpact

Closes-bug: #1461402
Change-Id: I81764cd8517484fbee4beae2b30668c8b180d677

22 files changed:
cinder/api/contrib/backups.py
cinder/api/contrib/cgsnapshots.py
cinder/api/contrib/consistencygroups.py
cinder/api/contrib/qos_specs_manage.py
cinder/api/contrib/quotas.py
cinder/api/contrib/services.py
cinder/api/contrib/types_extra_specs.py
cinder/api/contrib/types_manage.py
cinder/api/contrib/volume_manage.py
cinder/api/contrib/volume_transfer.py
cinder/api/contrib/volume_type_access.py
cinder/api/contrib/volume_type_encryption.py
cinder/api/openstack/wsgi.py
cinder/api/v2/snapshot_metadata.py
cinder/api/v2/snapshots.py
cinder/api/v2/volume_metadata.py
cinder/api/v2/volumes.py
cinder/tests/unit/api/contrib/test_backups.py
cinder/tests/unit/api/contrib/test_cgsnapshots.py
cinder/tests/unit/api/contrib/test_consistencygroups.py
cinder/tests/unit/api/contrib/test_volume_transfer.py
cinder/tests/unit/api/contrib/test_volume_type_encryption.py

index 1b68e1234e375dbae74c9312bea9afed747655a0..fa995228da15d14d83fe7b6600ce0abc0b61f0c8 100644 (file)
@@ -240,13 +240,12 @@ class BackupsController(wsgi.Controller):
     def create(self, req, body):
         """Create a new backup."""
         LOG.debug('Creating new backup %s', body)
-        if not self.is_valid_body(body, 'backup'):
-            raise exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'backup')
 
         context = req.environ['cinder.context']
+        backup = body['backup']
 
         try:
-            backup = body['backup']
             volume_id = backup['volume_id']
         except KeyError:
             msg = _("Incorrect request body format")
@@ -282,9 +281,7 @@ class BackupsController(wsgi.Controller):
         """Restore an existing backup to a volume."""
         LOG.debug('Restoring backup %(backup_id)s (%(body)s)',
                   {'backup_id': id, 'body': body})
-        if not self.is_valid_body(body, 'restore'):
-            msg = _("Incorrect request body format")
-            raise exc.HTTPBadRequest(explanation=msg)
+        self.assert_valid_body(body, 'restore')
 
         context = req.environ['cinder.context']
         restore = body['restore']
@@ -344,9 +341,7 @@ class BackupsController(wsgi.Controller):
     def import_record(self, req, body):
         """Import a backup."""
         LOG.debug('Importing record from %s.', body)
-        if not self.is_valid_body(body, 'backup-record'):
-            msg = _("Incorrect request body format.")
-            raise exc.HTTPBadRequest(explanation=msg)
+        self.assert_valid_body(body, 'backup-record')
         context = req.environ['cinder.context']
         import_data = body['backup-record']
         # Verify that body elements are provided
index 76aa382391376ebd2142ef81c49481a185241975..c269f6c4460d66dbd35b145c3a2b6ab9d3e7539f 100644 (file)
@@ -156,16 +156,10 @@ class CgsnapshotsController(wsgi.Controller):
     def create(self, req, body):
         """Create a new cgsnapshot."""
         LOG.debug('Creating new cgsnapshot %s', body)
-        if not self.is_valid_body(body, 'cgsnapshot'):
-            raise exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'cgsnapshot')
 
         context = req.environ['cinder.context']
-
-        try:
-            cgsnapshot = body['cgsnapshot']
-        except KeyError:
-            msg = _("Incorrect request body format")
-            raise exc.HTTPBadRequest(explanation=msg)
+        cgsnapshot = body['cgsnapshot']
 
         try:
             group_id = cgsnapshot['consistencygroup_id']
index 9a147292a7250eb60d7d2d55db800b5540d4fc81..9b9b90f6ef1ff3f78b5b18ca0997e7114ff239f8 100644 (file)
@@ -212,16 +212,10 @@ class ConsistencyGroupsController(wsgi.Controller):
     def create(self, req, body):
         """Create a new consistency group."""
         LOG.debug('Creating new consistency group %s', body)
-        if not self.is_valid_body(body, 'consistencygroup'):
-            raise exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'consistencygroup')
 
         context = req.environ['cinder.context']
-
-        try:
-            consistencygroup = body['consistencygroup']
-        except KeyError:
-            msg = _("Incorrect request body format")
-            raise exc.HTTPBadRequest(explanation=msg)
+        consistencygroup = body['consistencygroup']
         name = consistencygroup.get('name', None)
         description = consistencygroup.get('description', None)
         volume_types = consistencygroup.get('volume_types', None)
@@ -263,16 +257,10 @@ class ConsistencyGroupsController(wsgi.Controller):
         API above.
         """
         LOG.debug('Creating new consistency group %s.', body)
-        if not self.is_valid_body(body, 'consistencygroup-from-src'):
-            raise exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'consistencygroup-from-src')
 
         context = req.environ['cinder.context']
-
-        try:
-            consistencygroup = body['consistencygroup-from-src']
-        except KeyError:
-            msg = _("Incorrect request body format.")
-            raise exc.HTTPBadRequest(explanation=msg)
+        consistencygroup = body['consistencygroup-from-src']
         name = consistencygroup.get('name', None)
         description = consistencygroup.get('description', None)
         cgsnapshot_id = consistencygroup.get('cgsnapshot_id', None)
@@ -323,9 +311,8 @@ class ConsistencyGroupsController(wsgi.Controller):
         if not body:
             msg = _("Missing request body.")
             raise exc.HTTPBadRequest(explanation=msg)
-        if not self.is_valid_body(body, 'consistencygroup'):
-            msg = _("Incorrect request body format.")
-            raise exc.HTTPBadRequest(explanation=msg)
+
+        self.assert_valid_body(body, 'consistencygroup')
         context = req.environ['cinder.context']
 
         consistencygroup = body.get('consistencygroup', None)
index 434bacd9d44ef083937bfe2c76b4ff250579eafb..8d8f85285563c3a63bcc2724fd646a0480d2f5ba 100644 (file)
@@ -123,8 +123,7 @@ class QoSSpecsController(wsgi.Controller):
         context = req.environ['cinder.context']
         authorize(context)
 
-        if not self.is_valid_body(body, 'qos_specs'):
-            raise webob.exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'qos_specs')
 
         specs = body['qos_specs']
         name = specs.get('name', None)
@@ -166,8 +165,7 @@ class QoSSpecsController(wsgi.Controller):
         context = req.environ['cinder.context']
         authorize(context)
 
-        if not self.is_valid_body(body, 'qos_specs'):
-            raise webob.exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'qos_specs')
         specs = body['qos_specs']
         try:
             qos_specs.update(context, id, specs)
index ec0536957795daf29c25f16bea2da3e44b1a10cb..8fbafca97b36f21831793a21897f8737420d54de 100644 (file)
@@ -101,9 +101,7 @@ class QuotaSetsController(wsgi.Controller):
         context = req.environ['cinder.context']
         authorize_update(context)
         project_id = id
-        if not self.is_valid_body(body, 'quota_set'):
-            msg = (_("Missing required element quota_set in request body."))
-            raise webob.exc.HTTPBadRequest(explanation=msg)
+        self.assert_valid_body(body, 'quota_set')
 
         bad_keys = []
 
index ae716bb7f8a196668330d6bf43ca3ad52352bc70..469c32cd40a903d46a70956545b37a5b61261f39 100644 (file)
@@ -161,7 +161,8 @@ class ServiceController(wsgi.Controller):
         try:
             host = body['host']
         except (TypeError, KeyError):
-            raise webob.exc.HTTPBadRequest()
+            msg = _("Missing required element 'host' in request body.")
+            raise webob.exc.HTTPBadRequest(explanation=msg)
 
         ret_val['disabled'] = disabled
         if id == "disable-log-reason" and ext_loaded:
index 951368a75403e3868493fc971a8683d26eb15e90..e427713fcf5f22e5bc3c67565b72f123a1f4558f 100644 (file)
@@ -79,8 +79,7 @@ class VolumeTypeExtraSpecsController(wsgi.Controller):
         context = req.environ['cinder.context']
         authorize(context)
 
-        if not self.is_valid_body(body, 'extra_specs'):
-            raise webob.exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'extra_specs')
 
         self._check_type(context, type_id)
         specs = body['extra_specs']
index 33a4978bd5ec16d6c03daaf1312eb8ca97ec0ab9..46b23a63c97ab8a09a90a1ee67d15cebfa0882fd 100644 (file)
@@ -54,8 +54,7 @@ class VolumeTypesManageController(wsgi.Controller):
         context = req.environ['cinder.context']
         authorize(context)
 
-        if not self.is_valid_body(body, 'volume_type'):
-            raise webob.exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'volume_type')
 
         vol_type = body['volume_type']
         name = vol_type.get('name', None)
@@ -103,8 +102,7 @@ class VolumeTypesManageController(wsgi.Controller):
         context = req.environ['cinder.context']
         authorize(context)
 
-        if not self.is_valid_body(body, 'volume_type'):
-            raise webob.exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'volume_type')
 
         vol_type = body['volume_type']
         description = vol_type.get('description')
index 55e681f842802d8f49e1fa8fc2d25c3726f892a5..45008183b4e4c93b92badbd4ef7aeac0066524c6 100644 (file)
@@ -96,9 +96,7 @@ class VolumeManageController(wsgi.Controller):
         context = req.environ['cinder.context']
         authorize(context)
 
-        if not self.is_valid_body(body, 'volume'):
-            msg = _("Missing required element '%s' in request body") % 'volume'
-            raise exc.HTTPBadRequest(explanation=msg)
+        self.assert_valid_body(body, 'volume')
 
         volume = body['volume']
 
index 469f591ea0c3126455b2bba022071d6318a32a8b..bab74f6787f1d1a8e2b4915952f2a8f3628af231 100644 (file)
@@ -149,13 +149,12 @@ class VolumeTransferController(wsgi.Controller):
     def create(self, req, body):
         """Create a new volume transfer."""
         LOG.debug('Creating new volume transfer %s', body)
-        if not self.is_valid_body(body, 'transfer'):
-            raise exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'transfer')
 
         context = req.environ['cinder.context']
+        transfer = body['transfer']
 
         try:
-            transfer = body['transfer']
             volume_id = transfer['volume_id']
         except KeyError:
             msg = _("Incorrect request body format")
@@ -185,13 +184,12 @@ class VolumeTransferController(wsgi.Controller):
         """Accept a new volume transfer."""
         transfer_id = id
         LOG.debug('Accepting volume transfer %s', transfer_id)
-        if not self.is_valid_body(body, 'accept'):
-            raise exc.HTTPBadRequest()
+        self.assert_valid_body(body, 'accept')
 
         context = req.environ['cinder.context']
+        accept = body['accept']
 
         try:
-            accept = body['accept']
             auth_key = accept['auth_key']
         except KeyError:
             msg = _("Incorrect request body format")
index b91672f396a22d86b5e301b544fa9ea27c986783..154a7fe644741dbef595e94fa3b2b6baab8676c4 100644 (file)
@@ -107,8 +107,7 @@ class VolumeTypeActionController(wsgi.Controller):
     """The volume type access API controller for the OpenStack API."""
 
     def _check_body(self, body, action_name):
-        if not self.is_valid_body(body, action_name):
-            raise webob.exc.HTTPBadRequest()
+        self.assert_valid_body(body, action_name)
         access = body[action_name]
         project = access.get('project')
         if not uuidutils.is_uuid_like(project):
index 9cbfc7ae6a03fa39124c7051437c569fbd220b54..48c97706011ea707236448162cac3c26b46195eb 100644 (file)
@@ -112,9 +112,7 @@ class VolumeTypeEncryptionController(wsgi.Controller):
             expl = _('Cannot create encryption specs. Volume type in use.')
             raise webob.exc.HTTPBadRequest(explanation=expl)
 
-        if not self.is_valid_body(body, 'encryption'):
-            expl = _('Create body is not valid.')
-            raise webob.exc.HTTPBadRequest(explanation=expl)
+        self.assert_valid_body(body, 'encryption')
 
         self._check_type(context, type_id)
 
@@ -138,12 +136,8 @@ class VolumeTypeEncryptionController(wsgi.Controller):
         context = req.environ['cinder.context']
         authorize(context)
 
-        if not body:
-            expl = _('Request body empty.')
-            raise webob.exc.HTTPBadRequest(explanation=expl)
-        if not self.is_valid_body(body, 'encryption'):
-            expl = _('Update body is not valid. It must contain "encryption."')
-            raise webob.exc.HTTPBadRequest(explanation=expl)
+        self.assert_valid_body(body, 'encryption')
+
         if len(body) > 1:
             expl = _('Request body contains too many items.')
             raise webob.exc.HTTPBadRequest(explanation=expl)
index c38caa1e7bd9e03fca4302ec6dad08dcd2f0354c..74c36beaa0bc71372abb8c2ed659e7c602b30a2c 100644 (file)
@@ -1204,6 +1204,19 @@ class Controller(object):
 
         return True
 
+    @staticmethod
+    def assert_valid_body(body, entity_name):
+        # NOTE: After v1 api is deprecated need to merge 'is_valid_body' and
+        #       'assert_valid_body' in to one method. Right now it is not
+        #       possible to modify 'is_valid_body' to raise exception because
+        #       in case of V1 api when 'is_valid_body' return False,
+        #       'HTTPUnprocessableEntity' exception is getting raised and in
+        #       V2 api 'HTTPBadRequest' exception is getting raised.
+        if not Controller.is_valid_body(body, entity_name):
+            raise webob.exc.HTTPBadRequest(
+                explanation=_("Missing required element '%s' in "
+                              "request body.") % entity_name)
+
 
 class Fault(webob.exc.HTTPException):
     """Wrap webob.exc.HTTPException to provide API friendly response."""
index 18c2dd4a0c580fb620b7f46fafd0fd068eb783c6..fb6cab0f0ff3e46655bc689efe5104142c5e5c21 100644 (file)
@@ -48,13 +48,9 @@ class Controller(wsgi.Controller):
     @wsgi.serializers(xml=common.MetadataTemplate)
     @wsgi.deserializers(xml=common.MetadataDeserializer)
     def create(self, req, snapshot_id, body):
-        try:
-            metadata = body['metadata']
-        except (KeyError, TypeError):
-            msg = _("Malformed request body")
-            raise exc.HTTPBadRequest(explanation=msg)
-
+        self.assert_valid_body(body, 'metadata')
         context = req.environ['cinder.context']
+        metadata = body['metadata']
 
         new_metadata = self._update_snapshot_metadata(context,
                                                       snapshot_id,
@@ -66,11 +62,8 @@ class Controller(wsgi.Controller):
     @wsgi.serializers(xml=common.MetaItemTemplate)
     @wsgi.deserializers(xml=common.MetaItemDeserializer)
     def update(self, req, snapshot_id, id, body):
-        try:
-            meta_item = body['meta']
-        except (TypeError, KeyError):
-            expl = _('Malformed request body')
-            raise exc.HTTPBadRequest(explanation=expl)
+        self.assert_valid_body(body, 'meta')
+        meta_item = body['meta']
 
         if id not in meta_item:
             expl = _('Request body and URI mismatch')
@@ -91,13 +84,10 @@ class Controller(wsgi.Controller):
     @wsgi.serializers(xml=common.MetadataTemplate)
     @wsgi.deserializers(xml=common.MetadataDeserializer)
     def update_all(self, req, snapshot_id, body):
-        try:
-            metadata = body['metadata']
-        except (TypeError, KeyError):
-            expl = _('Malformed request body')
-            raise exc.HTTPBadRequest(explanation=expl)
-
+        self.assert_valid_body(body, 'metadata')
         context = req.environ['cinder.context']
+        metadata = body['metadata']
+
         new_metadata = self._update_snapshot_metadata(context,
                                                       snapshot_id,
                                                       metadata,
index d3976629d72299a9ee5b741096edc71e2d977143..84e97e2ce2eac44ed840c8f67eb2cb3d83a46438 100644 (file)
@@ -168,10 +168,7 @@ class SnapshotsController(wsgi.Controller):
         kwargs = {}
         context = req.environ['cinder.context']
 
-        if not self.is_valid_body(body, 'snapshot'):
-            msg = (_("Missing required element '%s' in request body") %
-                   'snapshot')
-            raise exc.HTTPBadRequest(explanation=msg)
+        self.assert_valid_body(body, 'snapshot')
 
         snapshot = body['snapshot']
         kwargs['metadata'] = snapshot.get('metadata', None)
index d34d40c126de6b0fc82da42b3882575e9d996b44..201b6d082269a9557b56a0ea317bdce8f574bdcb 100644 (file)
@@ -47,13 +47,9 @@ class Controller(wsgi.Controller):
     @wsgi.serializers(xml=common.MetadataTemplate)
     @wsgi.deserializers(xml=common.MetadataDeserializer)
     def create(self, req, volume_id, body):
-        try:
-            metadata = body['metadata']
-        except (KeyError, TypeError):
-            msg = _("Malformed request body")
-            raise webob.exc.HTTPBadRequest(explanation=msg)
-
+        self.assert_valid_body(body, 'metadata')
         context = req.environ['cinder.context']
+        metadata = body['metadata']
 
         new_metadata = self._update_volume_metadata(context,
                                                     volume_id,
@@ -65,11 +61,8 @@ class Controller(wsgi.Controller):
     @wsgi.serializers(xml=common.MetaItemTemplate)
     @wsgi.deserializers(xml=common.MetaItemDeserializer)
     def update(self, req, volume_id, id, body):
-        try:
-            meta_item = body['meta']
-        except (TypeError, KeyError):
-            expl = _('Malformed request body')
-            raise webob.exc.HTTPBadRequest(explanation=expl)
+        self.assert_valid_body(body, 'meta')
+        meta_item = body['meta']
 
         if id not in meta_item:
             expl = _('Request body and URI mismatch')
@@ -90,13 +83,10 @@ class Controller(wsgi.Controller):
     @wsgi.serializers(xml=common.MetadataTemplate)
     @wsgi.deserializers(xml=common.MetadataDeserializer)
     def update_all(self, req, volume_id, body):
-        try:
-            metadata = body['metadata']
-        except (TypeError, KeyError):
-            expl = _('Malformed request body')
-            raise webob.exc.HTTPBadRequest(explanation=expl)
-
+        self.assert_valid_body(body, 'metadata')
+        metadata = body['metadata']
         context = req.environ['cinder.context']
+
         new_metadata = self._update_volume_metadata(context,
                                                     volume_id,
                                                     metadata,
index 4be05fed1c2f28e5d799e697fee1a6fd70495ee5..3cdb088c67ef1cc755fdaab0b7993421518a87ec 100644 (file)
@@ -318,9 +318,7 @@ class VolumeController(wsgi.Controller):
     @wsgi.deserializers(xml=CreateDeserializer)
     def create(self, req, body):
         """Creates a new volume."""
-        if not self.is_valid_body(body, 'volume'):
-            msg = _("Missing required element '%s' in request body") % 'volume'
-            raise exc.HTTPBadRequest(explanation=msg)
+        self.assert_valid_body(body, 'volume')
 
         LOG.debug('Create volume request body: %s', body)
         context = req.environ['cinder.context']
index 7624efc07d8e520ca090b36a709bd9450cf60eac..c06a9c4c6e2650fd9a04548412d17bc5cc8693f0 100644 (file)
@@ -545,9 +545,8 @@ class BackupsAPITestCase(test.TestCase):
 
         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.')
+        self.assertEqual("Missing required element 'backup' in request body.",
+                         res_dict['badRequest']['message'])
 
     def test_create_backup_with_body_KeyError(self):
         # omit volume_id from body
@@ -912,8 +911,8 @@ class BackupsAPITestCase(test.TestCase):
 
         self.assertEqual(res.status_int, 400)
         self.assertEqual(res_dict['badRequest']['code'], 400)
-        self.assertEqual(res_dict['badRequest']['message'],
-                         'Incorrect request body format')
+        self.assertEqual("Missing required element 'restore' in request body.",
+                         res_dict['badRequest']['message'])
 
         db.backup_destroy(context.get_admin_context(), backup_id)
 
@@ -933,8 +932,8 @@ class BackupsAPITestCase(test.TestCase):
 
         self.assertEqual(res.status_int, 400)
         self.assertEqual(res_dict['badRequest']['code'], 400)
-        self.assertEqual(res_dict['badRequest']['message'],
-                         'Incorrect request body format')
+        self.assertEqual("Missing required element 'restore' in request body.",
+                         res_dict['badRequest']['message'])
 
     @mock.patch('cinder.volume.API.create')
     def test_restore_backup_volume_id_unspecified(self,
@@ -1512,5 +1511,6 @@ class BackupsAPITestCase(test.TestCase):
         # verify that request is successful
         self.assertEqual(res.status_int, 400)
         self.assertEqual(res_dict['badRequest']['code'], 400)
-        self.assertEqual(res_dict['badRequest']['message'],
-                         'Incorrect request body format.')
+        self.assertEqual("Missing required element 'backup-record' in "
+                         "request body.",
+                         res_dict['badRequest']['message'])
index 6a3113e835794cd6400bf2161d8af025856d9357..2e15aac4c0ae60f26090e66050160c29ce4b5f06 100644 (file)
@@ -383,9 +383,9 @@ class CgsnapshotsAPITestCase(test.TestCase):
 
         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.')
+        self.assertEqual("Missing required element 'cgsnapshot' in "
+                         "request body.",
+                         res_dict['badRequest']['message'])
 
     @mock.patch.object(consistencygroupAPI.API, 'create_cgsnapshot',
                        side_effect=exception.InvalidCgSnapshot(
index 3524a104ec09b19b9f028006e1b22f0da8b14279..d55f0666b5391628d108ce95a96e11a0f3c2b41b 100644 (file)
@@ -340,8 +340,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
 
         self.assertEqual(400, res.status_int)
         self.assertEqual(400, res_dict['badRequest']['code'])
-        self.assertEqual('The server could not comply with the request since'
-                         ' it is either malformed or otherwise incorrect.',
+        self.assertEqual("Missing required element 'consistencygroup' in "
+                         "request body.",
                          res_dict['badRequest']['message'])
 
     def test_delete_consistencygroup_available(self):
@@ -767,8 +767,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
 
         self.assertEqual(400, res.status_int)
         self.assertEqual(400, res_dict['badRequest']['code'])
-        msg = (_('The server could not comply with the request since '
-                 'it is either malformed or otherwise incorrect.'))
+        msg = _("Missing required element 'consistencygroup-from-src' in "
+                "request body.")
         self.assertEqual(msg, res_dict['badRequest']['message'])
 
     def test_create_consistencygroup_from_src_no_cgsnapshot_id(self):
index 97d3efd25bc7ffd361d893f6d0bd039acaa412d4..665b2e19d77cadc2c514ceda04797c3328b19f12 100644 (file)
@@ -313,9 +313,9 @@ class VolumeTransferAPITestCase(test.TestCase):
 
         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.')
+        self.assertEqual("Missing required element 'transfer' in "
+                         "request body.",
+                         res_dict['badRequest']['message'])
 
     def test_create_transfer_with_body_KeyError(self):
         body = {"transfer": {"display_name": "transfer1"}}
@@ -465,9 +465,8 @@ class VolumeTransferAPITestCase(test.TestCase):
 
         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.')
+        self.assertEqual("Missing required element 'accept' in request body.",
+                         res_dict['badRequest']['message'])
 
         db.volume_destroy(context.get_admin_context(), volume_id)
 
@@ -488,9 +487,8 @@ class VolumeTransferAPITestCase(test.TestCase):
 
         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.')
+        self.assertEqual("Missing required element 'accept' in request body.",
+                         res_dict['badRequest']['message'])
 
     def test_accept_transfer_invalid_id_auth_key(self):
         volume_id = self._create_volume()
index 8e7085c8b62ed92c075ffa99427af17f48617209..3542adc465c84a7db83a14eda22eb5b7bea404ca 100644 (file)
@@ -327,11 +327,13 @@ class VolumeTypeEncryptionTest(test.TestCase):
         db.volume_type_destroy(context.get_admin_context(), volume_type['id'])
 
     def test_create_no_body(self):
-        self._encryption_create_bad_body(body=None)
+        msg = "Missing required element 'encryption' in request body."
+        self._encryption_create_bad_body(body=None, msg=msg)
 
     def test_create_malformed_entity(self):
         body = {'encryption': 'string'}
-        self._encryption_create_bad_body(body=body)
+        msg = "Missing required element 'encryption' in request body."
+        self._encryption_create_bad_body(body=body, msg=msg)
 
     def test_create_negative_key_size(self):
         body = {"encryption": {'cipher': 'cipher',
@@ -552,11 +554,11 @@ class VolumeTypeEncryptionTest(test.TestCase):
 
     def test_update_item_invalid_body(self):
         update_body = {"key_size": "value1"}
-        msg = 'Update body is not valid. It must contain "encryption."'
+        msg = "Missing required element 'encryption' in request body."
         self._encryption_update_bad_body(update_body, msg)
 
     def _encryption_empty_update(self, update_body):
-        msg = 'Request body empty.'
+        msg = "Missing required element 'encryption' in request body."
         self._encryption_update_bad_body(update_body, msg)
 
     def test_update_no_body(self):