Browse Source

Merge "Should not skip volume_size check for bdm.image_id == image_ref case" into stable/stein

tags/19.3.1
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
042dc4f270
2 changed files with 37 additions and 6 deletions
  1. +6
    -6
      nova/compute/api.py
  2. +31
    -0
      nova/tests/unit/compute/test_compute_api.py

+ 6
- 6
nova/compute/api.py View File

@@ -1586,12 +1586,12 @@ class API(base.Base):
snapshot_id = bdm.snapshot_id
volume_id = bdm.volume_id
image_id = bdm.image_id
if (image_id is not None and
image_id != instance.get('image_ref')):
try:
self._get_image(context, image_id)
except Exception:
raise exception.InvalidBDMImage(id=image_id)
if image_id is not None:
if image_id != instance.get('image_ref'):
try:
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):


+ 31
- 0
nova/tests/unit/compute/test_compute_api.py View File

@@ -4604,6 +4604,37 @@ class _ComputeAPIUnitTestMixIn(object):
vol_type_requested.assert_any_call(bdms[1], volume_type,
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',
return_value=compute_api.MIN_COMPUTE_VOLUME_TYPE)
def test_the_specified_volume_type_id_assignment_to_name(


Loading…
Cancel
Save