Switch to in-process agent
This commit is contained in:
parent
c8ad00aff6
commit
c106df9215
|
@ -774,7 +774,7 @@ func (c *Config) normalizeAddrs() error {
|
|||
|
||||
addr, err = normalizeAdvertise(c.AdvertiseAddrs.HTTP, c.Addresses.HTTP, c.Ports.HTTP, c.DevMode)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to parse HTTP advertise address: %v", err)
|
||||
return fmt.Errorf("Failed to parse HTTP advertise address (%v, %v, %v, %v): %v", c.AdvertiseAddrs.HTTP, c.Addresses.HTTP, c.Ports.HTTP, c.DevMode, err)
|
||||
}
|
||||
c.AdvertiseAddrs.HTTP = addr
|
||||
|
||||
|
|
|
@ -102,7 +102,9 @@ func (a *TestAgent) Start() *TestAgent {
|
|||
|
||||
for i := 10; i >= 0; i-- {
|
||||
pickRandomPorts(a.Config)
|
||||
a.Config.NodeName = fmt.Sprintf("Node %d", a.Config.Ports.RPC)
|
||||
if a.Config.NodeName == "" {
|
||||
a.Config.NodeName = fmt.Sprintf("Node %d", a.Config.Ports.RPC)
|
||||
}
|
||||
|
||||
// write the keyring
|
||||
if a.Key != "" {
|
||||
|
@ -202,7 +204,7 @@ func (a *TestAgent) HTTPAddr() string {
|
|||
if a.Server == nil {
|
||||
return ""
|
||||
}
|
||||
return a.Server.Addr
|
||||
return "http://" + a.Server.Addr
|
||||
}
|
||||
|
||||
func (a *TestAgent) Client() *api.Client {
|
||||
|
@ -210,7 +212,7 @@ func (a *TestAgent) Client() *api.Client {
|
|||
conf.Address = a.HTTPAddr()
|
||||
c, err := api.NewClient(conf)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Error creating consul API client: %s", err))
|
||||
panic(fmt.Sprintf("Error creating Nomad API client: %s", err))
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
@ -249,6 +251,9 @@ func (a *TestAgent) config() *Config {
|
|||
config := nomad.DefaultConfig()
|
||||
conf.NomadConfig = config
|
||||
|
||||
// Set the name
|
||||
conf.NodeName = a.Name
|
||||
|
||||
// Bind and set ports
|
||||
conf.BindAddr = "127.0.0.1"
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestAgentInfoCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAgentInfoCommand_Run(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &AgentInfoCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -15,8 +15,8 @@ func TestAllocStatusCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAllocStatusCommand_Fails(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &AllocStatusCommand{Meta: Meta{Ui: ui}}
|
||||
|
@ -76,10 +76,8 @@ func TestAllocStatusCommand_Fails(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAllocStatusCommand_Run(t *testing.T) {
|
||||
srv, client, url := testServer(t, func(c *testutil.TestServerConfig) {
|
||||
c.DevMode = true
|
||||
})
|
||||
defer srv.Stop()
|
||||
srv, client, url := testServer(t, true, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
// Wait for a node to be ready
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
)
|
||||
|
||||
func TestAgentCheckCommand_ServerHealth(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &AgentCheckCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
"github.com/hashicorp/nomad/command/agent"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
|
@ -13,11 +13,10 @@ func TestClientConfigCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientConfigCommand_UpdateServers(t *testing.T) {
|
||||
srv, _, url := testServer(t, func(c *testutil.TestServerConfig) {
|
||||
c.Client.Enabled = true
|
||||
srv, _, url := testServer(t, true, func(c *agent.Config) {
|
||||
c.Server.BootstrapExpect = 0
|
||||
})
|
||||
defer srv.Stop()
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &ClientConfigCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestEvalStatusCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestEvalStatusCommand_Fails(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &EvalStatusCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestFSCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFSCommand_Fails(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &FSCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -43,8 +43,8 @@ func TestHelpers_FormatList(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHelpers_NodeID(t *testing.T) {
|
||||
srv, _, _ := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, _ := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
meta := Meta{Ui: new(cli.MockUi)}
|
||||
client, err := meta.Client()
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestInspectCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInspectCommand_Fails(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &InspectCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestLogsCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLogsCommand_Fails(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &LogsCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -169,8 +169,8 @@ func TestMonitor_Update_AllocModification(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMonitor_Monitor(t *testing.T) {
|
||||
srv, client, _ := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, client, _ := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
// Create the monitor
|
||||
ui := new(cli.MockUi)
|
||||
|
@ -215,8 +215,8 @@ func TestMonitor_Monitor(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMonitor_MonitorWithPrefix(t *testing.T) {
|
||||
srv, client, _ := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, client, _ := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
// Create the monitor
|
||||
ui := new(cli.MockUi)
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestNodeDrainCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNodeDrainCommand_Fails(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &NodeDrainCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/command/agent"
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
@ -15,11 +16,10 @@ func TestNodeStatusCommand_Implements(t *testing.T) {
|
|||
|
||||
func TestNodeStatusCommand_Self(t *testing.T) {
|
||||
// Start in dev mode so we get a node registration
|
||||
srv, client, url := testServer(t, func(c *testutil.TestServerConfig) {
|
||||
c.DevMode = true
|
||||
srv, client, url := testServer(t, true, func(c *agent.Config) {
|
||||
c.NodeName = "mynode"
|
||||
})
|
||||
defer srv.Stop()
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &NodeStatusCommand{Meta: Meta{Ui: ui}}
|
||||
|
@ -66,11 +66,10 @@ func TestNodeStatusCommand_Self(t *testing.T) {
|
|||
|
||||
func TestNodeStatusCommand_Run(t *testing.T) {
|
||||
// Start in dev mode so we get a node registration
|
||||
srv, client, url := testServer(t, func(c *testutil.TestServerConfig) {
|
||||
c.DevMode = true
|
||||
srv, client, url := testServer(t, true, func(c *agent.Config) {
|
||||
c.NodeName = "mynode"
|
||||
})
|
||||
defer srv.Stop()
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &NodeStatusCommand{Meta: Meta{Ui: ui}}
|
||||
|
@ -160,8 +159,8 @@ func TestNodeStatusCommand_Run(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNodeStatusCommand_Fails(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &NodeStatusCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestOperator_Raft_ListPeers_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOperator_Raft_ListPeers(t *testing.T) {
|
||||
s, _, addr := testServer(t, nil)
|
||||
defer s.Stop()
|
||||
s, _, addr := testServer(t, false, nil)
|
||||
defer s.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
c := &OperatorRaftListCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestOperator_Raft_RemovePeers_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOperator_Raft_RemovePeer(t *testing.T) {
|
||||
s, _, addr := testServer(t, nil)
|
||||
defer s.Stop()
|
||||
s, _, addr := testServer(t, false, nil)
|
||||
defer s.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
c := &OperatorRaftRemoveCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestServerMembersCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestServerMembersCommand_Run(t *testing.T) {
|
||||
srv, client, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, client, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &ServerMembersCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
|
@ -14,10 +13,8 @@ func TestStatusCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStatusCommand_Run(t *testing.T) {
|
||||
srv, client, url := testServer(t, func(c *testutil.TestServerConfig) {
|
||||
c.DevMode = true
|
||||
})
|
||||
defer srv.Stop()
|
||||
srv, client, url := testServer(t, true, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &StatusCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -12,8 +12,8 @@ func TestStopCommand_Implements(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStopCommand_Fails(t *testing.T) {
|
||||
srv, _, url := testServer(t, nil)
|
||||
defer srv.Stop()
|
||||
srv, _, url := testServer(t, false, nil)
|
||||
defer srv.Shutdown()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &StopCommand{Meta: Meta{Ui: ui}}
|
||||
|
|
|
@ -4,39 +4,22 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/command/agent"
|
||||
"github.com/hashicorp/nomad/helper"
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
)
|
||||
|
||||
// seen is used to track which tests we have already
|
||||
// marked as parallel. Marking twice causes panic.
|
||||
var seen map[*testing.T]struct{}
|
||||
|
||||
func init() {
|
||||
seen = make(map[*testing.T]struct{})
|
||||
}
|
||||
|
||||
func testServer(
|
||||
t *testing.T,
|
||||
cb testutil.ServerConfigCallback) (*testutil.TestServer, *api.Client, string) {
|
||||
|
||||
// Always run these tests in parallel.
|
||||
if _, ok := seen[t]; !ok {
|
||||
seen[t] = struct{}{}
|
||||
t.Parallel()
|
||||
}
|
||||
|
||||
func testServer(t *testing.T, runClient bool, cb func(*agent.Config)) (*agent.TestAgent, *api.Client, string) {
|
||||
// Make a new test server
|
||||
srv := testutil.NewTestServer(t, cb)
|
||||
a := agent.NewTestAgent(t.Name(), func(config *agent.Config) {
|
||||
config.Client.Enabled = runClient
|
||||
|
||||
// Make a client
|
||||
clientConf := api.DefaultConfig()
|
||||
clientConf.Address = "http://" + srv.HTTPAddr
|
||||
client, err := api.NewClient(clientConf)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
return srv, client, clientConf.Address
|
||||
if cb != nil {
|
||||
cb(config)
|
||||
}
|
||||
})
|
||||
|
||||
c := a.Client()
|
||||
return a, c, a.HTTPAddr()
|
||||
}
|
||||
|
||||
func testJob(jobID string) *api.Job {
|
||||
|
|
Loading…
Reference in New Issue