refactor to return a reason why core boot options disabled on !uefi

This commit is contained in:
Michael Hudson-Doyle 2023-09-04 16:14:37 +12:00
parent bb50ee9fe5
commit a594b09f9f
2 changed files with 35 additions and 7 deletions

View File

@ -387,6 +387,7 @@ class GuidedCapability(enum.Enum):
class GuidedDisallowedCapabilityReason(enum.Enum): class GuidedDisallowedCapabilityReason(enum.Enum):
TOO_SMALL = enum.auto() TOO_SMALL = enum.auto()
CORE_BOOT_ENCRYPTION_UNAVAILABLE = enum.auto() CORE_BOOT_ENCRYPTION_UNAVAILABLE = enum.auto()
NOT_UEFI = enum.auto()
@attr.s(auto_attribs=True) @attr.s(auto_attribs=True)

View File

@ -22,7 +22,7 @@ import os
import pathlib import pathlib
import select import select
import time import time
from typing import Any, Dict, List, Optional, Union from typing import Any, Callable, Dict, List, Optional, Union
import attr import attr
import pyudev import pyudev
@ -123,7 +123,7 @@ class CapabilityInfo:
allowed: List[GuidedCapability] = attr.Factory(list) allowed: List[GuidedCapability] = attr.Factory(list)
disallowed: List[GuidedDisallowedCapability] = attr.Factory(list) disallowed: List[GuidedDisallowedCapability] = attr.Factory(list)
def combine(self, other: "CapabilityInfo"): def combine(self, other: "CapabilityInfo") -> None:
for allowed_cap in other.allowed: for allowed_cap in other.allowed:
if allowed_cap not in self.allowed: if allowed_cap not in self.allowed:
self.allowed.append(allowed_cap) self.allowed.append(allowed_cap)
@ -140,6 +140,26 @@ class CapabilityInfo:
self.allowed.sort() self.allowed.sort()
self.disallowed.sort() self.disallowed.sort()
def disallow_if(
self,
filter: Callable[[GuidedCapability], bool],
reason: GuidedDisallowedCapabilityReason,
message: Optional[str] = None,
) -> None:
new_allowed = []
for cap in self.allowed:
if filter(cap):
self.disallowed.append(
GuidedDisallowedCapability(
capability=cap,
reason=reason,
message=message,
)
)
else:
new_allowed.append(cap)
self.allowed = new_allowed
@attr.s(auto_attribs=True) @attr.s(auto_attribs=True)
class VariationInfo: class VariationInfo:
@ -383,12 +403,19 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
if not self.app.opts.enhanced_secureboot: if not self.app.opts.enhanced_secureboot:
log.debug("Not offering enhanced_secureboot: commandline disabled") log.debug("Not offering enhanced_secureboot: commandline disabled")
continue continue
if self.model.bootloader != Bootloader.UEFI:
log.debug("Not offering core boot based install: not a UEFI system")
continue
info = self.info_for_system(name, label, system) info = self.info_for_system(name, label, system)
if info is not None: if info is None:
self._variation_info[name] = info continue
if self.model.bootloader != Bootloader.UEFI:
log.debug(
"Disabling core boot based install options on non-UEFI "
"system"
)
info.capability_info.disallow_if(
lambda cap: cap.is_core_boot(),
GuidedDisallowedCapabilityReason.NOT_UEFI,
)
self._variation_info[name] = info
elif catalog_entry.type.startswith("dd-"): elif catalog_entry.type.startswith("dd-"):
min_size = variation.size min_size = variation.size
self._variation_info[name] = VariationInfo.dd( self._variation_info[name] = VariationInfo.dd(