From 84722234b4ffd29a390609d1a6677b150408b67c Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Wed, 26 Oct 2016 14:08:46 -0700 Subject: [PATCH 1/2] Fixed a bunch of TLS related failures --- api/nodes.go | 7 +------ client/config/config.go | 1 + command/agent/config_parse_test.go | 2 +- command/agent/fs_endpoint_test.go | 1 - command/meta_test.go | 13 ++++++++++++- nomad/config.go | 1 + 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/api/nodes.go b/api/nodes.go index 1b5b3c03b..3c8db4060 100644 --- a/api/nodes.go +++ b/api/nodes.go @@ -4,8 +4,6 @@ import ( "fmt" "sort" "strconv" - - "github.com/hashicorp/go-cleanhttp" ) // Nodes is used to query node-related API endpoints @@ -82,10 +80,7 @@ func (n *Nodes) Stats(nodeID string, q *QueryOptions) (*HostStats, error) { if node.HTTPAddr == "" { return nil, fmt.Errorf("http addr of the node %q is running is not advertised", nodeID) } - client, err := NewClient(&Config{ - Address: fmt.Sprintf("http://%s", node.HTTPAddr), - HttpClient: cleanhttp.DefaultClient(), - }) + client, err := NewClient(n.client.config.CopyConfig(node.HTTPAddr, node.TLSEnabled)) if err != nil { return nil, err } diff --git a/client/config/config.go b/client/config/config.go index d31f61466..116c04774 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -158,6 +158,7 @@ func DefaultConfig() *Config { LogOutput: os.Stderr, Region: "global", StatsCollectionInterval: 1 * time.Second, + TLSConfig: &config.TLSConfig{}, } } diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 2ef33f6f1..14168ce8f 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -136,7 +136,7 @@ func TestConfig_Parse(t *testing.T) { TaskTokenTTL: "1s", Token: "12345", }, - TLSConfig: &TLSConfig{ + TLSConfig: &config.TLSConfig{ EnableHTTP: true, EnableRPC: true, VerifyServerHostname: true, diff --git a/command/agent/fs_endpoint_test.go b/command/agent/fs_endpoint_test.go index 6b611deeb..152832e99 100644 --- a/command/agent/fs_endpoint_test.go +++ b/command/agent/fs_endpoint_test.go @@ -16,7 +16,6 @@ import ( "time" "github.com/hashicorp/nomad/client/allocdir" - "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" "github.com/ugorji/go/codec" ) diff --git a/command/meta_test.go b/command/meta_test.go index d9f402e1f..fd2d7cac5 100644 --- a/command/meta_test.go +++ b/command/meta_test.go @@ -18,7 +18,18 @@ func TestMeta_FlagSet(t *testing.T) { }, { FlagSetClient, - []string{"address", "no-color", "region"}, + []string{ + "address", + "no-color", + "region", + "address", + "ca-cert", + "ca-path", + "client-cert", + "client-key", + "insecure", + "tls-skip-verify", + }, }, } diff --git a/nomad/config.go b/nomad/config.go index 68722f566..cfa64a5a5 100644 --- a/nomad/config.go +++ b/nomad/config.go @@ -243,6 +243,7 @@ func DefaultConfig() *Config { ConsulConfig: config.DefaultConsulConfig(), VaultConfig: config.DefaultVaultConfig(), RPCHoldTimeout: 5 * time.Second, + TLSConfig: &config.TLSConfig{}, } // Enable all known schedulers by default From 1098dc4aa38faca8003e2d11b0145a6b68396de4 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Wed, 26 Oct 2016 15:17:57 -0700 Subject: [PATCH 2/2] Fixed alloc dir move tests --- client/alloc_runner_test.go | 2 +- client/allocdir/alloc_dir_test.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/client/alloc_runner_test.go b/client/alloc_runner_test.go index 2644dc23d..9f4960671 100644 --- a/client/alloc_runner_test.go +++ b/client/alloc_runner_test.go @@ -554,7 +554,7 @@ func TestAllocRunner_MoveAllocDir(t *testing.T) { // Create another alloc runner alloc1 := mock.Alloc() - task = alloc.Job.TaskGroups[0].Tasks[0] + task = alloc1.Job.TaskGroups[0].Tasks[0] task.Driver = "mock_driver" task.Config = map[string]interface{}{ "run_for": "1s", diff --git a/client/allocdir/alloc_dir_test.go b/client/allocdir/alloc_dir_test.go index f90d864b5..948253865 100644 --- a/client/allocdir/alloc_dir_test.go +++ b/client/allocdir/alloc_dir_test.go @@ -292,17 +292,23 @@ func TestAllocDir_Snapshot(t *testing.T) { } func TestAllocDir_Move(t *testing.T) { - tmp, err := ioutil.TempDir("", "AllocDir") + tmp1, err := ioutil.TempDir("", "AllocDir") if err != nil { t.Fatalf("Couldn't create temp dir: %v", err) } - defer os.RemoveAll(tmp) + defer os.RemoveAll(tmp1) + + tmp2, err := ioutil.TempDir("", "AllocDir") + if err != nil { + t.Fatalf("Couldn't create temp dir: %v", err) + } + defer os.RemoveAll(tmp2) // Create two alloc dirs - d1 := NewAllocDir(tmp) + d1 := NewAllocDir(tmp1) defer d1.Destroy() - d2 := NewAllocDir(tmp) + d2 := NewAllocDir(tmp2) defer d2.Destroy() tasks := []*structs.Task{t1, t2}