Merge pull request #10026 from ioito/automated-cherry-pick-of-#10025-upstream-release-3.7

Automated cherry pick of #10025: fix(region): purge snapshot with not status check
This commit is contained in:
Zexi Li
2021-01-27 09:02:14 +08:00
committed by GitHub
2 changed files with 6 additions and 2 deletions
+2 -2
View File
@@ -630,9 +630,9 @@ func (snapshot *SSnapshot) purge(ctx context.Context, userCred mcclient.TokenCre
lockman.LockObject(ctx, snapshot)
defer lockman.ReleaseObject(ctx, snapshot)
err := snapshot.ValidateDeleteCondition(ctx)
err := snapshot.ValidatePurgeCondition(ctx)
if err != nil {
return err
return errors.Wrapf(err, "ValidatePurgeCondition for snapshot %s(%s)", snapshot.Name, snapshot.Id)
}
return snapshot.RealDelete(ctx, userCred)
}
+4
View File
@@ -621,6 +621,10 @@ func (self *SSnapshot) ValidateDeleteCondition(ctx context.Context) error {
if self.Status == api.SNAPSHOT_DELETING {
return httperrors.NewBadRequestError("Cannot delete snapshot in status %s", self.Status)
}
return self.ValidatePurgeCondition(ctx)
}
func (self *SSnapshot) ValidatePurgeCondition(ctx context.Context) error {
count, err := InstanceSnapshotJointManager.Query().Equals("snapshot_id", self.Id).CountWithError()
if err != nil {
return httperrors.NewInternalServerError("Fetch instance snapshot error %s", err)