diff --git a/pkg/multicloud/aliyun/aliyun.go b/pkg/multicloud/aliyun/aliyun.go index 346127b538..135a88037a 100644 --- a/pkg/multicloud/aliyun/aliyun.go +++ b/pkg/multicloud/aliyun/aliyun.go @@ -429,7 +429,7 @@ func (self *SAliyunClient) GetIHostById(id string) (cloudprovider.ICloudHost, er ihost, err := self.iregions[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -441,7 +441,7 @@ func (self *SAliyunClient) GetIVpcById(id string) (cloudprovider.ICloudVpc, erro ihost, err := self.iregions[i].GetIVpcById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -453,7 +453,7 @@ func (self *SAliyunClient) GetIStorageById(id string) (cloudprovider.ICloudStora ihost, err := self.iregions[i].GetIStorageById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/aliyun/provider/provider.go b/pkg/multicloud/aliyun/provider/provider.go index 18dc2955ef..82ff079b73 100644 --- a/pkg/multicloud/aliyun/provider/provider.go +++ b/pkg/multicloud/aliyun/provider/provider.go @@ -352,7 +352,7 @@ func (self *SAliyunProvider) GetICloudDnsZoneById(id string) (cloudprovider.IClo if err == nil { return privateIzone, nil } else { - if err != cloudprovider.ErrNotFound { + if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -361,7 +361,7 @@ func (self *SAliyunProvider) GetICloudDnsZoneById(id string) (cloudprovider.IClo if err == nil { return publicIzone, nil } else { - if err != cloudprovider.ErrNotFound { + if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/aliyun/ramimage.go b/pkg/multicloud/aliyun/ramimage.go index 7515110b20..18cbcb6cae 100644 --- a/pkg/multicloud/aliyun/ramimage.go +++ b/pkg/multicloud/aliyun/ramimage.go @@ -15,6 +15,8 @@ package aliyun import ( + "yunion.io/x/pkg/errors" + "yunion.io/x/onecloud/pkg/cloudprovider" ) @@ -55,7 +57,7 @@ const ( func (self *SAliyunClient) EnableImageImport() error { _, err := self.GetRole(AliyunECSImageImportRole) if err != nil { - if err != cloudprovider.ErrNotFound { + if errors.Cause(err) != cloudprovider.ErrNotFound { return err } _, err = self.CreateRole(AliyunECSImageImportRole, diff --git a/pkg/multicloud/aliyun/region.go b/pkg/multicloud/aliyun/region.go index 43a1dcb830..31516c0503 100644 --- a/pkg/multicloud/aliyun/region.go +++ b/pkg/multicloud/aliyun/region.go @@ -638,7 +638,7 @@ func (self *SRegion) GetIHostById(id string) (cloudprovider.ICloudHost, error) { ihost, err := izones[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -654,7 +654,7 @@ func (self *SRegion) GetIStorageById(id string) (cloudprovider.ICloudStorage, er istore, err := izones[i].GetIStorageById(id) if err == nil { return istore, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/aliyun/storagecache.go b/pkg/multicloud/aliyun/storagecache.go index 6a378ed656..521c4f4c66 100644 --- a/pkg/multicloud/aliyun/storagecache.go +++ b/pkg/multicloud/aliyun/storagecache.go @@ -157,15 +157,13 @@ func (self *SStoragecache) uploadImage(ctx context.Context, userCred mcclient.To bucketName := strings.ToLower(fmt.Sprintf("imgcache-%s-%s", self.region.GetId(), image.ImageId)) exist, err := self.region.IBucketExist(bucketName) if err != nil { - log.Errorf("IsBucketExist err %s", err) - return "", err + return "", errors.Wrapf(err, "IBucketExist(%s)", bucketName) } if !exist { log.Debugf("Bucket %s not exists, to create ...", bucketName) err = self.region.CreateIBucket(bucketName, "", "") if err != nil { - log.Errorf("Create bucket error %s", err) - return "", err + return "", errors.Wrapf(err, "CreateIBucket %s", bucketName) } } else { log.Debugf("Bucket %s exists", bucketName) @@ -175,15 +173,13 @@ func (self *SStoragecache) uploadImage(ctx context.Context, userCred mcclient.To bucket, err := self.region.GetIBucketByName(bucketName) if err != nil { - log.Errorf("Bucket error %s %s", bucketName, err) - return "", err + return "", errors.Wrapf(err, "GetIBucketByName %s", bucketName) } log.Debugf("To upload image to bucket %s ...", bucketName) err = cloudprovider.UploadObject(context.Background(), bucket, image.ImageId, 0, reader, sizeByte, "", "", nil, false) // err = bucket.PutObject(image.ImageId, reader) if err != nil { - log.Errorf("PutObject error %s %s", image.ImageId, err) - return "", err + return "", errors.Wrapf(err, "UploadObject %s", image.ImageId) } defer bucket.DeleteObject(context.Background(), image.ImageId) // remove object @@ -214,22 +210,19 @@ func (self *SStoragecache) uploadImage(ctx context.Context, userCred mcclient.To // ensure privileges err = self.region.GetClient().EnableImageImport() if err != nil { - log.Errorf("fail to enable import privileges: %s", err) - return "", err + return "", errors.Wrapf(err, "EnableImageImport") } task, err := self.region.ImportImage(imageName, image.OsArch, image.OsType, image.OsDistribution, bucketName, image.ImageId) if err != nil { - log.Errorf("ImportImage error %s %s %s", image.ImageId, bucketName, err) - return "", err + return "", errors.Wrapf(err, "ImportImage %s %s", image.ImageId, bucketName) } // timeout: 1hour = 3600 seconds err = self.region.waitTaskStatus(ImportImageTask, task.TaskId, TaskStatusFinished, 15*time.Second, 3600*time.Second) if err != nil { - log.Errorf("waitTaskStatus %s", err) - return task.ImageId, err + return task.ImageId, errors.Wrapf(err, "waitTaskStatus") } return task.ImageId, nil diff --git a/pkg/multicloud/aws/disk.go b/pkg/multicloud/aws/disk.go index 92bd67c2df..ada1598716 100644 --- a/pkg/multicloud/aws/disk.go +++ b/pkg/multicloud/aws/disk.go @@ -25,6 +25,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/pkg/errors" "yunion.io/x/onecloud/pkg/apis/billing" api "yunion.io/x/onecloud/pkg/apis/compute" @@ -188,7 +189,7 @@ func (self *SDisk) GetMountpoint() string { } func (self *SDisk) Delete(ctx context.Context) error { - if _, err := self.storage.zone.region.GetDisk(self.DiskId); err == cloudprovider.ErrNotFound { + if _, err := self.storage.zone.region.GetDisk(self.DiskId); err != nil && errors.Cause(err) == cloudprovider.ErrNotFound { log.Errorf("Failed to find disk %s when delete", self.DiskId) return nil } diff --git a/pkg/multicloud/ctyun/region.go b/pkg/multicloud/ctyun/region.go index 69c38423a9..1da74c1583 100644 --- a/pkg/multicloud/ctyun/region.go +++ b/pkg/multicloud/ctyun/region.go @@ -380,7 +380,7 @@ func (self *SRegion) GetIHostById(id string) (cloudprovider.ICloudHost, error) { ihost, err := izones[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -413,7 +413,7 @@ func (self *SRegion) GetIStorageById(id string) (cloudprovider.ICloudStorage, er istore, err := izones[i].GetIStorageById(id) if err == nil { return istore, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/esxi/fakeregion.go b/pkg/multicloud/esxi/fakeregion.go index fa32ab2760..ecaaca8394 100644 --- a/pkg/multicloud/esxi/fakeregion.go +++ b/pkg/multicloud/esxi/fakeregion.go @@ -15,6 +15,7 @@ package esxi import ( + "yunion.io/x/pkg/errors" "yunion.io/x/pkg/utils" api "yunion.io/x/onecloud/pkg/apis/compute" @@ -53,7 +54,7 @@ func (cli *SESXiClient) GetIVMById(id string) (cloudprovider.ICloudVM, error) { } for _, host := range hosts { vm, err := host.GetIVMById(id) - if err != cloudprovider.ErrNotFound { + if errors.Cause(err) != cloudprovider.ErrNotFound { return vm, err } } @@ -67,7 +68,7 @@ func (self *SESXiClient) GetIDiskById(id string) (cloudprovider.ICloudDisk, erro } for _, storage := range storages { disk, err := storage.GetIDiskById(id) - if err != cloudprovider.ErrNotFound { + if errors.Cause(err) != cloudprovider.ErrNotFound { return disk, err } } diff --git a/pkg/multicloud/esxi/host.go b/pkg/multicloud/esxi/host.go index 1c080c92ef..33769c774f 100644 --- a/pkg/multicloud/esxi/host.go +++ b/pkg/multicloud/esxi/host.go @@ -1260,7 +1260,7 @@ func (host *SHost) newLocalStorageCache() (*SDatastoreImageCache, error) { } _, err := ds.CheckFile(ctx, IMAGE_CACHE_DIR_NAME) if err != nil { - if err != cloudprovider.ErrNotFound { + if errors.Cause(err) != cloudprovider.ErrNotFound { // return nil, err if len(errmsg) > 0 { errmsg += "," diff --git a/pkg/multicloud/google/region.go b/pkg/multicloud/google/region.go index e384f1f436..5e0c6bbbd5 100644 --- a/pkg/multicloud/google/region.go +++ b/pkg/multicloud/google/region.go @@ -247,7 +247,7 @@ func (region *SRegion) GetIHostById(id string) (cloudprovider.ICloudHost, error) ihost, err := izones[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/huawei/huawei.go b/pkg/multicloud/huawei/huawei.go index 74453960c0..1d7fe36ea5 100644 --- a/pkg/multicloud/huawei/huawei.go +++ b/pkg/multicloud/huawei/huawei.go @@ -384,7 +384,7 @@ func (self *SHuaweiClient) GetIHostById(id string) (cloudprovider.ICloudHost, er ihost, err := self.iregions[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -396,7 +396,7 @@ func (self *SHuaweiClient) GetIVpcById(id string) (cloudprovider.ICloudVpc, erro ivpc, err := self.iregions[i].GetIVpcById(id) if err == nil { return ivpc, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -408,7 +408,7 @@ func (self *SHuaweiClient) GetIStorageById(id string) (cloudprovider.ICloudStora istorage, err := self.iregions[i].GetIStorageById(id) if err == nil { return istorage, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/huawei/region.go b/pkg/multicloud/huawei/region.go index 38227d1447..713bcce40f 100644 --- a/pkg/multicloud/huawei/region.go +++ b/pkg/multicloud/huawei/region.go @@ -644,7 +644,7 @@ func (self *SRegion) GetIHostById(id string) (cloudprovider.ICloudHost, error) { ihost, err := izones[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -677,7 +677,7 @@ func (self *SRegion) GetIStorageById(id string) (cloudprovider.ICloudStorage, er istore, err := izones[i].GetIStorageById(id) if err == nil { return istore, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/openstack/region.go b/pkg/multicloud/openstack/region.go index 195f3dc385..1a783ce5f6 100644 --- a/pkg/multicloud/openstack/region.go +++ b/pkg/multicloud/openstack/region.go @@ -121,7 +121,7 @@ func (region *SRegion) GetIHostById(id string) (cloudprovider.ICloudHost, error) ihost, err := izones[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/qcloud/qcloud.go b/pkg/multicloud/qcloud/qcloud.go index 9daa88e988..5676f193f2 100644 --- a/pkg/multicloud/qcloud/qcloud.go +++ b/pkg/multicloud/qcloud/qcloud.go @@ -883,7 +883,7 @@ func (client *SQcloudClient) GetIHostById(id string) (cloudprovider.ICloudHost, ihost, err := client.iregions[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -895,7 +895,7 @@ func (client *SQcloudClient) GetIVpcById(id string) (cloudprovider.ICloudVpc, er ihost, err := client.iregions[i].GetIVpcById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -907,7 +907,7 @@ func (client *SQcloudClient) GetIStorageById(id string) (cloudprovider.ICloudSto ihost, err := client.iregions[i].GetIStorageById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/qcloud/region.go b/pkg/multicloud/qcloud/region.go index c2b8090488..a67afd0008 100644 --- a/pkg/multicloud/qcloud/region.go +++ b/pkg/multicloud/qcloud/region.go @@ -322,7 +322,7 @@ func (self *SRegion) GetIHostById(id string) (cloudprovider.ICloudHost, error) { ihost, err := izones[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -338,7 +338,7 @@ func (self *SRegion) GetIStorageById(id string) (cloudprovider.ICloudStorage, er istore, err := izones[i].GetIStorageById(id) if err == nil { return istore, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/ucloud/region.go b/pkg/multicloud/ucloud/region.go index 32e470fe03..d6eaa97fbb 100644 --- a/pkg/multicloud/ucloud/region.go +++ b/pkg/multicloud/ucloud/region.go @@ -310,7 +310,7 @@ func (self *SRegion) GetIHostById(id string) (cloudprovider.ICloudHost, error) { ihost, err := izones[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -343,7 +343,7 @@ func (self *SRegion) GetIStorageById(id string) (cloudprovider.ICloudStorage, er istore, err := izones[i].GetIStorageById(id) if err == nil { return istore, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } diff --git a/pkg/multicloud/ucloud/ucloud.go b/pkg/multicloud/ucloud/ucloud.go index b3a07968c4..d2c1cb1e0c 100644 --- a/pkg/multicloud/ucloud/ucloud.go +++ b/pkg/multicloud/ucloud/ucloud.go @@ -337,7 +337,7 @@ func (self *SUcloudClient) GetIHostById(id string) (cloudprovider.ICloudHost, er ihost, err := self.iregions[i].GetIHostById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -349,7 +349,7 @@ func (self *SUcloudClient) GetIVpcById(id string) (cloudprovider.ICloudVpc, erro ihost, err := self.iregions[i].GetIVpcById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } } @@ -361,7 +361,7 @@ func (self *SUcloudClient) GetIStorageById(id string) (cloudprovider.ICloudStora ihost, err := self.iregions[i].GetIStorageById(id) if err == nil { return ihost, nil - } else if err != cloudprovider.ErrNotFound { + } else if errors.Cause(err) != cloudprovider.ErrNotFound { return nil, err } }