diff --git a/mantle/cmd/kola/spawn.go b/mantle/cmd/kola/spawn.go index c71964e065..264cb76dae 100644 --- a/mantle/cmd/kola/spawn.go +++ b/mantle/cmd/kola/spawn.go @@ -32,7 +32,6 @@ import ( "github.com/coreos/coreos-assembler/mantle/kola" "github.com/coreos/coreos-assembler/mantle/platform" "github.com/coreos/coreos-assembler/mantle/platform/conf" - "github.com/coreos/coreos-assembler/mantle/platform/machine/qemu" ) var ( @@ -162,9 +161,8 @@ func runSpawn(cmd *cobra.Command, args []string) error { if spawnVerbose { fmt.Println("Spawning machine...") } - // use qemu-specific interface only if needed - if strings.HasPrefix(kolaPlatform, "qemu") && (spawnMachineOptions != "" || !spawnRemove) { - machineOpts := platform.QemuMachineOptions{ + if spawnMachineOptions != "" || !spawnRemove { + machineOpts := platform.MachineOptions{ DisablePDeathSig: !spawnRemove, } if spawnMachineOptions != "" { @@ -178,13 +176,7 @@ func runSpawn(cmd *cobra.Command, args []string) error { return errors.Wrapf(err, "Could not unmarshal machine options") } } - - switch qc := cluster.(type) { - case *qemu.Cluster: - mach, err = qc.NewMachineWithQemuOptions(userdata, machineOpts) - default: - plog.Fatalf("unreachable: qemu cluster %v unknown type", qc) - } + mach, err = cluster.NewMachineWithOptions(userdata, machineOpts) } else { mach, err = cluster.NewMachine(userdata) } diff --git a/mantle/kola/harness.go b/mantle/kola/harness.go index 8011f5546f..e0690853f0 100644 --- a/mantle/kola/harness.go +++ b/mantle/kola/harness.go @@ -1238,18 +1238,20 @@ ExecStart=%s DependencyDir: destDirs, Tags: []string{"external"}, - AdditionalDisks: targetMeta.AdditionalDisks, - PrimaryDisk: targetMeta.PrimaryDisk, - InjectContainer: targetMeta.InjectContainer, - MinMemory: targetMeta.MinMemory, - NumaNodes: targetMeta.NumaNodes, - MinDiskSize: targetMeta.MinDiskSize, - AdditionalNics: targetMeta.AdditionalNics, - AppendKernelArgs: targetMeta.AppendKernelArgs, - AppendFirstbootKernelArgs: targetMeta.AppendFirstbootKernelArgs, - InstanceType: targetMeta.InstanceType, - NonExclusive: !targetMeta.Exclusive, - Conflicts: targetMeta.Conflicts, + MachineOptions: platform.MachineOptions{ + AdditionalDisks: targetMeta.AdditionalDisks, + PrimaryDisk: targetMeta.PrimaryDisk, + MinMemory: targetMeta.MinMemory, + NumaNodes: targetMeta.NumaNodes, + MinDiskSize: targetMeta.MinDiskSize, + AdditionalNics: targetMeta.AdditionalNics, + AppendKernelArgs: targetMeta.AppendKernelArgs, + AppendFirstbootKernelArgs: targetMeta.AppendFirstbootKernelArgs, + InstanceType: targetMeta.InstanceType, + }, + InjectContainer: targetMeta.InjectContainer, + NonExclusive: !targetMeta.Exclusive, + Conflicts: targetMeta.Conflicts, Run: func(c cluster.TestCluster) { mach := c.Machines()[0] @@ -1620,7 +1622,7 @@ func makeNonExclusiveTest(bucket int, tests []*register.Test, flight platform.Fl if test.HasFlag(register.AllowConfigWarnings) { plog.Fatalf("Non-exclusive test %v cannot have AllowConfigWarnings flag", test.Name) } - if test.AppendKernelArgs != "" { + if test.MachineOptions.AppendKernelArgs != "" { plog.Fatalf("Non-exclusive test %v cannot have AppendKernelArgs", test.Name) } if !internetAccess && testRequiresInternet(test) { @@ -1782,8 +1784,8 @@ func getNeededMemoryMiB(t *register.Test) int { } } // If the test specifies MinMemory, use that. - if t.MinMemory != 0 { - return t.MinMemory + if t.MachineOptions.MinMemory != 0 { + return t.MachineOptions.MinMemory } // Fall back to architecture-specific defaults from the QEMU platform. return platform.DefaultMemoryMiB(Options.CosaBuildArch) @@ -1861,18 +1863,7 @@ func runTest(h *harness.H, t *register.Test, pltfrm string, flight platform.Flig if t.ClusterSize > 0 { var userdata *conf.UserData = t.UserData - options := platform.MachineOptions{ - MultiPathDisk: t.MultiPathDisk, - PrimaryDisk: t.PrimaryDisk, - AdditionalDisks: t.AdditionalDisks, - MinMemory: t.MinMemory, - MinDiskSize: t.MinDiskSize, - NumaNodes: t.NumaNodes, - AdditionalNics: t.AdditionalNics, - AppendKernelArgs: t.AppendKernelArgs, - AppendFirstbootKernelArgs: t.AppendFirstbootKernelArgs, - InstanceType: t.InstanceType, - } + options := t.MachineOptions if testSecureBoot(t) { options.Firmware = "uefi-secure" diff --git a/mantle/kola/register/register.go b/mantle/kola/register/register.go index ccb5d6ce26..6c5ade0c52 100644 --- a/mantle/kola/register/register.go +++ b/mantle/kola/register/register.go @@ -19,6 +19,7 @@ import ( "time" "github.com/coreos/coreos-assembler/mantle/kola/cluster" + "github.com/coreos/coreos-assembler/mantle/platform" "github.com/coreos/coreos-assembler/mantle/platform/conf" ) @@ -70,45 +71,20 @@ type Test struct { Timeout time.Duration // the duration for which a test will be allowed to run RequiredTag string // if specified, test is filtered by default unless tag is provided -- defaults to none Description string // test description - NumaNodes bool // simulate two NUMA nodes - // Whether the primary disk is multipathed. Deprecated in favour of PrimaryDisk. - MultiPathDisk bool - - // Sizes of additional empty disks to attach to the node, followed by - // comma-separated list of optional options (e.g. ["1G", - // "5G:mpath,foo,bar"]) -- defaults to none. - AdditionalDisks []string - - // Size of primary disk to attach to the node, followed by - // comma-separated list of optional options (e.g. "20G:mpath"]). - PrimaryDisk string + // MachineOptions contains options for machine creation (disks, memory, + // kernel args, etc.). The test harness passes these to + // NewMachineWithOptions when ClusterSize > 0. + MachineOptions platform.MachineOptions // InjectContainer will cause the ostree base image to be injected into the target InjectContainer bool - // Minimum amount of memory in MB required for test. - MinMemory int - // The artificially reserved memory count in MiB for the test. This is used // for budgeting memory usage for tests prior to the VMs starting up on the // QEMU platform. ReservedMemoryCountMiB int - // Minimum amount of primary disk in GB required for test. Deprecated in favour - // of PrimaryDisk. - MinDiskSize int - - // Additional amount of NICs required for test. - AdditionalNics int - - // Additional kernel arguments to append to the defaults. - AppendKernelArgs string - - // Additional first boot kernel arguments to append to the defaults. - AppendFirstbootKernelArgs string - - // ExternalTest is a path to a binary that will be uploaded ExternalTest string // DependencyDir is a path to directory that will be uploaded, normally used by external tests DependencyDir DepDirMap @@ -124,10 +100,6 @@ type Test struct { // Conflicts is non-empty iff nonexclusive is true // Contains the tests that conflict with this particular test Conflicts []string - - // If provided, this test will be run on the target instance type. - // This overrides the instance type set with `kola run` - InstanceType string } // Registered tests that run as part of `kola run` live here. Mapping of names diff --git a/mantle/kola/tests/coretest/core.go b/mantle/kola/tests/coretest/core.go index 4e27a89d10..2d8a3592cf 100644 --- a/mantle/kola/tests/coretest/core.go +++ b/mantle/kola/tests/coretest/core.go @@ -11,11 +11,8 @@ import ( "github.com/pborman/uuid" - "github.com/coreos/coreos-assembler/mantle/kola" - "github.com/coreos/coreos-assembler/mantle/kola/cluster" "github.com/coreos/coreos-assembler/mantle/kola/register" "github.com/coreos/coreos-assembler/mantle/platform" - "github.com/coreos/coreos-assembler/mantle/platform/machine/qemu" ) const ( @@ -64,31 +61,40 @@ func init() { register.RegisterTest(®ister.Test{ Name: "basic.uefi", Description: "Verify basic functionalities like SSH, systemd services, useradd, etc, with UEFI enabled", - Run: uefiWithBasicTests, + Run: LocalTests, Platforms: []string{"qemu"}, - ClusterSize: 0, + ClusterSize: 1, NativeFuncs: nativeFuncs, Architectures: []string{"x86_64", "aarch64"}, + MachineOptions: platform.MachineOptions{ + Firmware: uefi, + }, }) register.RegisterTest(®ister.Test{ Name: "basic.uefi-secure", Description: "Verify basic functionalities like SSH, systemd services, useradd, etc, with UEFI Secure Boot enabled", - Run: uefiSecureWithBasicTests, + Run: LocalTests, Platforms: []string{"qemu"}, - ClusterSize: 0, + ClusterSize: 1, NativeFuncs: nativeFuncs, Architectures: []string{"x86_64"}, + MachineOptions: platform.MachineOptions{ + Firmware: uefiSecure, + }, }) register.RegisterTest(®ister.Test{ Name: "basic.nvme", Description: "Verify basic functionalities like SSH, systemd services, useradd, etc, with nvme enabled", - Run: nvmeBasicTests, + Run: LocalTests, Platforms: []string{"qemu"}, - ClusterSize: 0, + ClusterSize: 1, NativeFuncs: nativeFuncs, // NVMe in theory is supported on all arches, but the way we test it seems to // only work on x86_64 and aarch64. Architectures: []string{"x86_64", "aarch64"}, + MachineOptions: platform.MachineOptions{ + Nvme: true, + }, }) register.RegisterTest(®ister.Test{ Name: "rootfs.uuid", @@ -113,47 +119,6 @@ func init() { }) } -func uefiWithBasicTests(c cluster.TestCluster) { - runBasicTests(c, uefi, false) -} - -func uefiSecureWithBasicTests(c cluster.TestCluster) { - runBasicTests(c, uefiSecure, false) -} - -func nvmeBasicTests(c cluster.TestCluster) { - runBasicTests(c, "", true) -} - -func runBasicTests(c cluster.TestCluster, firmware string, nvme bool) { - var err error - var m platform.Machine - - options := platform.QemuMachineOptions{ - Firmware: firmware, - Nvme: nvme, - } - switch pc := c.Cluster.(type) { - // These cases have to be separated because when put together to the same case statement - // the golang compiler no longer checks that the individual types in the case have the - // NewMachineWithQemuOptions function, but rather whether platform.Cluster - // does which fails - case *qemu.Cluster: - m, err = pc.NewMachineWithQemuOptions(nil, options) - default: - panic("Unsupported cluster type") - } - if err != nil { - c.Fatal(err) - } - - // copy over kolet into the machine - if err := kola.ScpKolet([]platform.Machine{m}); err != nil { - c.Fatal(err) - } - LocalTests(c) -} - func TestPortSsh() error { //t.Parallel() err := CheckPort("tcp", "127.0.0.1:22", PortTimeout) diff --git a/mantle/kola/tests/ignition/kdump.go b/mantle/kola/tests/ignition/kdump.go index 2429504ced..f58352ee11 100644 --- a/mantle/kola/tests/ignition/kdump.go +++ b/mantle/kola/tests/ignition/kdump.go @@ -11,7 +11,6 @@ import ( "github.com/coreos/coreos-assembler/mantle/kola/register" "github.com/coreos/coreos-assembler/mantle/platform" "github.com/coreos/coreos-assembler/mantle/platform/conf" - "github.com/coreos/coreos-assembler/mantle/platform/machine/qemu" "github.com/coreos/coreos-assembler/mantle/util" ) @@ -106,7 +105,7 @@ func setupSSHMachine(c cluster.TestCluster) SshServer { var address string var port string - options := platform.QemuMachineOptions{ + options := platform.MachineOptions{ HostForwardPorts: []platform.HostForwardPort{ {Service: "ssh", HostPort: 0, GuestPort: 22}, }, @@ -146,16 +145,7 @@ func setupSSHMachine(c cluster.TestCluster) SshServer { }`, strings.TrimSpace(string(pubkeyBuf)))) // start the machine - switch c := c.Cluster.(type) { - // These cases have to be separated because when put together to the same case statement - // the golang compiler no longer checks that the individual types in the case have the - // NewMachineWithQemuOptions function, but rather whether platform.Cluster - // does which fails - case *qemu.Cluster: - m, err = c.NewMachineWithQemuOptions(ignition, options) - default: - panic("unreachable") - } + m, err = c.Cluster.NewMachineWithOptions(ignition, options) if err != nil { c.Fatal(err) } @@ -253,7 +243,7 @@ func setupNFSMachine(c cluster.TestCluster) NfsServer { var m platform.Machine var err error - options := platform.QemuMachineOptions{ + options := platform.MachineOptions{ HostForwardPorts: []platform.HostForwardPort{ {Service: "ssh", HostPort: 0, GuestPort: 22}, // Kdump NFS option does not allow a custom port @@ -280,16 +270,7 @@ storage: - path: /var/nfs/crash`) // start the machine - switch c := c.Cluster.(type) { - // These cases have to be separated because when put together to the same case statement - // the golang compiler no longer checks that the individual types in the case have the - // NewMachineWithQemuOptions function, but rather whether platform.Cluster - // does which fails - case *qemu.Cluster: - m, err = c.NewMachineWithQemuOptions(nfs_server_butane, options) - default: - panic("unreachable") - } + m, err = c.Cluster.NewMachineWithOptions(nfs_server_butane, options) if err != nil { c.Fatal(err) } diff --git a/mantle/kola/tests/ignition/luks.go b/mantle/kola/tests/ignition/luks.go index 2efb066678..d601e7f1b0 100644 --- a/mantle/kola/tests/ignition/luks.go +++ b/mantle/kola/tests/ignition/luks.go @@ -74,7 +74,7 @@ func setupTangMachine(c cluster.TestCluster) ut.TangServer { var thumbprint []byte var tangAddress string - options := platform.QemuMachineOptions{ + options := platform.MachineOptions{ HostForwardPorts: []platform.HostForwardPort{ {Service: "ssh", HostPort: 0, GuestPort: 22}, {Service: "tang", HostPort: 0, GuestPort: 80}, @@ -87,20 +87,16 @@ func setupTangMachine(c cluster.TestCluster) ut.TangServer { } }`) - switch pc := c.Cluster.(type) { - // These cases have to be separated because when put together to the same case statement - // the golang compiler no longer checks that the individual types in the case have the - // NewMachineWithQemuOptions function, but rather whether platform.Cluster - // does which fails + switch c.Cluster.(type) { case *qemu.Cluster: - m, err = pc.NewMachineWithQemuOptions(ignition, options) + m, err = c.Cluster.NewMachineWithOptions(ignition, options) for _, hfp := range options.HostForwardPorts { if hfp.Service == "tang" { tangAddress = fmt.Sprintf("10.0.2.2:%d", hfp.HostPort) } } default: - m, err = pc.NewMachine(ignition) + m, err = c.Cluster.NewMachine(ignition) tangAddress = fmt.Sprintf("%s:80", m.PrivateIP()) } if err != nil { @@ -234,19 +230,14 @@ func runCexTest(c cluster.TestCluster) { } }`) - opts := platform.QemuMachineOptions{ - Cex: true, + opts := platform.MachineOptions{ + Cex: true, + MinMemory: 8192, } - opts.MinMemory = 8192 - switch pc := c.Cluster.(type) { - case *qemu.Cluster: - m, err = pc.NewMachineWithQemuOptions(ignition, opts) - if err != nil { - c.Fatalf("Unable to create test machine: %v", err) - } - default: - panic("Unsupported cluster type") + m, err = c.Cluster.NewMachineWithOptions(ignition, opts) + if err != nil { + c.Fatalf("Unable to create test machine: %v", err) } // copy over kolet into the machine diff --git a/mantle/kola/tests/misc/boot-mirror.go b/mantle/kola/tests/misc/boot-mirror.go index e246ac3714..38a366ddd7 100644 --- a/mantle/kola/tests/misc/boot-mirror.go +++ b/mantle/kola/tests/misc/boot-mirror.go @@ -26,7 +26,6 @@ import ( "github.com/coreos/coreos-assembler/mantle/kola/tests/util" "github.com/coreos/coreos-assembler/mantle/platform" "github.com/coreos/coreos-assembler/mantle/platform/conf" - "github.com/coreos/coreos-assembler/mantle/platform/machine/qemu" ut "github.com/coreos/coreos-assembler/mantle/util" ) @@ -94,11 +93,9 @@ func init() { func runBootMirrorTest(c cluster.TestCluster) { var m platform.Machine var err error - options := platform.QemuMachineOptions{ - MachineOptions: platform.MachineOptions{ - AdditionalDisks: []string{"5G", "5G"}, - MinMemory: 4096, - }, + options := platform.MachineOptions{ + AdditionalDisks: []string{"5G", "5G"}, + MinMemory: 4096, } // ppc64le uses 64K pages; see similar logic in harness.go and luks.go switch coreosarch.CurrentRpmArch() { @@ -108,7 +105,7 @@ func runBootMirrorTest(c cluster.TestCluster) { // FIXME: for QEMU tests kola currently assumes the host CPU architecture // matches the one under test userdata := bootmirror.Subst("LAYOUT", coreosarch.CurrentRpmArch()) - m, err = c.Cluster.(*qemu.Cluster).NewMachineWithQemuOptions(userdata, options) + m, err = c.Cluster.NewMachineWithOptions(userdata, options) if err != nil { c.Fatal(err) } @@ -146,11 +143,9 @@ func runBootMirrorTest(c cluster.TestCluster) { func runBootMirrorLUKSTest(c cluster.TestCluster) { var m platform.Machine var err error - options := platform.QemuMachineOptions{ - MachineOptions: platform.MachineOptions{ - AdditionalDisks: []string{"5G"}, - MinMemory: 4096, - }, + options := platform.MachineOptions{ + AdditionalDisks: []string{"5G"}, + MinMemory: 4096, } // ppc64le uses 64K pages; see similar logic in harness.go and luks.go switch coreosarch.CurrentRpmArch() { @@ -160,7 +155,7 @@ func runBootMirrorLUKSTest(c cluster.TestCluster) { // FIXME: for QEMU tests kola currently assumes the host CPU architecture // matches the one under test userdata := bootmirrorluks.Subst("LAYOUT", coreosarch.CurrentRpmArch()) - m, err = c.Cluster.(*qemu.Cluster).NewMachineWithQemuOptions(userdata, options) + m, err = c.Cluster.NewMachineWithOptions(userdata, options) if err != nil { c.Fatal(err) } diff --git a/mantle/kola/tests/misc/multipath.go b/mantle/kola/tests/misc/multipath.go index 088837e59a..cc643078c4 100644 --- a/mantle/kola/tests/misc/multipath.go +++ b/mantle/kola/tests/misc/multipath.go @@ -115,40 +115,48 @@ kernel_arguments: func init() { register.RegisterTest(®ister.Test{ - Name: "multipath.day1", - Description: "Verify that multipath can be configured day 1 through Ignition.", - Run: runMultipathDay1, - ClusterSize: 1, - Platforms: []string{"qemu"}, - UserData: mpath_on_boot_day1, - MultiPathDisk: true, + Name: "multipath.day1", + Description: "Verify that multipath can be configured day 1 through Ignition.", + Run: runMultipathDay1, + ClusterSize: 1, + Platforms: []string{"qemu"}, + UserData: mpath_on_boot_day1, + MachineOptions: platform.MachineOptions{ + MultiPathDisk: true, + }, }) register.RegisterTest(®ister.Test{ - Name: "multipath.day2", - Description: "Verify that multipath can be configured day 2 through Ignition.", - Run: runMultipathDay2, - ClusterSize: 1, - Platforms: []string{"qemu"}, - MultiPathDisk: true, + Name: "multipath.day2", + Description: "Verify that multipath can be configured day 2 through Ignition.", + Run: runMultipathDay2, + ClusterSize: 1, + Platforms: []string{"qemu"}, + MachineOptions: platform.MachineOptions{ + MultiPathDisk: true, + }, }) register.RegisterTest(®ister.Test{ - Name: "multipath.partition", - Description: "Verify that multipath can be configured for a partition.", - Run: runMultipathPartition, - ClusterSize: 1, - Platforms: []string{"qemu"}, - UserData: mpath_on_var_lib_containers, - AdditionalDisks: []string{"1G:mpath,wwn=1"}, + Name: "multipath.partition", + Description: "Verify that multipath can be configured for a partition.", + Run: runMultipathPartition, + ClusterSize: 1, + Platforms: []string{"qemu"}, + UserData: mpath_on_var_lib_containers, + MachineOptions: platform.MachineOptions{ + AdditionalDisks: []string{"1G:mpath,wwn=1"}, + }, }) // See https://issues.redhat.com/browse/OCPBUGS-56597 register.RegisterTest(®ister.Test{ - Name: "multipath.single-disk", - Description: "Verify that multipath can be reduced to one path", - Run: runMultipathReduceDisk, - ClusterSize: 1, - Platforms: []string{"qemu"}, - UserData: mpath_single_disk, - MultiPathDisk: true, + Name: "multipath.single-disk", + Description: "Verify that multipath can be reduced to one path", + Run: runMultipathReduceDisk, + ClusterSize: 1, + Platforms: []string{"qemu"}, + UserData: mpath_single_disk, + MachineOptions: platform.MachineOptions{ + MultiPathDisk: true, + }, }) } diff --git a/mantle/kola/tests/misc/network.go b/mantle/kola/tests/misc/network.go index cee6b8a57a..f073f0a19b 100644 --- a/mantle/kola/tests/misc/network.go +++ b/mantle/kola/tests/misc/network.go @@ -27,7 +27,6 @@ import ( "github.com/coreos/coreos-assembler/mantle/kola/register" "github.com/coreos/coreos-assembler/mantle/platform" "github.com/coreos/coreos-assembler/mantle/platform/conf" - "github.com/coreos/coreos-assembler/mantle/platform/machine/qemu" "github.com/coreos/coreos-assembler/mantle/util" ) @@ -68,17 +67,19 @@ func init() { kargs = "net.ifnames=0" } register.RegisterTest(®ister.Test{ - Run: InitInterfacesTest, - ClusterSize: 1, - Name: "rhcos.network.init-interfaces-test", - Description: "Verify init-interfaces script works in both fresh setup and reboot.", - Timeout: 40 * time.Minute, - Distros: []string{"rhcos"}, - Platforms: []string{"qemu"}, - RequiredTag: "openshift", - AdditionalNics: 2, - AppendKernelArgs: kargs, - UserData: userdata, + Run: InitInterfacesTest, + ClusterSize: 1, + Name: "rhcos.network.init-interfaces-test", + Description: "Verify init-interfaces script works in both fresh setup and reboot.", + Timeout: 40 * time.Minute, + Distros: []string{"rhcos"}, + Platforms: []string{"qemu"}, + RequiredTag: "openshift", + MachineOptions: platform.MachineOptions{ + AdditionalNics: 2, + AppendKernelArgs: kargs, + }, + UserData: userdata, }) } @@ -505,10 +506,8 @@ func setupMultipleNetworkTest(c cluster.TestCluster, primaryMac, secondaryMac st var m platform.Machine var err error - options := platform.QemuMachineOptions{ - MachineOptions: platform.MachineOptions{ - AdditionalNics: 2, - }, + options := platform.MachineOptions{ + AdditionalNics: 2, } // On s390x, multiple NICs are ordered by the CCW device number. Use classic ethX names to ensure consistent and ordered naming. if runtime.GOARCH == "s390x" { @@ -539,16 +538,7 @@ func setupMultipleNetworkTest(c cluster.TestCluster, primaryMac, secondaryMac st } }`, base64.StdEncoding.EncodeToString([]byte(captureMacsScript)))) - switch pc := c.Cluster.(type) { - // These cases have to be separated because when put together to the same case statement - // the golang compiler no longer checks that the individual types in the case have the - // NewMachineWithQemuOptions function, but rather whether platform.Cluster - // does which fails - case *qemu.Cluster: - m, err = pc.NewMachineWithQemuOptions(userdata, options) - default: - panic("unreachable") - } + m, err = c.Cluster.NewMachineWithOptions(userdata, options) if err != nil { c.Fatal(err) } diff --git a/mantle/kola/tests/ostree/sync.go b/mantle/kola/tests/ostree/sync.go index 9253e08209..085afb9fa6 100644 --- a/mantle/kola/tests/ostree/sync.go +++ b/mantle/kola/tests/ostree/sync.go @@ -96,24 +96,20 @@ func setupNFSMachine(c cluster.TestCluster) NfsServer { var err error var nfs_server string - options := platform.QemuMachineOptions{ + options := platform.MachineOptions{ HostForwardPorts: []platform.HostForwardPort{ {Service: "ssh", HostPort: 0, GuestPort: 22}, {Service: "nfs", HostPort: 2049, GuestPort: 2049}, }, + MinMemory: 2048, } - options.MinMemory = 2048 // start the machine - switch c := c.Cluster.(type) { - // These cases have to be separated because when put together to the same case statement - // the golang compiler no longer checks that the individual types in the case have the - // NewMachineWithQemuOptions function, but rather whether platform.Cluster - // does which fails + switch c.Cluster.(type) { case *qemu.Cluster: - m, err = c.NewMachineWithQemuOptions(nfs_server_butane, options) + m, err = c.Cluster.NewMachineWithOptions(nfs_server_butane, options) nfs_server = "10.0.2.2" default: - m, err = c.NewMachine(nfs_server_butane) + m, err = c.Cluster.NewMachine(nfs_server_butane) nfs_server = m.PrivateIP() } if err != nil { diff --git a/mantle/kola/tests/rhcos/upgrade.go b/mantle/kola/tests/rhcos/upgrade.go index 8f435c3354..ca5d895294 100644 --- a/mantle/kola/tests/rhcos/upgrade.go +++ b/mantle/kola/tests/rhcos/upgrade.go @@ -205,14 +205,14 @@ func rhcosUpgradeBasic(c cluster.TestCluster) { // no downgraded packages func rhcosUpgradeFromOcpRhcos(c cluster.TestCluster) { var m platform.Machine - options := platform.QemuMachineOptions{} + options := platform.MachineOptions{} ignition := conf.Ignition(`{ "ignition": { "version": "3.0.0" } }`) - switch pc := c.Cluster.(type) { + switch c.Cluster.(type) { case *qemu.Cluster: ostreeCommit := kola.CosaBuild.Meta.OstreeCommit temp := os.TempDir() @@ -228,7 +228,7 @@ func rhcosUpgradeFromOcpRhcos(c cluster.TestCluster) { defer os.Remove(rhcosQcow2) options.OverrideBackingFile = rhcosQcow2 - m, err = pc.NewMachineWithQemuOptions(ignition, options) + m, err = c.Cluster.NewMachineWithOptions(ignition, options) if err != nil { c.Fatal(err) } diff --git a/mantle/platform/machine/aws/cluster.go b/mantle/platform/machine/aws/cluster.go index 2fbf1e486e..9ef5d29771 100644 --- a/mantle/platform/machine/aws/cluster.go +++ b/mantle/platform/machine/aws/cluster.go @@ -37,26 +37,12 @@ func (ac *cluster) NewMachine(userdata *conf.UserData) (platform.Machine, error) } func (ac *cluster) NewMachineWithOptions(userdata *conf.UserData, options platform.MachineOptions) (platform.Machine, error) { + if err := options.EnsureNoQEMUOnlyOptions("aws"); err != nil { + return nil, err + } if len(options.AdditionalDisks) > 0 { return nil, errors.New("platform aws does not yet support additional disks") } - - if options.MultiPathDisk { - return nil, errors.New("platform aws does not support multipathed disks") - } - - if options.AdditionalNics > 0 { - return nil, errors.New("platform aws does not support additional nics") - } - - if options.AppendKernelArgs != "" { - return nil, errors.New("platform aws does not support appending kernel arguments") - } - - if options.AppendFirstbootKernelArgs != "" { - return nil, errors.New("platform aws does not support appending firstboot kernel arguments") - } - if options.InstanceType != "" { return nil, errors.New("platform aws does not support changing instance types") } diff --git a/mantle/platform/machine/azure/cluster.go b/mantle/platform/machine/azure/cluster.go index ae97127497..89a443d0d8 100644 --- a/mantle/platform/machine/azure/cluster.go +++ b/mantle/platform/machine/azure/cluster.go @@ -16,7 +16,6 @@ package azure import ( "crypto/rand" - "errors" "fmt" "os" "path/filepath" @@ -46,17 +45,8 @@ func (ac *cluster) NewMachine(userdata *conf.UserData) (platform.Machine, error) } func (ac *cluster) NewMachineWithOptions(userdata *conf.UserData, options platform.MachineOptions) (platform.Machine, error) { - if options.MultiPathDisk { - return nil, errors.New("platform azure does not support multipathed disks") - } - if options.AdditionalNics > 0 { - return nil, errors.New("platform azure does not support additional nics") - } - if options.AppendKernelArgs != "" { - return nil, errors.New("platform azure does not support appending kernel arguments") - } - if options.AppendFirstbootKernelArgs != "" { - return nil, errors.New("platform azure does not support appending firstboot kernel arguments") + if err := options.EnsureNoQEMUOnlyOptions("azure"); err != nil { + return nil, err } conf, err := ac.RenderUserData(userdata, map[string]string{ diff --git a/mantle/platform/machine/do/cluster.go b/mantle/platform/machine/do/cluster.go index f5808122d7..e88aad2f1d 100644 --- a/mantle/platform/machine/do/cluster.go +++ b/mantle/platform/machine/do/cluster.go @@ -37,21 +37,12 @@ func (dc *cluster) NewMachine(userdata *conf.UserData) (platform.Machine, error) } func (dc *cluster) NewMachineWithOptions(userdata *conf.UserData, options platform.MachineOptions) (platform.Machine, error) { + if err := options.EnsureNoQEMUOnlyOptions("do"); err != nil { + return nil, err + } if len(options.AdditionalDisks) > 0 { return nil, errors.New("platform do does not yet support additional disks") } - if options.MultiPathDisk { - return nil, errors.New("platform do does not support multipathed disks") - } - if options.AdditionalNics > 0 { - return nil, errors.New("platform do does not support additional nics") - } - if options.AppendKernelArgs != "" { - return nil, errors.New("platform do does not support appending kernel arguments") - } - if options.AppendFirstbootKernelArgs != "" { - return nil, errors.New("platform do does not support appending firstboot kernel arguments") - } if options.InstanceType != "" { return nil, errors.New("platform do does not support changing instance types") } diff --git a/mantle/platform/machine/esx/cluster.go b/mantle/platform/machine/esx/cluster.go index 16d372f963..dc1008064c 100644 --- a/mantle/platform/machine/esx/cluster.go +++ b/mantle/platform/machine/esx/cluster.go @@ -43,21 +43,12 @@ func (ec *cluster) NewMachine(userdata *platformConf.UserData) (platform.Machine } func (ec *cluster) NewMachineWithOptions(userdata *platformConf.UserData, options platform.MachineOptions) (platform.Machine, error) { + if err := options.EnsureNoQEMUOnlyOptions("esx"); err != nil { + return nil, err + } if len(options.AdditionalDisks) > 0 { return nil, errors.New("platform esx does not yet support additional disks") } - if options.MultiPathDisk { - return nil, errors.New("platform esx does not support multipathed disks") - } - if options.AdditionalNics > 0 { - return nil, errors.New("platform esx does not support additional nics") - } - if options.AppendKernelArgs != "" { - return nil, errors.New("platform esx does not support appending kernel arguments") - } - if options.AppendFirstbootKernelArgs != "" { - return nil, errors.New("platform esx does not support appending firstboot kernel arguments") - } if options.InstanceType != "" { return nil, errors.New("platform esx does not support changing instance types") } diff --git a/mantle/platform/machine/gcloud/cluster.go b/mantle/platform/machine/gcloud/cluster.go index 3a6ee4d094..8d46821618 100644 --- a/mantle/platform/machine/gcloud/cluster.go +++ b/mantle/platform/machine/gcloud/cluster.go @@ -37,17 +37,8 @@ func (gc *cluster) NewMachine(userdata *conf.UserData) (platform.Machine, error) } func (gc *cluster) NewMachineWithOptions(userdata *conf.UserData, options platform.MachineOptions) (platform.Machine, error) { - if options.MultiPathDisk { - return nil, errors.New("platform gcp does not support multipathed disks") - } - if options.AdditionalNics > 0 { - return nil, errors.New("platform gcp does not support additional nics") - } - if options.AppendKernelArgs != "" { - return nil, errors.New("platform gcp does not support appending kernel arguments") - } - if options.AppendFirstbootKernelArgs != "" { - return nil, errors.New("platform gcp does not support appending firstboot kernel arguments") + if err := options.EnsureNoQEMUOnlyOptions("gcp"); err != nil { + return nil, err } if options.InstanceType != "" { return nil, errors.New("platform gcp does not support changing instance types") diff --git a/mantle/platform/machine/openstack/cluster.go b/mantle/platform/machine/openstack/cluster.go index 3a634c2107..a78b29a938 100644 --- a/mantle/platform/machine/openstack/cluster.go +++ b/mantle/platform/machine/openstack/cluster.go @@ -35,21 +35,12 @@ func (oc *cluster) NewMachine(userdata *conf.UserData) (platform.Machine, error) } func (oc *cluster) NewMachineWithOptions(userdata *conf.UserData, options platform.MachineOptions) (platform.Machine, error) { + if err := options.EnsureNoQEMUOnlyOptions("openstack"); err != nil { + return nil, err + } if len(options.AdditionalDisks) > 0 { return nil, errors.New("platform openstack does not yet support additional disks") } - if options.MultiPathDisk { - return nil, errors.New("platform openstack does not support multipathed disks") - } - if options.AdditionalNics > 0 { - return nil, errors.New("platform openstack does not support additional nics") - } - if options.AppendKernelArgs != "" { - return nil, errors.New("platform openstack does not support appending kernel arguments") - } - if options.AppendFirstbootKernelArgs != "" { - return nil, errors.New("platform openstack does not support appending firstboot kernel arguments") - } if options.InstanceType != "" { return nil, errors.New("platform openstack does not support changing instance types") } diff --git a/mantle/platform/machine/qemu/cluster.go b/mantle/platform/machine/qemu/cluster.go index 356587f525..40481c4ea1 100644 --- a/mantle/platform/machine/qemu/cluster.go +++ b/mantle/platform/machine/qemu/cluster.go @@ -51,13 +51,6 @@ func (qc *Cluster) NewMachineWithOptions(userdata *conf.UserData, options platfo if options.InstanceType != "" { return nil, errors.New("platform qemu does not support changing instance types") } - return qc.NewMachineWithQemuOptions(userdata, platform.QemuMachineOptions{ - MachineOptions: options, - Firmware: options.Firmware, - }) -} - -func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options platform.QemuMachineOptions) (platform.Machine, error) { id := uuid.New() dir := filepath.Join(qc.RuntimeConf().OutputDir, id) diff --git a/mantle/platform/machine/qemuiso/cluster.go b/mantle/platform/machine/qemuiso/cluster.go index b32ae2b604..f56a47bc5e 100644 --- a/mantle/platform/machine/qemuiso/cluster.go +++ b/mantle/platform/machine/qemuiso/cluster.go @@ -49,12 +49,6 @@ func (qc *Cluster) NewMachineWithOptions(userdata *conf.UserData, options platfo if options.MultiPathDisk { return nil, errors.New("platform qemu-iso does not support multipathed primary disks") } - return qc.NewMachineWithQemuOptions(userdata, platform.QemuMachineOptions{ - MachineOptions: options, - }) -} - -func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options platform.QemuMachineOptions) (platform.Machine, error) { id := uuid.New() dir := filepath.Join(qc.RuntimeConf().OutputDir, id) diff --git a/mantle/platform/platform.go b/mantle/platform/platform.go index da2e0bb36d..b43b032a09 100644 --- a/mantle/platform/platform.go +++ b/mantle/platform/platform.go @@ -157,17 +157,71 @@ type Flight interface { } type MachineOptions struct { + AdditionalDisks []string + MinDiskSize int + InstanceType string + + // Fields below are only supported on QEMU-based platforms. + // Non-QEMU platforms call EnsureNoQEMUOnlyOptions() to reject them. MultiPathDisk bool PrimaryDisk string - AdditionalDisks []string MinMemory int - MinDiskSize int NumaNodes bool AdditionalNics int AppendKernelArgs string AppendFirstbootKernelArgs string - InstanceType string Firmware string + HostForwardPorts []HostForwardPort + DisablePDeathSig bool + OverrideBackingFile string + Nvme bool + Cex bool +} + +// EnsureNoQEMUOnlyOptions returns an error if any QEMU-only options +// are set. Non-QEMU platforms should call this to reject unsupported +// options early. +func (m *MachineOptions) EnsureNoQEMUOnlyOptions(platformName string) error { + if m.MultiPathDisk { + return fmt.Errorf("platform %s does not support multipathed disks", platformName) + } + if m.PrimaryDisk != "" { + return fmt.Errorf("platform %s does not support custom primary disks", platformName) + } + if m.MinMemory != 0 { + return fmt.Errorf("platform %s does not support setting minimum memory", platformName) + } + if m.NumaNodes { + return fmt.Errorf("platform %s does not support NUMA node simulation", platformName) + } + if m.AdditionalNics > 0 { + return fmt.Errorf("platform %s does not support additional NICs", platformName) + } + if m.AppendKernelArgs != "" { + return fmt.Errorf("platform %s does not support appending kernel arguments", platformName) + } + if m.AppendFirstbootKernelArgs != "" { + return fmt.Errorf("platform %s does not support appending firstboot kernel arguments", platformName) + } + if m.Firmware != "" { + return fmt.Errorf("platform %s does not support setting firmware", platformName) + } + if len(m.HostForwardPorts) > 0 { + return fmt.Errorf("platform %s does not support host forward ports", platformName) + } + if m.DisablePDeathSig { + return fmt.Errorf("platform %s does not support DisablePDeathSig", platformName) + } + if m.OverrideBackingFile != "" { + return fmt.Errorf("platform %s does not support OverrideBackingFile", platformName) + } + if m.Nvme { + return fmt.Errorf("platform %s does not support NVMe", platformName) + } + if m.Cex { + return fmt.Errorf("platform %s does not support Cex", platformName) + } + return nil } // SystemdDropin is a userdata type agnostic struct representing a systemd dropin diff --git a/mantle/platform/qemu.go b/mantle/platform/qemu.go index 3bc0fd7cb7..916a3e3b2f 100644 --- a/mantle/platform/qemu.go +++ b/mantle/platform/qemu.go @@ -66,17 +66,6 @@ type HostForwardPort struct { GuestPort int } -// QemuMachineOptions is specialized MachineOption struct for QEMU. -type QemuMachineOptions struct { - MachineOptions - HostForwardPorts []HostForwardPort - DisablePDeathSig bool - OverrideBackingFile string - Firmware string - Nvme bool - Cex bool -} - // QEMUMachine represents a qemu instance. type QEMUMachine interface { // Embedding the Machine interface