2016-03-12 02:24:58 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
2017-05-30 18:39:26 +00:00
|
|
|
"strings"
|
2016-03-12 02:24:58 +00:00
|
|
|
"testing"
|
2016-06-16 20:30:29 +00:00
|
|
|
"time"
|
2016-05-22 03:15:58 +00:00
|
|
|
|
2017-07-04 00:41:20 +00:00
|
|
|
"github.com/hashicorp/nomad/helper"
|
2016-05-22 03:15:58 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs/config"
|
2017-05-30 18:39:26 +00:00
|
|
|
"github.com/kr/pretty"
|
2016-03-12 02:24:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfig_Parse(t *testing.T) {
|
2017-07-20 05:42:15 +00:00
|
|
|
t.Parallel()
|
2016-03-12 02:24:58 +00:00
|
|
|
cases := []struct {
|
|
|
|
File string
|
|
|
|
Result *Config
|
|
|
|
Err bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"basic.hcl",
|
|
|
|
&Config{
|
|
|
|
Region: "foobar",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
NodeName: "my-web",
|
|
|
|
DataDir: "/tmp/nomad",
|
|
|
|
LogLevel: "ERR",
|
|
|
|
BindAddr: "192.168.0.1",
|
|
|
|
EnableDebug: true,
|
|
|
|
Ports: &Ports{
|
|
|
|
HTTP: 1234,
|
|
|
|
RPC: 2345,
|
|
|
|
Serf: 3456,
|
|
|
|
},
|
|
|
|
Addresses: &Addresses{
|
|
|
|
HTTP: "127.0.0.1",
|
|
|
|
RPC: "127.0.0.2",
|
|
|
|
Serf: "127.0.0.3",
|
|
|
|
},
|
|
|
|
AdvertiseAddrs: &AdvertiseAddrs{
|
|
|
|
RPC: "127.0.0.3",
|
|
|
|
Serf: "127.0.0.4",
|
|
|
|
},
|
|
|
|
Client: &ClientConfig{
|
|
|
|
Enabled: true,
|
|
|
|
StateDir: "/tmp/client-state",
|
|
|
|
AllocDir: "/tmp/alloc",
|
|
|
|
Servers: []string{"a.b.c:80", "127.0.0.1:1234"},
|
|
|
|
NodeClass: "linux-medium-64bit",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"baz": "zip",
|
|
|
|
},
|
|
|
|
Options: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"baz": "zip",
|
|
|
|
},
|
2016-08-04 22:03:56 +00:00
|
|
|
ChrootEnv: map[string]string{
|
|
|
|
"/opt/myapp/etc": "/etc",
|
|
|
|
"/opt/myapp/bin": "/bin",
|
|
|
|
},
|
2016-03-12 02:24:58 +00:00
|
|
|
NetworkInterface: "eth0",
|
|
|
|
NetworkSpeed: 100,
|
2017-03-14 19:56:31 +00:00
|
|
|
CpuCompute: 4444,
|
2016-03-12 02:24:58 +00:00
|
|
|
MaxKillTimeout: "10s",
|
|
|
|
ClientMinPort: 1000,
|
|
|
|
ClientMaxPort: 2000,
|
|
|
|
Reserved: &Resources{
|
2016-03-12 03:02:44 +00:00
|
|
|
CPU: 10,
|
|
|
|
MemoryMB: 10,
|
|
|
|
DiskMB: 10,
|
|
|
|
IOPS: 10,
|
|
|
|
ReservedPorts: "1,100,10-12",
|
|
|
|
ParsedReservedPorts: []int{1, 10, 11, 12, 100},
|
2016-03-12 02:24:58 +00:00
|
|
|
},
|
2017-01-31 23:32:20 +00:00
|
|
|
GCInterval: 6 * time.Second,
|
2017-03-11 00:27:00 +00:00
|
|
|
GCParallelDestroys: 6,
|
2017-01-31 23:32:20 +00:00
|
|
|
GCDiskUsageThreshold: 82,
|
|
|
|
GCInodeUsageThreshold: 91,
|
2017-05-30 18:39:26 +00:00
|
|
|
GCMaxAllocs: 50,
|
2017-07-04 00:41:20 +00:00
|
|
|
NoHostUUID: helper.BoolToPtr(false),
|
2016-03-12 02:24:58 +00:00
|
|
|
},
|
|
|
|
Server: &ServerConfig{
|
2017-07-19 16:38:35 +00:00
|
|
|
Enabled: true,
|
|
|
|
BootstrapExpect: 5,
|
|
|
|
DataDir: "/tmp/data",
|
|
|
|
ProtocolVersion: 3,
|
|
|
|
NumSchedulers: 2,
|
|
|
|
EnabledSchedulers: []string{"test"},
|
|
|
|
NodeGCThreshold: "12h",
|
|
|
|
EvalGCThreshold: "12h",
|
|
|
|
JobGCThreshold: "12h",
|
|
|
|
DeploymentGCThreshold: "12h",
|
|
|
|
HeartbeatGrace: 30 * time.Second,
|
|
|
|
MinHeartbeatTTL: 33 * time.Second,
|
|
|
|
MaxHeartbeatsPerSecond: 11.0,
|
|
|
|
RetryJoin: []string{"1.1.1.1", "2.2.2.2"},
|
|
|
|
StartJoin: []string{"1.1.1.1", "2.2.2.2"},
|
|
|
|
RetryInterval: "15s",
|
|
|
|
RejoinAfterLeave: true,
|
|
|
|
RetryMaxAttempts: 3,
|
|
|
|
EncryptKey: "abc",
|
2016-03-12 02:24:58 +00:00
|
|
|
},
|
|
|
|
Telemetry: &Telemetry{
|
2016-08-02 02:49:01 +00:00
|
|
|
StatsiteAddr: "127.0.0.1:1234",
|
|
|
|
StatsdAddr: "127.0.0.1:2345",
|
|
|
|
DisableHostname: true,
|
2016-12-13 21:10:39 +00:00
|
|
|
UseNodeName: false,
|
2016-08-02 02:49:01 +00:00
|
|
|
CollectionInterval: "3s",
|
|
|
|
collectionInterval: 3 * time.Second,
|
|
|
|
PublishAllocationMetrics: true,
|
|
|
|
PublishNodeMetrics: true,
|
2016-03-12 02:24:58 +00:00
|
|
|
},
|
|
|
|
LeaveOnInt: true,
|
|
|
|
LeaveOnTerm: true,
|
|
|
|
EnableSyslog: true,
|
|
|
|
SyslogFacility: "LOCAL1",
|
|
|
|
DisableUpdateCheck: true,
|
|
|
|
DisableAnonymousSignature: true,
|
|
|
|
Atlas: &AtlasConfig{
|
|
|
|
Infrastructure: "armon/test",
|
|
|
|
Token: "abcd",
|
|
|
|
Join: true,
|
|
|
|
Endpoint: "127.0.0.1:1234",
|
|
|
|
},
|
2016-05-22 03:15:58 +00:00
|
|
|
Consul: &config.ConsulConfig{
|
2016-10-27 18:29:12 +00:00
|
|
|
ServerServiceName: "nomad",
|
|
|
|
ClientServiceName: "nomad-client",
|
|
|
|
Addr: "127.0.0.1:9500",
|
|
|
|
Token: "token1",
|
|
|
|
Auth: "username:pass",
|
2017-01-21 01:04:52 +00:00
|
|
|
EnableSSL: &trueValue,
|
|
|
|
VerifySSL: &trueValue,
|
2016-10-27 18:29:12 +00:00
|
|
|
CAFile: "/path/to/ca/file",
|
|
|
|
CertFile: "/path/to/cert/file",
|
|
|
|
KeyFile: "/path/to/key/file",
|
2017-01-21 01:04:52 +00:00
|
|
|
ServerAutoJoin: &trueValue,
|
|
|
|
ClientAutoJoin: &trueValue,
|
|
|
|
AutoAdvertise: &trueValue,
|
|
|
|
ChecksUseAdvertise: &trueValue,
|
2016-05-11 22:22:00 +00:00
|
|
|
},
|
2016-08-06 01:13:06 +00:00
|
|
|
Vault: &config.VaultConfig{
|
|
|
|
Addr: "127.0.0.1:9500",
|
2016-10-11 01:04:39 +00:00
|
|
|
AllowUnauthenticated: &trueValue,
|
|
|
|
Enabled: &falseValue,
|
2017-01-19 21:40:32 +00:00
|
|
|
Role: "test_role",
|
2016-08-08 22:16:40 +00:00
|
|
|
TLSCaFile: "/path/to/ca/file",
|
|
|
|
TLSCaPath: "/path/to/ca",
|
|
|
|
TLSCertFile: "/path/to/cert/file",
|
|
|
|
TLSKeyFile: "/path/to/key/file",
|
2016-08-06 01:13:06 +00:00
|
|
|
TLSServerName: "foobar",
|
2016-10-11 01:04:39 +00:00
|
|
|
TLSSkipVerify: &trueValue,
|
2016-08-13 04:59:31 +00:00
|
|
|
TaskTokenTTL: "1s",
|
|
|
|
Token: "12345",
|
2016-08-06 01:13:06 +00:00
|
|
|
},
|
2016-10-26 21:08:46 +00:00
|
|
|
TLSConfig: &config.TLSConfig{
|
2016-10-24 20:46:22 +00:00
|
|
|
EnableHTTP: true,
|
|
|
|
EnableRPC: true,
|
|
|
|
VerifyServerHostname: true,
|
|
|
|
CAFile: "foo",
|
|
|
|
CertFile: "bar",
|
|
|
|
KeyFile: "pipe",
|
2017-04-30 14:40:04 +00:00
|
|
|
VerifyHTTPSClient: true,
|
2016-10-24 20:46:22 +00:00
|
|
|
},
|
2016-03-12 02:24:58 +00:00
|
|
|
HTTPAPIResponseHeaders: map[string]string{
|
|
|
|
"Access-Control-Allow-Origin": "*",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2017-05-30 18:39:26 +00:00
|
|
|
t.Run(tc.File, func(t *testing.T) {
|
|
|
|
path, err := filepath.Abs(filepath.Join("./config-test-fixtures", tc.File))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("file: %s\n\n%s", tc.File, err)
|
|
|
|
}
|
2016-03-12 02:24:58 +00:00
|
|
|
|
2017-05-30 18:39:26 +00:00
|
|
|
actual, err := ParseConfigFile(path)
|
|
|
|
if (err != nil) != tc.Err {
|
|
|
|
t.Fatalf("file: %s\n\n%s", tc.File, err)
|
|
|
|
}
|
2016-03-12 02:24:58 +00:00
|
|
|
|
2017-05-30 18:39:26 +00:00
|
|
|
if !reflect.DeepEqual(actual, tc.Result) {
|
|
|
|
t.Errorf("file: %s diff: (actual vs expected)\n\n%s", tc.File, strings.Join(pretty.Diff(actual, tc.Result), "\n"))
|
|
|
|
}
|
|
|
|
})
|
2016-03-12 02:24:58 +00:00
|
|
|
}
|
|
|
|
}
|