Fix some tests, eval monitor shows deployment id and deployment cancels based on version

This commit is contained in:
Alex Dadgar
2017-07-06 19:55:58 -07:00
parent 53c129493a
commit fe990ca3e0
4 changed files with 19 additions and 58 deletions

View File

@@ -21,13 +21,14 @@ const (
// evalState is used to store the current "state of the world"
// in the context of monitoring an evaluation.
type evalState struct {
status string
desc string
node string
job string
allocs map[string]*allocState
wait time.Duration
index uint64
status string
desc string
node string
deployment string
job string
allocs map[string]*allocState
wait time.Duration
index uint64
}
// newEvalState creates and initializes a new monitorState
@@ -111,6 +112,11 @@ func (m *monitor) update(update *evalState) {
m.ui.Output(fmt.Sprintf("Evaluation triggered by job %q", update.job))
}
// Check if the evaluation was triggered by a deployment
if existing.deployment == "" && update.deployment != "" {
m.ui.Output(fmt.Sprintf("Evaluation within deployment: %q", limit(update.deployment, m.length)))
}
// Check the allocations
for allocID, alloc := range update.allocs {
if existing, ok := existing.allocs[allocID]; !ok {
@@ -236,6 +242,7 @@ func (m *monitor) monitor(evalID string, allowPrefix bool) int {
state.desc = eval.StatusDescription
state.node = eval.NodeID
state.job = eval.JobID
state.deployment = eval.DeploymentID
state.wait = eval.Wait
state.index = eval.CreateIndex

View File

@@ -121,36 +121,6 @@ func TestJobEndpoint_Register_InvalidDriverConfig(t *testing.T) {
}
}
func TestJobEndpoint_Register_UpdateWarning(t *testing.T) {
s1 := testServer(t, func(c *Config) {
c.NumSchedulers = 0 // Prevent automatic dequeue
})
defer s1.Shutdown()
codec := rpcClient(t, s1)
testutil.WaitForLeader(t, s1.RPC)
// Create the register request with a job containing an invalid driver
// config
job := mock.Job()
job.Update.Stagger = 1 * time.Second
job.Update.MaxParallel = 1
req := &structs.JobRegisterRequest{
Job: job,
WriteRequest: structs.WriteRequest{Region: "global"},
}
// Fetch the response
var resp structs.JobRegisterResponse
err := msgpackrpc.CallWithCodec(codec, "Job.Register", req, &resp)
if err != nil {
t.Fatalf("err: %v", err)
}
if !strings.Contains(resp.Warnings, "Update stagger deprecated") {
t.Fatalf("expected a deprecation warning but got: %v", err)
}
}
func TestJobEndpoint_Register_Payload(t *testing.T) {
s1 := testServer(t, func(c *Config) {
c.NumSchedulers = 0 // Prevent automatic dequeue
@@ -2629,22 +2599,6 @@ func TestJobEndpoint_ValidateJob_InvalidSignals(t *testing.T) {
}
}
func TestJobEndpoint_ValidateJob_UpdateWarning(t *testing.T) {
// Create a mock job with an invalid config
job := mock.Job()
job.Update.Stagger = 1 * time.Second
job.Update.MaxParallel = 1
err, warnings := validateJob(job)
if err != nil {
t.Fatalf("Unexpected validation error; got %v", err)
}
if !strings.Contains(warnings.Error(), "Update stagger deprecated") {
t.Fatalf("expected a deprecation warning but got: %v", err)
}
}
func TestJobEndpoint_ValidateJobUpdate(t *testing.T) {
old := mock.Job()
new := mock.Job()

View File

@@ -191,7 +191,7 @@ func (a *allocReconciler) cancelDeployments() {
}
// Check if the deployment is active and referencing an older job and cancel it
if d.JobCreateIndex != a.job.CreateIndex || d.JobModifyIndex != a.job.JobModifyIndex {
if d.JobCreateIndex != a.job.CreateIndex || d.JobVersion != a.job.Version {
if d.Active() {
a.result.deploymentUpdates = append(a.result.deploymentUpdates, &structs.DeploymentStatusUpdate{
DeploymentID: a.deployment.ID,

View File

@@ -1219,7 +1219,7 @@ func TestReconciler_CancelDeployment_JobUpdate(t *testing.T) {
failed.Status = structs.DeploymentStatusFailed
// Make the job newer than the deployment
job.JobModifyIndex += 10
job.Version += 10
cases := []struct {
name string
@@ -1872,7 +1872,7 @@ func TestReconciler_StopOldCanaries(t *testing.T) {
d.TaskGroups[job.TaskGroups[0].Name] = s
// Update the job
job.JobModifyIndex += 10
job.Version += 10
// Create 10 allocations from the old job
var allocs []*structs.Allocation
@@ -2735,12 +2735,12 @@ func TestReconciler_FailedDeployment_NewJob(t *testing.T) {
// Up the job version
jobNew := job.Copy()
jobNew.JobModifyIndex += 100
jobNew.Version += 100
reconciler := NewAllocReconciler(testLogger(), allocUpdateFnDestructive, false, job.ID, jobNew, d, allocs, nil)
r := reconciler.Compute()
dnew := structs.NewDeployment(job)
dnew := structs.NewDeployment(jobNew)
dnew.TaskGroups[job.TaskGroups[0].Name] = &structs.DeploymentState{
DesiredTotal: 10,
}