From: Danny Al-Gaaf Date: Thu, 10 Mar 2016 12:45:09 +0000 (+0100) Subject: DRBD driver: resize volume if cloned image is larger X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0532c1583ba761a1a67b9608b46408827edec299;p=openstack-build%2Fcinder-build.git DRBD driver: resize volume if cloned image is larger 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 --- diff --git a/cinder/tests/unit/test_drbdmanagedrv.py b/cinder/tests/unit/test_drbdmanagedrv.py index f922b6f4c..070e5628f 100644 --- a/cinder/tests/unit/test_drbdmanagedrv.py +++ b/cinder/tests/unit/test_drbdmanagedrv.py @@ -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): diff --git a/cinder/volume/drivers/drbdmanagedrv.py b/cinder/volume/drivers/drbdmanagedrv.py index af9bc294d..fa38b891e 100644 --- a/cinder/volume/drivers/drbdmanagedrv.py +++ b/cinder/volume/drivers/drbdmanagedrv.py @@ -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 = {}