Skip to content

Commit

Permalink
Merge 73c226f into b5bddd1
Browse files Browse the repository at this point in the history
  • Loading branch information
yixuan0825 committed Nov 26, 2018
2 parents b5bddd1 + 73c226f commit 40eea5e
Show file tree
Hide file tree
Showing 19 changed files with 361 additions and 153 deletions.
24 changes: 13 additions & 11 deletions fakes/fake_block_device_mounter_utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions fakes/fake_block_device_utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 9 additions & 25 deletions fakes/fake_scbe_rest_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions fakes/fake_simple_rest_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions local/scbe/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,8 @@ type ScbeResponseHost struct {
StorageCluster string `json:"storage_cluster"`
PhysicalHost int `json:"physical_host"`
}

type ScbeVolumeMapInfo struct {
Host string
LunNumber int
}
27 changes: 15 additions & 12 deletions local/scbe/scbe.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package scbe
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"sync"

"github.com/IBM/ubiquity/database"
"github.com/IBM/ubiquity/resources"
"github.com/IBM/ubiquity/utils"
"github.com/IBM/ubiquity/utils/logs"
"strconv"
"strings"
"sync"
)

type scbeLocalClient struct {
Expand All @@ -47,7 +48,7 @@ const (
ComposeVolumeName = volumeNamePrefix + "%s_%s" // e.g u_instance1_volName
MaxVolumeNameLength = 63 // IBM block storage max volume name cannot exceed this length

GetVolumeConfigExtraParams = 2 // number of extra params added to the VolumeConfig beyond the scbe volume struct
GetVolumeConfigExtraParams = 3 // number of extra params added to the VolumeConfig beyond the scbe volume struct
)

var (
Expand Down Expand Up @@ -301,14 +302,14 @@ func (s *scbeLocalClient) RemoveVolume(removeVolumeRequest resources.RemoveVolum
}
}

hostAttach, err := scbeRestClient.GetVolMapping(existingVolume.WWN)
volMapInfo, err := scbeRestClient.GetVolMapping(existingVolume.WWN)
// get vol mapping will not return an error but an empty host in case the vol does no exist so no idempotent issue here.
if err != nil {
return s.logger.ErrorRet(err, "scbeRestClient.GetVolMapping failed")
}

if hostAttach != EmptyHost {
return s.logger.ErrorRet(&CannotDeleteVolWhichAttachedToHostError{removeVolumeRequest.Name, hostAttach}, "failed")
if volMapInfo.Host != EmptyHost {
return s.logger.ErrorRet(&CannotDeleteVolWhichAttachedToHostError{removeVolumeRequest.Name, volMapInfo.Host}, "failed")
}

err = scbeRestClient.DeleteVolume(existingVolume.WWN)
Expand Down Expand Up @@ -405,12 +406,13 @@ func (s *scbeLocalClient) GetVolumeConfig(getVolumeConfigRequest resources.GetVo
volConfig[resources.OptionNameForVolumeFsType] = scbeVolume.FSType

// The ubiquity remote will use this extra info to determine is-attached
hostAttach, err := scbeRestClient.GetVolMapping(scbeVolume.WWN)
volMapInfo, err := scbeRestClient.GetVolMapping(scbeVolume.WWN)
if err != nil {
return nil, s.logger.ErrorRet(err, "scbeRestClient.GetVolMapping failed")
}

volConfig[resources.ScbeKeyVolAttachToHost] = hostAttach
volConfig[resources.ScbeKeyVolAttachToHost] = volMapInfo.Host
volConfig[resources.ScbeKeyVolAttachLunNumToHost] = volMapInfo.LunNumber

return volConfig, nil
}
Expand Down Expand Up @@ -438,11 +440,11 @@ func (s *scbeLocalClient) Attach(attachRequest resources.AttachRequest) (string,
return "", s.logger.ErrorRet(err, "dataModel.GetVolume failed")
}

hostAttach, err := scbeRestClient.GetVolMapping(existingVolume.WWN)
volMapInfo, err := scbeRestClient.GetVolMapping(existingVolume.WWN)
if err != nil {
return "", s.logger.ErrorRet(err, "scbeRestClient.GetVolMapping failed")
}

hostAttach := volMapInfo.Host
if hostAttach == attachRequest.Host {
// if already map to the given host then just ignore and succeed to attach
s.logger.Info("Volume already attached, skip backend attach", logs.Args{{"volume", attachRequest.Name}, {"host", attachRequest.Host}})
Expand Down Expand Up @@ -480,11 +482,12 @@ func (s *scbeLocalClient) Detach(detachRequest resources.DetachRequest) (err err
return s.logger.ErrorRet(err, "dataModel.GetVolume failed")
}

hostAttach, err := scbeRestClient.GetVolMapping(existingVolume.WWN)
volMapInfo, err := scbeRestClient.GetVolMapping(existingVolume.WWN)
if err != nil {
return s.logger.ErrorRet(err, "scbeRestClient.GetVolMapping failed")
}

hostAttach := volMapInfo.Host
if hostAttach == EmptyHost {
s.logger.Warning("Volume is already detached from host.", logs.Args{{"volume", existingVolume.WWN}})
return nil
Expand Down

0 comments on commit 40eea5e

Please sign in to comment.