From f257d77aabb92b2992ce246dd95dc9929f6800af Mon Sep 17 00:00:00 2001 From: Michael Price Date: Thu, 10 Mar 2016 11:17:18 -0600 Subject: [PATCH] NetApp E-Series: Volumes not added to consisgroup Volumes were not being added to a consistency group upon creation when the consistencygroup_id is provided during the volume creation. This patch adds functionality to relevant methods in library.py to add the newly created volume to a consistency group when applicable. Closes-Bug: #1555933 Change-Id: I6d09b81571ce7b5c07d155cb4a70079fe35ed945 --- .../drivers/netapp/eseries/test_library.py | 20 +++++++++++++++++++ .../volume/drivers/netapp/eseries/library.py | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py b/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py index b8ff66753..ff4017c00 100644 --- a/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py +++ b/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py @@ -1244,6 +1244,22 @@ class NetAppEseriesLibraryTestCase(test.TestCase): self.assertEqual(result, actual) + def test_add_volume_to_consistencygroup(self): + fake_volume = cinder_utils.create_volume(self.ctxt) + fake_volume['consistencygroup'] = ( + cinder_utils.create_consistencygroup(self.ctxt)) + fake_volume['consistencygroup_id'] = fake_volume[ + 'consistencygroup']['id'] + cg = copy.deepcopy(eseries_fake.FAKE_CONSISTENCY_GROUP) + self.mock_object(self.library, '_get_consistencygroup', + mock.Mock(return_value=cg)) + update_members = self.mock_object(self.library, + '_update_consistency_group_members') + + self.library._add_volume_to_consistencygroup(fake_volume) + + update_members.assert_called_once_with(cg, [fake_volume], []) + @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall', new= cinder_utils.ZeroIntervalLoopingCall) def test_copy_volume_high_priority_readonly(self): @@ -1340,10 +1356,14 @@ class NetAppEseriesLibraryMultiAttachTestCase(test.TestCase): def test_create_volume(self): self.library._client.create_volume = mock.Mock( return_value=eseries_fake.VOLUME) + update_members = self.mock_object(self.library, + '_update_consistency_group_members') self.library.create_volume(get_fake_volume()) self.assertTrue(self.library._client.create_volume.call_count) + update_members.assert_not_called() + @ddt.data(('netapp_eseries_flash_read_cache', 'flash_cache', 'true'), ('netapp_eseries_flash_read_cache', 'flash_cache', 'false'), ('netapp_eseries_flash_read_cache', 'flash_cache', None), diff --git a/cinder/volume/drivers/netapp/eseries/library.py b/cinder/volume/drivers/netapp/eseries/library.py index 90cd85dc6..1ad5504c7 100644 --- a/cinder/volume/drivers/netapp/eseries/library.py +++ b/cinder/volume/drivers/netapp/eseries/library.py @@ -499,6 +499,11 @@ class NetAppESeriesLibrary(object): if storage_pool: return storage_pool.get('label') + def _add_volume_to_consistencygroup(self, volume): + if volume.get('consistencygroup_id'): + es_cg = self._get_consistencygroup(volume['consistencygroup']) + self._update_consistency_group_members(es_cg, [volume], []) + def create_volume(self, volume): """Creates a volume.""" @@ -521,6 +526,8 @@ class NetAppESeriesLibrary(object): self._create_volume(eseries_pool_label, eseries_volume_label, size_gb, extra_specs) + self._add_volume_to_consistencygroup(volume) + def _create_volume(self, eseries_pool_label, eseries_volume_label, size_gb, extra_specs=None): """Creates volume with given label and size.""" @@ -665,6 +672,8 @@ class NetAppESeriesLibrary(object): cinder_utils.synchronized(snapshot['id'])( self._create_volume_from_snapshot)(volume, es_snapshot) + self._add_volume_to_consistencygroup(volume) + def _copy_volume_high_priority_readonly(self, src_vol, dst_vol): """Copies src volume to dest volume.""" LOG.info(_LI("Copying src vol %(src)s to dest vol %(dst)s."), @@ -711,6 +720,7 @@ class NetAppESeriesLibrary(object): try: self._create_volume_from_snapshot(volume, es_snapshot) + self._add_volume_to_consistencygroup(volume) finally: try: self._client.delete_snapshot_group(es_snapshot['pitGroupRef']) -- 2.45.2