2019-03-29 18:47:40 +00:00
|
|
|
package apitests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-16 21:54:28 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
2019-03-29 18:47:40 +00:00
|
|
|
"github.com/hashicorp/nomad/api"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPI_OperatorSchedulerGetSetConfiguration(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
c, s := makeClient(t, nil, nil)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
operator := c.Operator()
|
2021-11-02 21:42:52 +00:00
|
|
|
var config *api.SchedulerConfigurationResponse
|
2019-03-29 18:47:40 +00:00
|
|
|
retry.Run(t, func(r *retry.R) {
|
|
|
|
var err error
|
|
|
|
config, _, err = operator.SchedulerGetConfiguration(nil)
|
|
|
|
r.Check(err)
|
|
|
|
})
|
2021-11-02 21:42:52 +00:00
|
|
|
require.True(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
|
|
|
|
require.False(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled)
|
|
|
|
require.False(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)
|
|
|
|
require.Nil(err)
|
|
|
|
require.NotZero(wm.LastIndex)
|
2020-06-26 14:48:33 +00:00
|
|
|
// non CAS requests should update on success
|
|
|
|
require.True(resp.Updated)
|
2019-03-29 18:47:40 +00:00
|
|
|
|
|
|
|
config, _, err = operator.SchedulerGetConfiguration(nil)
|
|
|
|
require.Nil(err)
|
2021-11-02 21:42:52 +00:00
|
|
|
require.False(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
|
|
|
|
require.True(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled)
|
|
|
|
require.True(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled)
|
2019-03-29 18:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPI_OperatorSchedulerCASConfiguration(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
c, s := makeClient(t, nil, nil)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
operator := c.Operator()
|
2021-11-02 21:42:52 +00:00
|
|
|
var config *api.SchedulerConfigurationResponse
|
2019-03-29 18:47:40 +00:00
|
|
|
retry.Run(t, func(r *retry.R) {
|
|
|
|
var err error
|
|
|
|
config, _, err = operator.SchedulerGetConfiguration(nil)
|
|
|
|
r.Check(err)
|
|
|
|
})
|
2021-11-02 21:42:52 +00:00
|
|
|
require.True(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
|
|
|
|
require.False(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled)
|
|
|
|
require.False(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
|
|
|
}
|
|
|
|
resp, wm, err := operator.SchedulerCASConfiguration(newConf, nil)
|
|
|
|
require.Nil(err)
|
|
|
|
require.NotZero(wm.LastIndex)
|
|
|
|
require.False(resp.Updated)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
resp, wm, err := operator.SchedulerCASConfiguration(newConf, nil)
|
|
|
|
require.Nil(err)
|
|
|
|
require.NotZero(wm.LastIndex)
|
|
|
|
require.True(resp.Updated)
|
|
|
|
}
|
2019-06-04 22:41:40 +00:00
|
|
|
|
|
|
|
config, _, err := operator.SchedulerGetConfiguration(nil)
|
|
|
|
require.Nil(err)
|
2021-11-02 21:42:52 +00:00
|
|
|
require.False(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
|
|
|
|
require.True(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled)
|
|
|
|
require.False(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled)
|
2019-03-29 18:47:40 +00:00
|
|
|
}
|