Skip to content

Commit

Permalink
mantle/kola: copy basic tests into formal kola workflow
Browse files Browse the repository at this point in the history
`cmd-kola` has non-conformed basic kola tests. These tests do not
benefit from the supporting functionality around kola test's such as
denylisting or other functionality. reduce `cmd-kola` and conform
the basic kola tests.

fixes coreos#3418

co-authored-by: AdamOBrien <[email protected]>
  • Loading branch information
prestist and Adam0Brien committed Dec 5, 2023
1 parent 5a1bd04 commit f854f01
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 45 deletions.
4 changes: 3 additions & 1 deletion mantle/kola/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ func filterTests(tests map[string]*register.Test, patterns []string, pltfrm stri
continue
}
}

if t.Nvme != QEMUOptions.Nvme {
continue
}
// Check native tests for arch-specific and distro-specfic exclusion
for k, NativeFuncWrap := range t.NativeFuncs {
_, excluded := isAllowed(Options.Distribution, nil, NativeFuncWrap.Exclusions)
Expand Down
3 changes: 3 additions & 0 deletions mantle/kola/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ type Test struct {
// Conflicts is non-empty iff nonexclusive is true
// Contains the tests that conflict with this particular test
Conflicts []string

// If true, this test will be run on NVMe storage
Nvme bool
}

// Registered tests that run as part of `kola run` live here. Mapping of names
Expand Down
147 changes: 135 additions & 12 deletions mantle/kola/tests/coretest/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ 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"
"github.com/coreos/coreos-assembler/mantle/util"
)

const (
DockerTimeout = time.Second * 60
PortTimeout = time.Second * 3
uefi = "uefi"
uefiSecure = "uefi-secure"
bios = "bios"
)

// RHCOS services we expect disabled/inactive
Expand All @@ -37,23 +43,87 @@ var offServices = []string{
"tcsd.service",
}

var nativeFuncs = map[string]register.NativeFuncWrap{
"PortSSH": register.CreateNativeFuncWrap(TestPortSsh),
"DbusPerms": register.CreateNativeFuncWrap(TestDbusPerms),
"ServicesActive": register.CreateNativeFuncWrap(TestServicesActive),
"ReadOnly": register.CreateNativeFuncWrap(TestReadOnlyFs),
"Useradd": register.CreateNativeFuncWrap(TestUseradd),
"MachineID": register.CreateNativeFuncWrap(TestMachineID),
"RHCOSGrowpart": register.CreateNativeFuncWrap(TestRHCOSGrowfs, []string{"fcos"}...),
"FCOSGrowpart": register.CreateNativeFuncWrap(TestFCOSGrowfs, []string{"rhcos"}...),
}

func init() {

register.RegisterTest(&register.Test{
Name: "basic",
Description: "Verify basic functionalities like SSH, systemd services, useradd, etc.",
Run: LocalTests,
ClusterSize: 1,
NativeFuncs: map[string]register.NativeFuncWrap{
"PortSSH": register.CreateNativeFuncWrap(TestPortSsh),
"DbusPerms": register.CreateNativeFuncWrap(TestDbusPerms),
"ServicesActive": register.CreateNativeFuncWrap(TestServicesActive),
"ReadOnly": register.CreateNativeFuncWrap(TestReadOnlyFs),
"Useradd": register.CreateNativeFuncWrap(TestUseradd),
"MachineID": register.CreateNativeFuncWrap(TestMachineID),
"RHCOSGrowpart": register.CreateNativeFuncWrap(TestRHCOSGrowfs, []string{"fcos"}...),
"FCOSGrowpart": register.CreateNativeFuncWrap(TestFCOSGrowfs, []string{"rhcos"}...),
},
Firmwares: []string{"bios"},
Platforms: []string{"qemu"},
Run: biosWithBasicTests,
ClusterSize: 0,
NativeFuncs: nativeFuncs,
})

register.RegisterTest(&register.Test{
Name: "basic.uefi",
Description: "Verify basic functionalities like SSH, systemd services, useradd, etc, with uefi enabled",
Firmwares: []string{uefi},
Platforms: []string{"qemu"},
Architectures: []string{"x86_64"},
Run: uefiWithBasicTests,
ClusterSize: 0,
NativeFuncs: nativeFuncs,
})

register.RegisterTest(&register.Test{
Name: "basic.uefi.secure",
Description: "Verify basic functionalities like SSH, systemd services, useradd, etc, with uefi enabled",
Firmwares: []string{uefiSecure},
Platforms: []string{"qemu"},
Architectures: []string{"x86_64"},
Run: uefiSecureWithBasicTests,
ClusterSize: 0,
NativeFuncs: nativeFuncs,
})

register.RegisterTest(&register.Test{
Name: "basic.nvme.bios",
Description: "Verify basic functionalities like SSH, systemd services, useradd, etc, with nvme enabled",
Firmwares: []string{"bios"},
Platforms: []string{"qemu"},
Architectures: []string{"x86_64"},
Nvme: true,
Run: nvmeAndBiosWithBasicTests,
ClusterSize: 0,
NativeFuncs: nativeFuncs,
})

register.RegisterTest(&register.Test{
Name: "basic.nvme.uefi",
Description: "Verify basic functionalities like SSH, systemd services, useradd, etc, with nvme and uefi enabled",
Firmwares: []string{uefi},
Platforms: []string{"qemu"},
Architectures: []string{"x86_64"},
Nvme: true,
Run: nvmeAnduefiWithBasicTests,
ClusterSize: 0,
NativeFuncs: nativeFuncs,
})

register.RegisterTest(&register.Test{
Name: "basic.nvme.uefi.secure",
Description: "Verify basic functionalities like SSH, systemd services, useradd, etc, with nvme and uefi-secure enabled",
Firmwares: []string{uefiSecure},
Platforms: []string{"qemu"},
Architectures: []string{"x86_64"},
Nvme: true,
Run: nvmeAnduefiSecureWithBasicTests,
ClusterSize: 0,
NativeFuncs: nativeFuncs,
})

// TODO: Enable DockerPing/DockerEcho once fixed
// TODO: Only enable PodmanPing on non qemu. Needs:
// https://github.com/coreos/mantle/issues/1132
Expand Down Expand Up @@ -92,6 +162,59 @@ func init() {
})
}

func biosWithBasicTests(c cluster.TestCluster) {
runBasicTests(c, bios, false)
}

func uefiWithBasicTests(c cluster.TestCluster) {
runBasicTests(c, uefi, false)
}

func uefiSecureWithBasicTests(c cluster.TestCluster) {
runBasicTests(c, uefiSecure, false)
}

func nvmeAndBiosWithBasicTests(c cluster.TestCluster) {
runBasicTests(c, bios, true)
}

func nvmeAnduefiWithBasicTests(c cluster.TestCluster) {
runBasicTests(c, uefi, true)
}

func nvmeAnduefiSecureWithBasicTests(c cluster.TestCluster) {
runBasicTests(c, uefiSecure, true)
}

func runBasicTests(c cluster.TestCluster, firmware string, nvme bool) {
var err error

options := platform.QemuMachineOptions{
MachineOptions: platform.MachineOptions{
Firmware: firmware,
},
}

if nvme {
// create an nvme disk for the tests TBD
}

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:
_, err = pc.NewMachineWithQemuOptions(nil, options)
default:
panic("Unspported cluster type")
}
if err != nil {
c.Fatal(err)
}

LocalTests(c)
}
func TestPortSsh() error {
//t.Parallel()
err := CheckPort("tcp", "127.0.0.1:22", PortTimeout)
Expand Down
3 changes: 3 additions & 0 deletions mantle/platform/machine/qemu/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options pl
if !qc.RuntimeConf().InternetAccess {
builder.RestrictNetworking = true
}
if options.Firmware != "" {
builder.Firmware = options.Firmware
}

inst, err := builder.Exec()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion mantle/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ type MachineOptions struct {
AdditionalNics int
AppendKernelArgs string
AppendFirstbootKernelArgs string
SkipStartMachine bool // Skip platform.StartMachine on machine bringup
SkipStartMachine bool // Skip platform.StartMachine on machine bringup
Firmware string // Firmware type to use for the machine
}

// SystemdDropin is a userdata type agnostic struct representing a systemd dropin
Expand Down
33 changes: 2 additions & 31 deletions src/cmd-kola
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import sys
# Just test these boot to start with. In the future we should at least
# do ostree upgrades with uefi etc. But we don't really need the *full*
# suite...if podman somehow broke with nvme or uefi I'd be amazed and impressed.
BASIC_SCENARIOS = ["nvme=true", "firmware=uefi"]
BASIC_SCENARIOS_SECURE_BOOT = ["firmware=uefi-secure"]
arch = platform.machine()

cosa_dir = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -24,9 +22,7 @@ basearch = cmdlib.get_basearch()
# Parse args and dispatch
parser = argparse.ArgumentParser()
parser.add_argument("--build", help="Build ID")
parser.add_argument("--basic-qemu-scenarios", help="Run the basic test across uefi-secure,nvme etc.", action='store_true')
parser.add_argument("--output-dir", help="Output directory")
parser.add_argument("--skip-secure-boot", help="Use with '--basic-qemu-scenarios' to skip the Secure Boot tests", action='store_true')
parser.add_argument("--upgrades", help="Run upgrade tests", action='store_true')
parser.add_argument("subargs", help="Remaining arguments for kola", nargs='*',
default=[])
Expand Down Expand Up @@ -58,33 +54,8 @@ subargs = args.subargs or [default_cmd]
kolaargs.extend(subargs)
kolaargs.extend(unknown_args)

if args.basic_qemu_scenarios:
if arch == "x86_64":
os.mkdir(outputdir) # Create the toplevel output dir
for scenario in BASIC_SCENARIOS:
kolaargs.extend(['--output-dir',
os.path.join(outputdir, scenario.replace('=', '-'))])
subargs = kolaargs + ['--qemu-' + scenario, 'basic']
print(subprocess.list2cmdline(subargs), flush=True)
subprocess.check_call(subargs)
if not args.skip_secure_boot:
for scenario in BASIC_SCENARIOS_SECURE_BOOT:
kolaargs.extend(['--output-dir',
os.path.join(outputdir, scenario.replace('=', '-'))])
# See https://issues.redhat.com/browse/COS-2000 - there's
# some bug with shim/grub2 that fails with secure boot on < ~1300MiB of RAM.
# But we're not going to block on that; real world OCP worker nodes are at least 16GiB etc.
subargs = kolaargs + ['--qemu-' + scenario, 'basic'] + ["--qemu-memory", "1536"]
print(subprocess.list2cmdline(subargs), flush=True)
subprocess.check_call(subargs)
else:
# Basic qemu scenarios using nvme and uefi
# are not supported on multi-arch
kolaargs.extend(['--output-dir', outputdir])
subargs = kolaargs + ['basic']
print(subprocess.list2cmdline(subargs), flush=True)
subprocess.check_call(subargs)
elif args.upgrades:

if args.upgrades:
kolaargs.extend(['--output-dir', outputdir])
if '--qemu-image-dir' not in unknown_args:
os.makedirs('tmp/kola-qemu-cache', exist_ok=True)
Expand Down

0 comments on commit f854f01

Please sign in to comment.