2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2019-05-20 15:37:36 +00:00
|
|
|
package deployment
|
|
|
|
|
|
|
|
import (
|
2019-06-04 18:31:42 +00:00
|
|
|
"fmt"
|
|
|
|
|
2019-05-20 15:37:36 +00:00
|
|
|
"github.com/hashicorp/nomad/e2e/framework"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2019-06-04 15:25:18 +00:00
|
|
|
"github.com/hashicorp/nomad/testutil"
|
2019-05-20 15:37:36 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/e2e/e2eutil"
|
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DeploymentTest struct {
|
|
|
|
framework.TC
|
|
|
|
jobIds []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
framework.AddSuites(&framework.TestSuite{
|
|
|
|
Component: "Deployment",
|
|
|
|
CanRunLocal: true,
|
|
|
|
Cases: []framework.TestCase{
|
|
|
|
new(DeploymentTest),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *DeploymentTest) BeforeAll(f *framework.F) {
|
|
|
|
// Ensure cluster has leader before running tests
|
|
|
|
e2eutil.WaitForLeader(f.T(), tc.Nomad())
|
|
|
|
e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 4)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *DeploymentTest) TestDeploymentAutoPromote(f *framework.F) {
|
|
|
|
t := f.T()
|
|
|
|
nomadClient := tc.Nomad()
|
2019-06-04 15:25:18 +00:00
|
|
|
run := structs.DeploymentStatusRunning
|
2019-05-20 15:37:36 +00:00
|
|
|
uuid := uuid.Generate()
|
2019-06-04 15:25:18 +00:00
|
|
|
// unique each run, cluster could have previous jobs
|
2019-05-20 15:37:36 +00:00
|
|
|
jobId := "deployment" + uuid[0:8]
|
|
|
|
tc.jobIds = append(tc.jobIds, jobId)
|
2020-01-28 22:33:59 +00:00
|
|
|
e2eutil.RegisterAndWaitForAllocs(t, nomadClient, "deployment/input/deployment_auto0.nomad", jobId, "")
|
2019-06-04 18:31:42 +00:00
|
|
|
ds := e2eutil.DeploymentsForJob(t, nomadClient, jobId)
|
|
|
|
require.Equal(t, 1, len(ds))
|
|
|
|
deploy := ds[0]
|
2019-05-20 15:37:36 +00:00
|
|
|
|
|
|
|
// Upgrade
|
2020-01-28 22:33:59 +00:00
|
|
|
e2eutil.RegisterAllocs(t, nomadClient, "deployment/input/deployment_auto1.nomad", jobId, "")
|
2019-05-20 15:37:36 +00:00
|
|
|
|
2019-06-04 15:25:18 +00:00
|
|
|
// Find the deployment we don't already have
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
2019-06-04 18:31:42 +00:00
|
|
|
ds = e2eutil.DeploymentsForJob(t, nomadClient, jobId)
|
2019-06-04 15:25:18 +00:00
|
|
|
for _, d := range ds {
|
|
|
|
if d.ID != deploy.ID {
|
|
|
|
deploy = d
|
|
|
|
return true, nil
|
|
|
|
}
|
2019-05-20 15:37:36 +00:00
|
|
|
}
|
2019-06-04 18:31:42 +00:00
|
|
|
return false, fmt.Errorf("missing update deployment for job %s", jobId)
|
2019-06-04 18:08:30 +00:00
|
|
|
}, func(e error) {
|
2019-06-04 18:31:42 +00:00
|
|
|
require.NoError(t, e)
|
2019-06-04 18:08:30 +00:00
|
|
|
})
|
2019-05-20 15:37:36 +00:00
|
|
|
|
|
|
|
// Deployment is auto pending the upgrade of "two" which has a longer time to health
|
2019-06-04 15:25:18 +00:00
|
|
|
e2eutil.WaitForDeployment(t, nomadClient, deploy.ID, run, structs.DeploymentStatusDescriptionRunningAutoPromotion)
|
2019-05-20 15:37:36 +00:00
|
|
|
|
|
|
|
// Deployment is eventually running
|
|
|
|
e2eutil.WaitForDeployment(t, nomadClient, deploy.ID, run, structs.DeploymentStatusDescriptionRunning)
|
2019-05-21 13:21:44 +00:00
|
|
|
|
|
|
|
deploy, _, _ = nomadClient.Deployments().Info(deploy.ID, nil)
|
2019-05-20 15:37:36 +00:00
|
|
|
require.Equal(t, run, deploy.Status)
|
|
|
|
require.Equal(t, structs.DeploymentStatusDescriptionRunning, deploy.StatusDescription)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *DeploymentTest) AfterEach(f *framework.F) {
|
|
|
|
nomadClient := tc.Nomad()
|
|
|
|
jobs := nomadClient.Jobs()
|
|
|
|
// Stop all jobs in test
|
|
|
|
for _, id := range tc.jobIds {
|
|
|
|
jobs.Deregister(id, true, nil)
|
|
|
|
}
|
2019-05-21 20:46:11 +00:00
|
|
|
tc.jobIds = []string{}
|
2019-05-20 15:37:36 +00:00
|
|
|
// Garbage collect
|
|
|
|
nomadClient.System().GarbageCollect()
|
|
|
|
}
|