distro: extend the ImageType interface with BootMode()

As a preparation to be able to determine the image boot mode when
importing it to the target environment (e.g. AWS), expose the
information on the `ImageType` level.

The image boot mode is determined based on the platform associated with
it.

The new method is not yet used by any code, but will be eventually used
by osbuild-composer server to set the proper value in the upload target
options for the worker. The worker will be then able to import the image
in the proper way to the cloud environment.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-05-17 17:46:58 +02:00 committed by Achilleas Koutsou
parent 2c686cc988
commit 594778a230
6 changed files with 53 additions and 23 deletions

View file

@ -19,15 +19,30 @@ const (
S390xArchName = "s390x"
)
type BootType string
type BootMode uint64
const (
UnsetBootType BootType = ""
LegacyBootType BootType = "legacy"
UEFIBootType BootType = "uefi"
HybridBootType BootType = "hybrid"
BOOT_NONE BootMode = iota
BOOT_LEGACY
BOOT_UEFI
BOOT_HYBRID
)
func (m BootMode) String() string {
switch m {
case BOOT_NONE:
return "none"
case BOOT_LEGACY:
return "legacy"
case BOOT_UEFI:
return "uefi"
case BOOT_HYBRID:
return "hybrid"
default:
panic("invalid boot mode")
}
}
// A Distro represents composer's notion of what a given distribution is.
type Distro interface {
// Returns the name of the distro.
@ -96,6 +111,9 @@ type ImageType interface {
// has no partition table. Only support for RHEL 8.5+
PartitionType() string
// Returns the corresponding boot mode ("legacy", "uefi", "hybrid") or "none"
BootMode() BootMode
// Returns the sets of packages to include and exclude when building the image.
// Indexed by a string label. How each set is labeled and used depends on the
// image type.

View file

@ -646,6 +646,17 @@ func (t *imageType) Exports() []string {
return []string{"assembler"}
}
func (t *imageType) BootMode() distro.BootMode {
if t.platform.GetUEFIVendor() != "" && t.platform.GetBIOSPlatform() != "" {
return distro.BOOT_HYBRID
} else if t.platform.GetUEFIVendor() != "" {
return distro.BOOT_UEFI
} else if t.platform.GetBIOSPlatform() != "" || t.platform.GetZiplSupport() {
return distro.BOOT_LEGACY
}
return distro.BOOT_NONE
}
func (t *imageType) getPartitionTable(
mountpoints []blueprint.FilesystemCustomization,
options distro.ImageOptions,

View file

@ -284,16 +284,15 @@ func (t *imageType) Exports() []string {
return t.exports
}
// getBootType returns the BootType which should be used for this particular image type
func (t *imageType) getBootType() distro.BootType {
func (t *imageType) BootMode() distro.BootMode {
if t.platform.GetUEFIVendor() != "" && t.platform.GetBIOSPlatform() != "" {
return distro.HybridBootType
return distro.BOOT_HYBRID
} else if t.platform.GetUEFIVendor() != "" {
return distro.UEFIBootType
return distro.BOOT_UEFI
} else if t.platform.GetBIOSPlatform() != "" || t.platform.GetZiplSupport() {
return distro.LegacyBootType
return distro.BOOT_LEGACY
}
return distro.UnsetBootType
return distro.BOOT_NONE
}
func (t *imageType) getPartitionTable(

View file

@ -131,16 +131,15 @@ func (t *imageType) Exports() []string {
return []string{"assembler"}
}
// getBootType returns the BootType which should be used for this particular image type
func (t *imageType) getBootType() distro.BootType {
func (t *imageType) BootMode() distro.BootMode {
if t.platform.GetUEFIVendor() != "" && t.platform.GetBIOSPlatform() != "" {
return distro.HybridBootType
return distro.BOOT_HYBRID
} else if t.platform.GetUEFIVendor() != "" {
return distro.UEFIBootType
return distro.BOOT_UEFI
} else if t.platform.GetBIOSPlatform() != "" || t.platform.GetZiplSupport() {
return distro.LegacyBootType
return distro.BOOT_LEGACY
}
return distro.UnsetBootType
return distro.BOOT_NONE
}
func (t *imageType) getPartitionTable(

View file

@ -134,16 +134,15 @@ func (t *imageType) Exports() []string {
return []string{"assembler"}
}
// getBootType returns the BootType which should be used for this particular image type
func (t *imageType) getBootType() distro.BootType {
func (t *imageType) BootMode() distro.BootMode {
if t.platform.GetUEFIVendor() != "" && t.platform.GetBIOSPlatform() != "" {
return distro.HybridBootType
return distro.BOOT_HYBRID
} else if t.platform.GetUEFIVendor() != "" {
return distro.UEFIBootType
return distro.BOOT_UEFI
} else if t.platform.GetBIOSPlatform() != "" || t.platform.GetZiplSupport() {
return distro.LegacyBootType
return distro.BOOT_LEGACY
}
return distro.UnsetBootType
return distro.BOOT_NONE
}
func (t *imageType) getPartitionTable(

View file

@ -191,6 +191,10 @@ func (t *TestImageType) PartitionType() string {
return ""
}
func (t *TestImageType) BootMode() distro.BootMode {
return distro.BOOT_HYBRID
}
func (t *TestImageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
return map[string][]rpmmd.PackageSet{
buildPkgsKey: {{