Skip to content

Commit

Permalink
Merge pull request #823 from SoftLayer/issues822
Browse files Browse the repository at this point in the history
#822 temp fix for an API bug in file|block volume-list
  • Loading branch information
CHRISTOPHER GALLO authored and GitHub Enterprise committed Dec 6, 2023
2 parents 3c9c75e + f31201b commit 752e510
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 2 deletions.
8 changes: 8 additions & 0 deletions plugin/managers/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ func (s storageManager) ListVolumes(volumeType string, datacenter string, userna

i := 0
resourceList := []datatypes.Network_Storage{}
// Shortcut the pagination because filtering by DC is bugged, remove this when CORE-1820 is released.
if (datacenter != "") {
return s.AccountService.Mask(mask).Filter(filters.Build()).GetIscsiNetworkStorage()
}
for {
resp, err := s.AccountService.Mask(mask).Filter(filters.Build()).Limit(metadata.LIMIT).Offset(i * metadata.LIMIT).GetIscsiNetworkStorage()
i++
Expand Down Expand Up @@ -384,6 +388,10 @@ func (s storageManager) ListVolumes(volumeType string, datacenter string, userna

i := 0
var resourceList []datatypes.Network_Storage
// Shortcut the pagination because filtering by DC is bugged, remove this when CORE-1820 is released.
if (datacenter != "") {
return s.AccountService.Mask(mask).Filter(filters.Build()).GetNasNetworkStorage()
}
for {
resp, err := s.AccountService.Mask(mask).Filter(filters.Build()).Limit(metadata.LIMIT).Offset(i * metadata.LIMIT).GetNasNetworkStorage()
i++
Expand Down
63 changes: 61 additions & 2 deletions plugin/managers/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ package managers_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
"github.com/softlayer/softlayer-go/session"
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
"fmt"
)

var _ = Describe("StorageManager", func() {
var (
fakeSLSession *session.Session
fakeHandler *testhelpers.FakeTransportHandler
StorageManager managers.StorageManager
)
BeforeEach(func() {
fakeSLSession = testhelpers.NewFakeSoftlayerSession(nil)
fakeHandler = testhelpers.GetSessionHandler(fakeSLSession)
StorageManager = managers.NewStorageManager(fakeSLSession)
})
AfterEach(func() {
fakeHandler.ClearApiCallLogs()
fakeHandler.ClearErrors()
})

Describe("GetBlockVolumeAccessList", func() {
Context("GetBlockVolumeAccessList given a volume id", func() {
Expand Down Expand Up @@ -99,14 +107,65 @@ var _ = Describe("StorageManager", func() {

Describe("ListBlockVolumes", func() {
Context("ListBlockVolumes under current account", func() {
It("Return no error", func() {
It("Block Happy Path", func() {
volumes, err := StorageManager.ListVolumes("block", "", "", "", "", 0, "")
Expect(err).ToNot(HaveOccurred())
Expect(len(volumes) > 0).To(BeTrue())
Expect(len(volumes)).Should(BeNumerically(">", 0))
for _, volume := range volumes {
Expect(volume.Id).NotTo(Equal(nil))
Expect(*volume.StorageType.KeyName).To(Equal("ENDURANCE_BLOCK_STORAGE"))
}
apiCalls := fakeHandler.ApiCallLogs
Expect(len(apiCalls)).To(Equal(1))
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
"Service": Equal("SoftLayer_Account"),
"Method": Equal("getIscsiNetworkStorage"),
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Limit": PointTo(Equal(50))})),
}))
})
It("File Happy Path", func() {
volumes, err := StorageManager.ListVolumes("file", "", "", "", "", 0, "")
Expect(err).ToNot(HaveOccurred())
Expect(len(volumes)).Should(BeNumerically(">", 0))
for _, volume := range volumes {
Expect(volume.Id).NotTo(Equal(nil))
Expect(*volume.StorageType.KeyName).To(Equal("ENDURANCE_FILE_STORAGE"))
}
apiCalls := fakeHandler.ApiCallLogs
Expect(len(apiCalls)).To(Equal(1))
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
"Service": Equal("SoftLayer_Account"),
"Method": Equal("getNasNetworkStorage"),
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Limit": PointTo(Equal(50))})),
}))
})
})
Context("Issue822 - Special case for ListVolumes with a datacenter filter", func() {
It("Block: No Result Limit", func() {
_, err := StorageManager.ListVolumes("block", "dal10", "", "", "", 0, "")
Expect(err).ToNot(HaveOccurred())
apiCalls := fakeHandler.ApiCallLogs
Expect(len(apiCalls)).To(Equal(1))
// See https://pkg.go.dev/github.com/onsi/gomega/gstruct for this stuff
fmt.Printf("APICALL: %+v", apiCalls[0].Options)
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
"Service": Equal("SoftLayer_Account"),
"Method": Equal("getIscsiNetworkStorage"),
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Limit": BeNil()})),
}))
})
It("File: No Result Limit", func() {
_, err := StorageManager.ListVolumes("file", "dal10", "", "", "", 0, "")
Expect(err).ToNot(HaveOccurred())
apiCalls := fakeHandler.ApiCallLogs
Expect(len(apiCalls)).To(Equal(1))
// See https://pkg.go.dev/github.com/onsi/gomega/gstruct for this stuff
fmt.Printf("APICALL: %+v", apiCalls[0].Options)
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
"Service": Equal("SoftLayer_Account"),
"Method": Equal("getNasNetworkStorage"),
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Limit": BeNil()})),
}))
})
})
})
Expand Down
46 changes: 46 additions & 0 deletions plugin/testfixtures/SoftLayer_Account/getNasNetworkStorage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"activeTransactionCount": 0,
"bytesUsed": "14381056",
"capacityGb": 20,
"id": 4917309,
"notes": "a random notes",
"replicationPartnerCount": 1,
"serviceResource": {
"backendIpAddress": "nfsdal0901a-fz.service.softlayer.com",
"datacenter": {
"name": "dal09"
},
"id": 41528,
"name": "Storage Type 01M Aggregate staasdal0901i_ssd01",
"type": {
"type": "NETAPP_STOR_AGGR"
}
},
"serviceResourceBackendIpAddress": "nfsdal0901a-fz.service.softlayer.com",
"storageType": {
"keyName": "ENDURANCE_FILE_STORAGE"
},
"username": "SL012345_1"
},
{
"activeTransactionCount": 0,
"bytesUsed": "7458816",
"capacityGb": 20,
"id": 21021427,
"replicationPartnerCount": 0,
"serviceResource": {
"backendIpAddress": "nfswdc0401a-fz.service.softlayer.com",
"id": 5373,
"name": "Storage Type 01 Aggregate staaswdc0401_hp01",
"type": {
"type": "NETAPP_STOR_AGGR"
}
},
"serviceResourceBackendIpAddress": "nfswdc0401a-fz.service.softlayer.com",
"storageType": {
"keyName": "ENDURANCE_FILE_STORAGE"
},
"username": "SL12345_1_REP_1"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"activeTransactionCount": 0,
"bytesUsed": "14381056",
"capacityGb": 20,
"id": 4917309,
"notes": "a random notes",
"replicationPartnerCount": 1,
"serviceResource": {
"backendIpAddress": "nfsdal0901a-fz.service.softlayer.com",
"datacenter": {
"name": "dal09"
},
"id": 41528,
"name": "Storage Type 01M Aggregate staasdal0901i_ssd01",
"type": {
"type": "NETAPP_STOR_AGGR"
}
},
"serviceResourceBackendIpAddress": "nfsdal0901a-fz.service.softlayer.com",
"storageType": {
"keyName": "ENDURANCE_FILE_STORAGE"
},
"username": "SL012345_1"
},
{
"activeTransactionCount": 0,
"bytesUsed": "7458816",
"capacityGb": 20,
"id": 21021427,
"replicationPartnerCount": 0,
"serviceResource": {
"backendIpAddress": "nfswdc0401a-fz.service.softlayer.com",
"id": 5373,
"name": "Storage Type 01 Aggregate staaswdc0401_hp01",
"type": {
"type": "NETAPP_STOR_AGGR"
}
},
"serviceResourceBackendIpAddress": "nfswdc0401a-fz.service.softlayer.com",
"storageType": {
"keyName": "ENDURANCE_FILE_STORAGE_REPLICANT"
},
"username": "SL12345_1_REP_1"
}
]

0 comments on commit 752e510

Please sign in to comment.