From fa1b8b399a79c7cb870aa56de3e769f130576466 Mon Sep 17 00:00:00 2001 From: TommyLike Date: Sat, 28 Jul 2018 13:46:25 +0800 Subject: [PATCH] Handle multiattach attribute when managing volumes This patch handles the multiattach attribute when managing existing volumes. Change-Id: Iade06a8b227f64f352719aaebfbeeb24e7fe9ea7 Closes-Bug:#1783790 --- .../volume/flows/test_manage_volume_flow.py | 24 ++++++++++++++++++- cinder/volume/flows/api/manage_existing.py | 6 +++++ ...e-when-manage-volume-yu7du8yth78i0e6b.yaml | 4 ++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 releasenotes/bug-1783790-multiattach-none-when-manage-volume-yu7du8yth78i0e6b.yaml diff --git a/cinder/tests/unit/volume/flows/test_manage_volume_flow.py b/cinder/tests/unit/volume/flows/test_manage_volume_flow.py index 67c0f6b1771..0b6ea2a8b32 100644 --- a/cinder/tests/unit/volume/flows/test_manage_volume_flow.py +++ b/cinder/tests/unit/volume/flows/test_manage_volume_flow.py @@ -38,7 +38,7 @@ class ManageVolumeFlowTestCase(test.TestCase): self.counter = float(0) def test_cast_manage_existing(self): - volume = fake_volume.fake_volume_type_obj(self.ctxt) + volume = fake_volume.fake_volume_obj(self.ctxt) spec = { 'name': 'name', @@ -62,6 +62,28 @@ class ManageVolumeFlowTestCase(test.TestCase): create_what.pop('volume_id') task.execute(self.ctxt, **create_what) + def test_create_db_entry_task_with_multiattach(self): + + fake_volume_type = fake_volume.fake_volume_type_obj( + self.ctxt, extra_specs={'multiattach': ' True'}) + + spec = { + 'name': 'name', + 'description': 'description', + 'host': 'host', + 'ref': 'ref', + 'volume_type': fake_volume_type, + 'metadata': {}, + 'availability_zone': 'availability_zone', + 'bootable': 'bootable', + 'volume_type_id': fake_volume_type.id, + 'cluster_name': 'fake_cluster' + } + task = manage_existing.EntryCreateTask(fake_volume_api.FakeDb()) + + result = task.execute(self.ctxt, **spec) + self.assertTrue(result['volume_properties']['multiattach']) + @staticmethod def _stub_volume_object_get(self): volume = { diff --git a/cinder/volume/flows/api/manage_existing.py b/cinder/volume/flows/api/manage_existing.py index e180b2ec5cf..0f7523ea914 100644 --- a/cinder/volume/flows/api/manage_existing.py +++ b/cinder/volume/flows/api/manage_existing.py @@ -53,6 +53,11 @@ class EntryCreateTask(flow_utils.CinderTask): volume_type = kwargs.pop('volume_type') volume_type_id = volume_type['id'] if volume_type else None + multiattach = False + if volume_type and volume_type.get('extra_specs'): + multiattach = volume_type['extra_specs'].get( + 'multiattach', '') == ' True' + volume_properties = { 'size': 0, 'user_id': context.user_id, @@ -68,6 +73,7 @@ class EntryCreateTask(flow_utils.CinderTask): 'volume_type_id': volume_type_id, 'metadata': kwargs.pop('metadata') or {}, 'bootable': kwargs.pop('bootable'), + 'multiattach': multiattach, } volume = objects.Volume(context=context, **volume_properties) diff --git a/releasenotes/bug-1783790-multiattach-none-when-manage-volume-yu7du8yth78i0e6b.yaml b/releasenotes/bug-1783790-multiattach-none-when-manage-volume-yu7du8yth78i0e6b.yaml new file mode 100644 index 00000000000..7429f6ab5c8 --- /dev/null +++ b/releasenotes/bug-1783790-multiattach-none-when-manage-volume-yu7du8yth78i0e6b.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - Now cinder will keep track of 'multiattach' attribute when managing + backend volumes.