]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Extend volume for GlusterFS
authorEric Harney <eharney@redhat.com>
Sat, 17 Aug 2013 17:05:38 +0000 (13:05 -0400)
committerEric Harney <eharney@redhat.com>
Mon, 26 Aug 2013 16:34:17 +0000 (12:34 -0400)
Add support for extend volume.

Change-Id: Ie9ba67d91de2da43e6b857b4256a445c5269c5cd

cinder/tests/test_glusterfs.py
cinder/volume/drivers/glusterfs.py

index 2715172ccf237b9567ee5ae8a674a2d58d12ee38..c08bcce810601f52ba2723b172ed65537e389f2f 100644 (file)
@@ -989,3 +989,34 @@ class GlusterFsDriverTestCase(test.TestCase):
                           'volume-%s' % self.VOLUME_UUID)
 
         mox.VerifyAll()
+
+    def test_extend_volume(self):
+        (mox, drv) = self._mox, self._driver
+
+        volume = self._simple_volume()
+
+        mox.StubOutWithMock(drv, '_execute')
+        mox.StubOutWithMock(drv, 'get_active_image_from_info')
+
+        drv.get_active_image_from_info(volume).AndReturn(volume['name'])
+
+        qemu_img_info_output = """image: volume-%s
+        file format: qcow2
+        virtual size: 1.0G (1073741824 bytes)
+        disk size: 473K
+        """ % self.VOLUME_UUID
+
+        volume_path = '%s/%s/volume-%s' % (self.TEST_MNT_POINT_BASE,
+                                           drv._get_hash_str(
+                                               self.TEST_EXPORT1),
+                                           self.VOLUME_UUID)
+        drv._execute('qemu-img', 'info', volume_path).\
+            AndReturn((qemu_img_info_output, ''))
+
+        drv._execute('qemu-img', 'resize', volume_path, '3G', run_as_root=True)
+
+        mox.ReplayAll()
+
+        drv.extend_volume(volume, 3)
+
+        mox.VerifyAll()
index 0236a027bd6f0348603367bf63e53bc23965bce5..ddc4fdb4024d7d7392b405b9722a649378bf3655 100644 (file)
@@ -701,6 +701,28 @@ class GlusterfsDriver(nfs.RemoteFsDriver):
             if temp_path is not None:
                 self._execute('rm', '-f', temp_path)
 
+    def extend_volume(self, volume, size_gb):
+        volume_path = self.local_path(volume)
+        volume_filename = os.path.basename(volume_path)
+
+        # Ensure no snapshots exist for the volume
+        active_image = self.get_active_image_from_info(volume)
+        if volume_filename != active_image:
+            msg = _('Extend volume is only supported for this'
+                    ' driver when no snapshots exist.')
+            raise exception.InvalidVolume(msg)
+
+        (out, err) = self._execute('qemu-img', 'info', volume_path)
+        backing_fmt = self._get_file_format(out)
+
+        if backing_fmt not in ['raw', 'qcow2']:
+            msg = _('Unrecognized backing format: %s')
+            raise exception.InvalidVolume(msg % backing_fmt)
+
+        # qemu-img can resize both raw and qcow2 files
+        cmd = ['qemu-img', 'resize', volume_path, '%sG' % size_gb]
+        self._execute(*cmd, run_as_root=True)
+
     def _do_create_volume(self, volume):
         """Create a volume on given glusterfs_share.