2017-02-10 01:58:20 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2022-03-17 13:34:57 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/api/internal/testutil"
|
2023-01-01 18:57:26 +00:00
|
|
|
"github.com/shoenig/test/must"
|
2017-02-10 01:58:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestOperator_RaftGetConfiguration(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2017-02-10 01:58:20 +00:00
|
|
|
c, s := makeClient(t, nil, nil)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
operator := c.Operator()
|
|
|
|
out, err := operator.RaftGetConfiguration(nil)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.NoError(t, err)
|
|
|
|
must.Len(t, 1, out.Servers)
|
|
|
|
must.True(t, out.Servers[0].Leader)
|
|
|
|
must.True(t, out.Servers[0].Voter)
|
2017-02-10 01:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOperator_RaftRemovePeerByAddress(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2017-02-10 01:58:20 +00:00
|
|
|
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.RaftRemovePeerByAddress("nope", nil)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.ErrorContains(t, err, `address "nope" was not found in the Raft configuration`)
|
2017-02-10 01:58:20 +00:00
|
|
|
}
|
2018-01-16 21:35:32 +00:00
|
|
|
|
|
|
|
func TestOperator_RaftRemovePeerByID(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2018-01-16 21:35:32 +00:00
|
|
|
c, s := makeClient(t, nil, nil)
|
|
|
|
defer s.Stop()
|
|
|
|
|
2023-01-01 18:57:26 +00:00
|
|
|
// If we get this error, it proves we sent the address all the way through.
|
2018-01-16 21:35:32 +00:00
|
|
|
operator := c.Operator()
|
|
|
|
err := operator.RaftRemovePeerByID("nope", nil)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.ErrorContains(t, err, `id "nope" was not found in the Raft configuration`)
|
2018-01-16 21:35:32 +00:00
|
|
|
}
|
2022-07-06 14:13:48 +00:00
|
|
|
|
|
|
|
func TestOperator_SchedulerGetConfiguration(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2022-07-06 14:13:48 +00:00
|
|
|
c, s := makeClient(t, nil, nil)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
schedulerConfig, _, err := c.Operator().SchedulerGetConfiguration(nil)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.NoError(t, err)
|
|
|
|
must.NotNil(t, schedulerConfig)
|
2022-07-06 14:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOperator_SchedulerSetConfiguration(t *testing.T) {
|
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2022-07-06 14:13:48 +00:00
|
|
|
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)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.NoError(t, err)
|
|
|
|
must.True(t, schedulerConfigUpdateResp.Updated)
|
2022-07-06 14:13:48 +00:00
|
|
|
|
2023-01-01 18:57:26 +00:00
|
|
|
// We can't exactly predict the query meta responses, so we test fields individually.
|
2022-07-06 14:13:48 +00:00
|
|
|
schedulerConfig, _, err := c.Operator().SchedulerGetConfiguration(nil)
|
2023-01-01 18:57:26 +00:00
|
|
|
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)
|
2022-07-06 14:13:48 +00:00
|
|
|
}
|