Skip to content

Commit

Permalink
[K10-1827] Enable SoftLayer file provider (#4647)
Browse files Browse the repository at this point in the history
* [K10-1827] Enable SoftLayer file provider

adding a constant for enable SL_file att name
enabling File and Disabling Block

* Adding test for file provider

* Fixing null-pointer

* Sorting tests

* Adding SoftlayerFile type

* Hardening IBM client and tests

* Support for SL file and tests

* Disbaling annoinyng ibm cli update

* find and replace fail

* Update go/src/kio/blockstorage/ibm/client_test.go

Co-Authored-By: depohmel <ilya@kasten.io>

* Update go/src/kio/blockstorage/ibm/client_test.go

Co-Authored-By: depohmel <ilya@kasten.io>

* Renaming TestSuite
  • Loading branch information
Ilya Kislenko committed Jul 8, 2019
1 parent 92fa1f7 commit be5b48a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 22 deletions.
2 changes: 2 additions & 0 deletions pkg/blockstorage/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
TypeCeph Type = "Ceph"
// TypeSoftlayerBlock captures enum value "SoftlayerBlock"
TypeSoftlayerBlock Type = "SoftlayerBlock"
// TypeSoftlayerFile captures enum value "SoftlayerFile"
TypeSoftlayerFile Type = "SoftlayerFile"
// TypeEFS captures enum value "EFS"
TypeEFS Type = "EFS"
)
5 changes: 5 additions & 0 deletions pkg/blockstorage/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func (*getter) Get(storageType blockstorage.Type, config map[string]string) (blo
return ibm.NewProvider(context.TODO(), config)
case blockstorage.TypeGPD:
return gcepd.NewProvider(config)
case blockstorage.TypeSoftlayerFile:
config[ibm.SoftlayerFileAttName] = "true"
return ibm.NewProvider(context.TODO(), config)
default:
return nil, errors.Errorf("Unsupported storage type %v", storageType)
}
Expand All @@ -47,6 +50,8 @@ func Supported(st blockstorage.Type) bool {
return true
case blockstorage.TypeGPD:
return true
case blockstorage.TypeSoftlayerFile:
return true
default:
return false
}
Expand Down
18 changes: 14 additions & 4 deletions pkg/blockstorage/ibm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,28 @@ func newClient(ctx context.Context, args map[string]string) (*client, error) {
defer zaplog.Sync() // nolint: errcheck

cfg, err := findDefaultConfig(ctx, args, zaplog)
if err != nil {
return nil, errors.Wrap(err, "Failed to get IBM client config")
if err != nil || cfg.Softlayer == nil {
return nil, errors.New("Failed to get IBM client config")
}

provName := softLayerCfg.SoftlayerBlockProviderName
if enableFile, ok := args[SoftlayerFileAttName]; ok && enableFile == "true" {
cfg.Softlayer.SoftlayerFileEnabled = true
cfg.Softlayer.SoftlayerBlockEnabled = false
provName = softLayerCfg.SoftlayerFileProviderName
} else {
cfg.Softlayer.SoftlayerFileEnabled = false
cfg.Softlayer.SoftlayerBlockEnabled = true
}

provReg, err := ibmprovutils.InitProviders(cfg, zaplog)
if err != nil {
return nil, errors.Wrap(err, "Failed to Init IBM providers")
}

session, _, err := ibmprovutils.OpenProviderSession(cfg, provReg, cfg.Softlayer.SoftlayerBlockProviderName, zaplog)
session, _, err := ibmprovutils.OpenProviderSession(cfg, provReg, provName, zaplog)
if err != nil {
return nil, errors.Wrapf(err, "Failed to create Open session for IBM provider. %s", cfg.Softlayer.SoftlayerBlockProviderName)
return nil, errors.Wrapf(err, "Failed to create Open session for IBM provider. %s", provName)
}

return &client{
Expand Down
30 changes: 28 additions & 2 deletions pkg/blockstorage/ibm/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const (
// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) }

type ClientSuite struct{}
type ClientSuite struct {
apiKey string
}

var _ = Suite(&ClientSuite{})

Expand All @@ -33,9 +35,15 @@ func (s *ClientSuite) SetUpSuite(c *C) {
if os.Getenv(IBMApiKeyEnv) == "" {
c.Skip(IBMApiKeyEnv + " envionment variable not set")
}
s.apiKey = os.Getenv(IBMApiKeyEnv)
}

func (s *ClientSuite) TearDownSuite(c *C) {
os.Setenv(IBMApiKeyEnv, s.apiKey)
os.Unsetenv(LibDefCfgEnv)
}

func (s *ClientSuite) TestClient(c *C) {
func (s *ClientSuite) TestAPIClient(c *C) {
var apiKey string
if apiK, ok := os.LookupEnv(IBMApiKeyEnv); ok {
apiKey = apiK
Expand All @@ -52,6 +60,24 @@ func (s *ClientSuite) TestClient(c *C) {
c.Assert(err, IsNil)
}

func (s *ClientSuite) TestIBMClientSoftlayerFile(c *C) {
var apiKey string
if apiK, ok := os.LookupEnv(IBMApiKeyEnv); ok {
apiKey = apiK
} else {
c.Skip(fmt.Sprintf("Could not find env var %s with API key", IBMApiKeyEnv))
}
ibmCli, err := newClient(context.Background(), map[string]string{APIKeyArgName: apiKey, SoftlayerFileAttName: "true"})
defer ibmCli.Service.Close()
c.Assert(err, IsNil)
c.Assert(ibmCli.Service, NotNil)
c.Assert(*ibmCli, FitsTypeOf, client{})
c.Assert(ibmCli.SLCfg.SoftlayerBlockEnabled, Equals, false)
c.Assert(ibmCli.SLCfg.SoftlayerFileEnabled, Equals, true)
_, err = ibmCli.Service.SnapshotsList()
c.Assert(err, IsNil)
}

func (s *ClientSuite) TestDefaultLibConfig(c *C) {
if tomlPath, ok := os.LookupEnv(workAroundEnv); ok {
err := os.Setenv(LibDefCfgEnv, filepath.Dir(tomlPath))
Expand Down
2 changes: 2 additions & 0 deletions pkg/blockstorage/ibm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ const (
LunIDAttName = "LunID"
// TargetIPsAttName attribute name for Volume.TargetIPAddresses
TargetIPsAttName = "TargetIPAddresses"
// SoftlayerFileAttName attribute name to enable softlayer file support
SoftlayerFileAttName = "SoftlayerFileEnabled"
)
5 changes: 4 additions & 1 deletion pkg/blockstorage/ibm/ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const (
)

func (s *ibmCloud) Type() blockstorage.Type {
if s.cli.SLCfg.SoftlayerFileEnabled {
return blockstorage.TypeSoftlayerFile
}
return blockstorage.TypeSoftlayerBlock
}

Expand Down Expand Up @@ -100,7 +103,7 @@ func (s *ibmCloud) volumeParse(ctx context.Context, vol *ibmprov.Volume) (*block
attribs[SnapshotSpaceAttName] = strconv.Itoa(*vol.SnapshotSpace)
}

if vol.LunID == "" {
if vol.LunID == "" && string(vol.Provider) == s.cli.SLCfg.SoftlayerBlockProviderName {
return nil, errors.New("LunID is missing from Volume info")
}
attribs[LunIDAttName] = vol.LunID
Expand Down
38 changes: 23 additions & 15 deletions pkg/blockstorage/ibm/ibmcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@ const (
testTagValue = "unittest"
)

type TestIBMCloudBlock struct {
provider blockstorage.Provider
cli *client
testVol *blockstorage.Volume
type TestIBMCloud struct {
provider blockstorage.Provider
cli *client
testVol *blockstorage.Volume
softlayerFile bool
volAtts map[string]string
}

//These are not executed as part of Pipeline, but usefull for development
var _ = Suite(&TestIBMCloudBlock{})
var softlayerVolAtts = map[string]string{
ProviderTypeAttName: string(ibmprov.VolumeProviderType("endurance")),
TierAttName: "2",
}

var _ = Suite(&TestIBMCloud{softlayerFile: false, volAtts: softlayerVolAtts})

// Commented out untill IBM fixes SL on their side.
// var _ = Suite(&TestIBMCloud{softlayerFile: true, volAtts: softlayerVolAtts})

func (s *TestIBMCloudBlock) SetUpSuite(c *C) {
func (s *TestIBMCloud) SetUpSuite(c *C) {
c.Skip("IBM tests are too flaky to run in CI")
var apiKey string
if apiK, ok := os.LookupEnv(IBMApiKeyEnv); ok {
Expand All @@ -38,6 +47,9 @@ func (s *TestIBMCloudBlock) SetUpSuite(c *C) {
c.Skip(fmt.Sprintf("Could not find env var %s with API key", IBMApiKeyEnv))
}
args := map[string]string{APIKeyArgName: apiKey}
if s.softlayerFile {
args[SoftlayerFileAttName] = "true"
}
var err error
ctx := context.Background()
s.provider, err = NewProvider(ctx, args)
Expand All @@ -47,13 +59,9 @@ func (s *TestIBMCloudBlock) SetUpSuite(c *C) {
c.Assert(err, IsNil)
c.Assert(s.cli, NotNil)
tmpVol := &blockstorage.Volume{
Attributes: make(map[string]string),
Attributes: s.volAtts,
}

tmpVol.VolumeType = string(s.cli.Service.Type())
provT := "endurance"
tmpVol.Attributes[ProviderTypeAttName] = string(ibmprov.VolumeProviderType(provT))
tmpVol.Attributes[TierAttName] = "2"
tmpVol.Size = 20
tmpVol.Tags = []*blockstorage.KeyValue{
{Key: testTagKey, Value: testTagValue},
Expand All @@ -65,7 +73,7 @@ func (s *TestIBMCloudBlock) SetUpSuite(c *C) {
c.Assert(s.testVol.ID, NotNil)
}

func (s TestIBMCloudBlock) TearDownSuite(c *C) {
func (s TestIBMCloud) TearDownSuite(c *C) {
c.Skip("IBM tests are too flaky to run in CI")
// Check whether or not the test volume was initialized
if _, ok := os.LookupEnv(IBMApiKeyEnv); !ok {
Expand All @@ -78,7 +86,7 @@ func (s TestIBMCloudBlock) TearDownSuite(c *C) {
c.Assert(err, IsNil)
}

func (s TestIBMCloudBlock) TestSnapshotCreate(c *C) {
func (s TestIBMCloud) TestSnapshotCreate(c *C) {
bsVol, err := s.provider.VolumeGet(context.Background(), s.testVol.ID, "")
c.Assert(err, IsNil)
c.Assert(bsVol.ID, Equals, s.testVol.ID)
Expand All @@ -102,7 +110,7 @@ func (s TestIBMCloudBlock) TestSnapshotCreate(c *C) {

}

func (s TestIBMCloudBlock) TestVolRestore(c *C) {
func (s TestIBMCloud) TestVolRestore(c *C) {
bsVol, err := s.provider.VolumeGet(context.Background(), s.testVol.ID, "")
c.Assert(err, IsNil)
snapTTags := map[string]string{"ibmblock_unit_test_snap": fmt.Sprintf("test-snap-%d", time.Now().Unix())}
Expand Down

0 comments on commit be5b48a

Please sign in to comment.