2017-03-30 19:35:50 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-03-26 21:04:58 +00:00
|
|
|
"github.com/hashicorp/consul/internal/testutil"
|
|
|
|
"github.com/hashicorp/consul/internal/testutil/retry"
|
2017-03-30 19:35:50 +00:00
|
|
|
)
|
|
|
|
|
2017-06-30 21:05:02 +00:00
|
|
|
func TestAPI_OperatorAutopilotGetSetConfiguration(t *testing.T) {
|
2017-03-30 19:35:50 +00:00
|
|
|
t.Parallel()
|
|
|
|
c, s := makeClient(t)
|
|
|
|
defer s.Stop()
|
2018-12-12 20:09:42 +00:00
|
|
|
s.WaitForSerfCheck(t)
|
2017-03-30 19:35:50 +00:00
|
|
|
|
|
|
|
operator := c.Operator()
|
|
|
|
config, err := operator.AutopilotGetConfiguration(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if !config.CleanupDeadServers {
|
|
|
|
t.Fatalf("bad: %v", config)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change a config setting
|
|
|
|
newConf := &AutopilotConfiguration{CleanupDeadServers: false}
|
|
|
|
if err := operator.AutopilotSetConfiguration(newConf, nil); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
config, err = operator.AutopilotGetConfiguration(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if config.CleanupDeadServers {
|
|
|
|
t.Fatalf("bad: %v", config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 21:05:02 +00:00
|
|
|
func TestAPI_OperatorAutopilotCASConfiguration(t *testing.T) {
|
2017-03-30 19:35:50 +00:00
|
|
|
t.Parallel()
|
|
|
|
c, s := makeClient(t)
|
|
|
|
defer s.Stop()
|
|
|
|
|
2018-08-06 23:46:09 +00:00
|
|
|
retry.Run(t, func(r *retry.R) {
|
|
|
|
operator := c.Operator()
|
|
|
|
config, err := operator.AutopilotGetConfiguration(nil)
|
2017-03-30 19:35:50 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
2018-08-06 23:46:09 +00:00
|
|
|
if !config.CleanupDeadServers {
|
|
|
|
t.Fatalf("bad: %v", config)
|
2017-03-30 19:35:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 23:46:09 +00:00
|
|
|
// Pass an invalid ModifyIndex
|
|
|
|
{
|
|
|
|
newConf := &AutopilotConfiguration{
|
|
|
|
CleanupDeadServers: false,
|
|
|
|
ModifyIndex: config.ModifyIndex - 1,
|
|
|
|
}
|
|
|
|
resp, err := operator.AutopilotCASConfiguration(newConf, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if resp {
|
|
|
|
t.Fatalf("bad: %v", resp)
|
|
|
|
}
|
2017-03-30 19:35:50 +00:00
|
|
|
}
|
2018-08-06 23:46:09 +00:00
|
|
|
|
|
|
|
// Pass a valid ModifyIndex
|
|
|
|
{
|
|
|
|
newConf := &AutopilotConfiguration{
|
|
|
|
CleanupDeadServers: false,
|
|
|
|
ModifyIndex: config.ModifyIndex,
|
|
|
|
}
|
|
|
|
resp, err := operator.AutopilotCASConfiguration(newConf, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if !resp {
|
|
|
|
t.Fatalf("bad: %v", resp)
|
|
|
|
}
|
2017-03-30 19:35:50 +00:00
|
|
|
}
|
2018-08-06 23:46:09 +00:00
|
|
|
})
|
2017-03-30 19:35:50 +00:00
|
|
|
}
|
|
|
|
|
2017-06-30 21:05:02 +00:00
|
|
|
func TestAPI_OperatorAutopilotServerHealth(t *testing.T) {
|
2017-03-30 19:35:50 +00:00
|
|
|
t.Parallel()
|
|
|
|
c, s := makeClientWithConfig(t, nil, func(c *testutil.TestServerConfig) {
|
|
|
|
c.RaftProtocol = 3
|
|
|
|
})
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
operator := c.Operator()
|
2017-05-04 22:52:53 +00:00
|
|
|
retry.Run(t, func(r *retry.R) {
|
2017-03-30 19:35:50 +00:00
|
|
|
out, err := operator.AutopilotServerHealth(nil)
|
|
|
|
if err != nil {
|
2017-04-29 16:34:02 +00:00
|
|
|
r.Fatalf("err: %v", err)
|
2017-03-30 19:35:50 +00:00
|
|
|
}
|
2017-04-29 16:34:02 +00:00
|
|
|
|
2017-03-30 19:35:50 +00:00
|
|
|
if len(out.Servers) != 1 ||
|
|
|
|
!out.Servers[0].Healthy ||
|
|
|
|
out.Servers[0].Name != s.Config.NodeName {
|
2017-04-29 16:34:02 +00:00
|
|
|
r.Fatalf("bad: %v", out)
|
2017-03-30 19:35:50 +00:00
|
|
|
}
|
2017-04-29 16:34:02 +00:00
|
|
|
})
|
2017-03-30 19:35:50 +00:00
|
|
|
}
|