From a74853db79d5c0874a762b1e953c9233c263bf7f Mon Sep 17 00:00:00 2001 From: tangbin Date: Fri, 17 Jul 2020 20:39:01 +0800 Subject: [PATCH] acl delete condition fix --- pkg/compute/models/loadbalanceracls.go | 33 +++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pkg/compute/models/loadbalanceracls.go b/pkg/compute/models/loadbalanceracls.go index 2167d24d8d..e47b04c6d9 100644 --- a/pkg/compute/models/loadbalanceracls.go +++ b/pkg/compute/models/loadbalanceracls.go @@ -363,22 +363,27 @@ func (lbacl *SLoadbalancerAcl) PerformPatch(ctx context.Context, userCred mcclie } func (lbacl *SLoadbalancerAcl) ValidateDeleteCondition(ctx context.Context) error { - man := CachedLoadbalancerAclManager - t := man.TableSpec().Instance() - pdF := t.Field("pending_deleted") + men := []db.IModelManager{ + LoadbalancerListenerManager, + CachedLoadbalancerAclManager, + } + lbaclId := lbacl.Id - n, err := t.Query(). - Filter(sqlchemy.OR(sqlchemy.IsNull(pdF), sqlchemy.IsFalse(pdF))). - Equals("acl_id", lbaclId). - CountWithError() - if err != nil { - return httperrors.NewInternalServerError("get acl count fail %s", err) - } - if n > 0 { - // return fmt.Errorf("acl %s is still referred to by %d %s", - // lbaclId, n, man.KeywordPlural()) - return httperrors.NewResourceBusyError("acl %s is still referred to by %d %s", lbaclId, n, man.KeywordPlural()) + for _, man := range men { + t := man.TableSpec().Instance() + pdF := t.Field("pending_deleted") + n, err := t.Query(). + Filter(sqlchemy.OR(sqlchemy.IsNull(pdF), sqlchemy.IsFalse(pdF))). + Equals("acl_id", lbaclId). + CountWithError() + if err != nil { + return httperrors.NewInternalServerError("get acl count fail %s", err) + } + if n > 0 { + return httperrors.NewResourceBusyError("acl %s is still referred to by %d %s", lbaclId, n, man.KeywordPlural()) + } } + return nil }