Skip to content

Commit 752e510

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #823 from SoftLayer/issues822
#822 temp fix for an API bug in file|block volume-list
2 parents 3c9c75e + f31201b commit 752e510

File tree

4 files changed

+161
-2
lines changed

4 files changed

+161
-2
lines changed

plugin/managers/storage.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ func (s storageManager) ListVolumes(volumeType string, datacenter string, userna
343343

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

385389
i := 0
386390
var resourceList []datatypes.Network_Storage
391+
// Shortcut the pagination because filtering by DC is bugged, remove this when CORE-1820 is released.
392+
if (datacenter != "") {
393+
return s.AccountService.Mask(mask).Filter(filters.Build()).GetNasNetworkStorage()
394+
}
387395
for {
388396
resp, err := s.AccountService.Mask(mask).Filter(filters.Build()).Limit(metadata.LIMIT).Offset(i * metadata.LIMIT).GetNasNetworkStorage()
389397
i++

plugin/managers/storage_test.go

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@ package managers_test
33
import (
44
. "github.com/onsi/ginkgo"
55
. "github.com/onsi/gomega"
6+
. "github.com/onsi/gomega/gstruct"
67
"github.com/softlayer/softlayer-go/session"
78
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
89
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
10+
"fmt"
911
)
1012

1113
var _ = Describe("StorageManager", func() {
1214
var (
1315
fakeSLSession *session.Session
16+
fakeHandler *testhelpers.FakeTransportHandler
1417
StorageManager managers.StorageManager
1518
)
1619
BeforeEach(func() {
1720
fakeSLSession = testhelpers.NewFakeSoftlayerSession(nil)
21+
fakeHandler = testhelpers.GetSessionHandler(fakeSLSession)
1822
StorageManager = managers.NewStorageManager(fakeSLSession)
1923
})
24+
AfterEach(func() {
25+
fakeHandler.ClearApiCallLogs()
26+
fakeHandler.ClearErrors()
27+
})
2028

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

100108
Describe("ListBlockVolumes", func() {
101109
Context("ListBlockVolumes under current account", func() {
102-
It("Return no error", func() {
110+
It("Block Happy Path", func() {
103111
volumes, err := StorageManager.ListVolumes("block", "", "", "", "", 0, "")
104112
Expect(err).ToNot(HaveOccurred())
105-
Expect(len(volumes) > 0).To(BeTrue())
113+
Expect(len(volumes)).Should(BeNumerically(">", 0))
106114
for _, volume := range volumes {
107115
Expect(volume.Id).NotTo(Equal(nil))
108116
Expect(*volume.StorageType.KeyName).To(Equal("ENDURANCE_BLOCK_STORAGE"))
109117
}
118+
apiCalls := fakeHandler.ApiCallLogs
119+
Expect(len(apiCalls)).To(Equal(1))
120+
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
121+
"Service": Equal("SoftLayer_Account"),
122+
"Method": Equal("getIscsiNetworkStorage"),
123+
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Limit": PointTo(Equal(50))})),
124+
}))
125+
})
126+
It("File Happy Path", func() {
127+
volumes, err := StorageManager.ListVolumes("file", "", "", "", "", 0, "")
128+
Expect(err).ToNot(HaveOccurred())
129+
Expect(len(volumes)).Should(BeNumerically(">", 0))
130+
for _, volume := range volumes {
131+
Expect(volume.Id).NotTo(Equal(nil))
132+
Expect(*volume.StorageType.KeyName).To(Equal("ENDURANCE_FILE_STORAGE"))
133+
}
134+
apiCalls := fakeHandler.ApiCallLogs
135+
Expect(len(apiCalls)).To(Equal(1))
136+
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
137+
"Service": Equal("SoftLayer_Account"),
138+
"Method": Equal("getNasNetworkStorage"),
139+
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Limit": PointTo(Equal(50))})),
140+
}))
141+
})
142+
})
143+
Context("Issue822 - Special case for ListVolumes with a datacenter filter", func() {
144+
It("Block: No Result Limit", func() {
145+
_, err := StorageManager.ListVolumes("block", "dal10", "", "", "", 0, "")
146+
Expect(err).ToNot(HaveOccurred())
147+
apiCalls := fakeHandler.ApiCallLogs
148+
Expect(len(apiCalls)).To(Equal(1))
149+
// See https://pkg.go.dev/github.com/onsi/gomega/gstruct for this stuff
150+
fmt.Printf("APICALL: %+v", apiCalls[0].Options)
151+
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
152+
"Service": Equal("SoftLayer_Account"),
153+
"Method": Equal("getIscsiNetworkStorage"),
154+
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Limit": BeNil()})),
155+
}))
156+
})
157+
It("File: No Result Limit", func() {
158+
_, err := StorageManager.ListVolumes("file", "dal10", "", "", "", 0, "")
159+
Expect(err).ToNot(HaveOccurred())
160+
apiCalls := fakeHandler.ApiCallLogs
161+
Expect(len(apiCalls)).To(Equal(1))
162+
// See https://pkg.go.dev/github.com/onsi/gomega/gstruct for this stuff
163+
fmt.Printf("APICALL: %+v", apiCalls[0].Options)
164+
Expect(apiCalls[0]).To(MatchFields(IgnoreExtras, Fields{
165+
"Service": Equal("SoftLayer_Account"),
166+
"Method": Equal("getNasNetworkStorage"),
167+
"Options": PointTo(MatchFields(IgnoreExtras, Fields{"Limit": BeNil()})),
168+
}))
110169
})
111170
})
112171
})
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"activeTransactionCount": 0,
4+
"bytesUsed": "14381056",
5+
"capacityGb": 20,
6+
"id": 4917309,
7+
"notes": "a random notes",
8+
"replicationPartnerCount": 1,
9+
"serviceResource": {
10+
"backendIpAddress": "nfsdal0901a-fz.service.softlayer.com",
11+
"datacenter": {
12+
"name": "dal09"
13+
},
14+
"id": 41528,
15+
"name": "Storage Type 01M Aggregate staasdal0901i_ssd01",
16+
"type": {
17+
"type": "NETAPP_STOR_AGGR"
18+
}
19+
},
20+
"serviceResourceBackendIpAddress": "nfsdal0901a-fz.service.softlayer.com",
21+
"storageType": {
22+
"keyName": "ENDURANCE_FILE_STORAGE"
23+
},
24+
"username": "SL012345_1"
25+
},
26+
{
27+
"activeTransactionCount": 0,
28+
"bytesUsed": "7458816",
29+
"capacityGb": 20,
30+
"id": 21021427,
31+
"replicationPartnerCount": 0,
32+
"serviceResource": {
33+
"backendIpAddress": "nfswdc0401a-fz.service.softlayer.com",
34+
"id": 5373,
35+
"name": "Storage Type 01 Aggregate staaswdc0401_hp01",
36+
"type": {
37+
"type": "NETAPP_STOR_AGGR"
38+
}
39+
},
40+
"serviceResourceBackendIpAddress": "nfswdc0401a-fz.service.softlayer.com",
41+
"storageType": {
42+
"keyName": "ENDURANCE_FILE_STORAGE"
43+
},
44+
"username": "SL12345_1_REP_1"
45+
}
46+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"activeTransactionCount": 0,
4+
"bytesUsed": "14381056",
5+
"capacityGb": 20,
6+
"id": 4917309,
7+
"notes": "a random notes",
8+
"replicationPartnerCount": 1,
9+
"serviceResource": {
10+
"backendIpAddress": "nfsdal0901a-fz.service.softlayer.com",
11+
"datacenter": {
12+
"name": "dal09"
13+
},
14+
"id": 41528,
15+
"name": "Storage Type 01M Aggregate staasdal0901i_ssd01",
16+
"type": {
17+
"type": "NETAPP_STOR_AGGR"
18+
}
19+
},
20+
"serviceResourceBackendIpAddress": "nfsdal0901a-fz.service.softlayer.com",
21+
"storageType": {
22+
"keyName": "ENDURANCE_FILE_STORAGE"
23+
},
24+
"username": "SL012345_1"
25+
},
26+
{
27+
"activeTransactionCount": 0,
28+
"bytesUsed": "7458816",
29+
"capacityGb": 20,
30+
"id": 21021427,
31+
"replicationPartnerCount": 0,
32+
"serviceResource": {
33+
"backendIpAddress": "nfswdc0401a-fz.service.softlayer.com",
34+
"id": 5373,
35+
"name": "Storage Type 01 Aggregate staaswdc0401_hp01",
36+
"type": {
37+
"type": "NETAPP_STOR_AGGR"
38+
}
39+
},
40+
"serviceResourceBackendIpAddress": "nfswdc0401a-fz.service.softlayer.com",
41+
"storageType": {
42+
"keyName": "ENDURANCE_FILE_STORAGE_REPLICANT"
43+
},
44+
"username": "SL12345_1_REP_1"
45+
}
46+
]

0 commit comments

Comments
 (0)