Add is_replicated() to Volume and VolumeType OVOs
This patch adds a convenience method `is_replicated` to Volume and Volume Type OVOs so it can be used throughout the code to provide consistency in the way we check the extra_specs in the drivers. Change-Id: I10a01dd2ec6824ae64c5cfb2cee20f96e9f5650e
This commit is contained in:
parent
3963595bed
commit
55529071f1
@ -548,6 +548,9 @@ class Volume(cleanable.CinderCleanableObject, base.CinderObject,
|
||||
list(volume_updates.keys()) +
|
||||
['volume_attachment', 'admin_metadata'])
|
||||
|
||||
def is_replicated(self):
|
||||
return self.volume_type and self.volume_type.is_replicated()
|
||||
|
||||
|
||||
@base.CinderObjectRegistry.register
|
||||
class VolumeList(base.ObjectListBase, base.CinderObject):
|
||||
|
@ -21,6 +21,7 @@ from cinder import exception
|
||||
from cinder.i18n import _
|
||||
from cinder import objects
|
||||
from cinder.objects import base
|
||||
from cinder.volume import utils
|
||||
from cinder.volume import volume_types
|
||||
|
||||
|
||||
@ -161,6 +162,9 @@ class VolumeType(base.CinderPersistentObject, base.CinderObject,
|
||||
return cls._from_db_object(context, cls(context),
|
||||
orm_obj, expected_attrs=expected_attrs)
|
||||
|
||||
def is_replicated(self):
|
||||
return utils.is_replicated_spec(self.extra_specs)
|
||||
|
||||
|
||||
@base.CinderObjectRegistry.register
|
||||
class VolumeTypeList(base.ObjectListBase, base.CinderObject):
|
||||
|
@ -553,6 +553,22 @@ class TestVolume(test_objects.BaseObjectsTestCase):
|
||||
self.assertEqual(is_set, converted_volume.obj_attr_is_set(key))
|
||||
self.assertEqual('host', converted_volume.host)
|
||||
|
||||
@ddt.data(True, False)
|
||||
def test_is_replicated(self, result):
|
||||
volume_type = fake_volume.fake_volume_type_obj(self.context)
|
||||
volume = fake_volume.fake_volume_obj(
|
||||
self.context, volume_type_id=volume_type.id)
|
||||
volume.volume_type = volume_type
|
||||
with mock.patch.object(volume_type, 'is_replicated',
|
||||
return_value=result) as is_replicated:
|
||||
self.assertEqual(result, volume.is_replicated())
|
||||
is_replicated.assert_called_once_with()
|
||||
|
||||
def test_is_replicated_no_type(self):
|
||||
volume = fake_volume.fake_volume_obj(
|
||||
self.context, volume_type_id=None, volume_type=None)
|
||||
self.assertFalse(volume.is_replicated())
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestVolumeList(test_objects.BaseObjectsTestCase):
|
||||
|
@ -210,6 +210,23 @@ class TestVolumeType(test_objects.BaseObjectsTestCase):
|
||||
self.assertEqual(get_specs_mock.return_value, volume_type.extra_specs)
|
||||
get_specs_mock.assert_called_once_with(self.context, vol_type['id'])
|
||||
|
||||
@ddt.data('<is> True', '<is> true', '<is> yes')
|
||||
def test_is_replicated_true(self, enabled):
|
||||
volume_type = fake_volume.fake_volume_type_obj(
|
||||
self.context, extra_specs={'replication_enabled': enabled})
|
||||
self.assertTrue(volume_type.is_replicated())
|
||||
|
||||
def test_is_replicated_no_specs(self):
|
||||
volume_type = fake_volume.fake_volume_type_obj(
|
||||
self.context, extra_specs={})
|
||||
self.assertFalse(volume_type.is_replicated())
|
||||
|
||||
@ddt.data('<is> False', '<is> false', '<is> f', 'baddata', 'bad data')
|
||||
def test_is_replicated_specs_false(self, not_enabled):
|
||||
volume_type = fake_volume.fake_volume_type_obj(
|
||||
self.context, extra_specs={'replication_enabled': not_enabled})
|
||||
self.assertFalse(volume_type.is_replicated())
|
||||
|
||||
|
||||
class TestVolumeTypeList(test_objects.BaseObjectsTestCase):
|
||||
@mock.patch('cinder.volume.volume_types.get_all_types')
|
||||
|
Loading…
x
Reference in New Issue
Block a user