Simplify BDM boot index checking

The previous code had a complex check which asserted that:

1. the boot index list contains 0
2. every element in the boot index list is 1 less than its successor

The second check was in a method called _subsequent_list, which I
assume was intended to be _sequential_list.

However, combined with the constraint that the boot index are >= 0,
the above 2 constraints are the same as asserting that each element in
the boot index list has the same value as its index in the list. This
is also much simpler to understand.

Change-Id: I8a3e7e6c4b72eb1c3707d54049d18dc29f606fe5
This commit is contained in:
Matthew Booth 2017-11-26 04:13:31 +00:00
parent 16a968363d
commit 7f4b49c9c9
1 changed files with 3 additions and 6 deletions

View File

@ -1279,11 +1279,6 @@ class API(base.Base):
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.
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.
@ -1292,7 +1287,9 @@ class API(base.Base):
if bdm.boot_index is not None
and bdm.boot_index >= 0])
if 0 not in boot_indexes or not _subsequent_list(boot_indexes):
# 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)):
# Convert the BlockDeviceMappingList to a list for repr details.
LOG.debug('Invalid block device mapping boot sequence for '
'instance: %s', list(block_device_mappings),