From 5dd5767d948aece5d985aca6b97b5442daca9ae4 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Mon, 22 Oct 2018 12:31:12 +0000 Subject: [PATCH 1/4] govet: treewide struct tag fix govet complains of the form struct field tag `required:true` not compatible with reflect.StructTag.Get: bad syntax for struct tag value --- cmd/climc/shell/disks.go | 4 +-- cmd/climc/shell/rates.go | 8 +++--- cmd/climc/shell/resource_details.go | 4 +-- cmd/climc/shell/resource_fees.go | 10 +++---- cmd/climc/shell/snapshots.go | 4 +-- .../models/loadbalancercertificates.go | 16 +++++------ pkg/lbagent/options.go | 18 ++++++------ pkg/mcclient/options/loadbalanceragents.go | 10 +++---- pkg/mcclient/options/loadbalancerbackends.go | 10 +++---- .../options/loadbalancercertificates.go | 8 +++--- .../options/loadbalancerlistenerrules.go | 2 +- pkg/mcclient/options/loadbalancerlisteners.go | 28 +++++++++---------- pkg/util/azure/shell/eip.go | 2 +- 13 files changed, 62 insertions(+), 62 deletions(-) diff --git a/cmd/climc/shell/disks.go b/cmd/climc/shell/disks.go index 32e9fe3456..0e559cdbaf 100644 --- a/cmd/climc/shell/disks.go +++ b/cmd/climc/shell/disks.go @@ -209,7 +209,7 @@ func init() { }) type DiskResetOptions struct { DISK string `help:"ID or name of disk"` - SNAPSHOT string `help:"snapshots ID of disk` + SNAPSHOT string `help:"snapshots ID of disk"` AutoStart bool `help:"Autostart guest"` } R(&DiskResetOptions{}, "disk-reset", "Resize a disk", func(s *mcclient.ClientSession, args *DiskResetOptions) error { @@ -227,7 +227,7 @@ func init() { }) type DiskCreateSnapshotOptions struct { DISK string `help:"ID or name of disk"` - SNAPSHOT_NAME string `help:"Snapshots name` + SNAPSHOT_NAME string `help:"Snapshot name"` } R(&DiskCreateSnapshotOptions{}, "disk-create-snapshot", "Disk create snapshot", func(s *mcclient.ClientSession, args *DiskCreateSnapshotOptions) error { params := jsonutils.NewDict() diff --git a/cmd/climc/shell/rates.go b/cmd/climc/shell/rates.go index 34f52ece8d..4ef1b4f787 100644 --- a/cmd/climc/shell/rates.go +++ b/cmd/climc/shell/rates.go @@ -13,10 +13,10 @@ func init() { */ type RateListOptions struct { options.BaseListOptions - RESTYPE string `"help":"res_type of the rate"` - ACTION string `"help":"action of list :querygroup or queryhistory"` - SubResType string `"help":"query the subResType"` - Id string `"help":"ID of rate"` + RESTYPE string `help:"res_type of the rate"` + ACTION string `help:"action of list :querygroup or queryhistory"` + SubResType string `help:"query the subResType"` + Id string `help:"ID of rate"` } R(&RateListOptions{}, "rate-list", "List all rates ", func(s *mcclient.ClientSession, args *RateListOptions) error { var params *jsonutils.JSONDict diff --git a/cmd/climc/shell/resource_details.go b/cmd/climc/shell/resource_details.go index 7ea8e8eee7..83a28a6e59 100644 --- a/cmd/climc/shell/resource_details.go +++ b/cmd/climc/shell/resource_details.go @@ -13,8 +13,8 @@ func init() { */ type ResourceDetailListOptions struct { options.BaseListOptions - QUERYTYPE string `"help":"query type of the resource_detail"` - ProjectId string `"help":"project id of the resource_detail"` + QUERYTYPE string `help:"query type of the resource_detail"` + ProjectId string `help:"project id of the resource_detail"` } R(&ResourceDetailListOptions{}, "resourcedetail-list", "List all resource details", func(s *mcclient.ClientSession, args *ResourceDetailListOptions) error { var params *jsonutils.JSONDict diff --git a/cmd/climc/shell/resource_fees.go b/cmd/climc/shell/resource_fees.go index 49e50764e2..f9b5781ae3 100644 --- a/cmd/climc/shell/resource_fees.go +++ b/cmd/climc/shell/resource_fees.go @@ -13,11 +13,11 @@ func init() { */ type ResourceFeeListOptions struct { options.BaseListOptions - STATTYPE string `"help":"stat type of the resource_fee"` - STATMONTH string `"help":"stat month of the resource_fee"` - ProjectId string `"help":"project id of the resource_fee"` - StartDay string `"help":"start day of the resource_fee"` - EndDay string `"help":"end day of the resource_fee"` + STATTYPE string `help:"stat type of the resource_fee"` + STATMONTH string `help:"stat month of the resource_fee"` + ProjectId string `help:"project id of the resource_fee"` + StartDay string `help:"start day of the resource_fee"` + EndDay string `help:"end day of the resource_fee"` } R(&ResourceFeeListOptions{}, "resourcefee-list", "List all resource fees", func(s *mcclient.ClientSession, args *ResourceFeeListOptions) error { var params *jsonutils.JSONDict diff --git a/cmd/climc/shell/snapshots.go b/cmd/climc/shell/snapshots.go index 967abb7387..cf63c3be9a 100644 --- a/cmd/climc/shell/snapshots.go +++ b/cmd/climc/shell/snapshots.go @@ -14,8 +14,8 @@ func init() { FakeDeleted bool `help:"Show fake deleted snapshot or not"` Local bool `help:"Show local snapshots"` Share bool `help:"Show shared snapshots"` - DiskType string `help: "Filter by disk type" choices:"sys|data"` - Provider string `help: "Cloud provider" choices:"Aliyun|VMware|Azure"` + DiskType string `help:"Filter by disk type" choices:"sys|data"` + Provider string `help:"Cloud provider" choices:"Aliyun|VMware|Azure"` Manager string `help:"Show snapshots belongs to a specific cloud provider"` } diff --git a/pkg/compute/models/loadbalancercertificates.go b/pkg/compute/models/loadbalancercertificates.go index 69ce56a696..c2531f9b37 100644 --- a/pkg/compute/models/loadbalancercertificates.go +++ b/pkg/compute/models/loadbalancercertificates.go @@ -44,14 +44,14 @@ type SLoadbalancerCertificate struct { PrivateKey string `create:"required" list:"admin" update:"user"` // derived attributes - PublicKeyAlgorithm string `create:"optional" list:user update:"user"` - PublicKeyBitLen int `create:"optional" list:user update:"user"` - SignatureAlgorithm string `create:"optional" list:user update:"user"` - FingerprintSha256 string `create:"optional" list:user update:"user"` - NotBefore time.Time `create:"optional" list:user update:"user"` - NotAfter time.Time `create:"optional" list:user update:"user"` - CommonName string `create:"optional" list:user update:"user"` - SubjectAlternativeNames string `create:"optional" list:user update:"user"` + PublicKeyAlgorithm string `create:"optional" list:"user" update:"user"` + PublicKeyBitLen int `create:"optional" list:"user" update:"user"` + SignatureAlgorithm string `create:"optional" list:"user" update:"user"` + FingerprintSha256 string `create:"optional" list:"user" update:"user"` + NotBefore time.Time `create:"optional" list:"user" update:"user"` + NotAfter time.Time `create:"optional" list:"user" update:"user"` + CommonName string `create:"optional" list:"user" update:"user"` + SubjectAlternativeNames string `create:"optional" list:"user" update:"user"` } func (man *SLoadbalancerCertificateManager) PreDeleteSubs(ctx context.Context, userCred mcclient.TokenCredential, q *sqlchemy.SQuery) { diff --git a/pkg/lbagent/options.go b/pkg/lbagent/options.go index 5f9ad42d6a..a0c61596b7 100644 --- a/pkg/lbagent/options.go +++ b/pkg/lbagent/options.go @@ -10,23 +10,23 @@ import ( ) type LbagentOptions struct { - ApiLbagentId string `require:true` - ApiLbagentHbInterval int `default:10` - ApiLbagentHbTimeoutRelaxation int `default:120 help:"If agent is to stale out in specified seconds in the future, consider it staled to avoid race condition when doing incremental api data fetch"` + ApiLbagentId string `require:"true"` + ApiLbagentHbInterval int `default:"10"` + ApiLbagentHbTimeoutRelaxation int `default:"120" help:"If agent is to stale out in specified seconds in the future, consider it staled to avoid race condition when doing incremental api data fetch"` ApiSyncInterval int - ApiListBatchSize int `default:1024` + ApiListBatchSize int `default:"1024"` - DataPreserveN int `default:8 help:"number of recent data to preserve on disk"` + DataPreserveN int `default:"8" help:"number of recent data to preserve on disk"` - BaseDataDir string // `required:true` + BaseDataDir string // `required:"true"` apiDataStoreDir string haproxyConfigDir string haproxyRunDir string - KeepalivedBin string `default:keepalived` - HaproxyBin string `default:haproxy` - GobetweenBin string `default:gobetween` + KeepalivedBin string `default:"keepalived"` + HaproxyBin string `default:"haproxy"` + GobetweenBin string `default:"gobetween"` } type Options struct { diff --git a/pkg/mcclient/options/loadbalanceragents.go b/pkg/mcclient/options/loadbalanceragents.go index 46d0263cd6..88e9e73116 100644 --- a/pkg/mcclient/options/loadbalanceragents.go +++ b/pkg/mcclient/options/loadbalanceragents.go @@ -14,16 +14,16 @@ type LoadbalancerAgentParamsOptions struct { VrrpPriority *int // required VrrpVirtualRouterId *int // required VrrpGarpMasterRefresh *int - VrrpPreempt string `choices:true|false` + VrrpPreempt string `choices:"true|false"` VrrpInterface string // required VrrpAdvertInt *int VrrpPass string HaproxyGlobalLog string - HaproxyGlobalNbthread *int `default:1 help:"enable experimental multi-threading support available since haproxy 1.8"` - HaproxyLogHttp string `choices:true|false` - HaproxyLogTcp string `choices:true|false` - HaproxyLogNormal string `choices:true|false` + HaproxyGlobalNbthread *int `default:"1" help:"enable experimental multi-threading support available since haproxy 1.8"` + HaproxyLogHttp string `choices:"true|false"` + HaproxyLogTcp string `choices:"true|false"` + HaproxyLogNormal string `choices:"true|false"` } func (opts *LoadbalancerAgentParamsOptions) setPrefixedParams(params *jsonutils.JSONDict, pref string) { diff --git a/pkg/mcclient/options/loadbalancerbackends.go b/pkg/mcclient/options/loadbalancerbackends.go index 76ceb3b1c4..7b89b874d0 100644 --- a/pkg/mcclient/options/loadbalancerbackends.go +++ b/pkg/mcclient/options/loadbalancerbackends.go @@ -1,11 +1,11 @@ package options type LoadbalancerBackendCreateOptions struct { - BackendGroup string `required:true` - Backend string `required:true` - BackendType string `default:guest` - Port *int `required:true` - Weight *int `default:1` + BackendGroup string `required:"true"` + Backend string `required:"true"` + BackendType string `default:"guest"` + Port *int `required:"true"` + Weight *int `default:"1"` } type LoadbalancerBackendListOptions struct { diff --git a/pkg/mcclient/options/loadbalancercertificates.go b/pkg/mcclient/options/loadbalancercertificates.go index 38b19c7d76..70d920b657 100644 --- a/pkg/mcclient/options/loadbalancercertificates.go +++ b/pkg/mcclient/options/loadbalancercertificates.go @@ -36,8 +36,8 @@ func loadbalancerCertificateLoadFiles(cert, pkey string, allowEmpty bool) (*json type LoadbalancerCertificateCreateOptions struct { NAME string - Cert string `required:true json:- help:"path to certificate file"` - Pkey string `required:true json:- help:"path to private key file"` + Cert string `required:"true" json:"-" help:"path to certificate file"` + Pkey string `required:"true" json:"-" help:"path to private key file"` } func (opts *LoadbalancerCertificateCreateOptions) Params() (*jsonutils.JSONDict, error) { @@ -72,8 +72,8 @@ type LoadbalancerCertificateListOptions struct { type LoadbalancerCertificateUpdateOptions struct { ID string - Cert string `json:- help:"path to certificate file"` - Pkey string `json:- help:"path to private key file"` + Cert string `json:"-" help:"path to certificate file"` + Pkey string `json:"-" help:"path to private key file"` } func (opts *LoadbalancerCertificateUpdateOptions) Params() (*jsonutils.JSONDict, error) { diff --git a/pkg/mcclient/options/loadbalancerlistenerrules.go b/pkg/mcclient/options/loadbalancerlistenerrules.go index 7d2e95cb69..d516023c13 100644 --- a/pkg/mcclient/options/loadbalancerlistenerrules.go +++ b/pkg/mcclient/options/loadbalancerlistenerrules.go @@ -2,7 +2,7 @@ package options type LoadbalancerListenerRuleCreateOptions struct { NAME string - Listener string `required:true` + Listener string `required:"true"` BackendGroup string Domain string Path string diff --git a/pkg/mcclient/options/loadbalancerlisteners.go b/pkg/mcclient/options/loadbalancerlisteners.go index e2bfe8f45e..1f5e8ff314 100644 --- a/pkg/mcclient/options/loadbalancerlisteners.go +++ b/pkg/mcclient/options/loadbalancerlisteners.go @@ -3,12 +3,12 @@ package options type LoadbalancerListenerCreateOptions struct { NAME string - Loadbalancer string `required:true` - ListenerType string `required:true choices:tcp|udp|http|https` - ListenerPort *int `required:true` + Loadbalancer string `required:"true"` + ListenerType string `required:"true" choices:"tcp|udp|http|https"` + ListenerPort *int `required:"true"` BackendGroup string - Scheduler string `required:true choices:"rr|wrr|wlc|sch|tch"` + Scheduler string `required:"true" choices:"rr|wrr|wlc|sch|tch"` Bandwidth *int ClientRequestTimeout *int @@ -40,19 +40,19 @@ type LoadbalancerListenerCreateOptions struct { StickySessionCookie string StickySessionCookieTimeout *int - XForwardedFor string `choices:true|false` - Gzip string `choices:true|false` + XForwardedFor string `choices:"true|false"` + Gzip string `choices:"true|false"` Certificate string TLSCipherPolicy string - EnableHttp2 string `choices:true|false` + EnableHttp2 string `choices:"true|false"` } type LoadbalancerListenerListOptions struct { BaseListOptions Loadbalancer string - ListenerType string `choices:tcp|udp|http|https` + ListenerType string `choices:"tcp|udp|http|https"` ListenerPort *int BackendGroup string @@ -88,12 +88,12 @@ type LoadbalancerListenerListOptions struct { StickySessionCookie string StickySessionCookieTimeout *int - XForwardedFor string `choices:true|false` - Gzip string `choices:true|false` + XForwardedFor string `choices:"true|false"` + Gzip string `choices:"true|false"` Certificate string TLSCipherPolicy string - EnableHttp2 string `choices:true|false` + EnableHttp2 string `choices:"true|false"` } type LoadbalancerListenerUpdateOptions struct { @@ -133,12 +133,12 @@ type LoadbalancerListenerUpdateOptions struct { StickySessionCookie string StickySessionCookieTimeout *int - XForwardedFor string `choices:true|false` - Gzip string `choices:true|false` + XForwardedFor string `choices:"true|false"` + Gzip string `choices:"true|false"` Certificate string TLSCipherPolicy string - EnableHttp2 string `choices:true|false` + EnableHttp2 string `choices:"true|false"` } type LoadbalancerListenerGetOptions struct { diff --git a/pkg/util/azure/shell/eip.go b/pkg/util/azure/shell/eip.go index 8c943453f1..30630a49ed 100644 --- a/pkg/util/azure/shell/eip.go +++ b/pkg/util/azure/shell/eip.go @@ -20,7 +20,7 @@ func init() { }) type EipAllocateOptions struct { - NAME string `help: "Eip Name"` + NAME string `help:"Eip Name"` } shellutils.R(&EipAllocateOptions{}, "eip-create", "Allocate an EIP", func(cli *azure.SRegion, args *EipAllocateOptions) error { if eip, err := cli.AllocateEIP(args.NAME); err != nil { From 760862f1a0f8d04f95007b56eb3295a695d9df40 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Sat, 20 Oct 2018 13:07:31 +0000 Subject: [PATCH 2/4] govet: unexported field with tag defined pkg/scheduler/cache/candidate/hosts.go:54: struct field storageTypes has json tag but is not exported --- pkg/scheduler/cache/candidate/hosts.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/scheduler/cache/candidate/hosts.go b/pkg/scheduler/cache/candidate/hosts.go index 7eda20c3ba..f353bd08e6 100644 --- a/pkg/scheduler/cache/candidate/hosts.go +++ b/pkg/scheduler/cache/candidate/hosts.go @@ -51,7 +51,7 @@ type HostDesc struct { // storage Storages []*Storage `json:"storages"` - storageTypes []string `json:"storage_types"` + StorageTypes []string `json:"storage_types"` // IO IOBoundCount int64 `json:"io_bound_count"` @@ -280,7 +280,7 @@ func (h *HostDesc) Get(key string) interface{} { return h.freeStorageSize(true, false) case "StorageTypes": - return h.storageTypes + return h.StorageTypes case "HostStatus": return h.HostStatus @@ -1163,7 +1163,7 @@ func (b *HostBuilder) fillStorages(desc *HostDesc, host *models.Host) error { desc.Storages = rets for storageType := range storageTypeMap { - desc.storageTypes = append(desc.storageTypes, storageType) + desc.StorageTypes = append(desc.StorageTypes, storageType) } return nil From 4f0b4ec7c91d11ceaa6f27b4142061d0cf9926d1 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Sat, 20 Oct 2018 13:51:31 +0000 Subject: [PATCH 3/4] govet: treewide # yunion.io/x/onecloud/pkg/lbagent/utils pkg/lbagent/utils/configdir.go:134: unreachable code # yunion.io/x/onecloud/pkg/mcclient/modules pkg/mcclient/modules/mod_domains.go:243: Sprintf format %s has arg len(result.Data) of wrong type int # yunion.io/x/onecloud/pkg/lbagent/models pkg/lbagent/models/reflect.go:68: Errorf call needs 1 arg but has 2 args # yunion.io/x/onecloud/pkg/cloudcommon/db pkg/cloudcommon/db/db_dispatcher.go:1064: Sprintf call needs 1 arg but has 2 args # yunion.io/x/onecloud/pkg/scheduler/core pkg/scheduler/core/context.go:579: assignment copies lock value to dataItem.Networks: sync.Map contains sync.Mutex # yunion.io/x/onecloud/pkg/scheduler/data_manager pkg/scheduler/data_manager/candidate_manager.go:353: Errorf format %#v reads arg #1, but call has 0 args # yunion.io/x/onecloud/pkg/scheduler/algorithm/predicates/baremetal pkg/scheduler/algorithm/predicates/baremetal/network_predicate.go:145: call of u.SetFiltedData copies lock value: sync.Map contains sync.Mutex # yunion.io/x/onecloud/pkg/scheduler/algorithm/predicates/guest pkg/scheduler/algorithm/predicates/guest/network_predicate.go:207: call of u.SetFiltedData copies lock value: sync.Map contains sync.Mutex # yunion.io/x/onecloud/pkg/cloudcommon/db/lockman pkg/cloudcommon/db/lockman/inmemory_test.go:49: loop variable id captured by func literal # yunion.io/x/onecloud/pkg/util/seclib2 pkg/util/seclib2/seclib.go:56: unreachable code # yunion.io/x/onecloud/cmd/climc/shell cmd/climc/shell/alarmlogs.go:46: result of fmt.Errorf call not used # yunion.io/x/onecloud/pkg/util/aliyun pkg/util/aliyun/disk.go:267: Errorf format %s has arg size of wrong type int64 pkg/util/aliyun/image.go:93: Sprintf format %s reads arg #1, but call has 0 args # yunion.io/x/onecloud/pkg/compute/models pkg/compute/models/cachedimages.go:161: Errorf format %d has arg imgId of wrong type string pkg/compute/models/disks.go:1274: Errorln call has possible formatting directive %s pkg/compute/models/guests.go:1749: Infof format %s has arg self.IsOwner(userCred) of wrong type bool pkg/compute/models/hosts.go:1134: Debugf format %s has arg storage of wrong type *models.SStorage pkg/compute/models/hosts.go:1135: Debugf format %s has arg self of wrong type *models.SHost # yunion.io/x/onecloud/pkg/util/azure pkg/util/azure/instance.go:536: unreachable code pkg/util/azure/network.go:128: unreachable code pkg/util/azure/storage.go:69: unreachable code # yunion.io/x/onecloud/pkg/util/azure/shell pkg/util/azure/shell/disk.go:20: unreachable code pkg/util/azure/shell/network.go:55: unreachable code --- cmd/climc/shell/alarmlogs.go | 5 +---- pkg/cloudcommon/db/db_dispatcher.go | 2 +- pkg/cloudcommon/db/lockman/inmemory_test.go | 2 +- pkg/compute/models/cachedimages.go | 2 +- pkg/compute/models/disks.go | 4 ++-- pkg/compute/models/guests.go | 1 - pkg/compute/models/hosts.go | 2 -- pkg/lbagent/models/reflect.go | 2 +- pkg/lbagent/utils/configdir.go | 2 -- pkg/mcclient/modules/mod_domains.go | 4 ++-- .../algorithm/predicates/baremetal/network_predicate.go | 2 +- .../algorithm/predicates/guest/network_predicate.go | 2 +- pkg/scheduler/core/context.go | 4 ++-- pkg/scheduler/data_manager/candidate_manager.go | 2 +- pkg/util/aliyun/disk.go | 2 +- pkg/util/aliyun/image.go | 2 +- pkg/util/azure/instance.go | 1 - pkg/util/azure/network.go | 1 - pkg/util/azure/shell/disk.go | 3 +-- pkg/util/azure/shell/network.go | 1 - pkg/util/azure/storage.go | 1 - pkg/util/seclib2/seclib.go | 1 - 22 files changed, 17 insertions(+), 31 deletions(-) diff --git a/cmd/climc/shell/alarmlogs.go b/cmd/climc/shell/alarmlogs.go index ef6f68e2c6..cecbabb45f 100644 --- a/cmd/climc/shell/alarmlogs.go +++ b/cmd/climc/shell/alarmlogs.go @@ -41,12 +41,9 @@ func init() { for i := 0; i < len(args.Label); i += 1 { sublabel := args.Label[:i+1] pid, _ := modules.TreeNodes.GetNodeIDByLabels(s, sublabel) - if pid < 0 { - fmt.Errorf("Invalid node data") - return nil + return fmt.Errorf("Invalid node data") } - segs[i] = fmt.Sprintf("%s=%d", names[i], pid) } diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index 49620e8fc8..f9ba0b73b2 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -1061,7 +1061,7 @@ func deleteItem(manager IModelManager, model IModel, ctx context.Context, userCr log.Debugf("deleteItem %s", jsonutils.Marshal(model)) if !model.AllowDeleteItem(ctx, userCred, query, data) { log.Errorf("not allow to delete") - return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s not allow to delete", manager.KeywordPlural(), model.GetId())) + return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s(%s) not allow to delete", manager.KeywordPlural(), model.GetId())) } err := model.ValidateDeleteCondition(ctx) diff --git a/pkg/cloudcommon/db/lockman/inmemory_test.go b/pkg/cloudcommon/db/lockman/inmemory_test.go index ad7b89866a..37714324d0 100644 --- a/pkg/cloudcommon/db/lockman/inmemory_test.go +++ b/pkg/cloudcommon/db/lockman/inmemory_test.go @@ -46,7 +46,7 @@ func TestInMemoryLockManager(t *testing.T) { ctx := context.WithValue(context.Background(), "ID", localId) for i := 0; i < cycle; i += 1 { obj := &FakeObject{Id: objId} - run(t, ctx, obj, localId, time.Duration(id)*time.Second) + run(t, ctx, obj, localId, time.Duration(localId)*time.Second) } wg.Done() }(id) diff --git a/pkg/compute/models/cachedimages.go b/pkg/compute/models/cachedimages.go index 5786fdd4b6..3d49d59128 100644 --- a/pkg/compute/models/cachedimages.go +++ b/pkg/compute/models/cachedimages.go @@ -158,7 +158,7 @@ func (manager *SCachedimageManager) cacheImageInfo(ctx context.Context, userCred return &imageCache, nil } else { - log.Errorf("fail to query image cahe %d", imgId) + log.Errorf("fetching image cache (%s) failed: %s", imgId, err) return nil, err } } else { // update diff --git a/pkg/compute/models/disks.go b/pkg/compute/models/disks.go index b1e418adcf..6eb70bbe11 100644 --- a/pkg/compute/models/disks.go +++ b/pkg/compute/models/disks.go @@ -1270,8 +1270,8 @@ func (manager *SDiskManager) AutoDiskSnapshot(ctx context.Context, userCred mccl continue } guests := disk.GetGuests() - if guests == nil || len(guests) > 1 { - log.Errorln("Disk %s not attach or attached more than one guest", disk.Id) + if len(guests) != 1 { + log.Errorf("Disk %s(%s) is attached to %d guest(s)", disk.Name, disk.Id, len(guests)) continue } if !utils.IsInStringArray(guests[0].Status, []string{VM_RUNNING, VM_READY}) { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 14fc02cda5..a6d1ea497b 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -1746,7 +1746,6 @@ func (self *SGuest) attach2Disk(disk *SDisk, userCred mcclient.TokenCredential, } func (self *SGuest) AllowPerformSaveImage(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { - log.Infof("permission: %s", self.IsOwner(userCred)) return self.IsOwner(userCred) } diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 2f8a81fd4f..f355be26d6 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -1131,8 +1131,6 @@ func (self *SHost) newCloudHostStorage(ctx context.Context, userCred mcclient.To return nil } storage := storageObj.(*SStorage) - log.Debugf("Storage: %s", storage) - log.Debugf("Host: %s", self) err = self.Attach2Storage(ctx, userCred, storage, "") return err } diff --git a/pkg/lbagent/models/reflect.go b/pkg/lbagent/models/reflect.go index e579f7a6da..de4dfaec90 100644 --- a/pkg/lbagent/models/reflect.go +++ b/pkg/lbagent/models/reflect.go @@ -65,7 +65,7 @@ func GetModels(opts *GetModelsOptions) error { } // error if we do not have valid date if max.IsZero() { - return time.Time{}, fmt.Errorf("cannot find next updated_at after '%q'", + return time.Time{}, fmt.Errorf("%s: cannot find next updated_at after '%q'", manKeyPlural, lastUpdatedAt) } diff --git a/pkg/lbagent/utils/configdir.go b/pkg/lbagent/utils/configdir.go index 5e4eb97ca5..39e96efd8f 100644 --- a/pkg/lbagent/utils/configdir.go +++ b/pkg/lbagent/utils/configdir.go @@ -130,8 +130,6 @@ func (m *ConfigDirManager) stagingDir() string { } time.Sleep(time.Millisecond) } - // TODO panic retries - return "" } func DirStagingToFinal(s string) string { diff --git a/pkg/mcclient/modules/mod_domains.go b/pkg/mcclient/modules/mod_domains.go index dc03eb31e8..b2627fb39f 100644 --- a/pkg/mcclient/modules/mod_domains.go +++ b/pkg/mcclient/modules/mod_domains.go @@ -238,9 +238,9 @@ func (this *DomainManager) DoDomainConfigDelete(s *mcclient.ClientSession, param if driver != "ldap" { if result, err := UsersV3.List(s, params); err != nil { log.Errorf("user list got error: %v", err) - return ret, httperrors.NewInternalServerError("Not allow delete: failed to fetch related user list.") + return ret, httperrors.NewInternalServerError("fetching user list failed: %s", err) } else if len(result.Data) > 0 { - return ret, httperrors.NewForbiddenError(fmt.Sprintf("Not allow delete: there still exists %s user related with domain %s.", objId, len(result.Data))) + return ret, httperrors.NewForbiddenError(fmt.Sprintf("cannot delete: there still exists %d user related with domain %s.", len(result.Data), objId)) } } diff --git a/pkg/scheduler/algorithm/predicates/baremetal/network_predicate.go b/pkg/scheduler/algorithm/predicates/baremetal/network_predicate.go index 05f10131ae..c569a8397e 100644 --- a/pkg/scheduler/algorithm/predicates/baremetal/network_predicate.go +++ b/pkg/scheduler/algorithm/predicates/baremetal/network_predicate.go @@ -142,7 +142,7 @@ func (p *NetworkPredicate) Execute(u *core.Unit, c core.Candidater) (bool, []cor } func (p *NetworkPredicate) OnSelect(u *core.Unit, c core.Candidater) bool { - u.SetFiltedData(c.IndexKey(), "networks", p.SelectedNetworks) + u.SetFiltedData(c.IndexKey(), "networks", &p.SelectedNetworks) return true } diff --git a/pkg/scheduler/algorithm/predicates/guest/network_predicate.go b/pkg/scheduler/algorithm/predicates/guest/network_predicate.go index bd6ece34bf..f15dae5fda 100644 --- a/pkg/scheduler/algorithm/predicates/guest/network_predicate.go +++ b/pkg/scheduler/algorithm/predicates/guest/network_predicate.go @@ -204,7 +204,7 @@ func (p *NetworkPredicate) Execute(u *core.Unit, c core.Candidater) (bool, []cor } func (p *NetworkPredicate) OnSelect(u *core.Unit, c core.Candidater) bool { - u.SetFiltedData(c.IndexKey(), "networks", p.SelectedNetworks) + u.SetFiltedData(c.IndexKey(), "networks", &p.SelectedNetworks) return true } diff --git a/pkg/scheduler/core/context.go b/pkg/scheduler/core/context.go index 133fb1e87e..a512b3ee3b 100644 --- a/pkg/scheduler/core/context.go +++ b/pkg/scheduler/core/context.go @@ -190,7 +190,7 @@ type Score struct { } type SchedContextDataItem struct { - Networks sync.Map + Networks *sync.Map Data map[string]interface{} } @@ -576,7 +576,7 @@ func (u *Unit) SetFiltedData(id string, name string, data interface{}) error { } if name == "network" { - dataItem.Networks = data.(sync.Map) + dataItem.Networks = data.(*sync.Map) } else { if m, ok := data.(map[string]interface{}); ok { for key, value := range m { diff --git a/pkg/scheduler/data_manager/candidate_manager.go b/pkg/scheduler/data_manager/candidate_manager.go index 93c5f4efb8..842bb80149 100644 --- a/pkg/scheduler/data_manager/candidate_manager.go +++ b/pkg/scheduler/data_manager/candidate_manager.go @@ -350,7 +350,7 @@ func (cm *CandidateManager) CleanDirtyCandidatesOnce(keys []string) { func ToHostCandidate(c interface{}) (*candidatecache.HostDesc, error) { h, ok := c.(*candidatecache.HostDesc) if !ok { - return nil, fmt.Errorf("%#v can't convert to *candidatecache.HostDesc") + return nil, fmt.Errorf("can't convert %#v to *candidatecache.HostDesc", c) } return h, nil } diff --git a/pkg/util/aliyun/disk.go b/pkg/util/aliyun/disk.go index d71f9f44b1..4b31697c2e 100644 --- a/pkg/util/aliyun/disk.go +++ b/pkg/util/aliyun/disk.go @@ -264,7 +264,7 @@ func (self *SRegion) resizeDisk(diskId string, size int64) error { _, err := self.ecsRequest("ResizeDisk", params) if err != nil { - log.Errorf("ResizeDisk %s to %s GiB fail %s", diskId, size, err) + log.Errorf("resizing disk (%s) to %d GiB failed: %s", diskId, size, err) return err } diff --git a/pkg/util/aliyun/image.go b/pkg/util/aliyun/image.go index 12e2948ec3..3f6947e89e 100644 --- a/pkg/util/aliyun/image.go +++ b/pkg/util/aliyun/image.go @@ -90,7 +90,7 @@ func (self *SImage) Delete() error { } func (self *SImage) GetGlobalId() string { - return fmt.Sprintf("%s-%s") + panic("not implemented") } func (self *SImage) GetIStoragecache() cloudprovider.ICloudStoragecache { diff --git a/pkg/util/azure/instance.go b/pkg/util/azure/instance.go index 36e88bcb4b..e297d8dd7c 100644 --- a/pkg/util/azure/instance.go +++ b/pkg/util/azure/instance.go @@ -533,7 +533,6 @@ func (region *SRegion) DeployVM(instanceId, name, password, publicKey string, de } else { return region.resetPassword(instanceId, instance.Properties.OsProfile.AdminUsername, password) } - return nil } } diff --git a/pkg/util/azure/network.go b/pkg/util/azure/network.go index 734f1bc716..70b3e81a54 100644 --- a/pkg/util/azure/network.go +++ b/pkg/util/azure/network.go @@ -125,7 +125,6 @@ func (self *SNetwork) Refresh() error { } else { return jsonutils.Update(self, new) } - return nil } func (self *SNetwork) GetAllocTimeoutSeconds() int { diff --git a/pkg/util/azure/shell/disk.go b/pkg/util/azure/shell/disk.go index dc87f1560d..64888aaa8b 100644 --- a/pkg/util/azure/shell/disk.go +++ b/pkg/util/azure/shell/disk.go @@ -17,7 +17,6 @@ func init() { printList(disks, len(disks), args.Offset, args.Limit, []string{}) return nil } - return nil }) type DiskCreateOptions struct { @@ -35,8 +34,8 @@ func init() { return err } else { printObject(disk) + return nil } - return nil }) type DiskOptions struct { diff --git a/pkg/util/azure/shell/network.go b/pkg/util/azure/shell/network.go index 89b26a508c..4ecf519f0a 100644 --- a/pkg/util/azure/shell/network.go +++ b/pkg/util/azure/shell/network.go @@ -52,7 +52,6 @@ func init() { printObject(networkInterface) return nil } - return nil }) type NetworkInterfaceCreateOptions struct { diff --git a/pkg/util/azure/storage.go b/pkg/util/azure/storage.go index 07c132a327..f81355ef79 100644 --- a/pkg/util/azure/storage.go +++ b/pkg/util/azure/storage.go @@ -66,7 +66,6 @@ func (self *SStorage) GetIDisk(diskId string) (cloudprovider.ICloudDisk, error) disk.storage = self return disk, nil } - return nil, cloudprovider.ErrNotImplemented } func (self *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) { diff --git a/pkg/util/seclib2/seclib.go b/pkg/util/seclib2/seclib.go index c83a9aea00..6f8c684375 100644 --- a/pkg/util/seclib2/seclib.go +++ b/pkg/util/seclib2/seclib.go @@ -53,7 +53,6 @@ func RandomPassword2(width int) string { return buf.String() } } - return "" } func AnalyzePasswordStrenth(passwd string) PasswordStrength { From 1ffc05de81ec7b9d77eb913a890b1c5efa40ebca Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Sat, 20 Oct 2018 14:00:51 +0000 Subject: [PATCH 4/4] Makefile: add vet target --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 20cb204796..14b769d1c5 100644 --- a/Makefile +++ b/Makefile @@ -51,12 +51,14 @@ build: prepare_dir fmt done -test: prepare_dir +test: @for PKG in $$( $(PKGS) | grep "$(filter-out $@,$(MAKECMDGOALS))" ); do \ echo $$PKG; \ $(GO_TEST) $$PKG; \ done +vet: + go vet ./... cmd/%: prepare_dir fmt $(GO_BUILD) -o $(BIN_DIR)/$(shell basename $@) $(REPO_PREFIX)/$@