From: Dermot Tynan Date: Thu, 2 May 2013 10:02:05 +0000 (+0100) Subject: Check that volume is at least minDisk size. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d0b5b93fe7611b35a8c6a9b09f46641f4fb859f4;p=openstack-build%2Fcinder-build.git Check that volume is at least minDisk size. 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 --- diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 523ebcf66..744baf5b4 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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"] diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 032f2d2f3..042ae6802 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -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)