From 67f6f67b8e01af5e17a21153c79db12af8e54521 Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Wed, 26 Jul 2023 13:26:11 -0600 Subject: [PATCH] boot: extend bootable raid for poweredge devices --- subiquity/common/filesystem/boot.py | 22 ++++++++++------- .../common/filesystem/tests/test_boot.py | 24 ++++++++++++++++--- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/subiquity/common/filesystem/boot.py b/subiquity/common/filesystem/boot.py index 77098114..70a86312 100644 --- a/subiquity/common/filesystem/boot.py +++ b/subiquity/common/filesystem/boot.py @@ -20,12 +20,24 @@ from typing import Any, Optional import attr +from subiquity.common.dmidecode import dmidecode_get from subiquity.common.filesystem import gaps, sizes from subiquity.models.filesystem import Bootloader, Disk, Partition, Raid, align_up log = logging.getLogger("subiquity.common.filesystem.boot") +def bootable_raid(raid: Raid): + if raid._m.bootloader != Bootloader.UEFI: + return False + if raid.container is not None and raid.container.metadata == "imsm": + return True + if "poweredge" in dmidecode_get("system-product-name").lower(): + # LP: #1961079 - all poweredge devices assumed to support raid UEFI boot + return True + return False + + @functools.singledispatch def is_boot_device(device): """Is `device` a boot device?""" @@ -45,10 +57,7 @@ def _is_boot_device_disk(disk): @is_boot_device.register(Raid) def _is_boot_device_raid(raid): - bl = raid._m.bootloader - if bl != Bootloader.UEFI: - return False - if not raid.container or raid.container.metadata != "imsm": + if not bootable_raid(raid): return False return any(p.grub_device for p in raid._partitions) @@ -344,10 +353,7 @@ def _can_be_boot_device_disk(disk, *, resize_partition=None, with_reformatting=F @can_be_boot_device.register(Raid) def _can_be_boot_device_raid(raid, *, resize_partition=None, with_reformatting=False): - bl = raid._m.bootloader - if bl != Bootloader.UEFI: - return False - if not raid.container or raid.container.metadata != "imsm": + if not bootable_raid(raid): return False if with_reformatting: return True diff --git a/subiquity/common/filesystem/tests/test_boot.py b/subiquity/common/filesystem/tests/test_boot.py index dd61a3ce..cbaf9cd5 100644 --- a/subiquity/common/filesystem/tests/test_boot.py +++ b/subiquity/common/filesystem/tests/test_boot.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import unittest -from unittest.mock import Mock +from unittest.mock import Mock, patch from subiquity.common.filesystem import boot from subiquity.models.filesystem import Bootloader @@ -26,7 +26,9 @@ class TestBootDevRaid(unittest.TestCase): raid = make_raid(make_model(Bootloader.BIOS)) self.assertFalse(boot.can_be_boot_device(raid)) - def test_UEFI_no_container(self): + @patch("subiquity.common.filesystem.boot.dmidecode_get") + def test_UEFI_no_container(self, dmi_get): + dmi_get.return_value = "" raid = make_raid(make_model(Bootloader.UEFI)) raid.container = None self.assertFalse(boot.can_be_boot_device(raid)) @@ -37,8 +39,24 @@ class TestBootDevRaid(unittest.TestCase): raid.container.metadata = "imsm" self.assertTrue(boot.can_be_boot_device(raid)) - def test_UEFI_container_non_imsm(self): + @patch("subiquity.common.filesystem.boot.dmidecode_get") + def test_UEFI_container_non_imsm(self, dmi_get): + dmi_get.return_value = "" raid = make_raid(make_model(Bootloader.UEFI)) raid.container = Mock() raid.container.metadata = "something else" self.assertFalse(boot.can_be_boot_device(raid)) + + @patch("subiquity.common.filesystem.boot.dmidecode_get") + def test_UEFI_spn_poweredge(self, dmi_get): + dmi_get.return_value = "CompanyName PowerEdge 1234" + raid = make_raid(make_model(Bootloader.UEFI)) + raid.container = None + self.assertTrue(boot.can_be_boot_device(raid)) + + @patch("subiquity.common.filesystem.boot.dmidecode_get") + def test_UEFI_spn_other(self, dmi_get): + dmi_get.return_value = "CompanyName ProductName 1227" + raid = make_raid(make_model(Bootloader.UEFI)) + raid.container = None + self.assertFalse(boot.can_be_boot_device(raid))