]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Implement extend volume functionality in Rbd
authorHaomai Wang <haomai@unitedstack.com>
Wed, 10 Jul 2013 09:10:09 +0000 (17:10 +0800)
committerHaomai Wang <haomai@unitedstack.com>
Fri, 12 Jul 2013 03:30:43 +0000 (11:30 +0800)
This implements the extend volume functionality for Rbd driver.

Implements: blueprint extend-rbd-volume
Change-Id: I7ddbd0dda742627e959ac672b125555225238030

cinder/tests/test_rbd.py
cinder/volume/drivers/rbd.py

index a36a278b2c1e290a2e125decbffa6ecde2169fc2..024a046c2302495232605908e08bdefc0b7d8953 100644 (file)
@@ -29,6 +29,7 @@ from cinder.openstack.common import timeutils
 from cinder import test
 from cinder.tests.image import fake as fake_image
 from cinder.tests.test_volume import DriverTestCase
+from cinder import units
 from cinder.volume import configuration as conf
 import cinder.volume.drivers.rbd as driver
 
@@ -385,6 +386,22 @@ class RBDTestCase(test.TestCase):
 
         self.driver._clone(volume, src_pool, src_image, src_snap)
 
+    def test_extend_volume(self):
+        fake_name = u'volume-00000001'
+        fake_size = '20'
+        fake_vol = {'project_id': 'testprjid', 'name': fake_name,
+                    'size': fake_size,
+                    'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'}
+
+        self.mox.StubOutWithMock(self.driver, '_resize')
+        size = int(fake_size) * units.GiB
+        self.driver._resize(fake_vol, size=size)
+
+        self.mox.ReplayAll()
+        self.driver.extend_volume(fake_vol, fake_size)
+
+        self.mox.VerifyAll()
+
     def test_rbd_volume_proxy_init(self):
         name = u'volume-00000001'
         snap = u'snapshot-name'
index 533d58441de168fa47a97d332f0423c9d86013db..4b050d365bd3be0c857fd18dd571450e4ac48b2a 100644 (file)
@@ -28,6 +28,7 @@ from oslo.config import cfg
 
 from cinder import exception
 from cinder.image import image_utils
+from cinder import units
 from cinder import utils
 
 from cinder.openstack.common import fileutils
@@ -358,8 +359,11 @@ class RBDDriver(driver.VolumeDriver):
                                      str(volume['name']),
                                      features=self.rbd.RBD_FEATURE_LAYERING)
 
-    def _resize(self, volume):
-        size = int(volume['size']) * 1024 ** 3
+    def _resize(self, volume, **kwargs):
+        size = kwargs.get('size', None)
+        if not size:
+            size = int(volume['size']) * units.GiB
+
         with RBDVolumeProxy(self, volume['name']) as vol:
             vol.resize(size)
 
@@ -545,3 +549,19 @@ class RBDDriver(driver.VolumeDriver):
             backup_service.restore(backup, volume['id'], rbd_fd)
 
         LOG.debug("volume restore complete.")
+
+    def extend_volume(self, volume, new_size):
+        """Extend an Existing Volume."""
+        old_size = volume['size']
+
+        try:
+            size = int(new_size) * units.GiB
+            self._resize(volume, size=size)
+        except Exception:
+            msg = _('Failed to Extend Volume '
+                    '%(volname)s') % {'volname': volume['name']}
+            LOG.error(msg)
+            raise exception.VolumeBackendAPIException(data=msg)
+
+        LOG.debug(_("Extend volume from %(old_size) to %(new_size)"),
+                  {'old_size': old_size, 'new_size': new_size})