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

Update account status to NotReady for expired lease #353

Merged
merged 4 commits into from
Jun 1, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## vNext
- Fix bug: Status change in account table fails for leased accounts that are expired. See https://github.com/Optum/dce/issues/344

## v0.30.1
- Added new tool in `tools` folder for generating Markdown and IAM example policy for AWS Nuke
Expand Down
12 changes: 12 additions & 0 deletions cmd/lambda/update_lease_status/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ func handleLeaseExpire(input *lambdaHandlerInput, prevLeaseStatus db.LeaseStatus
deferredErrors = append(deferredErrors, err)
}

// Update Account Status to "NotReady"
_, err = input.dbSvc.TransitionAccountStatus(
input.lease.AccountID,
db.Leased,
db.NotReady,
)

if err != nil {
log.Printf("Account status update: Failed to add account to reset queue for lease %s @ %s: %s", input.lease.PrincipalID, input.lease.AccountID, err)
deferredErrors = append(deferredErrors, err)
}

// Return errors
if len(deferredErrors) > 0 {
return multierrors.NewMultiError("Failed to lock over-budget account: ", deferredErrors)
Expand Down
2 changes: 2 additions & 0 deletions cmd/lambda/update_lease_status/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ has exceeded its budget of $100. Actual spend is $150
input.lease.LeaseStatus = test.expectedLeaseStatusTransition
return input.lease
}, test.transitionLeaseError)

dbSvc.On("TransitionAccountStatus", "1234567890", db.Leased, db.NotReady).Return(nil, nil)
}

// Should send a notification email
Expand Down
7 changes: 6 additions & 1 deletion tests/acceptance/update_lease_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,16 @@ func TestUpdateLeaseStatusLambda(t *testing.T) {
err = json.Unmarshal(result.Payload, &resp)
require.Nil(t, err)

// Check lease status is active
// Check lease status is inactive
lease, err := dbSvc.GetLease(accountID, "user")
require.Nil(t, err)
require.Equal(t, db.LeaseStatus("Inactive"), lease.LeaseStatus)
require.Equal(t, db.LeaseStatusReason("Expired"), lease.LeaseStatusReason)

// Check account status is updated to NotReady
account, err := dbSvc.GetAccount(accountID)
require.Nil(t, err)
require.Equal(t, db.NotReady, account.AccountStatus)
})

t.Run("Exceeded lease budget result in Inactive lease with reason OverBudget.", func(t *testing.T) {
Expand Down