From f31201b80ce4b556139ddc8c864dac5147e9cfc4 Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Tue, 5 Dec 2023 17:45:31 -0600 Subject: [PATCH] #822 temp fix for an API bug in file|block volume-list when requesting a datacenter --- plugin/managers/storage.go | 8 +++ plugin/managers/storage_test.go | 63 ++++++++++++++++++- .../getNasNetworkStorage.json | 46 ++++++++++++++ .../getNasNetworkStorage.json | 46 ++++++++++++++ 4 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 plugin/testfixtures/SoftLayer_Account/getNasNetworkStorage.json create mode 100644 plugin/testfixtures/SoftLayer_Network_Storage/getNasNetworkStorage.json diff --git a/plugin/managers/storage.go b/plugin/managers/storage.go index 29a50c0c..0d0816cb 100644 --- a/plugin/managers/storage.go +++ b/plugin/managers/storage.go @@ -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++ @@ -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++ diff --git a/plugin/managers/storage_test.go b/plugin/managers/storage_test.go index d942fc4d..eb3d43f9 100644 --- a/plugin/managers/storage_test.go +++ b/plugin/managers/storage_test.go @@ -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() { @@ -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()})), + })) }) }) }) diff --git a/plugin/testfixtures/SoftLayer_Account/getNasNetworkStorage.json b/plugin/testfixtures/SoftLayer_Account/getNasNetworkStorage.json new file mode 100644 index 00000000..3efb7cd3 --- /dev/null +++ b/plugin/testfixtures/SoftLayer_Account/getNasNetworkStorage.json @@ -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" + } +] \ No newline at end of file diff --git a/plugin/testfixtures/SoftLayer_Network_Storage/getNasNetworkStorage.json b/plugin/testfixtures/SoftLayer_Network_Storage/getNasNetworkStorage.json new file mode 100644 index 00000000..e58b7fdb --- /dev/null +++ b/plugin/testfixtures/SoftLayer_Network_Storage/getNasNetworkStorage.json @@ -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" + } +] \ No newline at end of file