test

package
v0.0.0-...-288f078 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0, Apache-2.0, CC-BY-SA-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package test provides fakes and other tools for testing cloud drivers and other dispatcher modules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerUUID

func ContainerUUID(i int) string

ContainerUUID returns a fake container UUID.

func InstanceType

func InstanceType(i int) arvados.InstanceType

InstanceType returns a fake arvados.InstanceType called "type{i}" with i CPUs and i GiB of memory.

func LoadTestKey

func LoadTestKey(c *check.C, fnm string) (ssh.PublicKey, ssh.Signer)

LoadTestKey returns a public/private ssh keypair, read from the files identified by the path of the private key.

Types

type CapacityError

type CapacityError struct{ InstanceTypeSpecific bool }

func (CapacityError) Error

func (e CapacityError) Error() string

func (CapacityError) IsCapacityError

func (e CapacityError) IsCapacityError() bool

func (CapacityError) IsInstanceTypeSpecific

func (e CapacityError) IsInstanceTypeSpecific() bool

type Queue

type Queue struct {
	// Containers represent the API server database contents.
	Containers []arvados.Container

	// ChooseType will be called for each entry in Containers. It
	// must not be nil.
	ChooseType func(*arvados.Container) ([]arvados.InstanceType, error)

	// Mimic railsapi implementation of MaxDispatchAttempts config
	MaxDispatchAttempts int

	Logger logrus.FieldLogger
	// contains filtered or unexported fields
}

Queue is a test stub for container.Queue. The caller specifies the initial queue state.

func (*Queue) Cancel

func (q *Queue) Cancel(uuid string) error

func (*Queue) Entries

func (q *Queue) Entries() (map[string]container.QueueEnt, time.Time)

Entries returns the containers that were queued when Update was last called.

func (*Queue) Forget

func (q *Queue) Forget(uuid string)

func (*Queue) Get

func (q *Queue) Get(uuid string) (arvados.Container, bool)

Get returns the container from the cached queue, i.e., as it was when Update was last called -- just like a container.Queue does. If the state has been changed (via Lock, Unlock, or Cancel) since the last Update, the updated state is returned.

func (*Queue) Lock

func (q *Queue) Lock(uuid string) error

func (*Queue) Notify

func (q *Queue) Notify(upd arvados.Container) bool

Notify adds/updates an entry in the Containers slice. This simulates the effect of an API update from someone other than the dispatcher -- e.g., crunch-run updating state to "Complete" when a container exits.

The resulting changes are not exposed through Get() or Entries() until the next call to Update().

Return value is true unless the update is rejected (invalid state transition).

func (*Queue) StateChanges

func (q *Queue) StateChanges() []QueueStateChange

All calls to Lock/Unlock/Cancel to date.

func (*Queue) Subscribe

func (q *Queue) Subscribe() <-chan struct{}

func (*Queue) Unlock

func (q *Queue) Unlock(uuid string) error

func (*Queue) Unsubscribe

func (q *Queue) Unsubscribe(ch <-chan struct{})

func (*Queue) Update

func (q *Queue) Update() error

Update rebuilds the current entries from the Containers slice.

type QueueStateChange

type QueueStateChange struct {
	UUID string
	From arvados.ContainerState
	To   arvados.ContainerState
}

type QuotaError

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

func (QuotaError) IsQuotaError

func (QuotaError) IsQuotaError() bool

type RateLimitError

type RateLimitError struct{ Retry time.Time }

func (RateLimitError) EarliestRetry

func (e RateLimitError) EarliestRetry() time.Time

func (RateLimitError) Error

func (e RateLimitError) Error() string

type SSHExecFunc

type SSHExecFunc func(env map[string]string, command string, stdin io.Reader, stdout, stderr io.Writer) uint32

An SSHExecFunc handles an "exec" session on a multiplexed SSH connection.

type SSHService

type SSHService struct {
	Exec           SSHExecFunc
	HostKey        ssh.Signer
	AuthorizedUser string
	AuthorizedKeys []ssh.PublicKey
	// contains filtered or unexported fields
}

An SSHService accepts SSH connections on an available TCP port and passes clients' "exec" sessions to the provided SSHExecFunc.

func (*SSHService) Address

func (ss *SSHService) Address() string

Address returns the host:port where the SSH server is listening. It returns "" if called before the server is ready to accept connections.

func (*SSHService) Close

func (ss *SSHService) Close()

Close shuts down the server and releases resources. Established connections are unaffected.

func (*SSHService) RemoteUser

func (ss *SSHService) RemoteUser() string

RemoteUser returns the username that will be accepted.

func (*SSHService) Start

func (ss *SSHService) Start() error

Start returns when the server is ready to accept connections.

type StubDriver

type StubDriver struct {
	HostKey        ssh.Signer
	AuthorizedKeys []ssh.PublicKey

	// SetupVM, if set, is called upon creation of each new
	// StubVM. This is the caller's opportunity to customize the
	// VM's error rate and other behaviors.
	//
	// If SetupVM returns an error, that error will be returned to
	// the caller of Create(), and the new VM will be discarded.
	SetupVM func(*StubVM) error

	// Bugf, if set, is called if a bug is detected in the caller
	// or stub. Typically set to (*check.C)Errorf. If unset,
	// logger.Warnf is called instead.
	Bugf func(string, ...interface{})

	// StubVM's fake crunch-run uses this Queue to read and update
	// container state.
	Queue *Queue

	// Frequency of artificially introduced errors on calls to
	// Create and Destroy. 0=always succeed, 1=always fail.
	ErrorRateCreate  float64
	ErrorRateDestroy float64

	// If Create() or Instances() is called too frequently, return
	// rate-limiting errors.
	MinTimeBetweenCreateCalls    time.Duration
	MinTimeBetweenInstancesCalls time.Duration

	QuotaMaxInstances int

	// If true, Create and Destroy calls block until Release() is
	// called.
	HoldCloudOps bool
	// contains filtered or unexported fields
}

A StubDriver implements cloud.Driver by setting up local SSH servers that do fake command executions.

func (*StubDriver) InstanceSet

InstanceSet returns a new *StubInstanceSet.

func (*StubDriver) InstanceSets

func (sd *StubDriver) InstanceSets() []*StubInstanceSet

InstanceSets returns all instances that have been created by the driver. This can be used to test a component that uses the driver but doesn't expose the InstanceSets it has created.

func (*StubDriver) ReleaseCloudOps

func (sd *StubDriver) ReleaseCloudOps(n int)

ReleaseCloudOps releases n pending Create/Destroy calls. If there are fewer than n blocked calls pending, it waits for the rest to arrive.

type StubInstanceSet

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

func (*StubInstanceSet) Create

func (sis *StubInstanceSet) Create(it arvados.InstanceType, image cloud.ImageID, tags cloud.InstanceTags, initCommand cloud.InitCommand, authKey ssh.PublicKey) (cloud.Instance, error)

func (*StubInstanceSet) Instances

func (sis *StubInstanceSet) Instances(cloud.InstanceTags) ([]cloud.Instance, error)

func (*StubInstanceSet) Stop

func (sis *StubInstanceSet) Stop()

func (*StubInstanceSet) StubVMs

func (sis *StubInstanceSet) StubVMs() (svms []*StubVM)

type StubVM

type StubVM struct {
	Boot                  time.Time
	Broken                time.Time
	ReportBroken          time.Time
	CrunchRunMissing      bool
	CrunchRunCrashRate    float64
	CrunchRunDetachDelay  time.Duration
	ArvMountMaxExitLag    time.Duration
	ArvMountDeadlockRate  float64
	ExecuteContainer      func(arvados.Container) int
	CrashRunningContainer func(arvados.Container)
	ExtraCrunchRunArgs    string // extra args expected after "crunch-run --detach --stdin-config "

	// Populated by (*StubInstanceSet)Create()
	InitCommand cloud.InitCommand

	SSHService SSHService

	sync.Mutex
	// contains filtered or unexported fields
}

StubVM is a fake server that runs an SSH service. It represents a VM running in a fake cloud.

Note this is distinct from a stubInstance, which is a snapshot of the VM's metadata. Like a VM in a real cloud, a StubVM keeps running (and might change IP addresses, shut down, etc.) without updating any stubInstances that have been returned to callers.

func (*StubVM) Exec

func (svm *StubVM) Exec(env map[string]string, command string, stdin io.Reader, stdout, stderr io.Writer) uint32

func (*StubVM) Instance

func (svm *StubVM) Instance() stubInstance

Jump to

Keyboard shortcuts

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