From: Yuriy Nesenenko Date: Thu, 1 Oct 2015 10:39:39 +0000 (+0300) Subject: Implement extend_volume method to Block Device driver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=82d51bfbf93283a92f18a50251e685a5eb62fc40;p=openstack-build%2Fcinder-build.git Implement extend_volume method to Block Device driver This patch adds the extend_volume method to Block Device driver to get the minimum features for this driver. Related blueprint: block-device-driver-minimum-features-set Change-Id: I6ca7ba4a407ab7d8171fc7d5d6fcb60a29de8f6b --- diff --git a/cinder/tests/unit/test_block_device.py b/cinder/tests/unit/test_block_device.py index acbeb7964..146b1fc68 100644 --- a/cinder/tests/unit/test_block_device.py +++ b/cinder/tests/unit/test_block_device.py @@ -286,3 +286,15 @@ class TestBlockDeviceDriver(cinder.test.TestCase): _get_used_dvc.return_value = set() self.assertEqual('/dev/loop2', self.drv.find_appropriate_size_device(size)) + + def test_extend_volume_exists(self): + TEST_VOLUME = {'name': 'vol1', 'id': 123} + with mock.patch.object(self.drv, '_get_devices_sizes', + return_value={'/dev/loop1': 1024}) as \ + mock_get_size: + with mock.patch.object(self.drv, 'local_path', + return_value='/dev/loop1') as lp_mocked: + self.assertRaises(cinder.exception.CinderException, + self.drv.extend_volume, TEST_VOLUME, 2) + lp_mocked.assert_called_once_with(TEST_VOLUME) + mock_get_size.assert_called_once_with(['/dev/loop1']) diff --git a/cinder/volume/drivers/block_device.py b/cinder/volume/drivers/block_device.py index 1937fd494..202706080 100644 --- a/cinder/volume/drivers/block_device.py +++ b/cinder/volume/drivers/block_device.py @@ -196,6 +196,16 @@ class BlockDeviceDriver(driver.BaseVD, driver.LocalVD, driver.CloneableVD, else: raise exception.CinderException(_("No big enough free disk")) + def extend_volume(self, volume, new_size): + dev_path = self.local_path(volume) + total_size = self._get_devices_sizes([dev_path]) + # Convert from Megabytes to Gigabytes + size = total_size[dev_path] / units.Ki + if size < new_size: + msg = _("Insufficient free space available to extend volume.") + LOG.error(msg, resource=volume) + raise exception.CinderException(msg) + # ####### Interface methods for DataPath (Target Driver) ######## def ensure_export(self, context, volume):