diff --git a/agent/consul/fsm/snapshot_oss.go b/agent/consul/fsm/snapshot_oss.go index 24ca4f031..cb45fff7e 100644 --- a/agent/consul/fsm/snapshot_oss.go +++ b/agent/consul/fsm/snapshot_oss.go @@ -82,7 +82,9 @@ func (s *snapshot) persistNodes(sink raft.SnapshotSink, for node := nodes.Next(); node != nil; node = nodes.Next() { n := node.(*structs.Node) req := structs.RegisterRequest{ + ID: n.ID, Node: n.Node, + Datacenter: n.Datacenter, Address: n.Address, TaggedAddresses: n.TaggedAddresses, NodeMeta: n.Meta, diff --git a/agent/consul/fsm/snapshot_oss_test.go b/agent/consul/fsm/snapshot_oss_test.go index 4b70f32eb..7c00ba767 100644 --- a/agent/consul/fsm/snapshot_oss_test.go +++ b/agent/consul/fsm/snapshot_oss_test.go @@ -14,7 +14,6 @@ import ( "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/lib" - // "github.com/pascaldekloe/goe/verify" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -29,8 +28,26 @@ func TestFSM_SnapshotRestore_OSS(t *testing.T) { } // Add some state - fsm.state.EnsureNode(1, &structs.Node{Node: "foo", Address: "127.0.0.1"}) - fsm.state.EnsureNode(2, &structs.Node{Node: "baz", Address: "127.0.0.2", TaggedAddresses: map[string]string{"hello": "1.2.3.4"}, Meta: map[string]string{"testMeta": "testing123"}}) + node1 := &structs.Node{ + ID: "610918a6-464f-fa9b-1a95-03bd6e88ed92", + Node: "foo", + Datacenter: "dc1", + Address: "127.0.0.1", + } + node2 := &structs.Node{ + ID: "40e4a748-2192-161a-0510-9bf59fe950b5", + Node: "baz", + Datacenter: "dc1", + Address: "127.0.0.2", + TaggedAddresses: map[string]string{ + "hello": "1.2.3.4", + }, + Meta: map[string]string{ + "testMeta": "testing123", + }, + } + assert.NoError(fsm.state.EnsureNode(1, node1)) + assert.NoError(fsm.state.EnsureNode(2, node2)) // Add a service instance with Connect config. connectConf := structs.ServiceConnect{ @@ -218,7 +235,9 @@ func TestFSM_SnapshotRestore_OSS(t *testing.T) { if len(nodes) != 2 { t.Fatalf("bad: %v", nodes) } - if nodes[0].Node != "baz" || + if nodes[0].ID != node2.ID || + nodes[0].Node != "baz" || + nodes[0].Datacenter != "dc1" || nodes[0].Address != "127.0.0.2" || len(nodes[0].Meta) != 1 || nodes[0].Meta["testMeta"] != "testing123" || @@ -226,7 +245,9 @@ func TestFSM_SnapshotRestore_OSS(t *testing.T) { nodes[0].TaggedAddresses["hello"] != "1.2.3.4" { t.Fatalf("bad: %v", nodes[0]) } - if nodes[1].Node != "foo" || + if nodes[1].ID != node1.ID || + nodes[1].Node != "foo" || + nodes[1].Datacenter != "dc1" || nodes[1].Address != "127.0.0.1" || len(nodes[1].TaggedAddresses) != 0 { t.Fatalf("bad: %v", nodes[1])