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