Files
nomad/api/operator_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

100 lines
2.8 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package api
import (
"testing"
"github.com/hashicorp/nomad/api/internal/testutil"
"github.com/shoenig/test/must"
)
func TestOperator_RaftGetConfiguration(t *testing.T) {
testutil.Parallel(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()
operator := c.Operator()
out, err := operator.RaftGetConfiguration(nil)
must.NoError(t, err)
must.Len(t, 1, out.Servers)
must.True(t, out.Servers[0].Leader)
must.True(t, out.Servers[0].Voter)
}
func TestOperator_RaftRemovePeerByID(t *testing.T) {
testutil.Parallel(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()
// If we get this error, it proves we sent the address all the way through.
operator := c.Operator()
err := operator.RaftRemovePeerByID("nope", nil)
must.ErrorContains(t, err, `id "nope" was not found in the Raft configuration`)
}
func TestOperator_SchedulerGetConfiguration(t *testing.T) {
testutil.Parallel(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()
schedulerConfig, _, err := c.Operator().SchedulerGetConfiguration(nil)
must.NoError(t, err)
must.NotNil(t, schedulerConfig)
}
func TestOperator_SchedulerSetConfiguration(t *testing.T) {
testutil.Parallel(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()
newSchedulerConfig := SchedulerConfiguration{
SchedulerAlgorithm: SchedulerAlgorithmSpread,
PreemptionConfig: PreemptionConfig{
SystemSchedulerEnabled: true,
SysBatchSchedulerEnabled: true,
BatchSchedulerEnabled: true,
ServiceSchedulerEnabled: true,
},
MemoryOversubscriptionEnabled: true,
RejectJobRegistration: true,
PauseEvalBroker: true,
}
schedulerConfigUpdateResp, _, err := c.Operator().SchedulerSetConfiguration(&newSchedulerConfig, nil)
must.NoError(t, err)
must.True(t, schedulerConfigUpdateResp.Updated)
// We can't exactly predict the query meta responses, so we test fields individually.
schedulerConfig, _, err := c.Operator().SchedulerGetConfiguration(nil)
must.NoError(t, err)
must.Eq(t, SchedulerAlgorithmSpread, schedulerConfig.SchedulerConfig.SchedulerAlgorithm)
must.True(t, schedulerConfig.SchedulerConfig.PauseEvalBroker)
must.True(t, schedulerConfig.SchedulerConfig.RejectJobRegistration)
must.True(t, schedulerConfig.SchedulerConfig.MemoryOversubscriptionEnabled)
must.Eq(t, schedulerConfig.SchedulerConfig.PreemptionConfig, newSchedulerConfig.PreemptionConfig)
}
func TestOperator_AutopilotState(t *testing.T) {
testutil.Parallel(t)
c, s, _ := makeACLClient(t, nil, nil)
defer s.Stop()
operator := c.Operator()
// Make authenticated request.
_, _, err := operator.AutopilotServerHealth(nil)
must.NoError(t, err)
// Make unauthenticated request.
c.SetSecretID("")
_, _, err = operator.AutopilotServerHealth(nil)
must.ErrorContains(t, err, "403")
}