kola

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2019 License: Apache-2.0 Imports: 34 Imported by: 2

README

Adding Tests

Quick Start

  1. Fork and clone the mantle repository
  2. Move into kola/tests/ and look for the package your test would best fit
  3. Edit the file and add your test(s), ensuring that you register your new test(s) in the packages init()
  4. Commit, push, and PR your result
Example

Say we wanted to add a simple noop test in the podman test package. If we follow the above instructions it would look like this:

$ git clone git@github.com:$GITHUB_USERNAME/mantle.git
<snip/>
$ pushd kola/tests/
$ $EDITOR podman/podman.go  # Add the test
// Test: I'm a NOOP!
func podmanNOOP(c cluster.TestCluster) {
    // NOOP!
}
$ $EDITOR podman/podman.go # Register the test in the init
func init() {
    register.Register(&register.Test{
        Run:         podmanNOOP,
        ClusterSize: 1,
        Name:        `podman.noop`,
        Distros:     []string{"rhcos"},
    })
<snip/>
$ popd
$ ./build kola
# Check and ensure the test is there
$ ./bin/kola list | grep podman
podman.base                                     [all]                                   [all]   [rhcos]
podman.network                                  [all]                                   [all]   [rhcos]
podman.noop                                     [all]                                   [all]   [rhcos]
podman.workflow                                 [all]                                   [all]   [rhcos]
# Run your test and see what happens
$ sudo ./bin/kola run -b rhcos --qemu-image `pwd`/rhcos-410.8.20190502.0-qemu.qcow2 podman.noop
=== RUN   podman.noop
--- PASS: podman.noop (21.08s)
PASS, output in _kola_temp/qemu-2019-05-08-1535-16606
# git add/commit/push...
# Open PR to get the test added!

Grouping Tests

Sometimes it makes sense to group tests together under a specific package, especially when these tests are related and require the same test parameters. For kola it only takes a forwarding function to do testing groups. This forwarding function should take cluster.TestCluster as it's only input, and execute running other tests with cluster.TestCluster.Run().

It is worth noting that the tests within the group are executed sequentially and on the same machine. As such, it is not recommended to group tests which modify the system state.

Additionally, the FailFast flag can be enabled during the test registration to skip any remaining steps after a failure has occurred.

Continuing with the look at the podman package we can see that podman.base is registered like so:

    register.Register(&register.Test{
            Run:         podmanBaseTest,
            ClusterSize: 1,
            Name:        `podman.base`,
            Distros:     []string{"rhcos"},
    })

If we look at podmanBaseTest it becomes very obvious that it's not a test of it's own, but a group of tests.

func podmanBaseTest(c cluster.TestCluster) {
        c.Run("info", podmanInfo)
        c.Run("resources", podmanResources)
        c.Run("network", podmanNetworksReliably)
}

Adding New Packages

If you need to add a new testing package there are few steps that must be done.

  1. Create a new directory in kola/tests/ which is descriptive of what will be tested.
  2. Add at least one file in the new directory with it's package the same name as it's directory name
  3. Edit the kola/registry/registry.go file to include your new package
  4. Add and register your new tests

As an example, let's say you want to add a new test package called foo.

  1. First create kola/tests/foo/
  2. Then echo "package foo" > kola/tests/foo/foo.go
  3. Next, edit kola/registry/registry.go and add this to the imports _ "github.com/coreos/mantle/kola/tests/foo"
package registry

// Tests imported for registration side effects. These make up the OS test suite and is explicitly imported from the main package.
import (
        _ "github.com/coreos/mantle/kola/tests/coretest"
        _ "github.com/coreos/mantle/kola/tests/crio"
        _ "github.com/coreos/mantle/kola/tests/docker"
        _ "github.com/coreos/mantle/kola/tests/etcd"
        _ "github.com/coreos/mantle/kola/tests/foo"
<snip/>
  1. Lastly, use $EDITOR on kola/tests/foo/foo.go adding in new test groups and tests.

Full Example

File: kola/tests/foo/foo.go
// Copyright 2019 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.

package foo

import (
        "github.com/coreos/mantle/kola/cluster"
        "github.com/coreos/mantle/kola/register"
)

// init runs when the package is imported and takes care of registering tests
func init() {
    register.Register(&register.Test{ // See: https://godoc.org/github.com/coreos/mantle/kola/register#Test
            Run:         exampleTestGroup,
            ClusterSize: 1,
            Name:        `example.example`,
            Flags:       []register.Flag{}, // See: https://godoc.org/github.com/coreos/mantle/kola/register#Flag
            Distros:     []string{"rhcos"},
            FailFast:    true,
    })
}

// exampleTestGroup groups all of the example.example tests together
func exampleTestGroup(c cluster.TestCluster) {
    c.Run("test1", exampleTestOne)
    c.Run("test2", exampleTestTwo)
}

// The first example test (and it does nothing!)
func exampleTestOne(c cluster.TestCluster) {
    // NOOP!
}

// The second example test and it makes sure os-release has content
func exampleTestTwo(c cluster.TestCluster) {
    // Get the first machine in the cluster
    m := c.Machines()[0]
    osrelease := c.MustSSH(m, `cat /etc/os-release`)
    if string(osrelease) == "" {
        c.Errorf("/etc/os-release was empty. Expected content.")
    }
}
File: kola/registry/registry.go
package registry

// Tests imported for registration side effects. These make up the OS test suite and is explicitly imported from the main package.
import (
        _ "github.com/coreos/mantle/kola/tests/coretest"
        _ "github.com/coreos/mantle/kola/tests/crio"
        _ "github.com/coreos/mantle/kola/tests/docker"
        _ "github.com/coreos/mantle/kola/tests/etcd"
        _ "github.com/coreos/mantle/kola/tests/flannel"
        _ "github.com/coreos/mantle/kola/tests/foo"
        _ "github.com/coreos/mantle/kola/tests/ignition"
        _ "github.com/coreos/mantle/kola/tests/kubernetes"
        _ "github.com/coreos/mantle/kola/tests/locksmith"
        _ "github.com/coreos/mantle/kola/tests/metadata"
        _ "github.com/coreos/mantle/kola/tests/misc"
        _ "github.com/coreos/mantle/kola/tests/ostree"
        _ "github.com/coreos/mantle/kola/tests/packages"
        _ "github.com/coreos/mantle/kola/tests/podman"
        _ "github.com/coreos/mantle/kola/tests/rkt"
        _ "github.com/coreos/mantle/kola/tests/rpmostree"
        _ "github.com/coreos/mantle/kola/tests/systemd"
        _ "github.com/coreos/mantle/kola/tests/torcx"
        _ "github.com/coreos/mantle/kola/tests/update"
)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Options          = platform.Options{}
	AWSOptions       = awsapi.Options{Options: &Options}       // glue to set platform options from main
	AzureOptions     = azureapi.Options{Options: &Options}     // glue to set platform options from main
	DOOptions        = doapi.Options{Options: &Options}        // glue to set platform options from main
	ESXOptions       = esxapi.Options{Options: &Options}       // glue to set platform options from main
	GCEOptions       = gcloudapi.Options{Options: &Options}    // glue to set platform options from main
	OpenStackOptions = openstackapi.Options{Options: &Options} // glue to set platform options from main
	PacketOptions    = packetapi.Options{Options: &Options}    // glue to set platform options from main
	QEMUOptions      = qemu.Options{Options: &Options}         // glue to set platform options from main

	TestParallelism   int    //glue var to set test parallelism from main
	TAPFile           string // if not "", write TAP results here
	TorcxManifestFile string // torcx manifest to expose to tests, if set
	// TorcxManifest is the unmarshalled torcx manifest file. It is available for
	// tests to access via `kola.TorcxManifest`. It will be nil if there was no
	// manifest given to kola.
	TorcxManifest *torcx.Manifest = nil

	UpdatePayloadFile string
)

Functions

func CheckConsole added in v0.8.0

func CheckConsole(output []byte, t *register.Test) []string

CheckConsole checks some console output for badness and returns short descriptions of any badness it finds. If t is specified, its flags are respected.

func NewFlight added in v0.12.0

func NewFlight(pltfrm string) (flight platform.Flight, err error)

func RunTests

func RunTests(pattern, pltfrm, outputDir string) error

RunTests is a harness for running multiple tests in parallel. Filters tests based on a glob pattern and by platform. Has access to all tests either registered in this package or by imported packages that register tests in their init() function. outputDir is where various test logs and data will be written for analysis after the test run. If it already exists it will be erased!

func SetupOutputDir added in v0.6.0

func SetupOutputDir(outputDir, platform string) (string, error)

Types

type NativeRunner

type NativeRunner func(funcName string, m platform.Machine) error

NativeRunner is a closure passed to all kola test functions and used to run native go functions directly on kola machines. It is necessary glue until kola does introspection.

Directories

Path Synopsis
tests
flannel
flannel tests.
flannel tests.
rkt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL