2015-08-11 21:27:14 +00:00
|
|
|
package mock
|
|
|
|
|
2015-10-31 01:34:23 +00:00
|
|
|
import (
|
2017-08-07 21:21:00 +00:00
|
|
|
"fmt"
|
2015-10-31 01:34:23 +00:00
|
|
|
"time"
|
2015-11-13 01:47:51 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2015-10-31 01:34:23 +00:00
|
|
|
)
|
2015-08-11 21:27:14 +00:00
|
|
|
|
|
|
|
func Node() *structs.Node {
|
|
|
|
node := &structs.Node{
|
2015-09-07 22:23:03 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
2016-08-16 06:11:57 +00:00
|
|
|
SecretID: structs.GenerateUUID(),
|
2015-08-11 21:27:14 +00:00
|
|
|
Datacenter: "dc1",
|
|
|
|
Name: "foobar",
|
|
|
|
Attributes: map[string]string{
|
2016-08-16 06:11:57 +00:00
|
|
|
"kernel.name": "linux",
|
|
|
|
"arch": "x86",
|
|
|
|
"nomad.version": "0.5.0",
|
|
|
|
"driver.exec": "1",
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
Resources: &structs.Resources{
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 4000,
|
2015-08-11 21:27:14 +00:00
|
|
|
MemoryMB: 8192,
|
|
|
|
DiskMB: 100 * 1024,
|
|
|
|
IOPS: 150,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
&structs.NetworkResource{
|
2015-09-13 02:34:46 +00:00
|
|
|
Device: "eth0",
|
|
|
|
CIDR: "192.168.0.100/32",
|
|
|
|
MBits: 1000,
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Reserved: &structs.Resources{
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 100,
|
2015-08-11 21:27:14 +00:00
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
2015-09-13 02:34:46 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
&structs.NetworkResource{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
2015-11-14 02:35:49 +00:00
|
|
|
ReservedPorts: []structs.Port{{Label: "main", Value: 22}},
|
2015-09-13 02:34:46 +00:00
|
|
|
MBits: 1,
|
|
|
|
},
|
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
Links: map[string]string{
|
|
|
|
"consul": "foobar.dc1",
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
2016-03-28 19:25:16 +00:00
|
|
|
"pci-dss": "true",
|
|
|
|
"database": "mysql",
|
|
|
|
"version": "5.6",
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
NodeClass: "linux-medium-pci",
|
|
|
|
Status: structs.NodeStatusReady,
|
|
|
|
}
|
2016-01-27 01:34:41 +00:00
|
|
|
node.ComputeClass()
|
2015-08-11 21:27:14 +00:00
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
func Job() *structs.Job {
|
|
|
|
job := &structs.Job{
|
2015-09-15 18:12:46 +00:00
|
|
|
Region: "global",
|
2015-09-07 22:23:03 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
2015-08-14 05:07:01 +00:00
|
|
|
Name: "my-job",
|
2017-09-07 23:56:15 +00:00
|
|
|
Namespace: structs.DefaultNamespace,
|
2015-08-14 05:07:01 +00:00
|
|
|
Type: structs.JobTypeService,
|
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
2015-08-11 21:27:14 +00:00
|
|
|
Constraints: []*structs.Constraint{
|
|
|
|
&structs.Constraint{
|
2016-02-05 00:50:20 +00:00
|
|
|
LTarget: "${attr.kernel.name}",
|
2015-08-11 21:27:14 +00:00
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
|
|
|
&structs.TaskGroup{
|
|
|
|
Name: "web",
|
|
|
|
Count: 10,
|
2016-09-14 22:43:42 +00:00
|
|
|
EphemeralDisk: &structs.EphemeralDisk{
|
|
|
|
SizeMB: 150,
|
2016-08-25 17:27:19 +00:00
|
|
|
},
|
2015-10-31 01:34:23 +00:00
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
2016-02-02 23:08:07 +00:00
|
|
|
Attempts: 3,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeDelay,
|
2015-10-31 01:34:23 +00:00
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
Tasks: []*structs.Task{
|
|
|
|
&structs.Task{
|
|
|
|
Name: "web",
|
2015-08-29 23:24:01 +00:00
|
|
|
Driver: "exec",
|
2015-11-14 02:09:42 +00:00
|
|
|
Config: map[string]interface{}{
|
2015-08-29 23:24:01 +00:00
|
|
|
"command": "/bin/date",
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
2015-10-23 21:52:06 +00:00
|
|
|
Env: map[string]string{
|
|
|
|
"FOO": "bar",
|
|
|
|
},
|
2016-06-12 23:36:49 +00:00
|
|
|
Services: []*structs.Service{
|
2015-11-27 03:26:00 +00:00
|
|
|
{
|
|
|
|
Name: "${TASK}-frontend",
|
|
|
|
PortLabel: "http",
|
2016-03-26 19:49:49 +00:00
|
|
|
Tags: []string{"pci:${meta.pci-dss}", "datacenter:${node.datacenter}"},
|
2016-03-28 19:25:16 +00:00
|
|
|
Checks: []*structs.ServiceCheck{
|
|
|
|
{
|
|
|
|
Name: "check-table",
|
|
|
|
Type: structs.ServiceCheckScript,
|
2016-03-28 21:36:51 +00:00
|
|
|
Command: "/usr/local/check-table-${meta.database}",
|
2016-03-28 19:25:16 +00:00
|
|
|
Args: []string{"${meta.version}"},
|
|
|
|
Interval: 30 * time.Second,
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
2015-11-27 03:26:00 +00:00
|
|
|
},
|
2015-12-15 18:43:56 +00:00
|
|
|
{
|
|
|
|
Name: "${TASK}-admin",
|
|
|
|
PortLabel: "admin",
|
|
|
|
},
|
2015-11-27 03:26:00 +00:00
|
|
|
},
|
2016-02-11 01:46:35 +00:00
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
2015-08-11 21:27:14 +00:00
|
|
|
Resources: &structs.Resources{
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 500,
|
2015-08-11 21:27:14 +00:00
|
|
|
MemoryMB: 256,
|
2015-09-13 23:40:31 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
&structs.NetworkResource{
|
|
|
|
MBits: 50,
|
2015-12-15 18:43:56 +00:00
|
|
|
DynamicPorts: []structs.Port{{Label: "http"}, {Label: "admin"}},
|
2015-09-13 23:40:31 +00:00
|
|
|
},
|
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
2016-04-26 00:20:25 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"elb_check_type": "http",
|
|
|
|
"elb_check_interval": "30s",
|
|
|
|
"elb_check_min": "3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
|
|
|
},
|
2016-01-12 17:50:33 +00:00
|
|
|
Status: structs.JobStatusPending,
|
2017-04-13 20:54:57 +00:00
|
|
|
Version: 0,
|
2016-01-12 17:50:33 +00:00
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
2015-08-11 21:27:14 +00:00
|
|
|
}
|
2016-07-20 23:07:15 +00:00
|
|
|
job.Canonicalize()
|
2015-08-11 21:27:14 +00:00
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2015-10-14 23:43:06 +00:00
|
|
|
func SystemJob() *structs.Job {
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
2017-09-07 23:56:15 +00:00
|
|
|
Namespace: structs.DefaultNamespace,
|
2015-10-14 23:43:06 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
|
|
|
Name: "my-job",
|
|
|
|
Type: structs.JobTypeSystem,
|
|
|
|
Priority: 100,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Constraints: []*structs.Constraint{
|
|
|
|
&structs.Constraint{
|
2016-02-05 00:50:20 +00:00
|
|
|
LTarget: "${attr.kernel.name}",
|
2015-10-14 23:43:06 +00:00
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
|
|
|
&structs.TaskGroup{
|
2015-10-15 20:14:44 +00:00
|
|
|
Name: "web",
|
|
|
|
Count: 1,
|
2015-10-31 01:34:23 +00:00
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
2016-02-02 23:08:07 +00:00
|
|
|
Attempts: 3,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeDelay,
|
2015-10-31 01:34:23 +00:00
|
|
|
},
|
2016-09-14 22:43:42 +00:00
|
|
|
EphemeralDisk: structs.DefaultEphemeralDisk(),
|
2015-10-14 23:43:06 +00:00
|
|
|
Tasks: []*structs.Task{
|
|
|
|
&structs.Task{
|
|
|
|
Name: "web",
|
|
|
|
Driver: "exec",
|
2015-11-14 02:09:42 +00:00
|
|
|
Config: map[string]interface{}{
|
2015-10-14 23:43:06 +00:00
|
|
|
"command": "/bin/date",
|
|
|
|
},
|
2016-08-16 17:49:45 +00:00
|
|
|
Env: map[string]string{},
|
2015-10-14 23:43:06 +00:00
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
&structs.NetworkResource{
|
|
|
|
MBits: 50,
|
2015-11-14 02:35:49 +00:00
|
|
|
DynamicPorts: []structs.Port{{Label: "http"}},
|
2015-10-14 23:43:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-02-11 01:46:35 +00:00
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
2015-10-14 23:43:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
|
|
|
},
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
}
|
2016-12-12 21:32:30 +00:00
|
|
|
job.Canonicalize()
|
2015-10-14 23:43:06 +00:00
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2015-12-18 20:26:28 +00:00
|
|
|
func PeriodicJob() *structs.Job {
|
|
|
|
job := Job()
|
2015-12-05 00:53:36 +00:00
|
|
|
job.Type = structs.JobTypeBatch
|
2015-12-18 20:26:28 +00:00
|
|
|
job.Periodic = &structs.PeriodicConfig{
|
|
|
|
Enabled: true,
|
|
|
|
SpecType: structs.PeriodicSpecCron,
|
2015-12-05 00:53:36 +00:00
|
|
|
Spec: "*/30 * * * *",
|
2015-12-18 20:26:28 +00:00
|
|
|
}
|
2016-12-12 21:32:30 +00:00
|
|
|
job.Status = structs.JobStatusRunning
|
2015-12-18 20:26:28 +00:00
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2015-08-11 21:27:14 +00:00
|
|
|
func Eval() *structs.Evaluation {
|
|
|
|
eval := &structs.Evaluation{
|
2017-09-07 23:56:15 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Priority: 50,
|
|
|
|
Type: structs.JobTypeService,
|
|
|
|
JobID: structs.GenerateUUID(),
|
|
|
|
Status: structs.EvalStatusPending,
|
2015-08-11 21:27:14 +00:00
|
|
|
}
|
|
|
|
return eval
|
|
|
|
}
|
|
|
|
|
2016-07-20 21:09:03 +00:00
|
|
|
func JobSummary(jobID string) *structs.JobSummary {
|
|
|
|
js := &structs.JobSummary{
|
2017-09-07 23:56:15 +00:00
|
|
|
JobID: jobID,
|
|
|
|
Namespace: structs.DefaultNamespace,
|
2016-07-20 21:09:03 +00:00
|
|
|
Summary: map[string]structs.TaskGroupSummary{
|
2016-07-21 21:43:21 +00:00
|
|
|
"web": {
|
|
|
|
Queued: 0,
|
|
|
|
Starting: 0,
|
2016-07-20 21:09:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return js
|
|
|
|
}
|
|
|
|
|
2015-08-11 21:27:14 +00:00
|
|
|
func Alloc() *structs.Allocation {
|
|
|
|
alloc := &structs.Allocation{
|
2015-09-07 22:23:03 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
|
|
|
EvalID: structs.GenerateUUID(),
|
2016-01-14 20:57:43 +00:00
|
|
|
NodeID: "12345678-abcd-efab-cdef-123456789abc",
|
2017-09-07 23:56:15 +00:00
|
|
|
Namespace: structs.DefaultNamespace,
|
2015-08-29 23:24:01 +00:00
|
|
|
TaskGroup: "web",
|
2015-08-11 21:27:14 +00:00
|
|
|
Resources: &structs.Resources{
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 500,
|
2015-09-14 00:06:34 +00:00
|
|
|
MemoryMB: 256,
|
2016-08-29 19:49:52 +00:00
|
|
|
DiskMB: 150,
|
2015-08-11 21:27:14 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
&structs.NetworkResource{
|
2015-09-13 02:13:00 +00:00
|
|
|
Device: "eth0",
|
2015-09-14 00:06:34 +00:00
|
|
|
IP: "192.168.0.100",
|
2016-03-01 22:09:25 +00:00
|
|
|
ReservedPorts: []structs.Port{{Label: "main", Value: 5000}},
|
|
|
|
MBits: 50,
|
2015-11-14 02:35:49 +00:00
|
|
|
DynamicPorts: []structs.Port{{Label: "http"}},
|
2015-09-14 00:06:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskResources: map[string]*structs.Resources{
|
|
|
|
"web": &structs.Resources{
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 500,
|
2015-09-14 00:06:34 +00:00
|
|
|
MemoryMB: 256,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
&structs.NetworkResource{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
2015-11-14 02:35:49 +00:00
|
|
|
ReservedPorts: []structs.Port{{Label: "main", Value: 5000}},
|
2015-09-14 00:06:34 +00:00
|
|
|
MBits: 50,
|
2017-01-24 17:36:22 +00:00
|
|
|
DynamicPorts: []structs.Port{{Label: "http"}},
|
2015-09-14 00:06:34 +00:00
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-08-29 19:49:52 +00:00
|
|
|
SharedResources: &structs.Resources{
|
|
|
|
DiskMB: 150,
|
|
|
|
},
|
2015-08-25 23:19:21 +00:00
|
|
|
Job: Job(),
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
2015-08-11 21:27:14 +00:00
|
|
|
}
|
|
|
|
alloc.JobID = alloc.Job.ID
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2016-08-19 01:14:58 +00:00
|
|
|
func VaultAccessor() *structs.VaultAccessor {
|
|
|
|
return &structs.VaultAccessor{
|
|
|
|
Accessor: structs.GenerateUUID(),
|
|
|
|
NodeID: structs.GenerateUUID(),
|
|
|
|
AllocID: structs.GenerateUUID(),
|
|
|
|
CreationTTL: 86400,
|
|
|
|
Task: "foo",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-24 21:49:23 +00:00
|
|
|
func Deployment() *structs.Deployment {
|
|
|
|
return &structs.Deployment{
|
2017-05-05 20:52:01 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
|
|
|
JobID: structs.GenerateUUID(),
|
2017-09-07 23:56:15 +00:00
|
|
|
Namespace: structs.DefaultNamespace,
|
2017-05-05 20:52:01 +00:00
|
|
|
JobVersion: 2,
|
|
|
|
JobModifyIndex: 20,
|
|
|
|
JobCreateIndex: 18,
|
|
|
|
TaskGroups: map[string]*structs.DeploymentState{
|
|
|
|
"web": &structs.DeploymentState{
|
|
|
|
DesiredTotal: 10,
|
|
|
|
},
|
|
|
|
},
|
2017-04-24 21:49:23 +00:00
|
|
|
Status: structs.DeploymentStatusRunning,
|
2017-06-29 05:00:18 +00:00
|
|
|
StatusDescription: structs.DeploymentStatusDescriptionRunning,
|
2017-04-24 21:49:23 +00:00
|
|
|
ModifyIndex: 23,
|
|
|
|
CreateIndex: 21,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-11 21:27:14 +00:00
|
|
|
func Plan() *structs.Plan {
|
|
|
|
return &structs.Plan{
|
|
|
|
Priority: 50,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func PlanResult() *structs.PlanResult {
|
|
|
|
return &structs.PlanResult{}
|
|
|
|
}
|
2017-08-07 21:21:00 +00:00
|
|
|
|
|
|
|
func ACLPolicy() *structs.ACLPolicy {
|
2017-08-30 17:06:56 +00:00
|
|
|
ap := &structs.ACLPolicy{
|
2017-08-08 06:02:03 +00:00
|
|
|
Name: fmt.Sprintf("policy-%s", structs.GenerateUUID()),
|
|
|
|
Description: "Super cool policy!",
|
2017-08-07 21:21:00 +00:00
|
|
|
Rules: `
|
|
|
|
namespace "default" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
2017-08-08 06:10:39 +00:00
|
|
|
node {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
agent {
|
|
|
|
policy = "read"
|
|
|
|
}
|
2017-08-07 21:21:00 +00:00
|
|
|
`,
|
|
|
|
CreateIndex: 10,
|
|
|
|
ModifyIndex: 20,
|
|
|
|
}
|
2017-08-30 17:06:56 +00:00
|
|
|
ap.SetHash()
|
|
|
|
return ap
|
2017-08-07 21:21:00 +00:00
|
|
|
}
|
2017-08-12 22:18:47 +00:00
|
|
|
|
|
|
|
func ACLToken() *structs.ACLToken {
|
2017-08-30 17:06:56 +00:00
|
|
|
tk := &structs.ACLToken{
|
2017-08-12 22:18:47 +00:00
|
|
|
AccessorID: structs.GenerateUUID(),
|
|
|
|
SecretID: structs.GenerateUUID(),
|
|
|
|
Name: "my cool token " + structs.GenerateUUID(),
|
|
|
|
Type: "client",
|
|
|
|
Policies: []string{"foo", "bar"},
|
|
|
|
Global: false,
|
|
|
|
CreateTime: time.Now().UTC(),
|
|
|
|
CreateIndex: 10,
|
|
|
|
ModifyIndex: 20,
|
|
|
|
}
|
2017-08-30 17:06:56 +00:00
|
|
|
tk.SetHash()
|
|
|
|
return tk
|
2017-08-12 22:18:47 +00:00
|
|
|
}
|
2017-08-21 02:59:25 +00:00
|
|
|
|
|
|
|
func ACLManagementToken() *structs.ACLToken {
|
|
|
|
return &structs.ACLToken{
|
|
|
|
AccessorID: structs.GenerateUUID(),
|
|
|
|
SecretID: structs.GenerateUUID(),
|
|
|
|
Name: "management " + structs.GenerateUUID(),
|
|
|
|
Type: "management",
|
|
|
|
Global: true,
|
|
|
|
CreateTime: time.Now().UTC(),
|
|
|
|
CreateIndex: 10,
|
|
|
|
ModifyIndex: 20,
|
|
|
|
}
|
|
|
|
}
|