Merge "Should not skip volume_size check for bdm.image_id == image_ref case" into stable/stein
This commit is contained in:
commit
042dc4f270
|
@ -1586,12 +1586,12 @@ class API(base.Base):
|
||||||
snapshot_id = bdm.snapshot_id
|
snapshot_id = bdm.snapshot_id
|
||||||
volume_id = bdm.volume_id
|
volume_id = bdm.volume_id
|
||||||
image_id = bdm.image_id
|
image_id = bdm.image_id
|
||||||
if (image_id is not None and
|
if image_id is not None:
|
||||||
image_id != instance.get('image_ref')):
|
if image_id != instance.get('image_ref'):
|
||||||
try:
|
try:
|
||||||
self._get_image(context, image_id)
|
self._get_image(context, image_id)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise exception.InvalidBDMImage(id=image_id)
|
raise exception.InvalidBDMImage(id=image_id)
|
||||||
if (bdm.source_type == 'image' and
|
if (bdm.source_type == 'image' and
|
||||||
bdm.destination_type == 'volume' and
|
bdm.destination_type == 'volume' and
|
||||||
not bdm.volume_size):
|
not bdm.volume_size):
|
||||||
|
|
|
@ -4604,6 +4604,37 @@ class _ComputeAPIUnitTestMixIn(object):
|
||||||
vol_type_requested.assert_any_call(bdms[1], volume_type,
|
vol_type_requested.assert_any_call(bdms[1], volume_type,
|
||||||
volume_types)
|
volume_types)
|
||||||
|
|
||||||
|
@mock.patch('nova.compute.api.API._get_image')
|
||||||
|
def test_validate_bdm_missing_volume_size(self, mock_get_image):
|
||||||
|
"""Tests that _validate_bdm fail if there volume_size not provided
|
||||||
|
"""
|
||||||
|
instance = self._create_instance_obj()
|
||||||
|
# first we test the case of instance.image_ref == bdm.image_id
|
||||||
|
bdms = objects.BlockDeviceMappingList(objects=[
|
||||||
|
objects.BlockDeviceMapping(
|
||||||
|
boot_index=0, image_id=instance.image_ref,
|
||||||
|
source_type='image', destination_type='volume',
|
||||||
|
volume_type=None, snapshot_id=None, volume_id=None,
|
||||||
|
volume_size=None)])
|
||||||
|
self.assertRaises(exception.InvalidBDM,
|
||||||
|
self.compute_api._validate_bdm,
|
||||||
|
self.context, instance, objects.Flavor(),
|
||||||
|
bdms)
|
||||||
|
self.assertEqual(0, mock_get_image.call_count)
|
||||||
|
# then we test the case of instance.image_ref != bdm.image_id
|
||||||
|
image_id = uuids.image_id
|
||||||
|
bdms = objects.BlockDeviceMappingList(objects=[
|
||||||
|
objects.BlockDeviceMapping(
|
||||||
|
boot_index=0, image_id=image_id,
|
||||||
|
source_type='image', destination_type='volume',
|
||||||
|
volume_type=None, snapshot_id=None, volume_id=None,
|
||||||
|
volume_size=None)])
|
||||||
|
self.assertRaises(exception.InvalidBDM,
|
||||||
|
self.compute_api._validate_bdm,
|
||||||
|
self.context, instance, objects.Flavor(),
|
||||||
|
bdms)
|
||||||
|
mock_get_image.assert_called_once_with(self.context, image_id)
|
||||||
|
|
||||||
@mock.patch.object(objects.service, 'get_minimum_version_all_cells',
|
@mock.patch.object(objects.service, 'get_minimum_version_all_cells',
|
||||||
return_value=compute_api.MIN_COMPUTE_VOLUME_TYPE)
|
return_value=compute_api.MIN_COMPUTE_VOLUME_TYPE)
|
||||||
def test_the_specified_volume_type_id_assignment_to_name(
|
def test_the_specified_volume_type_id_assignment_to_name(
|
||||||
|
|
Loading…
Reference in New Issue