diff --git a/nova/compute/api.py b/nova/compute/api.py index f12760f7b5f9..495b54ea8be2 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1194,7 +1194,8 @@ class API(base.Base): bdm.instance_uuid = instance_uuid bdm.update_or_create() - def _validate_bdm(self, context, instance, instance_type, all_mappings): + def _validate_bdm(self, context, instance, instance_type, + block_device_mappings): def _subsequent_list(l): # Each device which is capable of being used as boot device should # be given a unique boot index, starting from 0 in ascending order. @@ -1204,17 +1205,18 @@ class API(base.Base): # Setting a negative value or None indicates that the device should not # be used for booting. boot_indexes = sorted([bdm.boot_index - for bdm in all_mappings + for bdm in block_device_mappings if bdm.boot_index is not None and bdm.boot_index >= 0]) if 0 not in boot_indexes or not _subsequent_list(boot_indexes): # Convert the BlockDeviceMappingList to a list for repr details. LOG.debug('Invalid block device mapping boot sequence for ' - 'instance: %s', list(all_mappings), instance=instance) + 'instance: %s', list(block_device_mappings), + instance=instance) raise exception.InvalidBDMBootSequence() - for bdm in all_mappings: + for bdm in block_device_mappings: # NOTE(vish): For now, just make sure the volumes are accessible. # Additionally, check that the volume can be attached to this # instance. @@ -1261,13 +1263,13 @@ class API(base.Base): "size")) ephemeral_size = sum(bdm.volume_size or 0 - for bdm in all_mappings + for bdm in block_device_mappings if block_device.new_format_is_ephemeral(bdm)) if ephemeral_size > instance_type['ephemeral_gb']: raise exception.InvalidBDMEphemeralSize() # There should be only one swap - swap_list = block_device.get_bdm_swap_list(all_mappings) + swap_list = block_device.get_bdm_swap_list(block_device_mappings) if len(swap_list) > 1: msg = _("More than one swap drive requested.") raise exception.InvalidBDMFormat(details=msg) @@ -1279,7 +1281,7 @@ class API(base.Base): max_local = CONF.max_local_block_devices if max_local >= 0: - num_local = len([bdm for bdm in all_mappings + num_local = len([bdm for bdm in block_device_mappings if bdm.destination_type == 'local']) if num_local > max_local: raise exception.InvalidBDMLocalsLimit() diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 76c44dd4a7d3..648ee83a9d19 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -1066,7 +1066,7 @@ class ComputeVolumeTestCase(BaseTestCase): def test_validate_bdm_media_service_exceptions(self): instance_type = {'swap': 1, 'ephemeral_gb': 1} - all_mappings = [fake_block_device.FakeDbBlockDeviceDict({ + bdms = [fake_block_device.FakeDbBlockDeviceDict({ 'id': 1, 'no_device': None, 'source_type': 'volume', @@ -1076,8 +1076,8 @@ class ComputeVolumeTestCase(BaseTestCase): 'device_name': 'vda', 'boot_index': 0, 'delete_on_termination': False}, anon=True)] - all_mappings = block_device_obj.block_device_make_list_from_dicts( - self.context, all_mappings) + bdms = block_device_obj.block_device_make_list_from_dicts( + self.context, bdms) # First we test a list of invalid status values that should result # in an InvalidVolume exception being raised. @@ -1107,7 +1107,7 @@ class ComputeVolumeTestCase(BaseTestCase): self.assertRaises(exception.InvalidVolume, self.compute_api._validate_bdm, self.context, self.instance, - instance_type, all_mappings) + instance_type, bdms) # Now we test a 404 case that results in InvalidBDMVolume. def fake_volume_get_not_found(self, context, volume_id): @@ -1117,7 +1117,7 @@ class ComputeVolumeTestCase(BaseTestCase): self.assertRaises(exception.InvalidBDMVolume, self.compute_api._validate_bdm, self.context, self.instance, - instance_type, all_mappings) + instance_type, bdms) # Check that the volume status is 'available' and attach_status is # 'detached' and accept the request if so @@ -1129,7 +1129,7 @@ class ComputeVolumeTestCase(BaseTestCase): self.stubs.Set(cinder.API, 'get', fake_volume_get_ok) self.compute_api._validate_bdm(self.context, self.instance, - instance_type, all_mappings) + instance_type, bdms) def test_volume_snapshot_create(self): self.assertRaises(messaging.ExpectedException,