Merge "Implement extend_volume method to Block Device driver"

This commit is contained in:
Jenkins 2015-10-04 10:59:00 +00:00 committed by Gerrit Code Review
commit 172f8ba6aa
2 changed files with 22 additions and 0 deletions

View File

@ -278,3 +278,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'])

View File

@ -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):