e2e/deployment find the second deployment, use its status

This commit is contained in:
Lang Martin 2019-06-04 11:25:18 -04:00
parent 344d5a83ad
commit 1635fa3c00
2 changed files with 33 additions and 15 deletions

View file

@ -1,9 +1,9 @@
package deployment
import (
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/e2e/framework"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require"
"github.com/hashicorp/nomad/e2e/e2eutil"
@ -34,29 +34,31 @@ func (tc *DeploymentTest) BeforeAll(f *framework.F) {
func (tc *DeploymentTest) TestDeploymentAutoPromote(f *framework.F) {
t := f.T()
nomadClient := tc.Nomad()
run := structs.DeploymentStatusRunning
uuid := uuid.Generate()
// unique each run, cluster could have previous jobs
jobId := "deployment" + uuid[0:8]
tc.jobIds = append(tc.jobIds, jobId)
e2eutil.RegisterAndWaitForAllocs(t, nomadClient, "deployment/input/deployment_auto0.nomad", jobId)
deploy := e2eutil.DeploymentsForJob(nomadClient, jobId)[0]
// Upgrade
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 {
if d.JobID == jobId {
if d.ID != deploy.ID {
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
run := structs.DeploymentStatusRunning
require.Equal(t, run, deploy.Status)
require.Equal(t, structs.DeploymentStatusDescriptionRunningAutoPromotion, deploy.StatusDescription)
e2eutil.WaitForDeployment(t, nomadClient, deploy.ID, run, structs.DeploymentStatusDescriptionRunningAutoPromotion)
// Deployment is eventually running
e2eutil.WaitForDeployment(t, nomadClient, deploy.ID, run, structs.DeploymentStatusDescriptionRunning)

View file

@ -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) {
testutil.WaitForResultRetries(retries, func() (bool, error) {
time.Sleep(time.Millisecond * 100)
@ -123,10 +139,10 @@ func WaitForDeployment(t *testing.T, nomadClient *api.Client, deployID string, s
return true, nil
}
return false, fmt.Errorf("expected status %s \"%s\", but got: %s \"%s\"",
deploy.Status,
deploy.StatusDescription,
status,
statusDesc,
deploy.Status,
deploy.StatusDescription,
)
}, func(err error) {