diff options
Diffstat (limited to 'nova/api/openstack/compute/legacy_v2/contrib/volumes.py')
-rw-r--r-- | nova/api/openstack/compute/legacy_v2/contrib/volumes.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/nova/api/openstack/compute/legacy_v2/contrib/volumes.py b/nova/api/openstack/compute/legacy_v2/contrib/volumes.py index aae3af8e87..c3c27d9ddb 100644 --- a/nova/api/openstack/compute/legacy_v2/contrib/volumes.py +++ b/nova/api/openstack/compute/legacy_v2/contrib/volumes.py @@ -355,8 +355,19 @@ class VolumeAttachmentController(wsgi.Controller): except KeyError: msg = _("volumeId must be specified.") raise exc.HTTPBadRequest(explanation=msg) + self._validate_volume_id(new_volume_id) - new_volume = self.volume_api.get(context, new_volume_id) + try: + new_volume = self.volume_api.get(context, new_volume_id) + except exception.VolumeNotFound as e: + # NOTE: This BadRequest is different from the above NotFound even + # though the same VolumeNotFound exception. This is intentional + # because new_volume_id is specified in a request body and if a + # nonexistent resource in the body (not URI) the code should be + # 400 Bad Request as API-WG guideline. On the other hand, + # old_volume_id is specified with URI. So it is valid to return + # NotFound response if that is not existent. + raise exc.HTTPBadRequest(explanation=e.format_message()) instance = common.get_instance(self.compute_api, context, server_id) |