From 58ff5e46cbe7394d048a74046cae7a3c870509d8 Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Tue, 30 Oct 2018 15:52:54 -0700 Subject: [PATCH 1/2] fsm: add missing ID/datacenter to persistNodes --- agent/consul/fsm/snapshot_oss.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/agent/consul/fsm/snapshot_oss.go b/agent/consul/fsm/snapshot_oss.go index 3650add7a..d204121ad 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, From cf2210b5c5c4f91d8a0c2825d11ff490d6d695e6 Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Tue, 30 Oct 2018 15:53:14 -0700 Subject: [PATCH 2/2] fsm: update snapshot/restore test to include ID and datacenter --- agent/consul/fsm/snapshot_oss_test.go | 31 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) 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])