Fix dropped check for boot_index 0 in _validate_bdm
This reverts commit 7f4b49c9c9
.
During refactor change I8a3e7e6c4b72eb1c3707d54049d18dc29f606fe5
the conditional that at least one BDM had to be the boot
device was inadvertantly dropped, presumably because there was
no test for that case.
The validation is added back here along with a test.
Change-Id: I299bf846b658f2bb6903c898d7deac748f8d90e4
Related-Bug: #1766306
This commit is contained in:
parent
048fa23100
commit
b9815c2331
|
@ -1277,6 +1277,11 @@ class API(base.Base):
|
||||||
|
|
||||||
def _validate_bdm(self, context, instance, instance_type,
|
def _validate_bdm(self, context, instance, instance_type,
|
||||||
block_device_mappings, supports_multiattach=False):
|
block_device_mappings, supports_multiattach=False):
|
||||||
|
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.
|
||||||
|
return all(el + 1 == l[i + 1] for i, el in enumerate(l[:-1]))
|
||||||
|
|
||||||
# Make sure that the boot indexes make sense.
|
# Make sure that the boot indexes make sense.
|
||||||
# Setting a negative value or None indicates that the device should not
|
# Setting a negative value or None indicates that the device should not
|
||||||
# be used for booting.
|
# be used for booting.
|
||||||
|
@ -1285,9 +1290,7 @@ class API(base.Base):
|
||||||
if bdm.boot_index is not None
|
if bdm.boot_index is not None
|
||||||
and bdm.boot_index >= 0])
|
and bdm.boot_index >= 0])
|
||||||
|
|
||||||
# Each device which is capable of being used as boot device should
|
if 0 not in boot_indexes or not _subsequent_list(boot_indexes):
|
||||||
# be given a unique boot index, starting from 0 in ascending order.
|
|
||||||
if any(i != v for i, v in enumerate(boot_indexes)):
|
|
||||||
# Convert the BlockDeviceMappingList to a list for repr details.
|
# Convert the BlockDeviceMappingList to a list for repr details.
|
||||||
LOG.debug('Invalid block device mapping boot sequence for '
|
LOG.debug('Invalid block device mapping boot sequence for '
|
||||||
'instance: %s', list(block_device_mappings),
|
'instance: %s', list(block_device_mappings),
|
||||||
|
|
|
@ -4201,6 +4201,18 @@ class _ComputeAPIUnitTestMixIn(object):
|
||||||
mock_attach_create.assert_called_once_with(
|
mock_attach_create.assert_called_once_with(
|
||||||
self.context, volume_id, instance.uuid)
|
self.context, volume_id, instance.uuid)
|
||||||
|
|
||||||
|
def test_validate_bdm_missing_boot_index(self):
|
||||||
|
"""Tests that _validate_bdm will fail if there is no boot_index=0 entry
|
||||||
|
"""
|
||||||
|
bdms = objects.BlockDeviceMappingList(objects=[
|
||||||
|
objects.BlockDeviceMapping(
|
||||||
|
boot_index=None, image_id=uuids.image_id,
|
||||||
|
source_type='image', destination_type='volume')])
|
||||||
|
self.assertRaises(exception.InvalidBDMBootSequence,
|
||||||
|
self.compute_api._validate_bdm,
|
||||||
|
self.context, objects.Instance(), objects.Flavor(),
|
||||||
|
bdms)
|
||||||
|
|
||||||
def _test_provision_instances_with_cinder_error(self,
|
def _test_provision_instances_with_cinder_error(self,
|
||||||
expected_exception):
|
expected_exception):
|
||||||
@mock.patch('nova.compute.utils.check_num_instances_quota')
|
@mock.patch('nova.compute.utils.check_num_instances_quota')
|
||||||
|
|
Loading…
Reference in New Issue