2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2019-09-12 16:00:21 +00:00
|
|
|
package connect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
capi "github.com/hashicorp/consul/api"
|
|
|
|
"github.com/hashicorp/nomad/e2e/e2eutil"
|
|
|
|
"github.com/hashicorp/nomad/e2e/framework"
|
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
|
|
)
|
|
|
|
|
2021-04-14 23:02:42 +00:00
|
|
|
const (
|
|
|
|
consulNamespace = "default"
|
|
|
|
)
|
|
|
|
|
2019-09-12 16:00:21 +00:00
|
|
|
type ConnectClientStateE2ETest struct {
|
|
|
|
framework.TC
|
2021-04-14 23:02:42 +00:00
|
|
|
jobIDs []string
|
2019-09-12 16:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *ConnectClientStateE2ETest) BeforeAll(f *framework.F) {
|
|
|
|
e2eutil.WaitForLeader(f.T(), tc.Nomad())
|
|
|
|
e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *ConnectClientStateE2ETest) AfterEach(f *framework.F) {
|
|
|
|
if os.Getenv("NOMAD_TEST_SKIPCLEANUP") == "1" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-14 23:02:42 +00:00
|
|
|
for _, id := range tc.jobIDs {
|
2019-09-12 16:00:21 +00:00
|
|
|
tc.Nomad().Jobs().Deregister(id, true, nil)
|
|
|
|
}
|
2021-04-14 23:02:42 +00:00
|
|
|
tc.jobIDs = []string{}
|
2019-09-12 16:00:21 +00:00
|
|
|
tc.Nomad().System().GarbageCollect()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *ConnectClientStateE2ETest) TestClientRestart(f *framework.F) {
|
|
|
|
t := f.T()
|
2020-06-19 18:03:10 +00:00
|
|
|
|
2019-09-12 16:00:21 +00:00
|
|
|
jobID := "connect" + uuid.Generate()[0:8]
|
2021-04-14 23:02:42 +00:00
|
|
|
tc.jobIDs = append(tc.jobIDs, jobID)
|
2019-09-12 16:00:21 +00:00
|
|
|
client := tc.Nomad()
|
|
|
|
consulClient := tc.Consul()
|
|
|
|
|
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, client,
|
2020-01-28 22:33:59 +00:00
|
|
|
"connect/input/demo.nomad", jobID, "")
|
2020-11-30 14:48:40 +00:00
|
|
|
f.Equal(2, len(allocs))
|
2019-09-12 16:00:21 +00:00
|
|
|
|
2021-04-14 23:02:42 +00:00
|
|
|
e2eutil.RequireConsulStatus(f.Assertions, consulClient, consulNamespace, "count-api-sidecar-proxy", capi.HealthPassing)
|
2019-09-12 16:00:21 +00:00
|
|
|
nodeID := allocs[0].NodeID
|
|
|
|
|
|
|
|
restartID, err := e2eutil.AgentRestart(client, nodeID)
|
|
|
|
if restartID != "" {
|
2021-04-14 23:02:42 +00:00
|
|
|
tc.jobIDs = append(tc.jobIDs, restartID)
|
2019-09-12 16:00:21 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
2019-09-18 20:34:57 +00:00
|
|
|
t.Skip("node cannot be restarted", err)
|
2019-09-12 16:00:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:02:42 +00:00
|
|
|
e2eutil.RequireConsulStatus(f.Assertions, consulClient, consulNamespace, "count-api-sidecar-proxy", capi.HealthPassing)
|
2019-09-12 16:00:21 +00:00
|
|
|
}
|