From cb2805f66f02b2c1b1bfc33fa3d2d4e5407e7441 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 20 Aug 2024 18:38:50 +0800 Subject: [PATCH] optimize(region,host): add details error message when adding net interface (#21061) --- pkg/compute/models/hosts.go | 3 ++- pkg/compute/models/wires.go | 6 +++--- pkg/hostman/hostinfo/hostinfo.go | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 56da5aa1bc..373407de86 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -5244,6 +5244,7 @@ func (h *SHost) EnableNetif(ctx context.Context, userCred mcclient.TokenCredenti log.Errorf("Cannot allocate IP %s, not reachable", ipAddr) return fmt.Errorf("Cannot allocate IP %s, not reachable", ipAddr) } else { + log.Infof("not found network with scope: %s, ip_addr: %s", NetworkManager.AllowScope(userCred), ipAddr) // the ipaddr is not usable, should be reset to empty ipAddr = "" } @@ -5287,7 +5288,7 @@ func (h *SHost) EnableNetif(ctx context.Context, userCred mcclient.TokenCredenti return fmt.Errorf("fail to find public network %s", err) } if net == nil { - return fmt.Errorf("No network found") + return fmt.Errorf("No auto_alloc network found of wire: %s(%s), netTypes: %v", wire.GetName(), wire.GetId(), netTypes) } } } diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index a4326b7cfc..b05e7ae774 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -1015,7 +1015,7 @@ func (swire *SWire) GetCandidatePrivateNetwork(ctx context.Context, userCred mcc func (swire *SWire) GetCandidateAutoAllocNetwork(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, isExit bool, serverTypes []string) (*SNetwork, error) { nets, err := swire.getAutoAllocNetworks(ctx, userCred, ownerId, scope) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "getAutoAllocNetworks with scope %s", scope) } return ChooseCandidateNetworks(nets, isExit, serverTypes), nil } @@ -1023,11 +1023,11 @@ func (swire *SWire) GetCandidateAutoAllocNetwork(ctx context.Context, userCred m func (swire *SWire) GetCandidateNetworkForIp(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, ipAddr string) (*SNetwork, error) { ip, err := netutils.NewIPV4Addr(ipAddr) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "netutils.NewIPV4Addr: %s", ipAddr) } netPrivates, err := swire.getPrivateNetworks(ctx, userCred, ownerId, scope) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "swire.getPrivateNetworks %s", swire.GetId()) } for _, net := range netPrivates { if net.IsAddressInRange(ip) { diff --git a/pkg/hostman/hostinfo/hostinfo.go b/pkg/hostman/hostinfo/hostinfo.go index d57fba0a88..9c98315824 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -1796,7 +1796,7 @@ func (h *SHostInfo) doUploadNicInfoInternal(ifname, mac string, vlanId int, wire } res, err := modules.Hosts.PerformAction(h.GetSession(), h.HostId, "add-netif", content) if err != nil { - return nil, errors.Wrap(err, "modules.Hosts.PerformAction add-netif") + return nil, errors.Wrapf(err, "modules.Hosts.PerformAction add-netif: %s", content.String()) } return json2HostDetails(res)