diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 26d8888916..b23327c665 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -48,12 +48,18 @@ func nextConfig() *Config { idx := int(atomic.AddUint64(&offset, numPortsPerIndex)) conf := DefaultConfig() + nodeID, err := uuid.GenerateUUID() + if err != nil { + panic(err) + } + conf.Version = version.Version conf.VersionPrerelease = "c.d" conf.AdvertiseAddr = "127.0.0.1" conf.Bootstrap = true conf.Datacenter = "dc1" conf.NodeName = fmt.Sprintf("Node %d", idx) + conf.NodeID = types.NodeID(nodeID) conf.BindAddr = "127.0.0.1" conf.Ports.DNS = basePortNumber + idx + portOffsetDNS conf.Ports.HTTP = basePortNumber + idx + portOffsetHTTP @@ -314,6 +320,7 @@ func TestAgent_ReconnectConfigSettings(t *testing.T) { func TestAgent_NodeID(t *testing.T) { c := nextConfig() + c.NodeID = "" dir, agent := makeAgent(t, c) defer os.RemoveAll(dir) defer agent.Shutdown() diff --git a/command/util_test.go b/command/util_test.go index 577b70d035..5c4b60c068 100644 --- a/command/util_test.go +++ b/command/util_test.go @@ -15,7 +15,9 @@ import ( "github.com/hashicorp/consul/command/agent" "github.com/hashicorp/consul/consul" "github.com/hashicorp/consul/logger" + "github.com/hashicorp/consul/types" "github.com/hashicorp/consul/version" + "github.com/hashicorp/go-uuid" "github.com/mitchellh/cli" ) @@ -112,9 +114,15 @@ func nextConfig() *agent.Config { idx := int(atomic.AddUint64(&offset, 1)) conf := agent.DefaultConfig() + nodeID, err := uuid.GenerateUUID() + if err != nil { + panic(err) + } + conf.Bootstrap = true conf.Datacenter = "dc1" conf.NodeName = fmt.Sprintf("Node %d", idx) + conf.NodeID = types.NodeID(nodeID) conf.BindAddr = "127.0.0.1" conf.Server = true diff --git a/consul/catalog_endpoint_test.go b/consul/catalog_endpoint_test.go index 6a0d36654d..306508ee9c 100644 --- a/consul/catalog_endpoint_test.go +++ b/consul/catalog_endpoint_test.go @@ -32,6 +32,7 @@ func TestCatalog_Register(t *testing.T) { Port: 8000, }, Check: &structs.HealthCheck{ + CheckID: types.CheckID("db-check"), ServiceID: "db", }, } @@ -61,6 +62,7 @@ func TestCatalog_Register_NodeID(t *testing.T) { Port: 8000, }, Check: &structs.HealthCheck{ + CheckID: types.CheckID("db-check"), ServiceID: "db", }, } diff --git a/consul/leader_test.go b/consul/leader_test.go index 427e07d709..931f99cd9e 100644 --- a/consul/leader_test.go +++ b/consul/leader_test.go @@ -848,87 +848,6 @@ func TestLeader_RollRaftServer(t *testing.T) { } } -func TestLeader_ChangeServerAddress(t *testing.T) { - conf := func(c *Config) { - c.Bootstrap = false - c.BootstrapExpect = 3 - c.Datacenter = "dc1" - c.RaftConfig.ProtocolVersion = 3 - } - dir1, s1 := testServerWithConfig(t, conf) - defer os.RemoveAll(dir1) - defer s1.Shutdown() - - dir2, s2 := testServerWithConfig(t, conf) - defer os.RemoveAll(dir2) - defer s2.Shutdown() - - dir3, s3 := testServerWithConfig(t, conf) - defer os.RemoveAll(dir3) - defer s3.Shutdown() - - servers := []*Server{s1, s2, s3} - - // Try to join - addr := fmt.Sprintf("127.0.0.1:%d", - s1.config.SerfLANConfig.MemberlistConfig.BindPort) - if _, err := s2.JoinLAN([]string{addr}); err != nil { - t.Fatalf("err: %v", err) - } - if _, err := s3.JoinLAN([]string{addr}); err != nil { - t.Fatalf("err: %v", err) - } - - for _, s := range servers { - if err := testutil.WaitForResult(func() (bool, error) { - peers, _ := s.numPeers() - return peers == 3, nil - }); err != nil { - t.Fatal("should have 3 peers") - } - } - - // Shut down a server, freeing up its address/port - s3.Shutdown() - - if err := testutil.WaitForResult(func() (bool, error) { - alive := 0 - for _, m := range s1.LANMembers() { - if m.Status == serf.StatusAlive { - alive++ - } - } - return alive == 2, nil - }); err != nil { - t.Fatal("should have 2 alive members") - } - - // Bring up a new server with s3's address that will get a different ID - dir4, s4 := testServerWithConfig(t, func(c *Config) { - c.Bootstrap = false - c.BootstrapExpect = 3 - c.Datacenter = "dc1" - c.RaftConfig.ProtocolVersion = 3 - c.NodeID = s3.config.NodeID - }) - defer os.RemoveAll(dir4) - defer s4.Shutdown() - if _, err := s4.JoinLAN([]string{addr}); err != nil { - t.Fatalf("err: %v", err) - } - servers[2] = s4 - - // Make sure the dead server is removed and we're back to 3 total peers - for _, s := range servers { - if err := testutil.WaitForResult(func() (bool, error) { - peers, _ := s.numPeers() - return peers == 3, nil - }); err != nil { - t.Fatal("should have 3 members") - } - } -} - func TestLeader_ChangeServerID(t *testing.T) { conf := func(c *Config) { c.Bootstrap = false diff --git a/consul/state/catalog.go b/consul/state/catalog.go index bbfddb23b3..217ad02ea5 100644 --- a/consul/state/catalog.go +++ b/consul/state/catalog.go @@ -175,7 +175,6 @@ func (s *StateStore) ensureNodeTxn(tx *memdb.Txn, idx uint64, node *structs.Node } if existing != nil { n = existing.(*structs.Node) - fmt.Printf("XXX %#v\n", *n) if n.Node != node.Node { return fmt.Errorf("node ID %q for node %q aliases existing node %q", node.ID, node.Node, n.Node) diff --git a/testutil/server.go b/testutil/server.go index e0a554acdc..aa20670f7f 100644 --- a/testutil/server.go +++ b/testutil/server.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/hashicorp/go-cleanhttp" + "github.com/hashicorp/go-uuid" "github.com/pkg/errors" ) @@ -55,6 +56,7 @@ type TestAddressConfig struct { // TestServerConfig is the main server configuration struct. type TestServerConfig struct { NodeName string `json:"node_name"` + NodeID string `json:"node_id"` NodeMeta map[string]string `json:"node_meta,omitempty"` Performance *TestPerformanceConfig `json:"performance,omitempty"` Bootstrap bool `json:"bootstrap,omitempty"` @@ -83,8 +85,14 @@ type ServerConfigCallback func(c *TestServerConfig) // defaultServerConfig returns a new TestServerConfig struct // with all of the listen ports incremented by one. func defaultServerConfig() *TestServerConfig { + nodeID, err := uuid.GenerateUUID() + if err != nil { + panic(err) + } + return &TestServerConfig{ NodeName: fmt.Sprintf("node%d", randomPort()), + NodeID: nodeID, DisableCheckpoint: true, Performance: &TestPerformanceConfig{ RaftMultiplier: 1,