Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor the lvm driver, fixed some bugs #616

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions contrib/drivers/huawei/dorado/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package dorado
import (
"crypto/md5"
"encoding/hex"
"fmt"
"regexp"
"strconv"
"strings"
"time"

log "github.com/golang/glog"
. "github.com/opensds/opensds/contrib/drivers/utils/config"
Expand Down Expand Up @@ -74,24 +72,3 @@ func Sector2Gb(sec string) int64 {
func Gb2Sector(gb int64) int64 {
return gb * UnitGi / 512
}

func WaitForCondition(f func() (bool, error), interval, timeout time.Duration) error {
endAt := time.Now().Add(timeout)
time.Sleep(time.Duration(interval))
for {
startTime := time.Now()
ok, err := f()
if err != nil {
return err
}
if ok {
return nil
}
if time.Now().After(endAt) {
break
}
elapsed := time.Now().Sub(startTime)
time.Sleep(interval - elapsed)
}
return fmt.Errorf("wait for condition timeout")
}
10 changes: 6 additions & 4 deletions contrib/drivers/huawei/dorado/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"math/rand"
"testing"
"time"

"github.com/opensds/opensds/pkg/utils"
)

func TestEncodeName(t *testing.T) {
Expand Down Expand Up @@ -96,7 +98,7 @@ func TestTruncateDescription(t *testing.T) {

func TestWaitForCondition(t *testing.T) {
var count = 0
err := WaitForCondition(func() (bool, error) {
err := utils.WaitForCondition(func() (bool, error) {
count++
time.Sleep(2 * time.Microsecond)
if count >= 5 {
Expand All @@ -109,7 +111,7 @@ func TestWaitForCondition(t *testing.T) {
}

count = 0
err = WaitForCondition(func() (bool, error) {
err = utils.WaitForCondition(func() (bool, error) {
count++
time.Sleep(1 * time.Millisecond)
if count >= 5 {
Expand All @@ -121,15 +123,15 @@ func TestWaitForCondition(t *testing.T) {
t.Errorf("Test WaitForCondition failed, %v", err)
}

err = WaitForCondition(func() (bool, error) {
err = utils.WaitForCondition(func() (bool, error) {
return true, fmt.Errorf("test error....")
}, 4*time.Millisecond, 100*time.Millisecond)
if err == nil {
t.Errorf("Test WaitForCondition failed, %v", err)
}

count = 0
err = WaitForCondition(func() (bool, error) {
err = utils.WaitForCondition(func() (bool, error) {
count++
time.Sleep(2 * time.Millisecond)
if count >= 5 {
Expand Down
5 changes: 3 additions & 2 deletions contrib/drivers/huawei/dorado/dorado.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
. "github.com/opensds/opensds/contrib/drivers/utils/config"
pb "github.com/opensds/opensds/pkg/dock/proto"
"github.com/opensds/opensds/pkg/model"
"github.com/opensds/opensds/pkg/utils"
"github.com/opensds/opensds/pkg/utils/config"
"github.com/satori/go.uuid"
)
Expand Down Expand Up @@ -82,7 +83,7 @@ func (d *Driver) createVolumeFromSnapshot(opt *pb.CreateVolumeOpts) (*model.Volu
}

log.Infof("Create Volume from snapshot, source_lun_id : %s , target_lun_id : %s", snapshot.Id, lun.Id)
err = WaitForCondition(func() (bool, error) {
err = utils.WaitForCondition(func() (bool, error) {
getVolumeResult, getVolumeErr := d.client.GetVolume(lun.Id)
if nil == getVolumeErr {
if getVolumeResult.HealthStatus == StatusHealth && getVolumeResult.RunningStatus == StatusVolumeReady {
Expand Down Expand Up @@ -138,7 +139,7 @@ func (d *Driver) copyVolume(opt *pb.CreateVolumeOpts, srcid, tgtid string) error
return err
}

err = WaitForCondition(func() (bool, error) {
err = utils.WaitForCondition(func() (bool, error) {
deleteLunCopyErr := d.client.DeleteLunCopy(luncopyid)
if nil == deleteLunCopyErr {
return true, nil
Expand Down
10 changes: 5 additions & 5 deletions contrib/drivers/huawei/dorado/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (r *ReplicaPairMgr) WaitVolumeOnline(client *DoradoClient, lun *Lun, interv
timeout = DefaultReplicaWaitTimeout
}

return WaitForCondition(func() (bool, error) {
return utils.WaitForCondition(func() (bool, error) {
lunInfo, err := client.GetVolume(lun.Id)
if err != nil {
log.Errorf("Get lun failed,%v ", err)
Expand Down Expand Up @@ -424,7 +424,7 @@ func (r *ReplicaCommonDriver) Switch(replicaId string) error {

interval := DefaultReplicaWaitInterval
timeout := DefaultReplicaWaitTimeout
return WaitForCondition(func() (bool, error) {
return utils.WaitForCondition(func() (bool, error) {
replicaPair, err := r.op.GetReplicationInfo(replicaId)
if err != nil {
return false, nil
Expand Down Expand Up @@ -476,7 +476,7 @@ func (r *ReplicaCommonDriver) WaitReplicaReady(replicaId string) error {
}
interval := DefaultReplicaWaitInterval
timeout := DefaultReplicaWaitTimeout
return WaitForCondition(func() (bool, error) {
return utils.WaitForCondition(func() (bool, error) {
replicaPair, err := r.op.GetReplicationInfo(replicaId)
if err != nil {
return false, nil
Expand All @@ -495,7 +495,7 @@ func (r *ReplicaCommonDriver) WaitReplicaReady(replicaId string) error {
func (r *ReplicaCommonDriver) WaitSecondAccess(replicaId string, accessMode string) {
interval := DefaultReplicaWaitInterval
timeout := DefaultReplicaWaitTimeout
WaitForCondition(func() (bool, error) {
utils.WaitForCondition(func() (bool, error) {
replicaPair, err := r.op.GetReplicationInfo(replicaId)
if err != nil {
return false, nil
Expand All @@ -507,7 +507,7 @@ func (r *ReplicaCommonDriver) WaitSecondAccess(replicaId string, accessMode stri
func (r *ReplicaCommonDriver) WaitExpectState(replicaId string, runningStatus, healthStatus []string) error {
interval := DefaultReplicaWaitInterval
timeout := DefaultReplicaWaitTimeout
return WaitForCondition(func() (bool, error) {
return utils.WaitForCondition(func() (bool, error) {
replicaPair, err := r.op.GetReplicationInfo(replicaId)
if err != nil {
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion contrib/drivers/huawei/fusionstorage/fusionstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (d *Driver) CreateSnapshot(opt *pb.CreateVolumeSnapshotOpts) (*VolumeSnapsh
return nil, err
}

log.Errorf("Create snapshot %s (%s) success.", opt.GetName(), opt.GetId())
log.Infof("Create snapshot %s (%s) success.", opt.GetName(), opt.GetId())
return &VolumeSnapshotSpec{
BaseModel: &BaseModel{
Id: opt.GetId(),
Expand Down
Loading