provisioning

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bundle

type Bundle struct {
	Source      string `json:"source"`
	Destination string `json:"destination"`
}

Bundle is an arbitrary collection of files to support Nomad, Consul, etc. that will be placed as part of provisioning.

type ClusterInfo

type ClusterInfo struct {
	ID           string
	Name         string
	NomadClient  *napi.Client
	ConsulClient *capi.Client
	VaultClient  *vapi.Client
}

ClusterInfo is a handle to a provisioned cluster, along with clients a test run can use to connect to the cluster.

type Deployment

type Deployment struct {
	// Note: these override each other. NomadLocalBinary > NomadSha > NomadVersion
	NomadLocalBinary string `json:"nomad_local_binary"`
	NomadSha         string `json:"nomad_sha"`
	NomadVersion     string `json:"nomad_version"`

	RemoteBinaryPath string   `json:"remote_binary_path"`
	Platform         string   `json:"platform"`
	Bundles          []Bundle `json:"bundles"`
	Steps            []string `json:"steps"`
}

type LinuxRunner

type LinuxRunner struct {
	// contains filtered or unexported fields
}

LinuxRunner is a ProvisioningRunner that runs on the executing host only. The Nomad configurations used with this runner will need to avoid port conflicts!

Must call Open before other methods.

func (*LinuxRunner) Close

func (runner *LinuxRunner) Close()

func (*LinuxRunner) Copy

func (runner *LinuxRunner) Copy(local, remote string) error

func (*LinuxRunner) LogOutput

func (runner *LinuxRunner) LogOutput(output string)

func (*LinuxRunner) Logf

func (runner *LinuxRunner) Logf(format string, args ...interface{})

func (*LinuxRunner) Open

func (runner *LinuxRunner) Open(t *testing.T) error

Open sets up the LinuxRunner to run using t as a logging mechanism.

func (*LinuxRunner) Run

func (runner *LinuxRunner) Run(script string) error

Run the script (including any arguments)

type Provisioner

type Provisioner interface {
	// SetupTestRun is called at the start of the entire test run.
	SetupTestRun(t *testing.T, opts SetupOptions) (*ClusterInfo, error)

	// SetupTestSuite is called at the start of each TestSuite.
	// TODO: no current provisioner implementation uses this, but we
	// could use it to provide each TestSuite with an entirely separate
	// Nomad cluster.
	SetupTestSuite(t *testing.T, opts SetupOptions) (*ClusterInfo, error)

	// SetupTestCase is called at the start of each TestCase in every TestSuite.
	SetupTestCase(t *testing.T, opts SetupOptions) (*ClusterInfo, error)

	// TearDownTestCase is called after each TestCase in every TestSuite.
	TearDownTestCase(t *testing.T, clusterID string) error

	// TearDownTestSuite is called after every TestSuite.
	TearDownTestSuite(t *testing.T, clusterID string) error

	// TearDownTestRun is called at the end of the entire test run.
	TearDownTestRun(t *testing.T, clusterID string) error
}

Provisioner interface is used by the test framework to provision Nomad. The Setup* methods should be used to create a Nomad cluster at the appropriate stage. The returned ClusterInfo handle helps TestCases isolate test state by using the ClusterInfo.ID as part of job IDs.

var DefaultProvisioner Provisioner = new(singleClusterProvisioner)

DefaultProvisioner is a noop provisioner that builds clients from environment variables according to the respective client configuration

func NewProvisioner

func NewProvisioner(config ProvisionerConfig) Provisioner

func PreProvisioner

func PreProvisioner(targets *ProvisioningTargets) Provisioner

PreProvisioner returns a provisioner that deploys Nomad to a cluster at the start of the whole test run and leaves it in place.

type ProvisionerConfig

type ProvisionerConfig struct {
	IsLocal         bool
	VagrantBox      string
	TerraformConfig string

	NomadSha         string
	NomadVersion     string
	NomadLocalBinary string
}

ProvisionerConfig defines options for the entire lifecycle of the provisioner.

type ProvisioningRunner

type ProvisioningRunner interface {
	Open(t *testing.T) error   // start the runner, caching connection info
	Run(string) error          // run one step
	Copy(string, string) error // copy a file
	Close()                    // clean up the runner, call in a defer
}

ProvisioningRunner is the interface for how a Provisioner will connect with a target and execute steps. Each target has its own runner.

type ProvisioningTarget

type ProvisioningTarget struct {
	Deployment Deployment             `json:"deployment"`
	Runner     map[string]interface{} `json:"runner"`
	// contains filtered or unexported fields
}

ProvisioningTarget is a specific host that will get a Nomad and/or Consul deployment.

type ProvisioningTargets

type ProvisioningTargets struct {
	Servers []*ProvisioningTarget `json:"servers"`
	Clients []*ProvisioningTarget `json:"clients"`
}

ProvisioningTargets is a set of hosts that will get a Nomad and/or Consul deployment.

func ProvisionerConfigTerraform

func ProvisionerConfigTerraform(config ProvisionerConfig) *ProvisioningTargets

ProvisionerConfigTerraform targets a Terraform cluster by reading the config from a file, as output by 'terraform output provisioning'. Malformed inputs will log.Fatal so that we halt the test run.

func ProvisionerConfigVagrant

func ProvisionerConfigVagrant(config ProvisionerConfig) *ProvisioningTargets

ProvisionerConfigVagrant targets a single-node Vagrant environment.

type SSHRunner

type SSHRunner struct {
	Key  string // `json:"key"`
	User string // `json:"user"`
	Host string // `json:"host"`
	Port int    // `json:"port"`
	// contains filtered or unexported fields
}

SSHRunner is a ProvisioningRunner that deploys via ssh. Terraform does all of this more elegantly and portably in its ssh communicator, but by shelling out we avoid pulling in TF's as a Nomad dependency, and avoid some long-standing issues with connections to Windows servers. The tradeoff is losing portability but in practice we're always going to run this from a Unixish machine.

func (*SSHRunner) Close

func (runner *SSHRunner) Close()

func (*SSHRunner) Copy

func (runner *SSHRunner) Copy(local, remote string) error

Copy uploads the local path to the remote path. We call into different copy methods for Linux vs Windows because their path semantics are slightly different and the typical ssh users have different permissions.

func (*SSHRunner) Log

func (runner *SSHRunner) Log(args ...interface{})

func (*SSHRunner) LogErrOutput

func (runner *SSHRunner) LogErrOutput(output string)

func (*SSHRunner) LogOutput

func (runner *SSHRunner) LogOutput(output string)

func (*SSHRunner) Logf

func (runner *SSHRunner) Logf(format string, args ...interface{})

func (*SSHRunner) Open

func (runner *SSHRunner) Open(t *testing.T) error

Open establishes the ssh connection. We keep this connection open so that we can multiplex subsequent ssh connections.

func (*SSHRunner) Run

func (runner *SSHRunner) Run(script string) error

type SetupOptions

type SetupOptions struct {
	Name         string
	ExpectConsul bool // If true, fails if a Consul client can't be configured
	ExpectVault  bool // If true, fails if a Vault client can't be configured
}

SetupOptions defines options to be given to the Provisioner when calling Setup* methods.

Jump to

Keyboard shortcuts

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