github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/internal/testing/apitests/operator_test.go (about) 1 package apitests 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/consul/sdk/testutil/retry" 7 "github.com/hashicorp/nomad/api" 8 "github.com/hashicorp/nomad/ci" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestAPI_OperatorSchedulerGetSetConfiguration(t *testing.T) { 13 ci.Parallel(t) 14 require := require.New(t) 15 c, s := makeClient(t, nil, nil) 16 defer s.Stop() 17 18 operator := c.Operator() 19 var config *api.SchedulerConfigurationResponse 20 retry.Run(t, func(r *retry.R) { 21 var err error 22 config, _, err = operator.SchedulerGetConfiguration(nil) 23 r.Check(err) 24 }) 25 require.True(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled) 26 require.False(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) 27 require.False(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) 28 29 // Change a config setting 30 newConf := &api.SchedulerConfiguration{ 31 PreemptionConfig: api.PreemptionConfig{ 32 SystemSchedulerEnabled: false, 33 BatchSchedulerEnabled: true, 34 ServiceSchedulerEnabled: true, 35 }, 36 } 37 resp, wm, err := operator.SchedulerSetConfiguration(newConf, nil) 38 require.Nil(err) 39 require.NotZero(wm.LastIndex) 40 // non CAS requests should update on success 41 require.True(resp.Updated) 42 43 config, _, err = operator.SchedulerGetConfiguration(nil) 44 require.Nil(err) 45 require.False(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled) 46 require.True(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) 47 require.True(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) 48 } 49 50 func TestAPI_OperatorSchedulerCASConfiguration(t *testing.T) { 51 ci.Parallel(t) 52 require := require.New(t) 53 c, s := makeClient(t, nil, nil) 54 defer s.Stop() 55 56 operator := c.Operator() 57 var config *api.SchedulerConfigurationResponse 58 retry.Run(t, func(r *retry.R) { 59 var err error 60 config, _, err = operator.SchedulerGetConfiguration(nil) 61 r.Check(err) 62 }) 63 require.True(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled) 64 require.False(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) 65 require.False(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) 66 67 // Pass an invalid ModifyIndex 68 { 69 newConf := &api.SchedulerConfiguration{ 70 PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: false, BatchSchedulerEnabled: true}, 71 ModifyIndex: config.SchedulerConfig.ModifyIndex - 1, 72 } 73 resp, wm, err := operator.SchedulerCASConfiguration(newConf, nil) 74 require.Nil(err) 75 require.NotZero(wm.LastIndex) 76 require.False(resp.Updated) 77 } 78 79 // Pass a valid ModifyIndex 80 { 81 newConf := &api.SchedulerConfiguration{ 82 PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: false, BatchSchedulerEnabled: true}, 83 ModifyIndex: config.SchedulerConfig.ModifyIndex, 84 } 85 resp, wm, err := operator.SchedulerCASConfiguration(newConf, nil) 86 require.Nil(err) 87 require.NotZero(wm.LastIndex) 88 require.True(resp.Updated) 89 } 90 91 config, _, err := operator.SchedulerGetConfiguration(nil) 92 require.Nil(err) 93 require.False(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled) 94 require.True(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) 95 require.False(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) 96 }