e2e/deployment find the second deployment, use its status
This commit is contained in:
parent
344d5a83ad
commit
1635fa3c00
|
@ -1,9 +1,9 @@
|
||||||
package deployment
|
package deployment
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hashicorp/nomad/api"
|
|
||||||
"github.com/hashicorp/nomad/e2e/framework"
|
"github.com/hashicorp/nomad/e2e/framework"
|
||||||
"github.com/hashicorp/nomad/nomad/structs"
|
"github.com/hashicorp/nomad/nomad/structs"
|
||||||
|
"github.com/hashicorp/nomad/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/hashicorp/nomad/e2e/e2eutil"
|
"github.com/hashicorp/nomad/e2e/e2eutil"
|
||||||
|
@ -34,29 +34,31 @@ func (tc *DeploymentTest) BeforeAll(f *framework.F) {
|
||||||
func (tc *DeploymentTest) TestDeploymentAutoPromote(f *framework.F) {
|
func (tc *DeploymentTest) TestDeploymentAutoPromote(f *framework.F) {
|
||||||
t := f.T()
|
t := f.T()
|
||||||
nomadClient := tc.Nomad()
|
nomadClient := tc.Nomad()
|
||||||
|
run := structs.DeploymentStatusRunning
|
||||||
uuid := uuid.Generate()
|
uuid := uuid.Generate()
|
||||||
|
// unique each run, cluster could have previous jobs
|
||||||
jobId := "deployment" + uuid[0:8]
|
jobId := "deployment" + uuid[0:8]
|
||||||
tc.jobIds = append(tc.jobIds, jobId)
|
tc.jobIds = append(tc.jobIds, jobId)
|
||||||
e2eutil.RegisterAndWaitForAllocs(t, nomadClient, "deployment/input/deployment_auto0.nomad", jobId)
|
e2eutil.RegisterAndWaitForAllocs(t, nomadClient, "deployment/input/deployment_auto0.nomad", jobId)
|
||||||
|
deploy := e2eutil.DeploymentsForJob(nomadClient, jobId)[0]
|
||||||
|
|
||||||
// Upgrade
|
// Upgrade
|
||||||
e2eutil.RegisterAllocs(t, nomadClient, "deployment/input/deployment_auto1.nomad", jobId)
|
e2eutil.RegisterAllocs(t, nomadClient, "deployment/input/deployment_auto1.nomad", jobId)
|
||||||
var deploy *api.Deployment
|
|
||||||
ds, _, err := nomadClient.Deployments().List(nil)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Find the deployment
|
// Find the deployment we don't already have
|
||||||
|
testutil.WaitForResult(func() (bool, error) {
|
||||||
|
ds := e2eutil.DeploymentsForJob(nomadClient, jobId)
|
||||||
for _, d := range ds {
|
for _, d := range ds {
|
||||||
if d.JobID == jobId {
|
if d.ID != deploy.ID {
|
||||||
deploy = d
|
deploy = d
|
||||||
break
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false, nil
|
||||||
|
}, func(e error) {})
|
||||||
|
|
||||||
// Deployment is auto pending the upgrade of "two" which has a longer time to health
|
// Deployment is auto pending the upgrade of "two" which has a longer time to health
|
||||||
run := structs.DeploymentStatusRunning
|
e2eutil.WaitForDeployment(t, nomadClient, deploy.ID, run, structs.DeploymentStatusDescriptionRunningAutoPromotion)
|
||||||
require.Equal(t, run, deploy.Status)
|
|
||||||
require.Equal(t, structs.DeploymentStatusDescriptionRunningAutoPromotion, deploy.StatusDescription)
|
|
||||||
|
|
||||||
// Deployment is eventually running
|
// Deployment is eventually running
|
||||||
e2eutil.WaitForDeployment(t, nomadClient, deploy.ID, run, structs.DeploymentStatusDescriptionRunning)
|
e2eutil.WaitForDeployment(t, nomadClient, deploy.ID, run, structs.DeploymentStatusDescriptionRunning)
|
||||||
|
|
|
@ -111,6 +111,22 @@ func WaitForAllocRunning(t *testing.T, nomadClient *api.Client, allocID string)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeploymentsForJob(nomadClient *api.Client, jobID string) []*api.Deployment {
|
||||||
|
ds, _, err := nomadClient.Deployments().List(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
out := []*api.Deployment{}
|
||||||
|
for _, d := range ds {
|
||||||
|
if d.JobID == jobID {
|
||||||
|
out = append(out, d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func WaitForDeployment(t *testing.T, nomadClient *api.Client, deployID string, status string, statusDesc string) {
|
func WaitForDeployment(t *testing.T, nomadClient *api.Client, deployID string, status string, statusDesc string) {
|
||||||
testutil.WaitForResultRetries(retries, func() (bool, error) {
|
testutil.WaitForResultRetries(retries, func() (bool, error) {
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Millisecond * 100)
|
||||||
|
@ -123,10 +139,10 @@ func WaitForDeployment(t *testing.T, nomadClient *api.Client, deployID string, s
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return false, fmt.Errorf("expected status %s \"%s\", but got: %s \"%s\"",
|
return false, fmt.Errorf("expected status %s \"%s\", but got: %s \"%s\"",
|
||||||
deploy.Status,
|
|
||||||
deploy.StatusDescription,
|
|
||||||
status,
|
status,
|
||||||
statusDesc,
|
statusDesc,
|
||||||
|
deploy.Status,
|
||||||
|
deploy.StatusDescription,
|
||||||
)
|
)
|
||||||
|
|
||||||
}, func(err error) {
|
}, func(err error) {
|
||||||
|
|
Loading…
Reference in a new issue