distro: housekeeping with cpu arch and arch.Name()

This commit is contained in:
Jordi Gil 2022-04-13 15:22:32 -04:00 committed by Tomáš Hozza
parent 02debc0cda
commit 616258ee25
20 changed files with 51 additions and 50 deletions

View file

@ -30,6 +30,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/boot/openstacktest"
"github.com/osbuild/osbuild-composer/internal/boot/vmwaretest"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/test"
"github.com/osbuild/osbuild-composer/internal/upload/vmware"
)
@ -392,7 +393,7 @@ func testBootUsingOpenStack(t *testing.T, imagePath string) {
currentArch := common.CurrentArch()
// skip on aarch64 because we don't have aarch64 openstack or kvm machines
if currentArch == "aarch64" {
if currentArch == distro.Aarch64ArchName {
t.Skip("Openstack boot test is skipped on aarch64.")
// if no credentials are given, fall back to qemu
} else if (creds == gophercloud.AuthOptions{}) {

View file

@ -139,7 +139,7 @@ func WithBootedQemuImage(image string, ns NetNS, f func() error) error {
"-nographic",
image,
)
} else if common.CurrentArch() == "aarch64" {
} else if common.CurrentArch() == distro.Aarch64ArchName {
// This command does not use KVM as I was unable to make it work in Beaker,
// once we have machines that can use KVM, enable it to make it faster
qemuCmd = ns.NamespacedCommand(

View file

@ -166,7 +166,7 @@ func (t *imageType) MIMEType() string {
func (t *imageType) OSTreeRef() string {
if t.rpmOstree {
return fmt.Sprintf(ostreeRef, t.arch.name)
return fmt.Sprintf(ostreeRef, t.Arch().Name())
}
return ""
}
@ -342,7 +342,7 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
p := &osbuild.Pipeline{}
p.SetBuild(t.buildPipeline(repos, *t.arch, buildPackageSpecs), "org.osbuild.rhel82")
if t.arch.Name() == "s390x" {
if t.arch.Name() == distro.S390xArchName {
p.AddStage(osbuild.NewKernelCmdlineStage(&osbuild.KernelCmdlineStageOptions{
RootFsUUID: "0bd700f8-090f-4556-b797-b340297ea1bd",
KernelOpts: "net.ifnames=0 crashkernel=auto",
@ -354,7 +354,7 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
if t.bootable {
p.AddStage(osbuild.NewFSTabStage(t.fsTabStageOptions(t.arch.uefi)))
if t.arch.Name() != "s390x" {
if t.arch.Name() != distro.S390xArchName {
p.AddStage(osbuild.NewGRUB2Stage(t.grub2StageOptions(t.kernelOptions, c.GetKernel(), t.arch.uefi)))
}
}
@ -404,7 +404,7 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
p.AddStage(osbuild.NewFirewallStage(t.firewallStageOptions(firewall)))
}
if t.arch.Name() == "s390x" {
if t.arch.Name() == distro.S390xArchName {
p.AddStage(osbuild.NewZiplStage(&osbuild.ZiplStageOptions{}))
}
@ -584,7 +584,7 @@ func qemuAssembler(format string, filename string, uefi bool, arch distro.Arch,
},
}
} else {
if arch.Name() == "ppc64le" {
if arch.Name() == distro.Ppc64leArchName {
options = osbuild.QEMUAssemblerOptions{
Bootloader: &osbuild.QEMUBootloader{
Type: "grub2",
@ -612,7 +612,7 @@ func qemuAssembler(format string, filename string, uefi bool, arch distro.Arch,
},
},
}
} else if arch.Name() == "s390x" {
} else if arch.Name() == distro.S390xArchName {
options = osbuild.QEMUAssemblerOptions{
Bootloader: &osbuild.QEMUBootloader{
Type: "zipl",

View file

@ -200,7 +200,7 @@ func (t *imageType) MIMEType() string {
func (t *imageType) OSTreeRef() string {
if t.rpmOstree {
return fmt.Sprintf(ostreeRef, t.arch.name)
return fmt.Sprintf(ostreeRef, t.Arch().Name())
}
return ""
}
@ -407,7 +407,7 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
p.SetBuild(t.buildPipeline(repos, *t.arch, buildPackageSpecs), "org.osbuild.rhel84")
}
if t.arch.Name() == "s390x" {
if t.arch.Name() == distro.S390xArchName {
if pt == nil {
panic("s390x image must have a partition table, this is a programming error")
}
@ -431,7 +431,7 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
}
if t.bootable {
if t.arch.Name() != "s390x" {
if t.arch.Name() != distro.S390xArchName {
p.AddStage(osbuild.NewGRUB2Stage(t.grub2StageOptions(pt, t.kernelOptions, c.GetKernel(), packageSpecs, t.arch.uefi, t.arch.legacy)))
}
}
@ -483,7 +483,7 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
p.AddStage(osbuild.NewFirewallStage(t.firewallStageOptions(firewall)))
}
if t.arch.Name() == "s390x" {
if t.arch.Name() == distro.S390xArchName {
p.AddStage(osbuild.NewZiplStage(&osbuild.ZiplStageOptions{}))
}
@ -653,7 +653,7 @@ func (t *imageType) selinuxStageOptions() *osbuild.SELinuxStageOptions {
}
func defaultPartitionTable(imageSize uint64, arch distro.Arch, rng *rand.Rand) disk.PartitionTable {
if arch.Name() == "x86_64" {
if arch.Name() == distro.X86_64ArchName {
return disk.PartitionTable{
Size: imageSize,
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
@ -696,7 +696,7 @@ func defaultPartitionTable(imageSize uint64, arch distro.Arch, rng *rand.Rand) d
},
},
}
} else if arch.Name() == "aarch64" {
} else if arch.Name() == distro.Aarch64ArchName {
return disk.PartitionTable{
Size: imageSize,
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
@ -732,7 +732,7 @@ func defaultPartitionTable(imageSize uint64, arch distro.Arch, rng *rand.Rand) d
},
},
}
} else if arch.Name() == "ppc64le" {
} else if arch.Name() == distro.Ppc64leArchName {
return disk.PartitionTable{
Size: imageSize,
UUID: "0x14fc63d2",
@ -756,7 +756,7 @@ func defaultPartitionTable(imageSize uint64, arch distro.Arch, rng *rand.Rand) d
},
},
}
} else if arch.Name() == "s390x" {
} else if arch.Name() == distro.S390xArchName {
return disk.PartitionTable{
Size: imageSize,
UUID: "0x14fc63d2",
@ -793,12 +793,12 @@ func qemuAssembler(pt *disk.PartitionTable, format string, filename string, imag
options.Bootloader = &osbuild.QEMUBootloader{
Type: "grub2",
}
} else if arch.Name() == "ppc64le" {
} else if arch.Name() == distro.Ppc64leArchName {
options.Bootloader = &osbuild.QEMUBootloader{
Type: "grub2",
Platform: "powerpc-ieee1275",
}
} else if arch.Name() == "s390x" {
} else if arch.Name() == distro.S390xArchName {
options.Bootloader = &osbuild.QEMUBootloader{
Type: "zipl",
}

View file

@ -220,7 +220,7 @@ func TestImageType_Name(t *testing.T) {
for _, dist := range rhelFamilyDistros {
t.Run(dist.name, func(t *testing.T) {
for _, mapping := range imgMap {
if mapping.arch == "s390x" && dist.name == "centos" {
if mapping.arch == distro.S390xArchName && dist.name == "centos" {
continue
}
arch, err := dist.distro.GetArch(mapping.arch)
@ -443,7 +443,7 @@ func TestDistro_ManifestError(t *testing.T) {
for _, archName := range r8distro.ListArches() {
arch, _ := r8distro.GetArch(archName)
for _, imgTypeName := range arch.ListImageTypes() {
if archName == "s390x" && imgTypeName == "tar" {
if archName == distro.S390xArchName && imgTypeName == "tar" {
// broken arch-imgType combination; see
// https://github.com/osbuild/osbuild-composer/issues/1220
continue
@ -514,7 +514,7 @@ func TestArchitecture_ListImageTypes(t *testing.T) {
for _, dist := range rhelFamilyDistros {
t.Run(dist.name, func(t *testing.T) {
for _, mapping := range imgMap {
if mapping.arch == "s390x" && dist.name == "centos" {
if mapping.arch == distro.S390xArchName && dist.name == "centos" {
continue
}
arch, err := dist.distro.GetArch(mapping.arch)
@ -623,7 +623,7 @@ func TestDistro_CustomFileSystemManifestError(t *testing.T) {
for _, archName := range d.ListArches() {
arch, _ := d.GetArch(archName)
for _, imgTypeName := range arch.ListImageTypes() {
if (archName == "s390x" && imgTypeName == "tar") || imgTypeName == "rhel-edge-installer" {
if (archName == distro.S390xArchName && imgTypeName == "tar") || imgTypeName == "rhel-edge-installer" {
continue
}
imgType, _ := arch.GetImageType(imgTypeName)
@ -660,7 +660,7 @@ func TestDistro_TestRootMountPoint(t *testing.T) {
for _, archName := range d.ListArches() {
arch, _ := d.GetArch(archName)
for _, imgTypeName := range arch.ListImageTypes() {
if (archName == "s390x" && imgTypeName == "tar") || imgTypeName == "rhel-edge-installer" {
if (archName == distro.S390xArchName && imgTypeName == "tar") || imgTypeName == "rhel-edge-installer" {
continue
}
imgType, _ := arch.GetImageType(imgTypeName)

View file

@ -60,7 +60,7 @@ func (t *imageTypeS2) MIMEType() string {
func (t *imageTypeS2) OSTreeRef() string {
if t.rpmOstree {
return fmt.Sprintf(ostreeRef, t.arch.name)
return fmt.Sprintf(ostreeRef, t.Arch().Name())
}
return ""
}

View file

@ -214,7 +214,7 @@ func (t *imageType) MIMEType() string {
func (t *imageType) OSTreeRef() string {
if t.rpmOstree {
return fmt.Sprintf(ostreeRef, t.arch.name)
return fmt.Sprintf(ostreeRef, t.Arch().Name())
}
return ""
}

View file

@ -317,7 +317,7 @@ func TestImageType_Name(t *testing.T) {
for _, dist := range rhelFamilyDistros {
t.Run(dist.name, func(t *testing.T) {
for _, mapping := range imgMap {
if mapping.arch == "s390x" && dist.name == "centos" {
if mapping.arch == distro.S390xArchName && dist.name == "centos" {
continue
}
arch, err := dist.distro.GetArch(mapping.arch)

View file

@ -62,7 +62,7 @@ func qcow2Pipelines(t *imageType, customizations *blueprint.Customizations, opti
}
func prependKernelCmdlineStage(pipeline *osbuild.Pipeline, t *imageType, pt *disk.PartitionTable) *osbuild.Pipeline {
if t.arch.name == distro.S390xArchName {
if t.Arch().Name() == distro.S390xArchName {
rootFs := pt.FindMountable("/")
if rootFs == nil {
panic("s390x image must have a root filesystem, this is a programming error")
@ -1461,9 +1461,9 @@ func simplifiedInstallerEFIBootTreePipeline(installDevice, kernelVer, arch strin
var architectures []string
if arch == "x86_64" {
if arch == distro.X86_64ArchName {
architectures = []string{"IA32", "X64"}
} else if arch == "aarch64" {
} else if arch == distro.Aarch64ArchName {
architectures = []string{"AA64"}
} else {
panic("unsupported architecture")
@ -1705,7 +1705,7 @@ func qemuPipeline(inputPipelineName, inputFilename, outputFilename string, forma
}
func bootloaderConfigStage(t *imageType, partitionTable *disk.PartitionTable, kernel *blueprint.KernelCustomization, kernelVer string, install, greenboot bool) *osbuild.Stage {
if t.arch.name == distro.S390xArchName {
if t.Arch().Name() == distro.S390xArchName {
return osbuild.NewZiplStage(new(osbuild.ZiplStageOptions))
}

View file

@ -278,7 +278,7 @@ func (t *imageType) MIMEType() string {
func (t *imageType) OSTreeRef() string {
d := t.arch.distro
if t.rpmOstree {
return fmt.Sprintf(d.ostreeRefTmpl, t.arch.name)
return fmt.Sprintf(d.ostreeRefTmpl, t.Arch().Name())
}
return ""
}

View file

@ -335,7 +335,7 @@ func TestImageType_Name(t *testing.T) {
for _, dist := range rhelFamilyDistros {
t.Run(dist.name, func(t *testing.T) {
for _, mapping := range imgMap {
if mapping.arch == "s390x" && dist.name == "centos" {
if mapping.arch == distro.S390xArchName && dist.name == "centos" {
continue
}
arch, err := dist.distro.GetArch(mapping.arch)

View file

@ -41,7 +41,7 @@ func qcow2Pipelines(t *imageType, customizations *blueprint.Customizations, opti
}
func prependKernelCmdlineStage(pipeline *osbuild.Pipeline, t *imageType, pt *disk.PartitionTable) *osbuild.Pipeline {
if t.arch.name == distro.S390xArchName {
if t.Arch().Name() == distro.S390xArchName {
rootFs := pt.FindMountable("/")
if rootFs == nil {
panic("s390x image must have a root filesystem, this is a programming error")
@ -238,7 +238,7 @@ func edgeInstallerPipelines(t *imageType, customizations *blueprint.Customizatio
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs[buildPkgsKey], t.arch.distro.runner))
installerPackages := packageSetSpecs[installerPkgsKey]
d := t.arch.distro
archName := t.arch.name
archName := t.Arch().Name()
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel")
ostreeRepoPath := "/ostree/repo"
payloadStages := ostreePayloadStages(options, ostreeRepoPath)
@ -285,7 +285,7 @@ func imageInstallerPipelines(t *imageType, customizations *blueprint.Customizati
if err != nil {
return nil, err
}
archName := t.arch.name
archName := t.Arch().Name()
d := t.arch.distro
pipelines = append(pipelines, *anacondaTreePipeline(repos, installerPackages, kernelVer, archName, d.product, d.osVersion, "BaseOS", true))
isolabel := fmt.Sprintf(d.isolabelTmpl, archName)
@ -741,7 +741,7 @@ func edgeSimplifiedInstallerPipelines(t *imageType, customizations *blueprint.Cu
// create boot ISO with raw image
d := t.arch.distro
archName := t.arch.name
archName := t.Arch().Name()
installerTreePipeline := simplifiedInstallerTreePipeline(repos, installerPackages, kernelVer, archName, d.product, d.osVersion, "edge", customizations.GetFDO())
isolabel := fmt.Sprintf(d.isolabelTmpl, archName)
efibootTreePipeline := simplifiedInstallerEFIBootTreePipeline(installDevice, kernelVer, archName, d.vendor, d.product, d.osVersion, isolabel, customizations.GetFDO())
@ -1100,7 +1100,7 @@ func qemuPipeline(inputPipelineName, inputFilename, outputFilename string, forma
}
func bootloaderConfigStage(t *imageType, partitionTable disk.PartitionTable, kernel *blueprint.KernelCustomization, kernelVer string, install, greenboot bool) *osbuild.Stage {
if t.arch.name == distro.S390xArchName {
if t.Arch().Name() == distro.S390xArchName {
return osbuild.NewZiplStage(new(osbuild.ZiplStageOptions))
}

View file

@ -209,9 +209,9 @@ func bootISOMonoStageOptions(kernelVer, arch, vendor, product, osVersion, isolab
func grubISOStageOptions(installDevice, kernelVer, arch, vendor, product, osVersion, isolabel string, fdo *blueprint.FDOCustomization) *osbuild.GrubISOStageOptions {
var architectures []string
if arch == "x86_64" {
if arch == distro.X86_64ArchName {
architectures = []string{"IA32", "X64"}
} else if arch == "aarch64" {
} else if arch == distro.Aarch64ArchName {
architectures = []string{"AA64"}
} else {
panic("unsupported architecture")

View file

@ -278,7 +278,7 @@ func (t *imageType) MIMEType() string {
func (t *imageType) OSTreeRef() string {
d := t.arch.distro
if t.rpmOstree {
return fmt.Sprintf(d.ostreeRefTmpl, t.arch.name)
return fmt.Sprintf(d.ostreeRefTmpl, t.Arch().Name())
}
return ""
}

View file

@ -318,7 +318,7 @@ func TestImageType_Name(t *testing.T) {
for _, dist := range rhelFamilyDistros {
t.Run(dist.name, func(t *testing.T) {
for _, mapping := range imgMap {
if mapping.arch == "s390x" && dist.name == "centos" {
if mapping.arch == distro.S390xArchName && dist.name == "centos" {
continue
}
arch, err := dist.distro.GetArch(mapping.arch)

View file

@ -230,7 +230,7 @@ func edgeInstallerPipelines(t *imageType, customizations *blueprint.Customizatio
pipelines = append(pipelines, *buildPipeline(repos, packageSetSpecs[buildPkgsKey], t.arch.distro.runner))
installerPackages := packageSetSpecs[installerPkgsKey]
d := t.arch.distro
archName := t.arch.name
archName := t.Arch().Name()
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel")
ostreeRepoPath := "/ostree/repo"
payloadStages := ostreePayloadStages(options, ostreeRepoPath)
@ -277,7 +277,7 @@ func imageInstallerPipelines(t *imageType, customizations *blueprint.Customizati
if err != nil {
return nil, err
}
archName := t.arch.name
archName := t.Arch().Name()
d := t.arch.distro
pipelines = append(pipelines, *anacondaTreePipeline(repos, installerPackages, kernelVer, archName, d.product, d.osVersion, "BaseOS", true))
isolabel := fmt.Sprintf(d.isolabelTmpl, archName)
@ -738,7 +738,7 @@ func edgeSimplifiedInstallerPipelines(t *imageType, customizations *blueprint.Cu
// create boot ISO with raw image
d := t.arch.distro
archName := t.arch.name
archName := t.Arch().Name()
installerTreePipeline := simplifiedInstallerTreePipeline(repos, installerPackages, kernelVer, archName, d.product, d.osVersion, "edge", customizations.GetFDO())
isolabel := fmt.Sprintf(d.isolabelTmpl, archName)
efibootTreePipeline := simplifiedInstallerEFIBootTreePipeline(installDevice, kernelVer, archName, d.vendor, d.product, d.osVersion, isolabel, customizations.GetFDO())
@ -1092,7 +1092,7 @@ func qemuPipeline(inputPipelineName, inputFilename, outputFilename string, forma
}
func bootloaderConfigStage(t *imageType, partitionTable disk.PartitionTable, kernelVer string, install, greenboot bool) *osbuild.Stage {
if t.arch.name == distro.S390xArchName {
if t.Arch().Name() == distro.S390xArchName {
return osbuild.NewZiplStage(new(osbuild.ZiplStageOptions))
}

View file

@ -209,9 +209,9 @@ func bootISOMonoStageOptions(kernelVer, arch, vendor, product, osVersion, isolab
func grubISOStageOptions(installDevice, kernelVer, arch, vendor, product, osVersion, isolabel string, fdo *blueprint.FDOCustomization) *osbuild.GrubISOStageOptions {
var architectures []string
if arch == "x86_64" {
if arch == distro.X86_64ArchName {
architectures = []string{"X64"}
} else if arch == "aarch64" {
} else if arch == distro.Aarch64ArchName {
architectures = []string{"AA64"}
} else {
panic("unsupported architecture")

View file

@ -223,7 +223,7 @@ func (t *imageType) MIMEType() string {
func (t *imageType) OSTreeRef() string {
if t.rpmOstree {
return fmt.Sprintf(ostreeRef, t.arch.name)
return fmt.Sprintf(ostreeRef, t.Arch().Name())
}
return ""
}

View file

@ -308,7 +308,7 @@ func TestImageType_Name(t *testing.T) {
for _, dist := range rhelFamilyDistros {
t.Run(dist.name, func(t *testing.T) {
for _, mapping := range imgMap {
if mapping.arch == "s390x" && dist.name == "centos" {
if mapping.arch == distro.S390xArchName && dist.name == "centos" {
continue
}
arch, err := dist.distro.GetArch(mapping.arch)

View file

@ -1097,7 +1097,7 @@ func qemuPipeline(inputPipelineName, inputFilename, outputFilename string, forma
}
func bootloaderConfigStage(t *imageType, partitionTable *disk.PartitionTable, kernel *blueprint.KernelCustomization, kernelVer string) *osbuild.Stage {
if t.arch.name == distro.S390xArchName {
if t.Arch().Name() == distro.S390xArchName {
return osbuild.NewZiplStage(new(osbuild.ZiplStageOptions))
}