]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Check that volume is at least minDisk size.
authorDermot Tynan <tynan@hp.com>
Thu, 2 May 2013 10:02:05 +0000 (11:02 +0100)
committerDermot Tynan <tynan@hp.com>
Fri, 3 May 2013 10:27:40 +0000 (11:27 +0100)
The Image service (such as Glance) provides a minDisk parameter to
indicate the minimum required disk size for the image. This change
ensures that the guidance is followed in the case of bootable
volumes.

Added unit test and fixed PEP8 issue.

Fixed issue with docstring.

Added a comment.

Fixes Bug #1175532

Change-Id: I505af53db70b5b286dbca2eaca4fc1f30a8c0b2a

cinder/tests/test_volume.py
cinder/volume/api.py

index 523ebcf661a12ba21490d9c48da6fb853d072e18..744baf5b49d7285b70acedbcd02e28eaf705fbe2 100644 (file)
@@ -894,6 +894,27 @@ class VolumeTestCase(test.TestCase):
                           self.context, 2,
                           'name', 'description', image_id=1)
 
+    def test_create_volume_with_mindisk_error(self):
+        """Verify volumes smaller than image minDisk will cause an error."""
+        class _FakeImageService:
+            def __init__(self, db_driver=None, image_service=None):
+                pass
+
+            def show(self, context, image_id):
+                return {'size': 2 * 1024 * 1024 * 1024,
+                        'disk_format': 'raw',
+                        'container_format': 'bare',
+                        'min_disk': 5}
+
+        image_id = '70a599e0-31e7-49b7-b260-868f441e862b'
+
+        volume_api = cinder.volume.api.API(image_service=_FakeImageService())
+
+        self.assertRaises(exception.InvalidInput,
+                          volume_api.create,
+                          self.context, 2,
+                          'name', 'description', image_id=1)
+
     def _do_test_create_volume_with_size(self, size):
         def fake_reserve(context, expire=None, project_id=None, **deltas):
             return ["RESERVATION"]
index 032f2d2f38978148558b613ade439bf554af2f7c..042ae6802ab4c2ad8a590dde791ceaa634038d0d 100644 (file)
@@ -149,6 +149,10 @@ class API(base.Base):
             if image_size_in_gb > size:
                 msg = _('Size of specified image is larger than volume size.')
                 raise exception.InvalidInput(reason=msg)
+            # Check image minDisk requirement is met for the particular volume
+            if size < image_meta.get('min_disk', 0):
+                msg = _('Image minDisk size is larger than the volume size.')
+                raise exception.InvalidInput(reason=msg)
 
         try:
             reservations = QUOTAS.reserve(context, volumes=1, gigabytes=size)