From b9c344e3df38cc1295de5249bc0960c4b576c91b Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Tue, 26 Jan 2021 14:46:47 +0800 Subject: [PATCH] fix(region): purge snapshot with not status check --- pkg/compute/models/purge.go | 4 ++-- pkg/compute/models/snapshots.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/compute/models/purge.go b/pkg/compute/models/purge.go index 04520639aa..9559e89e56 100644 --- a/pkg/compute/models/purge.go +++ b/pkg/compute/models/purge.go @@ -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) } diff --git a/pkg/compute/models/snapshots.go b/pkg/compute/models/snapshots.go index 088aa22827..ddda9b41ea 100644 --- a/pkg/compute/models/snapshots.go +++ b/pkg/compute/models/snapshots.go @@ -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)