]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Dell SC: create_cloned_volume didn't honor size
authorTom Swanson <tom_swanson@dell.com>
Tue, 8 Mar 2016 22:14:42 +0000 (16:14 -0600)
committerTom Swanson <tom_swanson@dell.com>
Tue, 8 Mar 2016 22:16:26 +0000 (16:16 -0600)
If the volume being created was larger than the cloned volume
the new volume was not being resized.

Change-Id: I43b9da93d8770a5630f7a6b2af2c164c3ed1f4ec
Closes-Bug: 1554741

cinder/tests/unit/test_dellsc.py
cinder/volume/drivers/dell/dell_storagecenter_common.py

index eca57d747108f02f13786605058362fae89f242d..75271ab2591210172428f662a0aa15fb739e5e65 100644 (file)
@@ -1187,8 +1187,42 @@ class DellSCSanISCSIDriverTestCase(test.TestCase):
                                   mock_close_connection,
                                   mock_open_connection,
                                   mock_init):
-        volume = {'id': self.volume_name + '_clone'}
-        src_vref = {'id': self.volume_name}
+        volume = {'id': self.volume_name + '_clone', 'size': 1}
+        src_vref = {'id': self.volume_name, 'size': 1}
+        ret = self.driver.create_cloned_volume(volume, src_vref)
+        mock_create_cloned_volume.assert_called_once_with(
+            self.volume_name + '_clone',
+            self.VOLUME,
+            None)
+        self.assertTrue(mock_find_volume.called)
+        self.assertEqual({}, ret)
+
+    @mock.patch.object(dell_storagecenter_iscsi.DellStorageCenterISCSIDriver,
+                       '_create_replications',
+                       return_value={})
+    @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+                       'find_sc',
+                       return_value=12345)
+    @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+                       'find_volume',
+                       return_value=VOLUME)
+    @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+                       'create_cloned_volume',
+                       return_value=VOLUME)
+    @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+                       'expand_volume',
+                       return_value=VOLUME)
+    def test_create_cloned_volume_expand(self,
+                                         mock_expand_volume,
+                                         mock_create_cloned_volume,
+                                         mock_find_volume,
+                                         mock_find_sc,
+                                         mock_create_replications,
+                                         mock_close_connection,
+                                         mock_open_connection,
+                                         mock_init):
+        volume = {'id': self.volume_name + '_clone', 'size': 2}
+        src_vref = {'id': self.volume_name, 'size': 1}
         ret = self.driver.create_cloned_volume(volume, src_vref)
         mock_create_cloned_volume.assert_called_once_with(
             self.volume_name + '_clone',
@@ -1196,6 +1230,7 @@ class DellSCSanISCSIDriverTestCase(test.TestCase):
             None)
         self.assertTrue(mock_find_volume.called)
         self.assertEqual({}, ret)
+        self.assertTrue(mock_expand_volume.called)
 
     @mock.patch.object(dell_storagecenter_iscsi.DellStorageCenterISCSIDriver,
                        '_create_replications',
@@ -1227,6 +1262,41 @@ class DellSCSanISCSIDriverTestCase(test.TestCase):
                           volume, src_vref)
         self.assertTrue(mock_delete_volume.called)
 
+    @mock.patch.object(dell_storagecenter_iscsi.DellStorageCenterISCSIDriver,
+                       '_create_replications',
+                       return_value={})
+    @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+                       'find_sc',
+                       return_value=12345)
+    @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+                       'find_volume',
+                       return_value=VOLUME)
+    @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+                       'create_cloned_volume',
+                       return_value=VOLUME)
+    @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+                       'delete_volume')
+    @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+                       'expand_volume')
+    def test_create_cloned_volume_expand_failed(self,
+                                                mock_expand_volume,
+                                                mock_delete_volume,
+                                                mock_create_cloned_volume,
+                                                mock_find_volume,
+                                                mock_find_sc,
+                                                mock_create_replications,
+                                                mock_close_connection,
+                                                mock_open_connection,
+                                                mock_init):
+        volume = {'id': self.volume_name + '_clone', 'size': 2}
+        src_vref = {'id': self.volume_name, 'size': 1}
+        mock_create_replications.side_effect = (
+            exception.VolumeBackendAPIException(data='abc'))
+        self.assertRaises(exception.VolumeBackendAPIException,
+                          self.driver.create_cloned_volume,
+                          volume, src_vref)
+        self.assertTrue(mock_delete_volume.called)
+
     @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
                        'delete_volume')
     @mock.patch.object(dell_storagecenter_iscsi.DellStorageCenterISCSIDriver,
@@ -1251,8 +1321,8 @@ class DellSCSanISCSIDriverTestCase(test.TestCase):
                                                    mock_init):
         mock_create_replications.side_effect = (
             exception.VolumeBackendAPIException(data='abc'))
-        volume = {'id': self.volume_name + '_clone'}
-        src_vref = {'id': self.volume_name}
+        volume = {'id': self.volume_name + '_clone', 'size': 1}
+        src_vref = {'id': self.volume_name, 'size': 1}
         self.assertRaises(exception.VolumeBackendAPIException,
                           self.driver.create_cloned_volume,
                           volume, src_vref)
@@ -1282,8 +1352,9 @@ class DellSCSanISCSIDriverTestCase(test.TestCase):
                                                     mock_open_connection,
                                                     mock_init):
         volume = {'id': self.volume_name + '_clone',
-                  'consistencygroup_id': 'guid'}
-        src_vref = {'id': self.volume_name}
+                  'consistencygroup_id': 'guid',
+                  'size': 1}
+        src_vref = {'id': self.volume_name, 'size': 1}
         self.driver.create_cloned_volume(volume, src_vref)
         mock_create_cloned_volume.assert_called_once_with(
             self.volume_name + '_clone',
index 329c7ff4249a92d5af668d3092e3d12b9489f2a3..1585bca2f7e0e74880131f479bc5dbe7e5faae97 100644 (file)
@@ -440,6 +440,15 @@ class DellCommonDriver(driver.ConsistencyGroupVD, driver.ManageableVD,
                         # Create our volume
                         scvolume = api.create_cloned_volume(
                             volume_name, srcvol, replay_profile_string)
+
+                        # Extend Volume
+                        if scvolume and volume['size'] > src_vref['size']:
+                            LOG.debug("Resize the new volume to %s.",
+                                      volume['size'])
+                            scvolume = api.expand_volume(scvolume,
+                                                         volume['size'])
+
+                        # If either of those didn't work we bail.
                         if scvolume is None:
                             raise exception.VolumeBackendAPIException(
                                 message=_('Unable to create volume '