]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Implement extend volume functionality in Sheepdog
authorHaomai Wang <haomai@unitedstack.com>
Tue, 16 Jul 2013 09:04:34 +0000 (17:04 +0800)
committerHaomai Wang <haomai@unitedstack.com>
Tue, 16 Jul 2013 12:43:12 +0000 (20:43 +0800)
This implements the extend volume functionality for Sheepdog driver.

Change-Id: Id7361e9571742bea210f13ced722829f489e7cb0
Implements: blueprint extend-sheepdog-volume

cinder/tests/test_sheepdog.py
cinder/volume/drivers/sheepdog.py

index b533516c94e97e03719aff96c42c5796fcb6e87f..9203f19ec2a6ad2f7d3ebb609d30cbb5372dcf0b 100644 (file)
@@ -23,6 +23,7 @@ import tempfile
 from cinder import exception
 from cinder.image import image_utils
 from cinder import test
+from cinder import units
 from cinder.volume.drivers.sheepdog import SheepdogDriver
 
 
@@ -125,3 +126,19 @@ class SheepdogTestCase(test.TestCase):
         self.driver.copy_image_to_volume(None, {'name': 'test',
                                                 'size': 1},
                                          FakeImageService(), None)
+
+    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()
index cbca091a833329ad38909d9463ac384fddff09d2..1e610fd0e801a3c34c1aafa9e8b955652d504b7a 100644 (file)
@@ -27,6 +27,7 @@ from oslo.config import cfg
 from cinder import exception
 from cinder.image import image_utils
 from cinder.openstack.common import log as logging
+from cinder import units
 from cinder.volume import driver
 
 
@@ -84,8 +85,10 @@ class SheepdogDriver(driver.VolumeDriver):
         if tmp_dir and not os.path.exists(tmp_dir):
             os.makedirs(tmp_dir)
 
-    def _resize(self, volume):
-        size = int(volume['size']) * (1024 ** 3)
+    def _resize(self, volume, size=None):
+        if not size:
+            size = int(volume['size']) * units.GiB
+
         self._try_execute('collie', 'vdi', 'resize',
                           volume['name'], size)
 
@@ -177,3 +180,19 @@ class SheepdogDriver(driver.VolumeDriver):
         if refresh:
             self._update_volume_stats()
         return self._stats
+
+    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})