Merge pull request #332 in YUNIONIO/onecloud from ~ZHOUYOUSONG/onecloud:bugfix/yousong-govet-onecloud to release/2.3.0

* commit '1ffc05de81ec7b9d77eb913a890b1c5efa40ebca':
  Makefile: add vet target
  govet: treewide
  govet: unexported field with tag defined
  govet: treewide struct tag fix
This commit is contained in:
周有松
2018-10-22 20:35:58 +08:00
37 changed files with 85 additions and 97 deletions
+3 -1
View File
@@ -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)/$@
+1 -4
View File
@@ -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)
}
+2 -2
View File
@@ -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()
+4 -4
View File
@@ -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
+2 -2
View File
@@ -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
+5 -5
View File
@@ -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
+2 -2
View File
@@ -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"`
}
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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}) {
-1
View File
@@ -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)
}
-2
View File
@@ -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
}
@@ -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) {
+1 -1
View File
@@ -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)
}
+9 -9
View File
@@ -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 {
-2
View File
@@ -130,8 +130,6 @@ func (m *ConfigDirManager) stagingDir() string {
}
time.Sleep(time.Millisecond)
}
// TODO panic retries
return ""
}
func DirStagingToFinal(s string) string {
+2 -2
View File
@@ -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))
}
}
+5 -5
View File
@@ -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) {
+5 -5
View File
@@ -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 {
@@ -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) {
@@ -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
+14 -14
View File
@@ -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 {
@@ -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
}
@@ -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
}
+3 -3
View File
@@ -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
+2 -2
View File
@@ -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 {
@@ -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
}
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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 {
-1
View File
@@ -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
}
}
-1
View File
@@ -125,7 +125,6 @@ func (self *SNetwork) Refresh() error {
} else {
return jsonutils.Update(self, new)
}
return nil
}
func (self *SNetwork) GetAllocTimeoutSeconds() int {
+1 -2
View File
@@ -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 {
+1 -1
View File
@@ -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 {
-1
View File
@@ -52,7 +52,6 @@ func init() {
printObject(networkInterface)
return nil
}
return nil
})
type NetworkInterfaceCreateOptions struct {
-1
View File
@@ -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) {
-1
View File
@@ -53,7 +53,6 @@ func RandomPassword2(width int) string {
return buf.String()
}
}
return ""
}
func AnalyzePasswordStrenth(passwd string) PasswordStrength {