mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #901 in YUNIONIO/onecloud from ~QIUJIAN/onecloud:hotfix/qj-aliyun-delete-fail to release/2.4.0
* commit '766039194898267d32322aca50213cc06daa82d6': return nil immediately if error is nil 修正:1. server detach disk 缺少parentTaskId 2. aliyun 关机后立即 detachDisk 会出现InvalidOperation.Conflict的错误
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package cloudprovider
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func IsError(err error, errs []string) bool {
|
||||
for i := range errs {
|
||||
if strings.Index(err.Error(), errs[i]) >= 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func RetryOnError(tryFunc func() error, errs []string, maxTries int) error {
|
||||
tried := 0
|
||||
for tried < maxTries {
|
||||
err := tryFunc()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if err != nil && !IsError(err, errs) {
|
||||
return err
|
||||
}
|
||||
tried += 1
|
||||
time.Sleep(10 * time.Duration(tried) * time.Second)
|
||||
}
|
||||
return ErrTimeout
|
||||
}
|
||||
@@ -1213,7 +1213,7 @@ func (self *SGuest) StartGuestDetachdiskTask(ctx context.Context, userCred mccli
|
||||
})
|
||||
}
|
||||
disk.SetStatus(userCred, DISK_DETACHING, "")
|
||||
return self.GetDriver().StartGuestDetachdiskTask(ctx, userCred, self, taskData, "")
|
||||
return self.GetDriver().StartGuestDetachdiskTask(ctx, userCred, self, taskData, parentTaskId)
|
||||
}
|
||||
|
||||
func (self *SGuest) AllowPerformDetachIsolatedDevice(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
|
||||
@@ -153,8 +153,9 @@ func (self *GuestDeleteTask) OnSyncConfigComplete(ctx context.Context, obj db.IS
|
||||
}
|
||||
|
||||
func (self *GuestDeleteTask) OnSyncConfigCompleteFailed(ctx context.Context, obj db.IStandaloneModel, err jsonutils.JSONObject) {
|
||||
guest := obj.(*models.SGuest)
|
||||
self.OnFailed(ctx, guest, err)
|
||||
// guest := obj.(*models.SGuest)
|
||||
// self.OnFailed(ctx, guest, err)
|
||||
self.OnSyncConfigComplete(ctx, obj, err) // ignore sync config failed error
|
||||
}
|
||||
|
||||
func (self *GuestDeleteTask) OnGuestDeleteFailed(ctx context.Context, obj db.IStandaloneModel, err jsonutils.JSONObject) {
|
||||
|
||||
@@ -82,7 +82,7 @@ func _jsonRequest(client *sdk.Client, domain string, version string, apiName str
|
||||
|
||||
resp, err := processCommonRequest(client, req)
|
||||
if err != nil {
|
||||
log.Errorf("request error %s", err)
|
||||
log.Errorf("request error %s with params %s", err, params)
|
||||
return nil, err
|
||||
}
|
||||
body, err := jsonutils.Parse(resp.GetHttpContentBytes())
|
||||
|
||||
@@ -512,7 +512,14 @@ func (self *SInstance) AttachDisk(ctx context.Context, diskId string) error {
|
||||
}
|
||||
|
||||
func (self *SInstance) DetachDisk(ctx context.Context, diskId string) error {
|
||||
return self.host.zone.region.DetachDisk(self.InstanceId, diskId)
|
||||
return cloudprovider.RetryOnError(
|
||||
func() error {
|
||||
return self.host.zone.region.DetachDisk(self.InstanceId, diskId)
|
||||
},
|
||||
[]string{
|
||||
`"Code":"InvalidOperation.Conflict"`,
|
||||
},
|
||||
4)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetInstance(instanceId string) (*SInstance, error) {
|
||||
|
||||
Reference in New Issue
Block a user