Skip to content

Commit

Permalink
pkg/arch: split arch from pkg/platform
Browse files Browse the repository at this point in the history
This allows importing the architecture separately, and will help getting
rid of inline string literals in composer.
  • Loading branch information
croissanne committed Nov 24, 2023
1 parent 3949edc commit 2a7af31
Show file tree
Hide file tree
Showing 41 changed files with 196 additions and 162 deletions.
16 changes: 8 additions & 8 deletions cmd/osbuild-dnf-json-tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/distro"
rhel "github.com/osbuild/images/pkg/distro/rhel8"
"github.com/osbuild/images/internal/dnfjson"
"github.com/osbuild/images/pkg/ostree"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
)

Expand Down Expand Up @@ -85,22 +85,22 @@ func TestDepsolvePackageSets(t *testing.T) {

// Set up temporary directory for rpm/dnf cache
dir := t.TempDir()
solver := dnfjson.NewSolver(cs9.ModulePlatformID(), cs9.Releasever(), platform.ARCH_X86_64.String(), cs9.Name(), dir)
solver := dnfjson.NewSolver(cs9.ModulePlatformID(), cs9.Releasever(), arch.ARCH_X86_64.String(), cs9.Name(), dir)

repos, err := rpmmd.LoadRepositories([]string{repoDir}, cs9.Name())
require.NoErrorf(t, err, "Failed to LoadRepositories %v", cs9.Name())
x86Repos, ok := repos[platform.ARCH_X86_64.String()]
require.Truef(t, ok, "failed to get %q repos for %q", platform.ARCH_X86_64.String(), cs9.Name())
x86Repos, ok := repos[arch.ARCH_X86_64.String()]
require.Truef(t, ok, "failed to get %q repos for %q", arch.ARCH_X86_64.String(), cs9.Name())

x86Arch, err := cs9.GetArch(platform.ARCH_X86_64.String())
require.Nilf(t, err, "failed to get %q arch of %q distro", platform.ARCH_X86_64.String(), cs9.Name())
x86Arch, err := cs9.GetArch(arch.ARCH_X86_64.String())
require.Nilf(t, err, "failed to get %q arch of %q distro", arch.ARCH_X86_64.String(), cs9.Name())

qcow2ImageTypeName := "qcow2"
qcow2Image, err := x86Arch.GetImageType(qcow2ImageTypeName)
require.Nilf(t, err, "failed to get %q image type of %q/%q distro/arch", qcow2ImageTypeName, cs9.Name(), platform.ARCH_X86_64.String())
require.Nilf(t, err, "failed to get %q image type of %q/%q distro/arch", qcow2ImageTypeName, cs9.Name(), arch.ARCH_X86_64.String())

manifestSource, _, err := qcow2Image.Manifest(&blueprint.Blueprint{Packages: []blueprint.Package{{Name: "bind"}}}, distro.ImageOptions{}, x86Repos, 0)
require.Nilf(t, err, "failed to initialise manifest for %q image type of %q/%q distro/arch", qcow2ImageTypeName, cs9.Name(), platform.ARCH_X86_64.String())
require.Nilf(t, err, "failed to initialise manifest for %q image type of %q/%q distro/arch", qcow2ImageTypeName, cs9.Name(), arch.ARCH_X86_64.String())
imagePkgSets := manifestSource.GetPackageSetChains()

gotPackageSpecsSets := make(map[string][]rpmmd.PackageSpec, len(imagePkgSets))
Expand Down
6 changes: 3 additions & 3 deletions internal/boot/context-managers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/osbuild/images/cmd/osbuild-image-tests/constants"
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/arch"
)

// WithNetworkNamespace provides the function f with a new network namespace
Expand Down Expand Up @@ -111,7 +111,7 @@ func WithBootedQemuImage(image string, ns NetNS, f func() error) error {
}

var qemuCmd *exec.Cmd
if common.CurrentArch() == "x86_64" {
if common.CurrentArch() == arch.ARCH_X86_64.String() {
hostDistroName, _, _, err := common.GetHostDistroName()
if err != nil {
return fmt.Errorf("cannot determing the current distro: %v", err)
Expand All @@ -136,7 +136,7 @@ func WithBootedQemuImage(image string, ns NetNS, f func() error) error {
"-nographic",
image,
)
} else if common.CurrentArch() == platform.ARCH_AARCH64.String() {
} else if common.CurrentArch() == arch.ARCH_AARCH64.String() {
// 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(
Expand Down
25 changes: 25 additions & 0 deletions pkg/arch/arch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package arch

type Arch uint64

const ( // architecture enum
ARCH_AARCH64 Arch = iota
ARCH_PPC64LE
ARCH_S390X
ARCH_X86_64
)

func (a Arch) String() string {
switch a {
case ARCH_AARCH64:
return "aarch64"
case ARCH_PPC64LE:
return "ppc64le"
case ARCH_S390X:
return "s390x"
case ARCH_X86_64:
return "x86_64"
default:
panic("invalid architecture")
}
}
9 changes: 5 additions & 4 deletions pkg/distro/fedora/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/osbuild/images/internal/environment"
"github.com/osbuild/images/internal/fsnode"
"github.com/osbuild/images/internal/oscap"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/platform"
Expand Down Expand Up @@ -532,23 +533,23 @@ func newDistro(version int) distro.Distro {

// Architecture definitions
x86_64 := architecture{
name: platform.ARCH_X86_64.String(),
name: arch.ARCH_X86_64.String(),
distro: &rd,
}

aarch64 := architecture{
name: platform.ARCH_AARCH64.String(),
name: arch.ARCH_AARCH64.String(),
distro: &rd,
}

ppc64le := architecture{
distro: &rd,
name: platform.ARCH_PPC64LE.String(),
name: arch.ARCH_PPC64LE.String(),
}

s390x := architecture{
distro: &rd,
name: platform.ARCH_S390X.String(),
name: arch.ARCH_S390X.String(),
}

ociImgType := qcow2ImgType
Expand Down
6 changes: 3 additions & 3 deletions pkg/distro/fedora/package_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/rpmmd"
)

Expand Down Expand Up @@ -364,7 +364,7 @@ func anacondaPackageSet(t *imageType) rpmmd.PackageSet {
}

switch t.Arch().Name() {
case platform.ARCH_X86_64.String():
case arch.ARCH_X86_64.String():
ps = ps.Append(rpmmd.PackageSet{
Include: []string{
"biosdevname",
Expand All @@ -374,7 +374,7 @@ func anacondaPackageSet(t *imageType) rpmmd.PackageSet {
},
})

case platform.ARCH_AARCH64.String():
case arch.ARCH_AARCH64.String():
ps = ps.Append(rpmmd.PackageSet{
Include: []string{
"dmidecode",
Expand Down
22 changes: 11 additions & 11 deletions pkg/distro/fedora/partition_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package fedora

import (
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/platform"
)

var defaultBasePartitionTables = distro.BasePartitionTableMap{
platform.ARCH_X86_64.String(): disk.PartitionTable{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Partitions: []disk.Partition{
Expand Down Expand Up @@ -60,7 +60,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
},
},
},
platform.ARCH_AARCH64.String(): disk.PartitionTable{
arch.ARCH_AARCH64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Partitions: []disk.Partition{
Expand Down Expand Up @@ -106,7 +106,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
},
},
},
platform.ARCH_PPC64LE.String(): disk.PartitionTable{
arch.ARCH_PPC64LE.String(): disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Partitions: []disk.Partition{
Expand Down Expand Up @@ -139,7 +139,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
},
},

platform.ARCH_S390X.String(): disk.PartitionTable{
arch.ARCH_S390X.String(): disk.PartitionTable{
UUID: "0x14fc63d2",
Type: "dos",
Partitions: []disk.Partition{
Expand Down Expand Up @@ -170,7 +170,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
}

var minimalrawPartitionTables = distro.BasePartitionTableMap{
platform.ARCH_X86_64.String(): disk.PartitionTable{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
StartOffset: 8 * common.MebiByte,
Expand Down Expand Up @@ -217,7 +217,7 @@ var minimalrawPartitionTables = distro.BasePartitionTableMap{
},
},
},
platform.ARCH_AARCH64.String(): disk.PartitionTable{
arch.ARCH_AARCH64.String(): disk.PartitionTable{
UUID: "0xc1748067",
Type: "dos",
StartOffset: 8 * common.MebiByte,
Expand Down Expand Up @@ -265,7 +265,7 @@ var minimalrawPartitionTables = distro.BasePartitionTableMap{
}

var iotBasePartitionTables = distro.BasePartitionTableMap{
platform.ARCH_X86_64.String(): disk.PartitionTable{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Partitions: []disk.Partition{
Expand Down Expand Up @@ -311,7 +311,7 @@ var iotBasePartitionTables = distro.BasePartitionTableMap{
},
},
},
platform.ARCH_AARCH64.String(): disk.PartitionTable{
arch.ARCH_AARCH64.String(): disk.PartitionTable{
UUID: "0xc1748067",
Type: "dos",
Partitions: []disk.Partition{
Expand Down Expand Up @@ -358,7 +358,7 @@ var iotBasePartitionTables = distro.BasePartitionTableMap{
}

var iotSimplifiedInstallerPartitionTables = distro.BasePartitionTableMap{
platform.ARCH_X86_64.String(): disk.PartitionTable{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Partitions: []disk.Partition{
Expand Down Expand Up @@ -428,7 +428,7 @@ var iotSimplifiedInstallerPartitionTables = distro.BasePartitionTableMap{
},
},
},
platform.ARCH_AARCH64.String(): disk.PartitionTable{
arch.ARCH_AARCH64.String(): disk.PartitionTable{
UUID: "0xc1748067",
Type: "dos",
Partitions: []disk.Partition{
Expand Down
4 changes: 2 additions & 2 deletions pkg/distro/rhel7/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package rhel7

import (
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/images/pkg/subscription"
)
Expand Down Expand Up @@ -273,7 +273,7 @@ func azureRhuiCommonPackageSet(t *imageType) rpmmd.PackageSet {
}

var azureRhuiBasePartitionTables = distro.BasePartitionTableMap{
platform.ARCH_X86_64.String(): disk.PartitionTable{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Size: 64 * common.GibiByte,
Expand Down
3 changes: 2 additions & 1 deletion pkg/distro/rhel7/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/platform"
Expand Down Expand Up @@ -200,7 +201,7 @@ func newDistro(distroName string) distro.Distro {

// Architecture definitions
x86_64 := architecture{
name: platform.ARCH_X86_64.String(),
name: arch.ARCH_X86_64.String(),
distro: &rd,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/distro/rhel7/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/users"
"github.com/osbuild/images/internal/workload"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/container"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/image"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
)

Expand All @@ -40,7 +40,7 @@ func osCustomizations(
kernelOptions = append(kernelOptions, bpKernel.Append)
}
osc.KernelOptionsAppend = kernelOptions
if t.platform.GetArch() != platform.ARCH_S390X {
if t.platform.GetArch() != arch.ARCH_S390X {
osc.KernelOptionsBootloader = true
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/distro/rhel7/partition_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package rhel7

import (
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/platform"
)

var defaultBasePartitionTables = distro.BasePartitionTableMap{
platform.ARCH_X86_64.String(): disk.PartitionTable{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Partitions: []disk.Partition{
Expand Down
6 changes: 3 additions & 3 deletions pkg/distro/rhel8/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package rhel8
import (
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/shell"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/images/pkg/subscription"
)
Expand Down Expand Up @@ -261,7 +261,7 @@ func azureEapPackageSet(t *imageType) rpmmd.PackageSet {
// PARTITION TABLES

var azureRhuiBasePartitionTables = distro.BasePartitionTableMap{
platform.ARCH_X86_64.String(): disk.PartitionTable{
arch.ARCH_X86_64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Size: 64 * common.GibiByte,
Expand Down Expand Up @@ -369,7 +369,7 @@ var azureRhuiBasePartitionTables = distro.BasePartitionTableMap{
},
},
},
platform.ARCH_AARCH64.String(): disk.PartitionTable{
arch.ARCH_AARCH64.String(): disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Size: 64 * common.GibiByte,
Expand Down
Loading

0 comments on commit 2a7af31

Please sign in to comment.