Merge "Don't allow empty or 0 volume size for images"
This commit is contained in:
@@ -1074,6 +1074,12 @@ class API(base.Base):
|
||||
self._get_image(context, image_id)
|
||||
except Exception:
|
||||
raise exception.InvalidBDMImage(id=image_id)
|
||||
if (bdm['source_type'] == 'image' and
|
||||
bdm['destination_type'] == 'volume' and
|
||||
not bdm['volume_size']):
|
||||
raise exception.InvalidBDM(message=_("Images with "
|
||||
"destination_type 'volume' need to have a non-zero "
|
||||
"size specified"))
|
||||
elif volume_id is not None:
|
||||
try:
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
|
||||
@@ -820,6 +820,7 @@ class ComputeVolumeTestCase(BaseTestCase):
|
||||
|
||||
volume_id = '55555555-aaaa-bbbb-cccc-555555555555'
|
||||
snapshot_id = '66666666-aaaa-bbbb-cccc-555555555555'
|
||||
image_id = '77777777-aaaa-bbbb-cccc-555555555555'
|
||||
|
||||
instance = self._create_fake_instance()
|
||||
instance_type = {'swap': 1, 'ephemeral_gb': 2}
|
||||
@@ -945,6 +946,20 @@ class ComputeVolumeTestCase(BaseTestCase):
|
||||
self.context, instance, instance_type,
|
||||
mappings + additional_swap)
|
||||
|
||||
image_no_size = [
|
||||
{
|
||||
'device_name': '/dev/sda4',
|
||||
'source_type': 'image',
|
||||
'image_id': image_id,
|
||||
'destination_type': 'volume',
|
||||
'boot_index': -1,
|
||||
'volume_size': None,
|
||||
}]
|
||||
self.assertRaises(exception.InvalidBDM,
|
||||
self.compute_api._validate_bdm,
|
||||
self.context, instance, instance_type,
|
||||
mappings + image_no_size)
|
||||
|
||||
def test_validate_bdm_media_service_exceptions(self):
|
||||
instance_type = {'swap': 1, 'ephemeral_gb': 1}
|
||||
all_mappings = [{'id': 1,
|
||||
|
||||
Reference in New Issue
Block a user