Skip to content

Commit

Permalink
mantle: Rework various bits to use new RpmArch() API
Browse files Browse the repository at this point in the history
Fedora/RHEL are *defined* to be self hosting; which means
cross compliation is not at all the default.  See also
https://blog.verbum.org/2012/10/13/building-everything-from-source-vs-self-hosting/

The mantle code was just using Portage architecture because
of CL; unifying on the RPM architecture names as are already used
by cosa will help consolidate things.

Further, we don't need to pass a "Board" all the way down
the stack; since we don't support cross compliation there's no
reason not to just call the new global API to get it.
  • Loading branch information
cgwalters authored and openshift-merge-robot committed Mar 20, 2020
1 parent db6caef commit 2c6efb2
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 60 deletions.
1 change: 0 additions & 1 deletion mantle/cmd/kola/kola.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ func writeProps() error {
Platform: kolaPlatform,
Distro: kola.Options.Distribution,
IgnitionVersion: kola.Options.IgnitionVersion,
Board: kola.QEMUOptions.Board,
OSContainer: kola.Options.OSContainer,
AWS: AWS{
Region: kola.AWSOptions.Region,
Expand Down
2 changes: 0 additions & 2 deletions mantle/cmd/kola/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
var (
outputDir string
kolaPlatform string
defaultTargetBoard = sdk.DefaultBoard()
kolaArchitectures = []string{"amd64"}
kolaPlatforms = []string{"aws", "azure", "do", "esx", "gce", "openstack", "packet", "qemu", "qemu-unpriv"}
kolaDistros = []string{"fcos", "rhcos"}
Expand Down Expand Up @@ -133,7 +132,6 @@ func init() {
sv(&kola.PacketOptions.StorageURL, "packet-storage-url", "gs://users.developer.core-os.net/"+os.Getenv("USER")+"/mantle", "Google Storage base URL for temporary uploads")

// QEMU-specific options
sv(&kola.QEMUOptions.Board, "board", defaultTargetBoard, "target board")
sv(&kola.QEMUOptions.Firmware, "qemu-firmware", "bios", "Boot firmware: bios,uefi,uefi-secure")
sv(&kola.QEMUOptions.DiskImage, "qemu-image", "", "path to CoreOS disk image")
sv(&kola.QEMUOptions.DiskSize, "qemu-size", "", "Resize target disk via qemu-img resize [+]SIZE")
Expand Down
2 changes: 1 addition & 1 deletion mantle/cmd/kola/qemuexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func init() {
func runQemuExec(cmd *cobra.Command, args []string) error {
var err error

builder := platform.NewBuilder(kola.QEMUOptions.Board, ignition, forceConfigInjection)
builder := platform.NewBuilder(ignition, forceConfigInjection)
if len(knetargs) > 0 {
builder.IgnitionNetworkKargs = knetargs
}
Expand Down
1 change: 0 additions & 1 deletion mantle/cmd/kola/testiso.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func runTestIso(cmd *cobra.Command, args []string) error {
CosaBuildDir: kola.Options.CosaBuild,
CosaBuild: kola.CosaBuild,

Board: kola.QEMUOptions.Board,
Firmware: kola.QEMUOptions.Firmware,
}

Expand Down
4 changes: 2 additions & 2 deletions mantle/kola/tests/ignition/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (

ignconverter "github.com/coreos/ign-converter"
ignv3types "github.com/coreos/ignition/v2/config/v3_0/types"
"github.com/coreos/mantle/kola"
"github.com/coreos/mantle/kola/cluster"
"github.com/coreos/mantle/kola/register"
"github.com/coreos/mantle/platform"
"github.com/coreos/mantle/platform/conf"
"github.com/coreos/mantle/platform/machine/unprivqemu"
"github.com/coreos/mantle/system"
"github.com/coreos/mantle/util"
)

Expand Down Expand Up @@ -181,7 +181,7 @@ func createClusterValidate(c cluster.TestCluster, options platform.MachineOption
func setupIgnitionConfig() {
containerpartdeviceid := "by-partlabel/CONTR"
logpartdeviceid := "by-partlabel/LOG"
if kola.QEMUOptions.Board == "s390x-usr" {
if system.RpmArch() == "s390x" {
containerpartdeviceid = "by-partuuid/63194b49-e4b7-43f9-9a8b-df0fd8279bb7"
logpartdeviceid = "by-partuuid/6385b84e-2c7b-4488-a870-667c565e01a8"
}
Expand Down
3 changes: 1 addition & 2 deletions mantle/platform/machine/unprivqemu/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ func (qc *Cluster) NewMachineWithOptions(userdata *conf.UserData, options platfo
consolePath: filepath.Join(dir, "console.txt"),
}

board := qc.flight.opts.Board
builder := platform.NewBuilder(board, confPath, false)
builder := platform.NewBuilder(confPath, false)
defer builder.Close()
builder.Uuid = qm.id
builder.Firmware = qc.flight.opts.Firmware
Expand Down
28 changes: 14 additions & 14 deletions mantle/platform/metal.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strings"

"github.com/coreos/mantle/cosa"
"github.com/coreos/mantle/system"
"github.com/coreos/mantle/system/exec"
"github.com/pkg/errors"
)
Expand All @@ -36,18 +37,17 @@ var liveKargs = []string{"ignition.firstboot", "ignition.platform.id=metal"}
var (
// TODO expose this as an API that can be used by cosa too
consoleKernelArgument = map[string]string{
"amd64-usr": "ttyS0",
"ppc64le-usr": "hvc0",
"arm64-usr": "ttyAMA0",
"s390x-usr": "ttysclp0",
"x86_64": "ttyS0",
"ppc64le": "hvc0",
"aarch64": "ttyAMA0",
"s390x": "ttysclp0",
}
)

type Install struct {
CosaBuildDir string
CosaBuild *cosa.Build

Board string
Firmware string
Insecure bool
QemuArgs []string
Expand Down Expand Up @@ -199,15 +199,15 @@ func (inst *Install) setup(kern *kernelSetup) (*installerRun, error) {
return nil, fmt.Errorf("Missing initramfs artifact")
}

builder := NewBuilder(inst.Board, "", false)
builder := NewBuilder("", false)
builder.Firmware = inst.Firmware
builder.AddDisk(&Disk{
Size: "12G", // Arbitrary
})

// This applies just in the legacy case
builder.Memory = 1536
if inst.Board == "s390x-usr" {
if system.RpmArch() == "s390x" {
// FIXME - determine why this is
builder.Memory = int(math.Max(float64(builder.Memory), 16384))
}
Expand Down Expand Up @@ -245,23 +245,23 @@ func (inst *Install) setup(kern *kernelSetup) (*installerRun, error) {

pxe := pxeSetup{}
pxe.tftpipaddr = "192.168.76.2"
switch inst.Board {
case "amd64-usr":
switch system.RpmArch() {
case "x86_64":
pxe.boottype = "pxe"
pxe.networkdevice = "e1000"
pxe.pxeimagepath = "/usr/share/syslinux/"
break
case "ppc64le-usr":
case "ppc64le":
pxe.boottype = "grub"
pxe.networkdevice = "virtio-net-pci"
break
case "s390x-usr":
case "s390x":
pxe.boottype = "pxe"
pxe.networkdevice = "virtio-net-ccw"
pxe.tftpipaddr = "10.0.2.2"
pxe.bootindex = "1"
default:
return nil, fmt.Errorf("Unsupported arch %s", inst.Board)
return nil, fmt.Errorf("Unsupported arch %s" + system.RpmArch())
}

mux := http.NewServeMux()
Expand Down Expand Up @@ -297,7 +297,7 @@ func (inst *Install) setup(kern *kernelSetup) (*installerRun, error) {
}

func renderBaseKargs(t *installerRun) []string {
return append(baseKargs, fmt.Sprintf("console=%s", consoleKernelArgument[t.inst.Board]))
return append(baseKargs, fmt.Sprintf("console=%s", consoleKernelArgument[system.RpmArch()]))
}

func renderInstallKargs(t *installerRun) []string {
Expand Down Expand Up @@ -338,7 +338,7 @@ func (t *installerRun) completePxeSetup(kargs []string) error {
KERNEL %s
APPEND initrd=%s %s
`, t.kern.kernel, t.kern.initramfs, kargsStr))
if t.inst.Board == "s390x-usr" {
if system.RpmArch() == "s390x" {
pxeconfig = []byte(kargsStr)
}
ioutil.WriteFile(filepath.Join(pxeconfigdir, "default"), pxeconfig, 0777)
Expand Down
64 changes: 27 additions & 37 deletions mantle/platform/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"syscall"

"github.com/coreos/mantle/system"
"github.com/coreos/mantle/system/exec"
"github.com/coreos/mantle/util"
"github.com/pkg/errors"
Expand Down Expand Up @@ -136,8 +136,6 @@ func (inst *QemuInstance) Destroy() {

// QemuBuilder is a configurator that can then create a qemu instance
type QemuBuilder struct {
Board string

// Config is a path to Ignition configuration
Config string

Expand Down Expand Up @@ -165,9 +163,8 @@ type QemuBuilder struct {
fds []*os.File
}

func NewBuilder(board, config string, forceIgnInjection bool) *QemuBuilder {
func NewBuilder(config string, forceIgnInjection bool) *QemuBuilder {
ret := QemuBuilder{
Board: board,
Config: config,
ForceConfigInjection: forceIgnInjection,
Firmware: "bios",
Expand All @@ -188,17 +185,17 @@ func (builder *QemuBuilder) AddFd(fd *os.File) string {
}

// virtio returns a virtio device argument for qemu, which is architecture dependent
func virtio(board, device, args string) string {
func virtio(device, args string) string {
var suffix string
switch board {
case "amd64-usr", "ppc64le-usr":
switch system.RpmArch() {
case "x86_64", "ppc64le":
suffix = "pci"
case "arm64-usr":
case "aarch64":
suffix = "device"
case "s390x-usr":
case "s390x":
suffix = "ccw"
default:
panic(board)
panic(fmt.Sprintf("RpmArch %s unhandled in virtio()", system.RpmArch()))
}
return fmt.Sprintf("virtio-%s-%s,%s", device, suffix, args)
}
Expand All @@ -215,7 +212,7 @@ func (builder *QemuBuilder) addQcow2DiskFd(fd *os.File, channel string, options
builder.diskId += 1
switch channel {
case "virtio":
builder.Append("-device", virtio(builder.Board, "blk", fmt.Sprintf("drive=%s%s", id, opts)))
builder.Append("-device", virtio("blk", fmt.Sprintf("drive=%s%s", id, opts)))
case "nvme":
builder.Append("-device", fmt.Sprintf("nvme,drive=%s%s", id, opts))
default:
Expand All @@ -238,14 +235,14 @@ func (builder *QemuBuilder) EnableUsermodeNetworking(forwardedPort uint) {
netdev += fmt.Sprintf(",hostname=%s", builder.Hostname)
}

builder.Append("-netdev", netdev, "-device", virtio(builder.Board, "net", "netdev=eth0"))
builder.Append("-netdev", netdev, "-device", virtio("net", "netdev=eth0"))
}

// supportsFwCfg if the target system supports injecting
// Ignition via the qemu -fw_cfg option.
func (builder *QemuBuilder) supportsFwCfg() bool {
switch builder.Board {
case "s390x-usr", "ppc64le-usr":
switch system.RpmArch() {
case "s390x", "ppc64le":
return false
}
return true
Expand All @@ -255,8 +252,8 @@ func (builder *QemuBuilder) supportsFwCfg() bool {
func (builder *QemuBuilder) supportsSwtpm() bool {
// Yes, this is the same as supportsFwCfg *currently* but
// might not be in the future.
switch builder.Board {
case "s390x-usr", "ppc64le-usr":
switch system.RpmArch() {
case "s390x", "ppc64le":
return false
}
return true
Expand Down Expand Up @@ -512,10 +509,10 @@ func (builder *QemuBuilder) finalize() {

// Then later, other non-x86_64 seemed to just copy that.
memory := 1024
switch builder.Board {
case "arm64-usr":
case "s390x-usr":
case "ppc64le-usr":
switch system.RpmArch() {
case "aarch64":
case "s390x":
case "ppc64le":
memory = 2048
}
builder.Memory = memory
Expand All @@ -529,40 +526,33 @@ func (builder *QemuBuilder) Append(args ...string) {

// baseQemuArgs takes a board and returns the basic qemu
// arguments needed for the current architecture.
func baseQemuArgs(board string) []string {
combo := runtime.GOARCH + "--" + board
switch combo {
case "amd64--amd64-usr":
func baseQemuArgs() []string {
switch system.RpmArch() {
case "x86_64":
return []string{
"qemu-system-x86_64",
"-machine", "accel=kvm",
"-cpu", "host",
}
case "amd64--arm64-usr":
return []string{
"qemu-system-aarch64",
"-machine", "virt",
"-cpu", "cortex-a57",
}
case "arm64--arm64-usr":
case "aarch64":
return []string{
"qemu-system-aarch64",
"-machine", "virt,accel=kvm,gic-version=3",
"-cpu", "host",
}
case "s390x--s390x-usr":
case "s390x":
return []string{
"qemu-system-s390x",
"-machine", "s390-ccw-virtio,accel=kvm",
"-cpu", "host",
}
case "ppc64le--ppc64le-usr":
case "ppc64le":
return []string{
"qemu-system-ppc64",
"-machine", "pseries,accel=kvm,kvm-type=HV",
}
default:
panic("host-guest combo not supported: " + combo)
panic(fmt.Sprintf("RpmArch %s combo not supported for qemu ", system.RpmArch()))
}
}

Expand Down Expand Up @@ -601,7 +591,7 @@ func (builder *QemuBuilder) Exec() (*QemuInstance, error) {

inst := QemuInstance{}

argv := baseQemuArgs(builder.Board)
argv := baseQemuArgs()
argv = append(argv, "-m", fmt.Sprintf("%d", builder.Memory))

switch builder.Firmware {
Expand All @@ -618,7 +608,7 @@ func (builder *QemuBuilder) Exec() (*QemuInstance, error) {

// We always provide a random source
argv = append(argv, "-object", "rng-random,filename=/dev/urandom,id=rng0",
"-device", virtio(builder.Board, "rng", "rng=rng0"))
"-device", virtio("rng", "rng=rng0"))
if builder.Uuid != "" {
argv = append(argv, "-uuid", builder.Uuid)
}
Expand Down

0 comments on commit 2c6efb2

Please sign in to comment.