Skip to content

Commit

Permalink
Merge "Fix dropped check for boot_index 0 in _validate_bdm" into stab…
Browse files Browse the repository at this point in the history
…le/queens
  • Loading branch information
Zuul authored and openstack-gerrit committed May 9, 2018
2 parents f95a10b + dcb5180 commit 7c7a5a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions nova/compute/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,11 @@ def _create_block_device_mapping(self, block_device_mapping):

def _validate_bdm(self, context, instance, instance_type,
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.
# Setting a negative value or None indicates that the device should not
# be used for booting.
Expand All @@ -1294,9 +1299,7 @@ def _validate_bdm(self, context, instance, instance_type,
if bdm.boot_index is not None
and bdm.boot_index >= 0])

# Each device which is capable of being used as boot device should
# be given a unique boot index, starting from 0 in ascending order.
if any(i != v for i, v in enumerate(boot_indexes)):
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(block_device_mappings),
Expand Down
12 changes: 12 additions & 0 deletions nova/tests/unit/compute/test_compute_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4218,6 +4218,18 @@ def test_validate_bdm_with_error_volume_new_flow(self, mock_attach_create,
mock_attach_create.assert_called_once_with(
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,
expected_exception):
@mock.patch('nova.compute.utils.check_num_instances_quota')
Expand Down

0 comments on commit 7c7a5a6

Please sign in to comment.