From 2f6678f9a7682b792691ed678995b124c7be7ed0 Mon Sep 17 00:00:00 2001 From: rainzm Date: Thu, 15 Oct 2020 15:06:02 +0800 Subject: [PATCH 1/2] fix(region): compute binded disk count when deleting snapshotpolicy --- pkg/compute/models/snapshotpolicy.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/compute/models/snapshotpolicy.go b/pkg/compute/models/snapshotpolicy.go index e7486e51d1..24c86e92d3 100644 --- a/pkg/compute/models/snapshotpolicy.go +++ b/pkg/compute/models/snapshotpolicy.go @@ -310,11 +310,11 @@ func (sp *SSnapshotPolicy) DetachAfterDelete(ctx context.Context, userCred mccli func (sp *SSnapshotPolicy) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error { // check if sp bind to some disks - sds, err := SnapshotPolicyDiskManager.FetchAllBySnapshotpolicyID(ctx, userCred, sp.GetId()) + count, err := SnapshotPolicyDiskManager.FetchDiskCountBySPID(sp.Id) if err != nil { - return errors.Wrap(err, "fetch bind info failed") + return errors.Wrap(err, "unable to FetchDiskCountBySPID") } - if len(sds) != 0 { + if count != 0 { return httperrors.NewBadRequestError("Couldn't delete snapshot policy binding to disks") } sp.SetStatus(userCred, api.SNAPSHOT_POLICY_DELETING, "") @@ -350,6 +350,7 @@ func (manager *SSnapshotPolicyManager) FetchCustomizeColumns( VirtualResourceDetails: virtRows[i], } rows[i] = objs[i].(*SSnapshotPolicy).getMoreDetails(rows[i]) + log.Infof("details: %v", rows[i]) } return rows From f6844e3c6dcfe73b7f65a1f082a0c01318ac9ed6 Mon Sep 17 00:00:00 2001 From: rainzm Date: Thu, 15 Oct 2020 15:12:34 +0800 Subject: [PATCH 2/2] feat: use details data to cover obj data in FetchCustomizeColumns --- pkg/cloudcommon/db/caller.go | 5 +++-- pkg/compute/models/snapshotpolicy.go | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/cloudcommon/db/caller.go b/pkg/cloudcommon/db/caller.go index edb4fc5279..720b923b9d 100644 --- a/pkg/cloudcommon/db/caller.go +++ b/pkg/cloudcommon/db/caller.go @@ -301,8 +301,9 @@ func FetchCustomizeColumns( retVal := make([]*jsonutils.JSONDict, ret[0].Len()) for i := 0; i < ret[0].Len(); i += 1 { jsonDict := ValueToJSONDict(ret[0].Index(i)) - jsonDict.Update(jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict)) - retVal[i] = jsonDict + objDict := jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict) + objDict.Update(jsonDict) + retVal[i] = objDict } return retVal, nil } diff --git a/pkg/compute/models/snapshotpolicy.go b/pkg/compute/models/snapshotpolicy.go index 24c86e92d3..1be9e1fe9f 100644 --- a/pkg/compute/models/snapshotpolicy.go +++ b/pkg/compute/models/snapshotpolicy.go @@ -350,7 +350,6 @@ func (manager *SSnapshotPolicyManager) FetchCustomizeColumns( VirtualResourceDetails: virtRows[i], } rows[i] = objs[i].(*SSnapshotPolicy).getMoreDetails(rows[i]) - log.Infof("details: %v", rows[i]) } return rows