diff --git a/nova/api/openstack/compute/schemas/volumes.py b/nova/api/openstack/compute/schemas/volumes.py index 6ac52354c1b3..4e68bc78e820 100644 --- a/nova/api/openstack/compute/schemas/volumes.py +++ b/nova/api/openstack/compute/schemas/volumes.py @@ -96,8 +96,9 @@ del update_volume_attachment['properties']['volumeAttachment'][ 'properties']['device'] # NOTE(brinzhang): Allow attachment_id, serverId, device, tag, and -# delete_on_termination to be specified for RESTfulness, even though -# we will not allow updating all of them. +# delete_on_termination (i.e., follow the content of the GET response) +# to be specified for RESTfulness, even though we will not allow updating +# all of them. update_volume_attachment_v285 = { 'type': 'object', 'properties': { diff --git a/nova/tests/unit/api/openstack/compute/test_volumes.py b/nova/tests/unit/api/openstack/compute/test_volumes.py index a2d9f07e9a1f..28c7b367383a 100644 --- a/nova/tests/unit/api/openstack/compute/test_volumes.py +++ b/nova/tests/unit/api/openstack/compute/test_volumes.py @@ -1384,6 +1384,22 @@ class UpdateVolumeAttachTests(VolumeAttachTestsV279): self.req, FAKE_UUID, FAKE_UUID_A, body=body) + @mock.patch.object(objects.BlockDeviceMapping, + 'get_by_volume_and_instance') + def test_update_volume_with_changed_attachment_id_old_microversion( + self, mock_get_vol_and_inst): + body = {'volumeAttachment': { + 'volumeId': FAKE_UUID_A, + 'id': uuids.attachment_id, + }} + req = self._get_req(body, microversion='2.84') + ex = self.assertRaises(exception.ValidationError, + self.attachments.update, + req, FAKE_UUID, + FAKE_UUID_A, body=body) + self.assertIn('Additional properties are not allowed', + six.text_type(ex)) + @mock.patch.object(objects.BlockDeviceMapping, 'get_by_volume_and_instance') def test_update_volume_with_changed_serverId(self, @@ -1411,6 +1427,22 @@ class UpdateVolumeAttachTests(VolumeAttachTestsV279): self.req, FAKE_UUID, FAKE_UUID_A, body=body) + @mock.patch.object(objects.BlockDeviceMapping, + 'get_by_volume_and_instance') + def test_update_volume_with_changed_serverId_old_microversion( + self, mock_get_vol_and_inst): + body = {'volumeAttachment': { + 'volumeId': FAKE_UUID_A, + 'serverId': uuids.server_id, + }} + req = self._get_req(body, microversion='2.84') + ex = self.assertRaises(exception.ValidationError, + self.attachments.update, + req, FAKE_UUID, + FAKE_UUID_A, body=body) + self.assertIn('Additional properties are not allowed', + six.text_type(ex)) + @mock.patch.object(objects.BlockDeviceMapping, 'get_by_volume_and_instance') def test_update_volume_with_changed_device(self, mock_get_vol_and_inst):