Documentation ¶
Index ¶
- Variables
- func AgentDisconnect(nodeID string, after time.Duration) (string, error)
- func AgentRestart(client *api.Client, nodeID string) (string, error)
- func AgentRestartAfter(nodeID string, after time.Duration) (string, error)
- func AllocChecks(allocID string) (string, error)
- func AllocExec(allocID, taskID, execCmd, ns string, wc *WaitConfig) (string, error)
- func AllocIDsFromAllocationListStubs(allocs []*api.AllocationListStub) []string
- func AllocLogs(allocID string, logStream LogStream) (string, error)
- func AllocStatuses(jobID, ns string) ([]string, error)
- func AllocStatusesRescheduled(jobID, ns string) ([]string, error)
- func AllocTaskEventsForJob(jobID, ns string) (map[string][]map[string]string, error)
- func AllocTaskLogs(allocID, task string, logStream LogStream) (string, error)
- func AllocsForJob(jobID, ns string) ([]map[string]string, error)
- func AllocsForNode(nodeID string) ([]map[string]string, error)
- func ChildrenJobSummary(jobID string) ([]map[string]string, error)
- func CleanupJobsAndGC(t *testing.T, jobIDs *[]string) func()
- func CleanupJobsAndGCWithContext(t *testing.T, ctx context.Context, jobIDs *[]string)
- func Command(cmd string, args ...string) (string, error)
- func ConsulClient(t *testing.T) *capi.Client
- func CreateConsulNamespaces(t *testing.T, client *capi.Client, namespaces []string)
- func CreateConsulPolicy(t *testing.T, client *capi.Client, namespace string, policy ConsulPolicy) string
- func CreateConsulToken(t *testing.T, client *capi.Client, namespace, policyID string) string
- func DeleteConsulConfigEntry(t *testing.T, client *capi.Client, namespace, kind, name string)
- func DeleteConsulKey(t *testing.T, client *capi.Client, namespace, key string)
- func DeleteConsulNamespaces(t *testing.T, client *capi.Client, namespaces []string)
- func DeleteConsulPolicies(t *testing.T, client *capi.Client, policies map[string][]string)
- func DeleteConsulTokens(t *testing.T, client *capi.Client, tokens map[string][]string)
- func DeploymentsForJob(t *testing.T, nomadClient *api.Client, jobID string) []*api.Deployment
- func Dispatch(jobID string, meta map[string]string, payload string) error
- func DispatchedJobs(jobID string) ([]map[string]string, error)
- func DumpEvals(c *api.Client, jobID string) string
- func GetField(output, key string) (string, error)
- func GetSection(output, key string) (string, error)
- func JobInspectTemplate(jobID, template string) (string, error)
- func LastDeploymentID(jobID, ns string) (string, error)
- func ListConsulNamespaces(t *testing.T, client *capi.Client) []string
- func ListLinuxClientNodes(client *api.Client) ([]string, error)
- func ListWindowsClientNodes(client *api.Client) ([]string, error)
- func NewE2EJob(jobfile string) framework.TestCase
- func NodeStatusList() ([]map[string]string, error)
- func NodeStatusListFiltered(filterFn func(string) bool) ([]map[string]string, error)
- func NomadClient(t *testing.T) *napi.Client
- func Parse2(t *testing.T, jobFile string) (*api.Job, error)
- func ParseColumns(section string) ([]map[string]string, error)
- func ParseFields(section string) (map[string]string, error)
- func PeriodicForce(jobID string) error
- func PreviouslyLaunched(jobID string) ([]map[string]string, error)
- func PutConsulKey(t *testing.T, client *capi.Client, namespace, key, value string)
- func ReadConsulConfigEntry(t *testing.T, client *capi.Client, namespace, kind, name string) capi.ConfigEntry
- func Register(jobID, jobFilePath string) error
- func RegisterAllocs(t *testing.T, nomadClient *api.Client, jobFile, jobID, cToken string) []*api.AllocationListStub
- func RegisterAndWaitForAllocs(t *testing.T, nomadClient *api.Client, jobFile, jobID, cToken string) []*api.AllocationListStub
- func RegisterFromJobspec(jobID, jobspec string) error
- func RegisterWithArgs(jobID, jobFilePath string, args ...string) error
- func RequireConsulDeregistered(require *require.Assertions, client *capi.Client, namespace, service string)
- func RequireConsulRegistered(require *require.Assertions, client *capi.Client, namespace, service string, ...)
- func RequireConsulStatus(require *require.Assertions, client *capi.Client, ...)
- func StopJob(jobID string, args ...string) error
- func VaultClient(t *testing.T) *vapi.Client
- func WaitForAllocFile(allocID, path string, test func(string) bool, wc *WaitConfig) error
- func WaitForAllocNotPending(t *testing.T, nomadClient *api.Client, allocID string)
- func WaitForAllocRunning(t *testing.T, nomadClient *api.Client, allocID string)
- func WaitForAllocStatus(t *testing.T, nomadClient *api.Client, allocID string, status string)
- func WaitForAllocStatusComparison(query func() ([]string, error), comparison func([]string) bool, wc *WaitConfig) error
- func WaitForAllocStatusExpected(jobID, ns string, expected []string) error
- func WaitForAllocStopped(t *testing.T, nomadClient *api.Client, allocID string)
- func WaitForAllocTaskComplete(t *testing.T, nomadClient *api.Client, allocID, task string)
- func WaitForAllocTaskRunning(t *testing.T, nomadClient *api.Client, allocID, task string)
- func WaitForAllocTaskState(t *testing.T, nomadClient *api.Client, allocID, task, state string)
- func WaitForAllocsNotPending(t *testing.T, nomadClient *api.Client, allocIDs []string)
- func WaitForAllocsRunning(t *testing.T, nomadClient *api.Client, allocIDs []string)
- func WaitForAllocsStatus(t *testing.T, nomadClient *api.Client, allocIDs []string, status string)
- func WaitForAllocsStopped(t *testing.T, nomadClient *api.Client, allocIDs []string)
- func WaitForDeployment(t *testing.T, nomadClient *api.Client, deployID string, status string, ...)
- func WaitForJobStopped(t *testing.T, nomadClient *api.Client, job string)
- func WaitForLastDeploymentStatus(jobID, ns, status string, wc *WaitConfig) error
- func WaitForLeader(t *testing.T, nomadClient *api.Client)
- func WaitForNodeStatus(nodeID, status string, wc *WaitConfig) error
- func WaitForNodesReady(t *testing.T, nomadClient *api.Client, nodes int)
- type AllocsByName
- type ConsulPolicy
- type LogStream
- type WaitConfig
Constants ¶
This section is empty.
Variables ¶
var EvalTemplate = template.Must(template.New("dump_eval").Parse(
`{{.Index}}/{{.Total}} Job {{.Eval.JobID}} Eval {{.Eval.ID}}
Type: {{.Eval.Type}}
TriggeredBy: {{.Eval.TriggeredBy}}
{{- if .Eval.DeploymentID}}
Deployment: {{.Eval.DeploymentID}}
{{- end}}
Status: {{.Eval.Status}} {{if .Eval.StatusDescription}}({{.Eval.StatusDescription}}){{end}}
{{- if .Eval.Wait}}
Wait: {{.Eval.Wait}} <- DEPRECATED
{{- end}}
{{- if not .Eval.WaitUntil.IsZero}}
WaitUntil: {{.Eval.WaitUntil}}
{{- end}}
{{- if .Eval.NextEval}}
NextEval: {{.Eval.NextEval}}
{{- end}}
{{- if .Eval.PreviousEval}}
PrevEval: {{.Eval.PreviousEval}}
{{- end}}
{{- if .Eval.BlockedEval}}
BlockedEval: {{.Eval.BlockedEval}}
{{- end}}
{{- if .Eval.FailedTGAllocs }}
Failed Allocs:
{{- end}}
{{- range $k, $v := .Eval.FailedTGAllocs}}
Failed Group: {{$k}}
NodesEvaluated: {{$v.NodesEvaluated}}
NodesFiltered: {{$v.NodesFiltered}}
NodesAvailable: {{range $dc, $n := $v.NodesAvailable}}{{$dc}}:{{$n}} {{end}}
NodesExhausted: {{$v.NodesExhausted}}
ClassFiltered: {{len $v.ClassFiltered}}
ConstraintFilt: {{len $v.ConstraintFiltered}}
DimensionExhst: {{range $d, $n := $v.DimensionExhausted}}{{$d}}:{{$n}} {{end}}
ResourcesExhst: {{range $r, $n := $v.ResourcesExhausted}}{{$r}}:{{$n}} {{end}}
QuotaExhausted: {{range $i, $q := $v.QuotaExhausted}}{{$q}} {{end}}
CoalescedFail: {{$v.CoalescedFailures}}
ScoreMetaData: {{len $v.ScoreMetaData}}
AllocationTime: {{$v.AllocationTime}}
{{- end}}
{{- if .Eval.QueuedAllocations}}
QueuedAllocs: {{range $k, $n := .Eval.QueuedAllocations}}{{$k}}:{{$n}} {{end}}
{{- end}}
SnapshotIdx: {{.Eval.SnapshotIndex}}
CreateIndex: {{.Eval.CreateIndex}}
ModifyIndex: {{.Eval.ModifyIndex}}
`))
Functions ¶
func AgentDisconnect ¶
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 ¶
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 ¶
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 AllocChecks ¶
AllocChecks returns the CLI output from 'nomad alloc checks' on the given alloc ID.
func AllocExec ¶
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 ¶
func AllocIDsFromAllocationListStubs(allocs []*api.AllocationListStub) []string
func AllocStatuses ¶
AllocStatuses returns a slice of client statuses
func AllocStatusesRescheduled ¶
AllocStatusesRescheduled is a helper function that pulls out client statuses only from rescheduled allocs.
func AllocTaskEventsForJob ¶
AllocTaskEventsForJob returns a map of allocation IDs containing a map of Task Event key value pairs
func AllocsForJob ¶
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 ¶
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 CleanupJobsAndGC ¶
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 ¶
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 ¶
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 ¶
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 ¶
CreateConsulNamespaces will create each namespace in Consul, with a description containing the namespace name.
Requires Consul Enterprise.
func CreateConsulPolicy ¶
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 ¶
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 ¶
DeleteConsulConfigEntry deletes the ConfigEntry of the given namespace, kind, and name.
Requires Consul Enterprise.
func DeleteConsulKey ¶
DeleteConsulKey deletes the key from the Consul KV store from given namespace.
Requires Consul Enterprise.
func DeleteConsulNamespaces ¶
DeleteConsulNamespaces will delete each namespace from Consul.
Requires Consul Enterprise.
func DeleteConsulPolicies ¶
DeleteConsulPolicies is used to delete a set Consul ACL policies from Consul.
Requires Consul Enterprise.
func DeleteConsulTokens ¶
DeleteConsulTokens is used to delete a set of tokens from Consul.
Requires Consul Enterprise.
func DeploymentsForJob ¶
func DumpEvals ¶
DumpEvals for a job. This is intended to be used during test development or prior to exiting a test after an assertion failed.
func GetField ¶
GetField returns the value of an output field (ex. the "Submit Date" field of `nomad job status :id`)
func GetSection ¶
GetSection returns a section, with its field header but without its title. (ex. the Allocations section of `nomad job status :id`)
func JobInspectTemplate ¶
JobInspectTemplate runs nomad job inspect and formats the output using the specified go template
func LastDeploymentID ¶
func ListConsulNamespaces ¶
ListConsulNamespaces will list the namespaces in Consul.
Requires Consul Enterprise.
func ListLinuxClientNodes ¶
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 ¶
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 NodeStatusList ¶
func NodeStatusListFiltered ¶
func NomadClient ¶
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 ParseColumns ¶
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 ¶
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 ¶
PeriodicForce forces a periodic job to dispatch
func PutConsulKey ¶
PutConsulKey sets key:value in the Consul KV store under given namespace.
Requires Consul Enterprise.
func ReadConsulConfigEntry ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func RequireConsulDeregistered(require *require.Assertions, client *capi.Client, namespace, service string)
RequireConsulDeregistered asserts that the service eventually is de-registered from Consul.
func RequireConsulRegistered ¶
func RequireConsulRegistered(require *require.Assertions, client *capi.Client, namespace, service string, count int)
RequireConsulRegistered assert that the service is registered in Consul.
func RequireConsulStatus ¶
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 VaultClient ¶
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 ¶
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 ¶
func WaitForAllocRunning ¶
func WaitForAllocStatus ¶
func WaitForAllocStatusComparison ¶
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 ¶
WaitForAllocStatusExpected polls 'nomad job status' and exactly compares the status of all allocations (including any previous versions) against the expected list.
func WaitForAllocStopped ¶
func WaitForAllocTaskRunning ¶
func WaitForAllocTaskState ¶
func WaitForAllocsNotPending ¶
func WaitForAllocsRunning ¶
func WaitForAllocsStatus ¶
func WaitForAllocsStopped ¶
func WaitForDeployment ¶
func WaitForJobStopped ¶
WaitForJobStopped stops a job and waits for all of its allocs to terminate.
func WaitForLastDeploymentStatus ¶
func WaitForLastDeploymentStatus(jobID, ns, status string, wc *WaitConfig) error
func WaitForNodeStatus ¶
func WaitForNodeStatus(nodeID, status string, wc *WaitConfig) error
Types ¶
type AllocsByName ¶
type AllocsByName []*api.AllocationListStub
AllocsByName sorts allocs by Name
func (AllocsByName) Len ¶
func (a AllocsByName) Len() int
func (AllocsByName) Less ¶
func (a AllocsByName) Less(i, j int) bool
func (AllocsByName) Swap ¶
func (a AllocsByName) Swap(i, j int)
type ConsulPolicy ¶
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 WaitConfig ¶
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