Documentation ¶
Overview ¶
Package test provides fakes and other tools for testing cloud drivers and other dispatcher modules.
Index ¶
- func ContainerUUID(i int) string
- func InstanceType(i int) arvados.InstanceType
- func LoadTestKey(c *check.C, fnm string) (ssh.PublicKey, ssh.Signer)
- type CapacityError
- type Queue
- func (q *Queue) Cancel(uuid string) error
- func (q *Queue) Entries() (map[string]container.QueueEnt, time.Time)
- func (q *Queue) Forget(uuid string)
- func (q *Queue) Get(uuid string) (arvados.Container, bool)
- func (q *Queue) Lock(uuid string) error
- func (q *Queue) Notify(upd arvados.Container) bool
- func (q *Queue) StateChanges() []QueueStateChange
- func (q *Queue) Subscribe() <-chan struct{}
- func (q *Queue) Unlock(uuid string) error
- func (q *Queue) Unsubscribe(ch <-chan struct{})
- func (q *Queue) Update() error
- type QueueStateChange
- type QuotaError
- type RateLimitError
- type SSHExecFunc
- type SSHService
- type StubDriver
- type StubInstanceSet
- func (sis *StubInstanceSet) Create(it arvados.InstanceType, image cloud.ImageID, tags cloud.InstanceTags, ...) (cloud.Instance, error)
- func (sis *StubInstanceSet) InstanceQuotaGroup(it arvados.InstanceType) cloud.InstanceQuotaGroup
- func (sis *StubInstanceSet) Instances(cloud.InstanceTags) ([]cloud.Instance, error)
- func (sis *StubInstanceSet) Stop()
- func (sis *StubInstanceSet) StubVMs() (svms []*StubVM)
- type StubVM
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
Types ¶
type CapacityError ¶
func (CapacityError) Error ¶
func (e CapacityError) Error() string
func (CapacityError) IsCapacityError ¶
func (e CapacityError) IsCapacityError() bool
func (CapacityError) IsInstanceQuotaGroupSpecific ¶
func (e CapacityError) IsInstanceQuotaGroupSpecific() 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) Entries ¶
Entries returns the containers that were queued when Update was last called.
func (*Queue) Get ¶
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) Notify ¶
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.
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 ¶
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 ¶
func (sd *StubDriver) InstanceSet(params json.RawMessage, id cloud.InstanceSetID, _ cloud.SharedResourceTags, logger logrus.FieldLogger, reg *prometheus.Registry) (cloud.InstanceSet, error)
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) InstanceQuotaGroup ¶
func (sis *StubInstanceSet) InstanceQuotaGroup(it arvados.InstanceType) cloud.InstanceQuotaGroup
InstanceQuotaGroup returns the first character of the given instance's ProviderType. Use ProviderTypes like "a1", "a2", "b1", "b2" to test instance quota group behaviors.
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.