]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Implement extend_volume method to Block Device driver
authorYuriy Nesenenko <ynesenenko@mirantis.com>
Thu, 1 Oct 2015 10:39:39 +0000 (13:39 +0300)
committerYuriy Nesenenko <ynesenenko@mirantis.com>
Thu, 1 Oct 2015 10:39:39 +0000 (13:39 +0300)
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

cinder/tests/unit/test_block_device.py
cinder/volume/drivers/block_device.py

index acbeb79647e712289b5725211072c6311b647507..146b1fc68840b5b8c0d769f95c6a95dc51aa57d3 100644 (file)
@@ -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'])
index 1937fd494d3b8e57a25a2bce9ae0a047a18e4b5e..202706080f4dc5cc61b7c9b149565ae98a762b0b 100644 (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):