diff --git a/cinder/objects/volume.py b/cinder/objects/volume.py index a528182f261..b3a1dfce072 100644 --- a/cinder/objects/volume.py +++ b/cinder/objects/volume.py @@ -567,6 +567,9 @@ class Volume(cleanable.CinderCleanableObject, base.CinderObject, def is_replicated(self): return self.volume_type and self.volume_type.is_replicated() + def is_multiattach(self): + return self.volume_type and self.volume_type.is_multiattach() + @base.CinderObjectRegistry.register class VolumeList(base.ObjectListBase, base.CinderObject): diff --git a/cinder/objects/volume_type.py b/cinder/objects/volume_type.py index 73d366a080c..09d63f51e29 100644 --- a/cinder/objects/volume_type.py +++ b/cinder/objects/volume_type.py @@ -165,6 +165,9 @@ class VolumeType(base.CinderPersistentObject, base.CinderObject, def is_replicated(self): return utils.is_replicated_spec(self.extra_specs) + def is_multiattach(self): + return utils.is_multiattach_spec(self.extra_specs) + @base.CinderObjectRegistry.register class VolumeTypeList(base.ObjectListBase, base.CinderObject): diff --git a/cinder/tests/unit/objects/test_volume_type.py b/cinder/tests/unit/objects/test_volume_type.py index 2371a5ca08d..0b3fbf9fa9b 100644 --- a/cinder/tests/unit/objects/test_volume_type.py +++ b/cinder/tests/unit/objects/test_volume_type.py @@ -227,6 +227,18 @@ class TestVolumeType(test_objects.BaseObjectsTestCase): self.context, extra_specs={'replication_enabled': not_enabled}) self.assertFalse(volume_type.is_replicated()) + @ddt.data(' False', ' false', ' f') + def test_is_multiattach_specs_false(self, false): + volume_type = fake_volume.fake_volume_type_obj( + self.context, extra_specs={'multiattach': false}) + self.assertFalse(volume_type.is_multiattach()) + + @ddt.data(' True', ' True') + def test_is_multiattach_specs_true(self, true): + volume_type = fake_volume.fake_volume_type_obj( + self.context, extra_specs={'multiattach': true}) + self.assertTrue(volume_type.is_multiattach()) + class TestVolumeTypeList(test_objects.BaseObjectsTestCase): @mock.patch('cinder.volume.volume_types.get_all_types') diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index e448b9f27e3..078d1781641 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -967,6 +967,11 @@ def is_replicated_spec(extra_specs): is_replicated_str(extra_specs.get('replication_enabled'))) +def is_multiattach_spec(extra_specs): + return (extra_specs and + is_replicated_str(extra_specs.get('multiattach'))) + + def group_get_by_id(group_id): ctxt = context.get_admin_context() group = db.group_get(ctxt, group_id)