diff --git a/cinder/tests/unit/attachments/test_attachments_api.py b/cinder/tests/unit/attachments/test_attachments_api.py index f6c25913ac3..d2b59e51fd9 100644 --- a/cinder/tests/unit/attachments/test_attachments_api.py +++ b/cinder/tests/unit/attachments/test_attachments_api.py @@ -314,3 +314,14 @@ class AttachmentManagerTestCase(test.TestCase): self.context, aref, connector) + + def test_attachment_create_creating_volume(self): + """Test attachment_create on a creating volume.""" + volume_params = {'status': 'creating'} + + vref = tests_utils.create_volume(self.context, **volume_params) + self.assertRaises(exception.InvalidVolume, + self.volume_api.attachment_create, + self.context, + vref, + fake.UUID1) diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 8069d716e27..0dbcdc7921c 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -2079,7 +2079,7 @@ class API(base.Base): if not result: override = False - if instance_uuid: + if instance_uuid and vref.status in ('in-use', 'reserved'): # Refresh the volume reference in case multiple instances were # being concurrently attached to the same non-multiattach # volume. @@ -2094,9 +2094,11 @@ class API(base.Base): break if not override: - msg = (_('Volume %(vol_id)s status must be %(statuses)s') % + msg = (_('Volume %(vol_id)s status must be %(statuses)s to ' + 'reserve, but the current status is %(current)s.') % {'vol_id': vref.id, - 'statuses': utils.build_or_str(expected['status'])}) + 'statuses': utils.build_or_str(expected['status']), + 'current': vref.status}) raise exception.InvalidVolume(reason=msg) values = {'volume_id': vref.id,