'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()
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.