Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVPROD-12451 Update last communication time during host reprovisioning #8507

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions model/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,18 +1663,20 @@ func (h *Host) MarkAsReprovisioning(ctx context.Context) error {
needsAgentMonitor = h.StartedBy == evergreen.User
}

now := time.Now()
err := UpdateOne(ctx, bson.M{
IdKey: h.Id,
NeedsReprovisionKey: h.NeedsReprovision,
StatusKey: bson.M{"$in": allowedStatuses},
},
bson.M{
"$set": bson.M{
AgentStartTimeKey: utility.ZeroTime,
ProvisionedKey: false,
StatusKey: evergreen.HostProvisioning,
NeedsNewAgentKey: needsAgent,
NeedsNewAgentMonitorKey: needsAgentMonitor,
AgentStartTimeKey: utility.ZeroTime,
ProvisionedKey: false,
StatusKey: evergreen.HostProvisioning,
NeedsNewAgentKey: needsAgent,
NeedsNewAgentMonitorKey: needsAgentMonitor,
LastCommunicationTimeKey: now,
},
},
)
Expand All @@ -1687,6 +1689,7 @@ func (h *Host) MarkAsReprovisioning(ctx context.Context) error {
h.Status = evergreen.HostProvisioning
h.NeedsNewAgent = needsAgent
h.NeedsNewAgentMonitor = needsAgentMonitor
h.LastCommunicationTime = now

return nil
}
Expand Down
13 changes: 11 additions & 2 deletions service/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/evergreen-ci/evergreen/model/event"
"github.com/evergreen-ci/evergreen/model/host"
"github.com/evergreen-ci/evergreen/model/user"
"github.com/evergreen-ci/evergreen/units"
"github.com/evergreen-ci/gimlet"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -61,15 +62,17 @@ func TestModifyHostStatusWithUpdateStatus(t *testing.T) {
t.Run("SuccessfullyUnquarantinesHostAndMarksAsReprovisioning", func(t *testing.T) {
user := user.DBUser{Id: "user"}
h := host.Host{
Id: "h2",
Status: evergreen.HostQuarantined,
Id: "h2",
Provider: evergreen.ProviderNameStatic,
Status: evergreen.HostQuarantined,
Distro: distro.Distro{
BootstrapSettings: distro.BootstrapSettings{
Method: distro.BootstrapMethodSSH,
Communication: distro.BootstrapMethodSSH,
},
},
NumAgentCleanupFailures: 10,
LastCommunicationTime: time.Now().Add(-24 * time.Hour),
}
require.NoError(h.Insert(ctx))

Expand All @@ -79,10 +82,16 @@ func TestModifyHostStatusWithUpdateStatus(t *testing.T) {
assert.Equal(h.Status, evergreen.HostProvisioning)
assert.Equal(host.ReprovisionToNew, h.NeedsReprovision)

// Verify that host monitoring job does not immediately re-quarantine host
// due to long time since last communication
j := units.NewHostMonitoringCheckJob(env, &h, "job_id")
j.Run(ctx)

dbHost, err := host.FindOneId(ctx, h.Id)
require.NoError(err)
require.NotNil(t, dbHost)
assert.Equal(0, dbHost.NumAgentCleanupFailures)
assert.Equal(evergreen.HostProvisioning, dbHost.Status)
})
t.Run("FailsToDecommissionStaticHosts", func(t *testing.T) {
user := user.DBUser{Id: "user"}
Expand Down
Loading