Skip to content

Commit

Permalink
fix(HMS-2757): fetch reservation id for update
Browse files Browse the repository at this point in the history
Signed-off-by: Lukáš Zapletal <[email protected]>
  • Loading branch information
lzap committed Oct 11, 2023
1 parent 19c066b commit f012208
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions internal/dao/pgx/pubkey_pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (x *pubkeyDao) Update(ctx context.Context, pubkey *models.Pubkey) error {
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func (x *pubkeyDao) Delete(ctx context.Context, id int64) error {
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func (x *pubkeyDao) UnscopedDeleteResource(ctx context.Context, id int64) error
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
24 changes: 12 additions & 12 deletions internal/dao/pgx/reservation_pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (x *reservationDao) CreateAWS(ctx context.Context, reservation *models.AWSR
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}

return nil
Expand Down Expand Up @@ -84,7 +84,7 @@ func (x *reservationDao) CreateAzure(ctx context.Context, reservation *models.Az
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}

return nil
Expand Down Expand Up @@ -115,7 +115,7 @@ func (x *reservationDao) CreateGCP(ctx context.Context, reservation *models.GCPR
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}

return nil
Expand Down Expand Up @@ -160,7 +160,7 @@ func (x *reservationDao) CreateInstance(ctx context.Context, instance *models.Re
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}

return nil
Expand All @@ -179,7 +179,7 @@ func (x *reservationDao) UpdateReservationInstance(ctx context.Context, reservat
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}

return nil
Expand Down Expand Up @@ -300,7 +300,7 @@ func (x *reservationDao) UpdateStatus(ctx context.Context, id int64, status stri
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand All @@ -313,7 +313,7 @@ func (x *reservationDao) UnscopedUpdateAWSDetail(ctx context.Context, id int64,
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand All @@ -326,7 +326,7 @@ func (x *reservationDao) UpdateReservationIDForAWS(ctx context.Context, id int64
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand All @@ -339,7 +339,7 @@ func (x *reservationDao) UpdateOperationNameForGCP(ctx context.Context, id int64
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand All @@ -352,7 +352,7 @@ func (x *reservationDao) FinishWithSuccess(ctx context.Context, id int64) error
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand All @@ -365,7 +365,7 @@ func (x *reservationDao) FinishWithError(ctx context.Context, id int64, errorStr
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand All @@ -378,7 +378,7 @@ func (x *reservationDao) Delete(ctx context.Context, id int64) error {
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dao/pgx/service_pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func UnscopedUpdatePubkey(ctx context.Context, pubkey *models.Pubkey) error {
return fmt.Errorf("pgx error: %w", err)
}
if tag.RowsAffected() != 1 {
return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch)
return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch)
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions internal/jobs/launch_instance_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func DoEnsurePubkeyOnAWS(ctx context.Context, args *LaunchInstanceAWSTaskArgs) e

// update the AWS key name in reservation details
awsReservation.Detail.PubkeyName = ec2Name
logger.Debug().Msgf("Updating AWS reservation detail %d", awsReservation.Reservation.ID)
err = resDao.UnscopedUpdateAWSDetail(ctx, awsReservation.Reservation.ID, awsReservation.Detail)
if err != nil {
span.SetStatus(codes.Error, "failed to save AWS pubkey name to DB")
Expand Down

0 comments on commit f012208

Please sign in to comment.