Skip to content

Commit 71b296b

Browse files
kola: refactor iso.as-disk* tests
1 parent 519f028 commit 71b296b

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

mantle/kola/tests/iso/live-as-disk.go

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"github.com/coreos/coreos-assembler/mantle/kola"
77
"github.com/coreos/coreos-assembler/mantle/kola/cluster"
88
"github.com/coreos/coreos-assembler/mantle/kola/register"
9+
"github.com/coreos/coreos-assembler/mantle/platform"
910
"github.com/coreos/coreos-assembler/mantle/platform/conf"
1011
"github.com/coreos/coreos-assembler/mantle/platform/machine/qemu"
12+
"github.com/pkg/errors"
1113
)
1214

1315
func init() {
@@ -16,7 +18,6 @@ func init() {
1618
register.RegisterTest(isoTest("as-disk", isoAsDisk, []string{"x86_64"}))
1719
register.RegisterTest(isoTest("as-disk.uefi", isoAsDiskUefi, []string{"x86_64"}))
1820
register.RegisterTest(isoTest("as-disk.uefi-secure", isoAsDiskUefiSecure, []string{"x86_64"}))
19-
register.RegisterTest(isoTest("as-disk.4k.uefi", isoAsDisk4kUefi, []string{"x86_64"}))
2021
}
2122

2223
func isoAsDisk(c cluster.TestCluster) {
@@ -40,53 +41,57 @@ func isoAsDiskUefiSecure(c cluster.TestCluster) {
4041
isoTestAsDisk(c, opts)
4142
}
4243

43-
func isoAsDisk4kUefi(c cluster.TestCluster) {
44-
opts := IsoTestOpts{
45-
enable4k: true,
46-
enableUefi: true,
47-
}
48-
opts.SetInsecureOnDevBuild()
49-
isoTestAsDisk(c, opts)
50-
}
51-
5244
func isoTestAsDisk(c cluster.TestCluster, opts IsoTestOpts) {
53-
var outdir string
54-
//var qc *qemu.Cluster
55-
switch pc := c.Cluster.(type) {
56-
case *qemu.Cluster:
57-
outdir = pc.RuntimeConf().OutputDir
58-
//qc = pc
59-
default:
45+
qc, ok := c.Cluster.(*qemu.Cluster)
46+
if !ok {
6047
c.Fatalf("Unsupported cluster type")
6148
}
6249

63-
isopath := filepath.Join(kola.CosaBuild.Dir, kola.CosaBuild.Meta.BuildArtifacts.LiveIso.Path)
64-
builder, config, err := newQemuBuilder(opts, outdir)
50+
config, err := conf.EmptyIgnition().Render(conf.FailWarnings)
6551
if err != nil {
6652
c.Fatal(err)
6753
}
68-
defer builder.Close()
69-
// Drop the bootindex bit (applicable to all arches except s390x and ppc64le); we want it to be the default
70-
if err := builder.AddIso(isopath, "", true); err != nil {
54+
config.AddSystemdUnit("live-signal-ok.service", liveSignalOKUnit, conf.Enable)
55+
config.AddSystemdUnit("verify-no-efi-boot-entry.service", verifyNoEFIBootEntry, conf.Enable)
56+
keys, err := qc.Keys()
57+
if err != nil {
7158
c.Fatal(err)
7259
}
60+
config.CopyKeys(keys)
7361

74-
completionChannel, err := builder.VirtioChannelRead("testisocompletion")
75-
if err != nil {
76-
c.Fatal(err)
62+
overrideFW := func(builder *platform.QemuBuilder) error {
63+
switch {
64+
case opts.enableUefiSecure:
65+
builder.Firmware = "uefi-secure"
66+
case opts.enableUefi:
67+
builder.Firmware = "uefi"
68+
}
69+
return nil
7770
}
7871

79-
config.AddSystemdUnit("live-signal-ok.service", liveSignalOKUnit, conf.Enable)
80-
config.AddSystemdUnit("verify-no-efi-boot-entry.service", verifyNoEFIBootEntry, conf.Enable)
81-
builder.SetConfig(config)
72+
errchan := make(chan error)
73+
setupDisks := func(_ platform.QemuMachineOptions, builder *platform.QemuBuilder) error {
74+
output, err := builder.VirtioChannelRead("testisocompletion")
75+
if err != nil {
76+
return errors.Wrap(err, "setting up virtio-serial channel")
77+
}
8278

83-
mach, err := builder.Exec()
79+
// Read line in a goroutine and send errors to channel
80+
go func() {
81+
errchan <- CheckTestOutput(output, []string{liveOKSignal})
82+
}()
83+
84+
isopath := filepath.Join(kola.CosaBuild.Dir, kola.CosaBuild.Meta.BuildArtifacts.LiveIso.Path)
85+
return builder.AddIso(isopath, "", false)
86+
}
87+
88+
callacks := qemu.BuilderCallbacks{SetupDisks: setupDisks, OverrideDefaults: overrideFW}
89+
_, err = qc.NewMachineWithQemuOptionsAndBuilderCallbacks(config, platform.QemuMachineOptions{}, callacks)
8490
if err != nil {
85-
c.Fatal(err)
91+
c.Fatalf("Unable to create test machine: %v", err)
8692
}
87-
defer mach.Destroy()
8893

89-
err = awaitCompletion(c, mach, opts.console, outdir, completionChannel, nil, []string{liveOKSignal})
94+
err = <-errchan
9095
if err != nil {
9196
c.Fatal(err)
9297
}

0 commit comments

Comments
 (0)