e2eutil

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MPL-2.0 Imports: 28 Imported by: 217

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentDisconnect added in v1.3.0

func AgentDisconnect(nodeID string, after time.Duration) (string, error)

AgentDisconnect is a test helper function that runs a raw_exec job that will disconnect a client at the network level and reconnect it after the specified period of time.

Returns once the job is registered with the job ID of the restart job and any registration errors, not after the duration, so that callers can take actions while the client is down.

func AgentRestart added in v0.10.0

func AgentRestart(client *api.Client, nodeID string) (string, error)

AgentRestart is a test helper function that restarts a client node running under systemd using a raw_exec job. Returns the job ID of the restart job so that callers can clean it up.

func AgentRestartAfter added in v1.3.0

func AgentRestartAfter(nodeID string, after time.Duration) (string, error)

AgentRestartAfter is a test helper function that runs a raw_exec job that will stop a client and restart it after the specified period of time. The node must be running under systemd.

Returns once the job is registered with the job ID of the restart job and any registration errors, not after the duration, so that callers can take actions while the client is down.

func AllocExec added in v1.0.0

func AllocExec(allocID, taskID, execCmd, ns string, wc *WaitConfig) (string, error)

AllocExec is a convenience wrapper that runs 'nomad alloc exec' with the passed execCmd via '/bin/sh -c', retrying if the task isn't ready

func AllocIDsFromAllocationListStubs added in v0.10.4

func AllocIDsFromAllocationListStubs(allocs []*api.AllocationListStub) []string

func AllocLogs added in v0.12.10

func AllocLogs(allocID string, logStream LogStream) (string, error)

func AllocStatuses added in v1.0.0

func AllocStatuses(jobID, ns string) ([]string, error)

AllocStatuses returns a slice of client statuses

func AllocStatusesRescheduled added in v1.0.0

func AllocStatusesRescheduled(jobID, ns string) ([]string, error)

AllocStatusesRescheduled is a helper function that pulls out client statuses only from rescheduled allocs.

func AllocTaskEventsForJob added in v1.1.0

func AllocTaskEventsForJob(jobID, ns string) (map[string][]map[string]string, error)

AllocTaskEventsForJob returns a map of allocation IDs containing a map of Task Event key value pairs

func AllocTaskLogs added in v0.12.10

func AllocTaskLogs(allocID, task string, logStream LogStream) (string, error)

func AllocsForJob added in v1.0.0

func AllocsForJob(jobID, ns string) ([]map[string]string, error)

AllocsForJob returns a slice of key->value maps, each describing the values of the 'nomad job status' Allocations section (not actual structs.Allocation objects, query the API if you want those)

func AllocsForNode added in v1.0.0

func AllocsForNode(nodeID string) ([]map[string]string, error)

AllocsForNode returns a slice of key->value maps, each describing the values of the 'nomad node status' Allocations section (not actual structs.Allocation objects, query the API if you want those)

func ChildrenJobSummary added in v1.0.4

func ChildrenJobSummary(jobID string) ([]map[string]string, error)

func CleanupJobsAndGC added in v1.3.0

func CleanupJobsAndGC(t *testing.T, jobIDs *[]string) func()

CleanupJobsAndGC stops and purges the list of jobIDs and runs a system gc. Returns a func so that the return value can be used in t.Cleanup

func CleanupJobsAndGCWithContext added in v1.3.0

func CleanupJobsAndGCWithContext(t *testing.T, ctx context.Context, jobIDs *[]string)

CleanupJobsAndGCWithContext stops and purges the list of jobIDs and runs a system gc. The passed context allows callers to cancel the execution of the cleanup as they desire. This is useful for tests which attempt to remove the job as part of their run, but may fail before that point is reached.

func Command added in v0.12.10

func Command(cmd string, args ...string) (string, error)

Command sends a command line argument to Nomad and returns the unbuffered stdout as a string (or, if there's an error, the stderr)

func ConsulClient added in v1.3.0

func ConsulClient(t *testing.T) *capi.Client

ConsulClient creates a default Consul client based on the env vars from the test environment. Fails the test if it can't be created

func CreateConsulNamespaces added in v1.1.0

func CreateConsulNamespaces(t *testing.T, client *capi.Client, namespaces []string)

CreateConsulNamespaces will create each namespace in Consul, with a description containing the namespace name.

Requires Consul Enterprise.

func CreateConsulPolicy added in v1.1.0

func CreateConsulPolicy(t *testing.T, client *capi.Client, namespace string, policy ConsulPolicy) string

CreateConsulPolicy is used to create a Consul ACL policy backed by the given ConsulPolicy in the specified namespace.

Requires Consul Enterprise.

func CreateConsulToken added in v1.1.0

func CreateConsulToken(t *testing.T, client *capi.Client, namespace, policyID string) string

CreateConsulToken is used to create a Consul ACL token backed by the policy of the given policyID in the specified namespace.

Requires Consul Enterprise.

func DeleteConsulConfigEntry added in v1.1.0

func DeleteConsulConfigEntry(t *testing.T, client *capi.Client, namespace, kind, name string)

DeleteConsulConfigEntry deletes the ConfigEntry of the given namespace, kind, and name.

Requires Consul Enterprise.

func DeleteConsulKey added in v1.1.0

func DeleteConsulKey(t *testing.T, client *capi.Client, namespace, key string)

DeleteConsulKey deletes the key from the Consul KV store from given namespace.

Requires Consul Enterprise.

func DeleteConsulNamespaces added in v1.1.0

func DeleteConsulNamespaces(t *testing.T, client *capi.Client, namespaces []string)

DeleteConsulNamespaces will delete each namespace from Consul.

Requires Consul Enterprise.

func DeleteConsulPolicies added in v1.1.0

func DeleteConsulPolicies(t *testing.T, client *capi.Client, policies map[string][]string)

DeleteConsulPolicies is used to delete a set Consul ACL policies from Consul.

Requires Consul Enterprise.

func DeleteConsulTokens added in v1.1.0

func DeleteConsulTokens(t *testing.T, client *capi.Client, tokens map[string][]string)

DeleteConsulTokens is used to delete a set of tokens from Consul.

Requires Consul Enterprise.

func DeploymentsForJob added in v0.9.3

func DeploymentsForJob(t *testing.T, nomadClient *api.Client, jobID string) []*api.Deployment

func Dispatch added in v1.0.6

func Dispatch(jobID string, meta map[string]string, payload string) error

Dispatch dispatches a parameterized job

func DispatchedJobs added in v1.0.6

func DispatchedJobs(jobID string) ([]map[string]string, error)

func GetField added in v1.0.0

func GetField(output, key string) (string, error)

GetField returns the value of an output field (ex. the "Submit Date" field of `nomad job status :id`)

func GetSection added in v1.0.0

func GetSection(output, key string) (string, error)

GetSection returns a section, with its field header but without its title. (ex. the Allocations section of `nomad job status :id`)

func JobInspectTemplate added in v1.0.4

func JobInspectTemplate(jobID, template string) (string, error)

JobInspectTemplate runs nomad job inspect and formats the output using the specified go template

func LastDeploymentID added in v1.0.0

func LastDeploymentID(jobID, ns string) (string, error)

func ListConsulNamespaces added in v1.1.0

func ListConsulNamespaces(t *testing.T, client *capi.Client) []string

ListConsulNamespaces will list the namespaces in Consul.

Requires Consul Enterprise.

func ListLinuxClientNodes added in v0.10.4

func ListLinuxClientNodes(client *api.Client) ([]string, error)

ListLinuxClientNodes returns a list of Linux client IDs, so that tests can skip operating-specific tests if there are no Linux clients available Returns an error only on client errors.

func ListWindowsClientNodes added in v0.10.4

func ListWindowsClientNodes(client *api.Client) ([]string, error)

ListWindowsClientNodes returns a list of Windows client IDs, so that tests can skip operating-specific tests if there are no Windows clients available. Returns an error only on client errors.

func NewE2EJob added in v1.0.0

func NewE2EJob(jobfile string) framework.TestCase

func NodeStatusList added in v1.0.0

func NodeStatusList() ([]map[string]string, error)

func NodeStatusListFiltered added in v1.0.0

func NodeStatusListFiltered(filterFn func(string) bool) ([]map[string]string, error)

func NomadClient added in v1.3.0

func NomadClient(t *testing.T) *napi.Client

NomadClient creates a default Nomad client based on the env vars from the test environment. Fails the test if it can't be created

func Parse2 added in v1.0.4

func Parse2(t *testing.T, jobFile string) (*api.Job, error)

func ParseColumns added in v1.0.0

func ParseColumns(section string) ([]map[string]string, error)

ParseColumns maps the CLI output for a columized section (without title) to a slice of key->value pairs for each row in that section. (ex. the Allocations section of `nomad job status :id`)

func ParseFields added in v1.0.0

func ParseFields(section string) (map[string]string, error)

ParseFields maps the CLI output for a key-value section (without title) to map of the key->value pairs in that section (ex. the Latest Deployment section of `nomad job status :id`)

func PeriodicForce added in v1.0.4

func PeriodicForce(jobID string) error

PeriodicForce forces a periodic job to dispatch

func PreviouslyLaunched added in v1.0.4

func PreviouslyLaunched(jobID string) ([]map[string]string, error)

func PutConsulKey added in v1.1.0

func PutConsulKey(t *testing.T, client *capi.Client, namespace, key, value string)

PutConsulKey sets key:value in the Consul KV store under given namespace.

Requires Consul Enterprise.

func ReadConsulConfigEntry added in v1.1.0

func ReadConsulConfigEntry(t *testing.T, client *capi.Client, namespace, kind, name string) capi.ConfigEntry

ReadConsulConfigEntry retrieves the ConfigEntry of the given namespace, kind, and name.

Requires Consul Enterprise.

func Register added in v1.0.0

func Register(jobID, jobFilePath string) error

Register registers a jobspec from a file but with a unique ID. The caller is responsible for recording that ID for later cleanup.

func RegisterAllocs added in v0.9.2

func RegisterAllocs(t *testing.T, nomadClient *api.Client, jobFile, jobID, cToken string) []*api.AllocationListStub

func RegisterAndWaitForAllocs

func RegisterAndWaitForAllocs(t *testing.T, nomadClient *api.Client, jobFile, jobID, cToken string) []*api.AllocationListStub

RegisterAndWaitForAllocs wraps RegisterAllocs but blocks until Evals successfully create Allocs.

func RegisterFromJobspec added in v1.0.0

func RegisterFromJobspec(jobID, jobspec string) error

RegisterFromJobspec registers a jobspec from a string, also with a unique ID. The caller is responsible for recording that ID for later cleanup.

func RegisterWithArgs added in v1.2.4

func RegisterWithArgs(jobID, jobFilePath string, args ...string) error

RegisterWithArgs registers a jobspec from a file but with a unique ID. The optional args are added to the run command. The caller is responsible for recording that ID for later cleanup.

func RequireConsulDeregistered added in v0.10.0

func RequireConsulDeregistered(require *require.Assertions, client *capi.Client, namespace, service string)

RequireConsulDeregistered asserts that the service eventually is de-registered from Consul.

func RequireConsulRegistered added in v1.0.2

func RequireConsulRegistered(require *require.Assertions, client *capi.Client, namespace, service string, count int)

RequireConsulRegistered assert that the service is registered in Consul.

func RequireConsulStatus added in v0.10.0

func RequireConsulStatus(require *require.Assertions, client *capi.Client, namespace, service, expectedStatus string)

RequireConsulStatus asserts the aggregate health of the service converges to the expected status.

func StopJob added in v1.3.0

func StopJob(jobID string, args ...string) error

func VaultClient added in v1.3.0

func VaultClient(t *testing.T) *vapi.Client

VaultClient creates a default Vault client based on the env vars from the test environment. Fails the test if it can't be created

func WaitForAllocFile added in v1.0.0

func WaitForAllocFile(allocID, path string, test func(string) bool, wc *WaitConfig) error

WaitForAllocFile is a helper that grabs a file via alloc fs and tests its contents; useful for checking the results of rendered templates

func WaitForAllocNotPending added in v0.10.4

func WaitForAllocNotPending(t *testing.T, nomadClient *api.Client, allocID string)

func WaitForAllocRunning

func WaitForAllocRunning(t *testing.T, nomadClient *api.Client, allocID string)

func WaitForAllocStatus added in v1.2.0

func WaitForAllocStatus(t *testing.T, nomadClient *api.Client, allocID string, status string)

func WaitForAllocStatusComparison added in v1.0.0

func WaitForAllocStatusComparison(query func() ([]string, error), comparison func([]string) bool, wc *WaitConfig) error

WaitForAllocStatusComparison is a convenience wrapper that polls the query function until the comparison function returns true.

func WaitForAllocStatusExpected added in v1.0.0

func WaitForAllocStatusExpected(jobID, ns string, expected []string) error

WaitForAllocStatusExpected polls 'nomad job status' and exactly compares the status of all allocations (including any previous versions) against the expected list.

func WaitForAllocStopped added in v0.11.0

func WaitForAllocStopped(t *testing.T, nomadClient *api.Client, allocID string)

func WaitForAllocTaskRunning added in v0.12.10

func WaitForAllocTaskRunning(t *testing.T, nomadClient *api.Client, allocID, task string)

func WaitForAllocsNotPending added in v0.10.4

func WaitForAllocsNotPending(t *testing.T, nomadClient *api.Client, allocIDs []string)

func WaitForAllocsRunning added in v0.10.4

func WaitForAllocsRunning(t *testing.T, nomadClient *api.Client, allocIDs []string)

func WaitForAllocsStatus added in v1.2.0

func WaitForAllocsStatus(t *testing.T, nomadClient *api.Client, allocIDs []string, status string)

func WaitForAllocsStopped added in v1.1.0

func WaitForAllocsStopped(t *testing.T, nomadClient *api.Client, allocIDs []string)

func WaitForDeployment added in v0.9.2

func WaitForDeployment(t *testing.T, nomadClient *api.Client, deployID string, status string, statusDesc string)

func WaitForJobStopped added in v0.12.4

func WaitForJobStopped(t *testing.T, nomadClient *api.Client, job string)

WaitForJobStopped stops a job and waits for all of its allocs to terminate.

func WaitForLastDeploymentStatus added in v1.0.0

func WaitForLastDeploymentStatus(jobID, ns, status string, wc *WaitConfig) error

func WaitForLeader

func WaitForLeader(t *testing.T, nomadClient *api.Client)

func WaitForNodeStatus added in v1.3.0

func WaitForNodeStatus(nodeID, status string, wc *WaitConfig) error

func WaitForNodesReady

func WaitForNodesReady(t *testing.T, nomadClient *api.Client, nodes int)

WaitForNodesReady waits until at least `nodes` number of nodes are ready or fails the test.

Types

type AllocsByName added in v1.1.0

type AllocsByName []*api.AllocationListStub

AllocsByName sorts allocs by Name

func (AllocsByName) Len added in v1.1.0

func (a AllocsByName) Len() int

func (AllocsByName) Less added in v1.1.0

func (a AllocsByName) Less(i, j int) bool

func (AllocsByName) Swap added in v1.1.0

func (a AllocsByName) Swap(i, j int)

type ConsulPolicy added in v1.1.0

type ConsulPolicy struct {
	Name  string // e.g. nomad-operator
	Rules string // e.g. service "" { policy="write" }
}

ConsulPolicy is used for create Consul ACL policies that Consul ACL tokens can make use of.

type LogStream added in v0.12.10

type LogStream int
const (
	LogsStdErr LogStream = iota
	LogsStdOut
)

type WaitConfig added in v1.0.0

type WaitConfig struct {
	Interval time.Duration
	Retries  int64
}

WaitConfig is an interval and wait time that can be passed to a waiter function, but with a default value that comes from the OrDefault method if the config is nil

func (*WaitConfig) OrDefault added in v1.0.0

func (wc *WaitConfig) OrDefault() (time.Duration, int64)

OrDefault returns a default wait config of 10s.

Jump to

Keyboard shortcuts

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