Skip to content

Commit

Permalink
Check that volume is at least minDisk size.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Dermot Tynan committed May 3, 2013
1 parent 11a949c commit d0b5b93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cinder/tests/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,27 @@ def show(self, context, image_id):
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"]
Expand Down
4 changes: 4 additions & 0 deletions cinder/volume/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ def as_int(s):
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)
Expand Down

0 comments on commit d0b5b93

Please sign in to comment.