Allow renaming nodes when ID is unchanged

This commit is contained in:
Pierre Souchay 2018-04-18 15:39:38 +02:00
parent a9868ae956
commit 89ab642928
2 changed files with 2 additions and 17 deletions

View File

@ -355,11 +355,7 @@ func (s *Store) ensureNodeTxn(tx *memdb.Txn, idx uint64, node *structs.Node) err
if existing != nil {
n = existing.(*structs.Node)
if n.Node != node.Node {
if n.Address != node.Address {
return fmt.Errorf("node ID %q for node %q (%s) aliases existing node %q (%s)",
node.ID, node.Node, node.Address, n.Node, n.Address)
}
fmt.Printf("Node renaming: %s VS %s -- idx=%d\n", node.Node, n.Node, idx)
// We are actually renaming a node, remove its reference first
err := s.deleteNodeTxn(tx, idx, n.Node)
if err != nil {
return fmt.Errorf("Error while renaming Node ID: %q from %s to %s",

View File

@ -466,18 +466,7 @@ func TestStateStore_EnsureNode(t *testing.T) {
t.Fatalf("err: %v", err)
}
// Now try to add another node with the same ID
in = &structs.Node{
Node: "nope",
ID: types.NodeID("cda916bc-a357-4a19-b886-59419fcee50c"),
Address: "1.2.3.4",
}
err = s.EnsureNode(5, in)
if err == nil || !strings.Contains(err.Error(), "aliases existing node") {
t.Fatalf("err: %v", err)
}
// Renaming a node should work as long as IP did not change
// Renaming a node should work if ID is the same
in = &structs.Node{
Node: "node1-renamed",
ID: types.NodeID("cda916bc-a357-4a19-b886-59419fcee50c"),