talos/internal/integration/integration_test.go
Andrey Smirnov 923ef4537b test: implement new class of tests: provision tests (upgrades)
This class of tests is included/excluded by build tags, but as it is
pretty different from other integration tests, we build it as separate
executable. Provision tests provision cluster for the test run, perform
some actions and verify results (could be upgrade, reset, scale up/down,
etc.)

There's now framework to implement upgrade tests, first of the tests
tests upgrade from latest 0.3 (0.3.2 at the moment) to current version
of Talos (being built in CI). Tests starts by booting with 0.3
kernel/initramfs, runs 0.3 installer to install 0.3.2 cluster, wait for
bootstrap, followed by upgrade to 0.4 in rolling fashion. As Firecracker
supports bootloader, this boots 0.4 system from boot disk (as installed
by installer).

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2020-02-21 07:04:03 -08:00

125 lines
5.2 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// +build integration
// Package integration_test contains core runners for integration tests
package integration_test
import (
"context"
"flag"
"path/filepath"
"testing"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/talos/cmd/osctl/pkg/client/config"
"github.com/talos-systems/talos/internal/integration/api"
"github.com/talos-systems/talos/internal/integration/base"
"github.com/talos-systems/talos/internal/integration/cli"
"github.com/talos-systems/talos/internal/integration/k8s"
provision_test "github.com/talos-systems/talos/internal/integration/provision"
"github.com/talos-systems/talos/internal/pkg/provision"
"github.com/talos-systems/talos/internal/pkg/provision/providers"
"github.com/talos-systems/talos/pkg/version"
)
// Accumulated list of all the suites to run
var allSuites []suite.TestingSuite
// Flag values
var (
talosConfig string
endpoint string
k8sEndpoint string
expectedVersion string
osctlPath string
provisionerName string
clusterName string
stateDir string
)
func TestIntegration(t *testing.T) {
if talosConfig == "" {
t.Error("--talos.config is not provided")
}
var cluster provision.Cluster
if provisionerName != "" {
// use provisioned cluster state as discovery source
ctx := context.Background()
provisioner, err := providers.Factory(ctx, provisionerName)
if err != nil {
t.Error("error iniitalizing provisioner", err)
}
defer provisioner.Close() //nolint: errcheck
cluster, err = provisioner.Reflect(ctx, clusterName, stateDir)
if err != nil {
t.Error("error reflecting cluster via provisioner", err)
}
}
provision_test.DefaultSettings.CurrentVersion = expectedVersion
for _, s := range allSuites {
if configuredSuite, ok := s.(base.ConfiguredSuite); ok {
configuredSuite.SetConfig(base.TalosSuite{
Endpoint: endpoint,
K8sEndpoint: k8sEndpoint,
Cluster: cluster,
TalosConfig: talosConfig,
Version: expectedVersion,
OsctlPath: osctlPath,
})
}
var suiteName string
if namedSuite, ok := s.(base.NamedSuite); ok {
suiteName = namedSuite.SuiteName()
}
t.Run(suiteName, func(tt *testing.T) {
suite.Run(tt, s) //nolint: scopelint
})
}
}
func init() {
defaultTalosConfig, _ := config.GetDefaultPath() //nolint: errcheck
defaultStateDir, err := config.GetTalosDirectory()
if err == nil {
defaultStateDir = filepath.Join(defaultStateDir, "clusters")
}
flag.StringVar(&talosConfig, "talos.config", defaultTalosConfig, "The path to the Talos configuration file")
flag.StringVar(&endpoint, "talos.endpoint", "", "endpoint to use (overrides config)")
flag.StringVar(&k8sEndpoint, "talos.k8sendpoint", "", "Kubernetes endpoint to use (overrides kubeconfig)")
flag.StringVar(&provisionerName, "talos.provisioner", "", "Talos cluster provisioner to use, if not set cluster state is disabled")
flag.StringVar(&stateDir, "talos.state", defaultStateDir, "directory path to store cluster state")
flag.StringVar(&clusterName, "talos.name", "talos-default", "the name of the cluster")
flag.StringVar(&expectedVersion, "talos.version", version.Tag, "expected Talos version")
flag.StringVar(&osctlPath, "talos.osctlpath", "osctl", "The path to 'osctl' binary")
flag.StringVar(&provision_test.DefaultSettings.CIDR, "talos.provision.cidr", provision_test.DefaultSettings.CIDR, "CIDR to use to provision clusters (provision tests only)")
flag.Var(&provision_test.DefaultSettings.RegistryMirrors, "talos.provision.registry-mirror", "registry mirrors to use (provision tests only)")
flag.IntVar(&provision_test.DefaultSettings.MTU, "talos.provision.mtu", provision_test.DefaultSettings.MTU, "MTU to use for cluster network (provision tests only)")
flag.Int64Var(&provision_test.DefaultSettings.CPUs, "talos.provision.cpu", provision_test.DefaultSettings.CPUs, "CPU count for each VM (provision tests only)")
flag.Int64Var(&provision_test.DefaultSettings.MemMB, "talos.provision.mem", provision_test.DefaultSettings.MemMB, "memory (in MiB) for each VM (provision tests only)")
flag.Int64Var(&provision_test.DefaultSettings.DiskGB, "talos.provision.disk", provision_test.DefaultSettings.DiskGB, "disk size (in GiB) for each VM (provision tests only)")
flag.IntVar(&provision_test.DefaultSettings.MasterNodes, "talos.provision.masters", provision_test.DefaultSettings.MasterNodes, "master node count (provision tests only)")
flag.IntVar(&provision_test.DefaultSettings.WorkerNodes, "talos.provision.workers", provision_test.DefaultSettings.WorkerNodes, "worker node count (provision tests only)")
flag.StringVar(&provision_test.DefaultSettings.TargetInstallImageRegistry, "talos.provision.target-installer-registry", provision_test.DefaultSettings.TargetInstallImageRegistry, "image registry for target installer image (provision tests only)")
allSuites = append(allSuites, api.GetAllSuites()...)
allSuites = append(allSuites, cli.GetAllSuites()...)
allSuites = append(allSuites, k8s.GetAllSuites()...)
allSuites = append(allSuites, provision_test.GetAllSuites()...)
}