Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 57 additions & 10 deletions mantle/cmd/kola/testiso.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,16 @@ func newBaseQemuBuilder() *platform.QemuBuilder {
return builder
}

func newQemuBuilder(isPXE bool, outdir string) (*platform.QemuBuilder, *conf.Conf, error) {
func newQemuBuilder(outdir string) (*platform.QemuBuilder, *conf.Conf, error) {
builder := newBaseQemuBuilder()
sectorSize := 0
if kola.QEMUOptions.Native4k {
sectorSize = 4096
}

if system.RpmArch() == "s390x" && isPXE {
// For s390x PXE installs the network device has the bootindex of 1.
// Do not use a primary disk in case of net-booting for this test
//TBD: see if we can remove this and just use AddDisk and inject bootindex during startup
if system.RpmArch() == "s390x" || system.RpmArch() == "aarch64" {
// s390x and aarch64 need to use bootindex as they don't support boot once
builder.AddDisk(&platform.Disk{
Size: "12G", // Arbitrary

Expand Down Expand Up @@ -365,7 +365,47 @@ func runTestIso(cmd *cobra.Command, args []string) error {
return nil
}

func awaitCompletion(inst *platform.QemuInstance, outdir string, qchan *os.File, expected []string) error {
// Currently effective on aarch64: switches the boot order to boot from disk on reboot. For s390x and aarch64, bootindex
// is used to boot from the network device (boot once is not supported). For s390x, the boot ordering was not a problem as it
// would always read from disk first. For aarch64, the bootindex needs to be switched to boot from disk before a reboot
func switchBootOrder(tempdir string) error {
if tempdir == "" || (system.RpmArch() != "s390x" && system.RpmArch() != "aarch64") {
//Not applicable for iso installs and other arches
return nil
}
monitor, devs, err := platform.ListQMPDevices(tempdir)
if monitor != nil {
defer monitor.Disconnect()
}
if err != nil {
return errors.Wrapf(err, "Could not list devices")
}
var blkdev string
var netdev string
for _, dev := range devs.Return {
switch dev.Type {
case "child<virtio-net-pci>", "child<virtio-net-ccw>":
netdev = filepath.Join("/machine/peripheral-anon", dev.Name)
break
case "child<virtio-blk-device>", "child<virtio-blk-pci>", "child<virtio-blk-ccw>":
blkdev = filepath.Join("/machine/peripheral-anon", dev.Name)
break
default:
break
}
}
// unset bootindex for the network device
if err := platform.SetBootIndexForDevice(monitor, netdev, -1); err != nil {
return errors.Wrapf(err, "Could not set bootindex for netdev")
}
// set bootindex to 1 to boot from disk
if err := platform.SetBootIndexForDevice(monitor, blkdev, 1); err != nil {
return errors.Wrapf(err, "Could not set bootindex for blkdev")
}
return nil
}

func awaitCompletion(inst *platform.QemuInstance, outdir string, tempdir string, qchan *os.File, expected []string) error {
errchan := make(chan error)
go func() {
time.Sleep(installTimeout)
Expand Down Expand Up @@ -416,6 +456,13 @@ func awaitCompletion(inst *platform.QemuInstance, outdir string, qchan *os.File,
errchan <- fmt.Errorf("Unexpected string from completion channel: %s expected: %s", line, exp)
return
}
// switch the boot order here, we are well into the installation process. Only used for PXE test now
if line == liveOKSignal {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is completely fine for now though I think the functionality would better live in metal.go - that's intending to be the abstraction over performing an install, whereas testiso.go is just about testing.

Concretely eventually we want kola run -p pxe-install podman.* and cosa run -p pxe-install which would run tests/give you ssh after doing a PXE install, rather than how testiso.go is hardcoded to just a sanity check.

Fine for now though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree. I was going to do some refactoring around this and try to move everything to metal. But - for this particular case, is there a better place in metal.go to figure out that we have started with the installation process and can switch the boot order?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's totally fine as is, feel free to just add a comment for this and we can do it later. Given the size of change here I'd prefer to get it in than force you into rebasing later etc.

But if you want to take a quick shot at it I think what metal.go should do is inject its own Ignition to write to a separate virtio channel, distinct from what testiso.go is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah..ok got it ..yes..i'll try to tackle that separately :) i'll stick with these changes for now and probably move some of the QMP bits to its own package.

if err := switchBootOrder(tempdir); err != nil {
errchan <- errors.Wrapf(err, "switching boot order failed")
return
}
}
}
// OK!
errchan <- nil
Expand Down Expand Up @@ -443,7 +490,7 @@ func testPXE(inst platform.Install, outdir string, offline bool) error {
return err
}

builder, virtioJournalConfig, err := newQemuBuilder(true, outdir)
builder, virtioJournalConfig, err := newQemuBuilder(outdir)
if err != nil {
return err
}
Expand Down Expand Up @@ -481,7 +528,7 @@ func testPXE(inst platform.Install, outdir string, offline bool) error {
signals = append(signals, liveOKSignal)
}
signals = append(signals, signalCompleteString)
return awaitCompletion(mach.QemuInst, outdir, completionChannel, signals)
return awaitCompletion(mach.QemuInst, outdir, mach.Tempdir, completionChannel, signals)
}

func testLiveIso(inst platform.Install, outdir string, offline bool) error {
Expand All @@ -496,7 +543,7 @@ func testLiveIso(inst platform.Install, outdir string, offline bool) error {
return err
}

builder, virtioJournalConfig, err := newQemuBuilder(true, outdir)
builder, virtioJournalConfig, err := newQemuBuilder(outdir)
if err != nil {
return err
}
Expand All @@ -522,7 +569,7 @@ func testLiveIso(inst platform.Install, outdir string, offline bool) error {
}
defer mach.Destroy()

return awaitCompletion(mach.QemuInst, outdir, completionChannel, []string{liveOKSignal, signalCompleteString})
return awaitCompletion(mach.QemuInst, outdir, "", completionChannel, []string{liveOKSignal, signalCompleteString})
}

func testLiveLogin(outdir string) error {
Expand Down Expand Up @@ -550,5 +597,5 @@ func testLiveLogin(outdir string) error {
}
defer mach.Destroy()

return awaitCompletion(mach, outdir, completionChannel, []string{"coreos-liveiso-success"})
return awaitCompletion(mach, outdir, "", completionChannel, []string{"coreos-liveiso-success"})
}
2 changes: 2 additions & 0 deletions mantle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ require (
github.com/coreos/ioprogress v0.0.0-20151023204047-4637e494fd9b
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f
github.com/coreos/vcontext v0.0.0-20191017033345-260217907eb5 // indirect
github.com/digitalocean/go-libvirt v0.0.0-20200810224808-b9c702499bf7 // indirect
github.com/digitalocean/go-qemu v0.0.0-20200529005954-1b453d036a9c
github.com/digitalocean/godo v1.33.0
github.com/dimchansky/utfbom v1.1.0 // indirect
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813
Expand Down
4 changes: 4 additions & 0 deletions mantle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/digitalocean/go-libvirt v0.0.0-20200810224808-b9c702499bf7 h1:7469SEjOVNTL7ZRvLOJYp2jkQaLhggxYithWSHvXIGs=
github.com/digitalocean/go-libvirt v0.0.0-20200810224808-b9c702499bf7/go.mod h1:UMlaMc4V1DeGbb53Bw12wwvepjpg/D8xhrdL0wfS6Hs=
github.com/digitalocean/go-qemu v0.0.0-20200529005954-1b453d036a9c h1:N2oJLGil1ov9DNz8wx0/IiBZ0kOlRQlHHwx2CFGmovA=
github.com/digitalocean/go-qemu v0.0.0-20200529005954-1b453d036a9c/go.mod h1:/YnlngP1PARC0SKAZx6kaAEMOp8bNTQGqS+Ka3MctNI=
github.com/digitalocean/godo v1.33.0 h1:JNZ/0v/Wp//UAIh84YWZ/x5neB3V5lKgcCHzyqErMJQ=
github.com/digitalocean/godo v1.33.0/go.mod h1:iJnN9rVu6K5LioLxLimlq0uRI+y/eAQjROUmeU/r0hY=
github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4=
Expand Down
38 changes: 27 additions & 11 deletions mantle/platform/metal.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type Install struct {
}

type InstalledMachine struct {
tempdir string
Tempdir string
QemuInst *QemuInstance
}

Expand Down Expand Up @@ -150,8 +150,8 @@ func (inst *InstalledMachine) Destroy() error {
inst.QemuInst.Destroy()
inst.QemuInst = nil
}
if inst.tempdir != "" {
return os.RemoveAll(inst.tempdir)
if inst.Tempdir != "" {
return os.RemoveAll(inst.Tempdir)
}
return nil
}
Expand Down Expand Up @@ -305,9 +305,17 @@ func (inst *Install) setup(kern *kernelSetup, legacy bool) (*installerRun, error
pxe.networkdevice = "e1000"
pxe.pxeimagepath = "/usr/share/syslinux/"
break
case "aarch64":
pxe.boottype = "grub"
pxe.networkdevice = "virtio-net-pci"
pxe.bootfile = "/boot/grub2/grubaa64.efi"
pxe.pxeimagepath = "/boot/efi/EFI/fedora/grubaa64.efi"
pxe.bootindex = "1"
break
case "ppc64le":
pxe.boottype = "grub"
pxe.networkdevice = "virtio-net-pci"
pxe.bootfile = "/boot/grub2/powerpc-ieee1275/core.elf"
break
case "s390x":
pxe.boottype = "pxe"
Expand Down Expand Up @@ -381,7 +389,6 @@ func (t *installerRun) completePxeSetup(kargs []string) error {
}
kargsStr := strings.Join(kargs, " ")

var bootfile string
switch t.pxe.boottype {
case "pxe":
pxeconfigdir := filepath.Join(t.tftpdir, "pxelinux.cfg")
Expand Down Expand Up @@ -420,17 +427,22 @@ func (t *installerRun) completePxeSetup(kargs []string) error {
}
}
}
bootfile = "/" + pxeimages[0]
t.pxe.bootfile = "/" + pxeimages[0]
break
case "grub":
bootfile = "/boot/grub2/powerpc-ieee1275/core.elf"
if err := exec.Command("grub2-mknetdir", "--net-directory="+t.tftpdir).Run(); err != nil {
return err
}
if t.pxe.pxeimagepath != "" {
dstpath := filepath.Join(t.tftpdir, "boot/grub2")
if err := exec.Command("/usr/lib/coreos-assembler/cp-reflink", t.pxe.pxeimagepath, dstpath).Run(); err != nil {
return err
}
}
ioutil.WriteFile(filepath.Join(t.tftpdir, "boot/grub2/grub.cfg"), []byte(fmt.Sprintf(`
default=0
timeout=1
menuentry "CoreOS (BIOS)" {
menuentry "CoreOS (BIOS/UEFI)" {
echo "Loading kernel"
linux /%s %s
echo "Loading initrd"
Expand All @@ -442,8 +454,6 @@ func (t *installerRun) completePxeSetup(kargs []string) error {
panic("Unhandled boottype " + t.pxe.boottype)
}

t.pxe.bootfile = bootfile

return nil
}

Expand All @@ -469,6 +479,12 @@ func cat(outfile string, infiles ...string) error {

func (t *installerRun) run() (*QemuInstance, error) {
builder := t.builder
// qmp device for switching boot order (needed for aarch64)
qmpPath := filepath.Join(t.tempdir, "qmp.sock")
qmpID := "pxe-qmp"
builder.Append("-chardev", fmt.Sprintf("socket,id=%s,path=%s,server,nowait", qmpID, qmpPath))
builder.Append("-mon", fmt.Sprintf("chardev=%s,mode=control", qmpID))

netdev := fmt.Sprintf("%s,netdev=mynet0,mac=52:54:00:12:34:56", t.pxe.networkdevice)
if t.pxe.bootindex == "" {
builder.Append("-boot", "once=n", "-option-rom", "/usr/share/qemu/pxe-rtl8139.rom")
Expand Down Expand Up @@ -515,7 +531,7 @@ func (inst *Install) runPXE(kern *kernelSetup, legacy, offline bool) (*Installed
t.tempdir = "" // Transfer ownership
return &InstalledMachine{
QemuInst: qinst,
tempdir: tempdir,
Tempdir: tempdir,
}, nil
}

Expand Down Expand Up @@ -641,6 +657,6 @@ WantedBy=multi-user.target
cleanupTempdir = false // Transfer ownership
return &InstalledMachine{
QemuInst: qinst,
tempdir: tempdir,
Tempdir: tempdir,
}, nil
}
83 changes: 83 additions & 0 deletions mantle/platform/qmp_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2020 Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// The Qemu Machine Protocol - to remotely query and operate a qemu instance (https://wiki.qemu.org/Documentation/QMP)

package platform

import (
"encoding/json"
"fmt"
"path/filepath"
"time"

"github.com/coreos/mantle/util"
"github.com/pkg/errors"

"github.com/digitalocean/go-qemu/qmp"
)

type QOMDev struct {
Return []struct {
Name string `json:"name"`
Type string `json:"type"`
} `json:"return"`
}

// Create a new QMP socket connection
func newQMPMonitor(sockaddr string) (*qmp.SocketMonitor, error) {
qmpPath := filepath.Join(sockaddr, "qmp.sock")
var monitor *qmp.SocketMonitor
var err error
if err := util.Retry(10, 1*time.Second, func() error {
monitor, err = qmp.NewSocketMonitor("unix", qmpPath, 2*time.Second)
if err != nil {
return err
}
return nil
}); err != nil {
return nil, errors.Wrapf(err, "Connecting to qemu monitor")
}
return monitor, nil
}

// Executes a query which provides the list of devices and their names
func ListQMPDevices(sockaddr string) (*qmp.SocketMonitor, *QOMDev, error) {
monitor, err := newQMPMonitor(sockaddr)
if err != nil {
return nil, nil, errors.Wrapf(err, "Could not open monitor")
}

monitor.Connect()
listcmd := []byte(`{ "execute": "qom-list", "arguments": { "path": "/machine/peripheral-anon" } }`)
out, err := monitor.Run(listcmd)
if err != nil {
return monitor, nil, errors.Wrapf(err, "Running QMP list command")
}

var devs QOMDev
if err = json.Unmarshal(out, &devs); err != nil {
return monitor, nil, errors.Wrapf(err, "De-serializing QMP output")
}
return monitor, &devs, nil
}

// Set the bootindex for the particular device
func SetBootIndexForDevice(monitor *qmp.SocketMonitor, device string, bootindex int) error {
cmd := fmt.Sprintf(`{ "execute":"qom-set", "arguments": { "path":"%s", "property":"bootindex", "value":%d } }`, device, bootindex)
if _, err := monitor.Run([]byte(cmd)); err != nil {
return errors.Wrapf(err, "Running QMP command")
}
return nil
}
Loading