Using bootable if set for disk

If nailgun will send as bootable flag for disk we have to use this
disk and place '/boot' on it

Change-Id: I881d9fd4bb378dec78fd86aff0c314c910525110
Closes-bug: 1567450
This commit is contained in:
Krzysztof Szukiełojć 2016-04-21 12:04:59 +02:00
parent b54d0412a3
commit 5a56d6a4e8
2 changed files with 25 additions and 2 deletions

View File

@ -137,6 +137,10 @@ class Nailgun(BaseDataDriver):
@property
def boot_disks(self):
"""Property to get suitable list of disks to place '/boot'
:returns: list of disk where boot partition can be placed
"""
# FIXME(agordeev): NVMe drives should be skipped as
# accessing such drives during the boot typically
# requires using UEFI which is still not supported
@ -163,9 +167,19 @@ class Nailgun(BaseDataDriver):
md_boot_disks = [
disk for disk in self.md_os_disks if disk in suitable_disks]
if md_boot_disks:
return md_boot_disks
disks = md_boot_disks
else:
return suitable_disks
disks = suitable_disks
bootable_disk = [disk for disk in disks
if disk.get('bootable')]
if bootable_disk:
if len(bootable_disk) >= 2:
raise errors.WrongPartitionSchemeError(
"More than one bootable disk found! %{0}".
format(bootable_disk))
return bootable_disk
return disks
def _have_boot_partition(self, disks):
return any(self._is_boot_disk(d) for d in disks)

View File

@ -1757,6 +1757,15 @@ class TestNailgunMockedMeta(unittest2.TestCase):
drv.partition_scheme.fs_by_mount('/boot').device,
'/dev/sda3')
def test_boot_partition_bootable_flag(self, mock_lbd, mock_image_meta):
data = copy.deepcopy(PROVISION_SAMPLE_DATA)
data['ks_meta']['pm_data']['ks_spaces'][1]['bootable'] = True
mock_lbd.return_value = LIST_BLOCK_DEVICES_SAMPLE
drv = nailgun.Nailgun(data)
self.assertEqual(
drv.partition_scheme.fs_by_mount('/boot').device,
'/dev/sdb3')
def test_elevate_keep_data_single_disk(self, mock_lbd, mock_image_meta):
data = copy.deepcopy(PROVISION_SAMPLE_DATA)
data['ks_meta']['pm_data']['ks_spaces'] = SINGLE_DISK_KS_SPACES