MinDisk size based on the flavor's Disk size

When you create an instance from image  the instance disk size
is expanded to the disk size specified in the flavor.

Normally you cannot use the snapshot  for creating an instance
with smaller disk size (flavor)  because it  potentialy
causes a data corruption.

Every snapshots minDisk size should be inherited from the flavor.

bug 1200279

Change-Id: I1d0e909b78db2c863b4fbb54ad9065207f1a0abe
This commit is contained in:
Ann Kamyshnikova 2013-07-12 17:17:40 +04:00
parent 77a66a248b
commit 6104225fd0
2 changed files with 29 additions and 8 deletions

View File

@ -1804,13 +1804,14 @@ class API(base.Base):
except exception.ImageNotFound:
return None, None
flavor = flavors.extract_flavor(instance)
#disk format of vhd is non-shrinkable
if orig_image.get('disk_format') == 'vhd':
instance_type = flavors.extract_flavor(instance)
min_disk = instance_type['root_gb']
min_disk = flavor['root_gb']
else:
#set new image values to the original image values
min_disk = orig_image.get('min_disk')
min_disk = max(orig_image.get('min_disk'),
flavor['root_gb'])
min_ram = orig_image.get('min_ram')

View File

@ -6066,6 +6066,21 @@ class ComputeAPITestCase(BaseTestCase):
self.assertEqual(properties['instance_uuid'], instance['uuid'])
self.assertEqual(properties['extra_param'], 'value1')
def test_snapshot_mindisk_with_bigger_flavor(self):
"""If minDisk is smaller than flavor root_gb, the latter should be
used as minDisk
"""
self.fake_image['min_disk'] = 0
self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show)
instance = self._create_fake_instance()
image = self.compute_api.snapshot(self.context, instance, 'snap1',
{'extra_param': 'value1'})
self.assertEqual(image['min_disk'], 1)
db.instance_destroy(self.context, instance['uuid'])
def test_snapshot_minram_mindisk(self):
"""Ensure a snapshots min_ram and min_disk are correct.
@ -6127,14 +6142,19 @@ class ComputeAPITestCase(BaseTestCase):
A snapshots min_ram and min_disk should be set to default if
an instances original image cannot be found.
"""
# Cells tests will call this a 2nd time in child cell with
# the newly created image_id, and we want that one to succeed.
old_show = fake_image._FakeImageService.show
flag = []
def fake_show(*args):
raise exception.ImageNotFound(image_id="fake")
if not flag:
flag.append(1)
raise exception.ImageNotFound(image_id="fake")
else:
return old_show(*args)
if not self.__class__.__name__ == "CellsComputeAPITestCase":
# Cells tests will call this a 2nd time in child cell with
# the newly created image_id, and we want that one to succeed.
self.stubs.Set(fake_image._FakeImageService, 'show', fake_show)
self.stubs.Set(fake_image._FakeImageService, 'show', fake_show)
instance = self._create_fake_instance()