From a32e24ff3e2c3083b42dd3654355f8c101363147 Mon Sep 17 00:00:00 2001 From: Ildiko Vancsa Date: Fri, 19 Jan 2018 18:38:13 +0100 Subject: [PATCH] Add back support for the multiattach flag for volume create As the 'multiattach' request parameter in volume create is not formally deprecated out of the REST API via microversion, we need to keep the functionality working. Currently the 'multiattach' attribute on the volume is set by the volume_type only, which means that we cannot create a multi-attach volume the old way, the volume gets created with 'multiattach': false. This patch fixes that. Closes-Bug: #1745219 Change-Id: Iac67f112b0dc9353c6a66e6fbc81cc8324a2b37c --- cinder/tests/unit/volume/test_volume.py | 12 ++++++++++++ cinder/volume/api.py | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/volume/test_volume.py b/cinder/tests/unit/volume/test_volume.py index 791cfd4cfb5..ef84c103012 100644 --- a/cinder/tests/unit/volume/test_volume.py +++ b/cinder/tests/unit/volume/test_volume.py @@ -628,6 +628,18 @@ class VolumeTestCase(base.BaseVolumeTestCase): self.assertEqual(foo['id'], vol['volume_type_id']) self.assertTrue(vol['multiattach']) + def test_create_volume_with_multiattach_no_volume_type(self): + """Tests creating a volume with multiattach=True but no special type. + + This tests the pre 3.50 microversion behavior of being able to create + a volume with the multiattach request parameter regardless of a + multiattach-capable volume type. + """ + volume_api = cinder.volume.api.API() + volume = volume_api.create( + self.context, 1, 'name', 'description', multiattach=True) + self.assertTrue(volume.multiattach) + @mock.patch.object(key_manager, 'API', fake_keymgr.fake_api) def test_create_volume_with_encrypted_volume_type_aes(self): ctxt = context.get_admin_context() diff --git a/cinder/volume/api.py b/cinder/volume/api.py index f9d11e5e501..a59bd2f5c70 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -349,7 +349,8 @@ class API(base.Base): # Refresh the object here, otherwise things ain't right vref = objects.Volume.get_by_id( context, vref['id']) - vref.multiattach = self._is_multiattach(volume_type) + vref.multiattach = (self._is_multiattach(volume_type) or + multiattach) vref.save() LOG.info("Create volume request issued successfully.", resource=vref)