]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
DRBD driver: resize volume if cloned image is larger
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 10 Mar 2016 12:45:09 +0000 (13:45 +0100)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 11 Mar 2016 09:51:08 +0000 (10:51 +0100)
Extend volume if during create_cloned_volume() the new
volume is larger than the image it was cloned from.

Closes-Bug: #1554756

Change-Id: Id43e18c32c241a30cb35effe1fab8effe4517ba9
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
cinder/tests/unit/test_drbdmanagedrv.py
cinder/volume/drivers/drbdmanagedrv.py

index f922b6f4c434969e4bc29f4ad9a56b38d06e23fa..070e5628f08246acd39803e39864bd6de02f14e1 100644 (file)
@@ -459,6 +459,39 @@ class DrbdManageIscsiTestCase(test.TestCase):
         self.assertEqual("list_snapshots", dmd.odm.calls[7][0])
         self.assertEqual("remove_snapshot", dmd.odm.calls[8][0])
 
+    def test_create_cloned_volume_larger_size(self):
+        srcvol = {'project_id': 'testprjid',
+                  'name': 'testvol',
+                  'size': 1,
+                  'id': 'ba253fd0-8068-11e4-98c0-5254008ea111',
+                  'volume_type_id': 'drbdmanage',
+                  'created_at': timeutils.utcnow()}
+
+        newvol = {'size': 5,
+                  'id': 'ca253fd0-8068-11e4-98c0-5254008ea111'}
+
+        dmd = drv.DrbdManageIscsiDriver(configuration=self.configuration)
+        dmd.odm = DrbdManageFakeDriver()
+        dmd.create_cloned_volume(newvol, srcvol)
+        self.assertEqual("list_volumes", dmd.odm.calls[0][0])
+        self.assertEqual("list_assignments", dmd.odm.calls[1][0])
+        self.assertEqual("create_snapshot", dmd.odm.calls[2][0])
+        self.assertEqual("run_external_plugin", dmd.odm.calls[3][0])
+        self.assertEqual("list_snapshots", dmd.odm.calls[4][0])
+        self.assertEqual("restore_snapshot", dmd.odm.calls[5][0])
+        self.assertEqual("run_external_plugin", dmd.odm.calls[6][0])
+        self.assertEqual("list_snapshots", dmd.odm.calls[7][0])
+        self.assertEqual("remove_snapshot", dmd.odm.calls[8][0])
+
+        # resize image checks
+        self.assertEqual("list_volumes", dmd.odm.calls[9][0])
+        self.assertEqual(newvol['id'], dmd.odm.calls[9][3]["aux:cinder-id"])
+        self.assertEqual("resize_volume", dmd.odm.calls[10][0])
+        self.assertEqual("res", dmd.odm.calls[10][1])
+        self.assertEqual(2, dmd.odm.calls[10][2])
+        self.assertEqual(-1, dmd.odm.calls[10][3])
+        self.assertEqual(5242880, dmd.odm.calls[10][4])
+
 
 class DrbdManageDrbdTestCase(DrbdManageIscsiTestCase):
 
index af9bc294dcf22b135c9b92eb6bb0cbc34dd1f3ca..fa38b891ee69aa579d55bc8309a94bbc1e97505e 100644 (file)
@@ -595,6 +595,14 @@ class DrbdManageBaseDriver(driver.VolumeDriver):
 
         self.delete_snapshot(snapshot)
 
+        if (('size' in volume) and (volume['size'] > src_vref['size'])):
+            LOG.debug("resize volume '%(dst_vol)s' from %(src_size)d to "
+                      "%(dst_size)d",
+                      {'dst_vol': volume['id'],
+                       'src_size': src_vref['size'],
+                       'dst_size': volume['size']})
+            self.extend_volume(volume, volume['size'])
+
     def _update_volume_stats(self):
         data = {}