diff --git a/nova/compute/api.py b/nova/compute/api.py index 336601fcaadc..f898acda802c 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1310,7 +1310,7 @@ class API(base.Base): "(source: 'blank', dest: 'volume') need to have non-zero " "size")) - ephemeral_size = sum(bdm.volume_size or 0 + ephemeral_size = sum(bdm.volume_size or instance_type['ephemeral_gb'] for bdm in block_device_mappings if block_device.new_format_is_ephemeral(bdm)) if ephemeral_size > instance_type['ephemeral_gb']: diff --git a/nova/exception.py b/nova/exception.py index 234d502b9f6a..6fbed08ef84a 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -219,7 +219,9 @@ class InvalidBDMLocalsLimit(InvalidBDM): class InvalidBDMEphemeralSize(InvalidBDM): msg_fmt = _("Ephemeral disks requested are larger than " - "the instance type allows.") + "the instance type allows. If no size is given " + "in one block device mapping, flavor ephemeral " + "size will be used.") class InvalidBDMSwapSize(InvalidBDM): diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 643491902035..6b6b7101026c 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -1056,6 +1056,40 @@ class ComputeVolumeTestCase(BaseTestCase): self.context, instance, instance_type, mappings_) + def test_validate_bdm_with_more_than_one_default(self): + instance_type = {'swap': 1, 'ephemeral_gb': 1} + all_mappings = [fake_block_device.FakeDbBlockDeviceDict({ + 'id': 1, + 'no_device': None, + 'source_type': 'volume', + 'destination_type': 'volume', + 'snapshot_id': None, + 'volume_size': 1, + 'device_name': 'vda', + 'boot_index': 0, + 'delete_on_termination': False}, anon=True), + fake_block_device.FakeDbBlockDeviceDict({ + 'device_name': '/dev/vdb', + 'source_type': 'blank', + 'destination_type': 'local', + 'device_type': 'disk', + 'volume_size': None, + 'boot_index': -1}, anon=True), + fake_block_device.FakeDbBlockDeviceDict({ + 'device_name': '/dev/vdc', + 'source_type': 'blank', + 'destination_type': 'local', + 'device_type': 'disk', + 'volume_size': None, + 'boot_index': -1}, anon=True)] + all_mappings = block_device_obj.block_device_make_list_from_dicts( + self.context, all_mappings) + + self.assertRaises(exception.InvalidBDMEphemeralSize, + self.compute_api._validate_bdm, + self.context, self.instance, + instance_type, all_mappings) + def test_validate_bdm_media_service_exceptions(self): instance_type = {'swap': 1, 'ephemeral_gb': 1} bdms = [fake_block_device.FakeDbBlockDeviceDict({