Files
nomad/command/operator_raft_remove_test.go
Tim Gross 27caae2b2a api: make attempting to remove peer by address a no-op (#25599)
In Nomad 1.4.0 we removed support for Raft Protocol v2 entirely. But the
`Operator.RemoveRaftPeerByAddress` RPC handler was left in place, along with its
supporting HTTP API and command line flags. Using this API will always result in
the Raft library error "operation not supported with current protocol version".

Unfortunately it's still possible in unit tests to exercise this code path, and
these tests are quite flaky. This changeset turns the RPC handler and HTTP API
into a no-op, removes the associated command line flags, and removes the flaky
tests. I've also cleaned up the test for `RemoveRaftPeerByID` to consolidate
test servers and use `shoenig/test`.

Fixes: https://hashicorp.atlassian.net/browse/NET-12413
Ref: https://github.com/hashicorp/nomad/pull/13467
Ref: https://developer.hashicorp.com/nomad/docs/upgrade/upgrade-specific#raft-protocol-version-2-unsupported
Ref: https://github.com/hashicorp/nomad-enterprise/actions/runs/13201513025/job/36855234398?pr=2302
2025-04-10 09:19:25 -04:00

35 lines
906 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package command
import (
"testing"
"github.com/hashicorp/cli"
"github.com/hashicorp/nomad/ci"
"github.com/shoenig/test/must"
)
func TestOperator_Raft_RemovePeer(t *testing.T) {
ci.Parallel(t)
var _ cli.Command = &OperatorRaftRemoveCommand{}
s, _, addr := testServer(t, false, nil)
defer s.Shutdown()
ui := cli.NewMockUi()
c := &OperatorRaftRemoveCommand{Meta: Meta{Ui: ui}}
args := []string{"-address=" + addr}
code := c.Run(args)
must.One(t, code)
must.StrContains(t, ui.ErrorWriter.String(), "Missing peer id required")
ui.ErrorWriter.Reset()
args = []string{"-address=" + addr, "-peer-id=nope"}
code = c.Run(args)
must.One(t, code)
// If we get this error, it proves we sent the peer ID all the way thru
must.StrContains(t, ui.ErrorWriter.String(), "id \"nope\" was not found in the Raft configuration")
}