From 3190de69430057da541294986114867ad4ce406f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Szukie=C5=82oj=C4=87?= Date: Thu, 21 Apr 2016 12:04:59 +0200 Subject: [PATCH] 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 --- bareon/drivers/data/nailgun.py | 18 ++++++++++++++++-- bareon/tests/test_nailgun.py | 9 +++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bareon/drivers/data/nailgun.py b/bareon/drivers/data/nailgun.py index 2ae56dc..668546c 100644 --- a/bareon/drivers/data/nailgun.py +++ b/bareon/drivers/data/nailgun.py @@ -154,6 +154,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 @@ -180,9 +184,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) diff --git a/bareon/tests/test_nailgun.py b/bareon/tests/test_nailgun.py index 6f89354..351c98a 100644 --- a/bareon/tests/test_nailgun.py +++ b/bareon/tests/test_nailgun.py @@ -1762,6 +1762,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