2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2019-03-29 18:47:40 +00:00
|
|
|
package apitests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/api"
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2023-01-02 14:06:20 +00:00
|
|
|
"github.com/shoenig/test/must"
|
|
|
|
"github.com/shoenig/test/wait"
|
2019-03-29 18:47:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPI_OperatorSchedulerGetSetConfiguration(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2023-01-02 14:06:20 +00:00
|
|
|
|
2019-03-29 18:47:40 +00:00
|
|
|
c, s := makeClient(t, nil, nil)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
operator := c.Operator()
|
2021-11-02 21:42:52 +00:00
|
|
|
var config *api.SchedulerConfigurationResponse
|
2023-01-02 14:06:20 +00:00
|
|
|
var err error
|
|
|
|
f := func() error {
|
2019-03-29 18:47:40 +00:00
|
|
|
config, _, err = operator.SchedulerGetConfiguration(nil)
|
2023-01-02 14:06:20 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
must.Wait(t, wait.InitialSuccess(wait.ErrorFunc(f)))
|
|
|
|
must.True(t, config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
|
|
|
|
must.False(t, config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled)
|
|
|
|
must.False(t, config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled)
|
2019-03-29 18:47:40 +00:00
|
|
|
|
|
|
|
// Change a config setting
|
2019-06-04 22:41:40 +00:00
|
|
|
newConf := &api.SchedulerConfiguration{
|
|
|
|
PreemptionConfig: api.PreemptionConfig{
|
|
|
|
SystemSchedulerEnabled: false,
|
|
|
|
BatchSchedulerEnabled: true,
|
|
|
|
ServiceSchedulerEnabled: true,
|
|
|
|
},
|
|
|
|
}
|
2019-03-29 18:47:40 +00:00
|
|
|
resp, wm, err := operator.SchedulerSetConfiguration(newConf, nil)
|
2023-01-02 14:06:20 +00:00
|
|
|
must.NoError(t, err)
|
|
|
|
must.Positive(t, wm.LastIndex)
|
|
|
|
must.True(t, resp.Updated) // non CAS requests should update on success
|
2019-03-29 18:47:40 +00:00
|
|
|
|
|
|
|
config, _, err = operator.SchedulerGetConfiguration(nil)
|
2023-01-02 14:06:20 +00:00
|
|
|
must.NoError(t, err)
|
|
|
|
must.False(t, config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
|
|
|
|
must.True(t, config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled)
|
|
|
|
must.True(t, config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled)
|
2019-03-29 18:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPI_OperatorSchedulerCASConfiguration(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2023-01-02 14:06:20 +00:00
|
|
|
|
2019-03-29 18:47:40 +00:00
|
|
|
c, s := makeClient(t, nil, nil)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
operator := c.Operator()
|
2021-11-02 21:42:52 +00:00
|
|
|
var config *api.SchedulerConfigurationResponse
|
2023-01-02 14:06:20 +00:00
|
|
|
var err error
|
|
|
|
f := func() error {
|
2019-03-29 18:47:40 +00:00
|
|
|
config, _, err = operator.SchedulerGetConfiguration(nil)
|
2023-01-02 14:06:20 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
must.Wait(t, wait.InitialSuccess(wait.ErrorFunc(f)))
|
|
|
|
must.True(t, config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
|
|
|
|
must.False(t, config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled)
|
|
|
|
must.False(t, config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled)
|
2019-03-29 18:47:40 +00:00
|
|
|
|
|
|
|
// Pass an invalid ModifyIndex
|
|
|
|
{
|
|
|
|
newConf := &api.SchedulerConfiguration{
|
2019-06-04 22:41:40 +00:00
|
|
|
PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: false, BatchSchedulerEnabled: true},
|
2021-11-02 21:42:52 +00:00
|
|
|
ModifyIndex: config.SchedulerConfig.ModifyIndex - 1,
|
2019-03-29 18:47:40 +00:00
|
|
|
}
|
2023-01-02 14:06:20 +00:00
|
|
|
var resp *api.SchedulerSetConfigurationResponse
|
|
|
|
var wm *api.WriteMeta
|
|
|
|
resp, wm, err = operator.SchedulerCASConfiguration(newConf, nil)
|
|
|
|
must.NoError(t, err)
|
|
|
|
must.Positive(t, wm.LastIndex)
|
|
|
|
must.False(t, resp.Updated)
|
2019-03-29 18:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pass a valid ModifyIndex
|
|
|
|
{
|
|
|
|
newConf := &api.SchedulerConfiguration{
|
2019-06-04 22:41:40 +00:00
|
|
|
PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: false, BatchSchedulerEnabled: true},
|
2021-11-02 21:42:52 +00:00
|
|
|
ModifyIndex: config.SchedulerConfig.ModifyIndex,
|
2019-03-29 18:47:40 +00:00
|
|
|
}
|
2023-01-02 14:06:20 +00:00
|
|
|
var resp *api.SchedulerSetConfigurationResponse
|
|
|
|
var wm *api.WriteMeta
|
|
|
|
resp, wm, err = operator.SchedulerCASConfiguration(newConf, nil)
|
|
|
|
must.NoError(t, err)
|
|
|
|
must.Positive(t, wm.LastIndex)
|
|
|
|
must.True(t, resp.Updated)
|
2019-03-29 18:47:40 +00:00
|
|
|
}
|
2019-06-04 22:41:40 +00:00
|
|
|
|
2023-01-02 14:06:20 +00:00
|
|
|
config, _, err = operator.SchedulerGetConfiguration(nil)
|
|
|
|
must.NoError(t, err)
|
|
|
|
must.False(t, config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
|
|
|
|
must.True(t, config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled)
|
|
|
|
must.False(t, config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled)
|
2019-03-29 18:47:40 +00:00
|
|
|
}
|