Skip to content

Commit a08f43b

Browse files
cloud-iaas-fabric-automation cloud-iaas-fabric-automationGitHub Enterprise
authored andcommitted
Merge pull request #935 from SoftLayer/issues934
Fixed nil pointer issue in 'vs storage'.
2 parents a0d2d91 + c556209 commit a08f43b

File tree

7 files changed

+310
-32
lines changed

7 files changed

+310
-32
lines changed

plugin/commands/virtual/storage.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,16 @@ func (cmd *StorageCommand) Run(args []string) error {
8585

8686
tableIscsi := cmd.UI.Table([]string{T("\nLUN name"), T("capacity"), T("Target address"), T("Location"), T("Notes")})
8787
for _, iscsi := range iscsiStorageData {
88+
notes := ""
89+
if iscsi.Notes != nil {
90+
notes = *iscsi.Notes
91+
}
8892
tableIscsi.Add(
8993
*iscsi.Username,
9094
utils.FormatIntPointer(iscsi.CapacityGb),
9195
*iscsi.ServiceResourceBackendIpAddress,
9296
*iscsi.AllowedVirtualGuests[0].Datacenter.LongName,
93-
*iscsi.Notes)
97+
notes)
9498
}
9599
utils.PrintTable(cmd.UI, tableIscsi, outputFormat)
96100

@@ -107,12 +111,16 @@ func (cmd *StorageCommand) Run(args []string) error {
107111
cmd.UI.Print("\nFile Storage Details")
108112
tableNas := cmd.UI.Table([]string{T("Volume name"), T("capacity"), T("Hostname"), T("Location"), T("Notes")})
109113
for _, nas := range nasStorageData {
114+
notes := ""
115+
if nas.Notes != nil {
116+
notes = *nas.Notes
117+
}
110118
tableNas.Add(
111119
*nas.Username,
112120
utils.FormatIntPointer(nas.CapacityGb),
113121
*nas.ServiceResourceBackendIpAddress,
114122
*nas.AllowedVirtualGuests[0].Datacenter.LongName,
115-
*nas.Notes)
123+
notes)
116124
}
117125
utils.PrintTable(cmd.UI, tableNas, outputFormat)
118126

plugin/commands/virtual/storage_test.go

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,82 +22,75 @@ var _ = Describe("virtual storage", func() {
2222
fakeSession *session.Session
2323
slCommand *metadata.SoftlayerCommand
2424
fakeVSManager *testhelpers.FakeVirtualServerManager
25+
fakeHandler *testhelpers.FakeTransportHandler
2526
)
2627
BeforeEach(func() {
2728
fakeUI = terminal.NewFakeUI()
28-
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
29+
fakeSession = testhelpers.NewFakeSoftlayerSession(nil)
30+
fakeHandler = testhelpers.GetSessionHandler(fakeSession)
2931
fakeVSManager = new(testhelpers.FakeVirtualServerManager)
3032
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
3133
cliCommand = virtual.NewStorageCommand(slCommand)
3234
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
33-
cliCommand.VirtualServerManager = fakeVSManager
35+
36+
})
37+
38+
AfterEach(func() {
39+
// Clear API call logs and any errors that might have been set after every test
40+
fakeHandler.ClearApiCallLogs()
41+
fakeHandler.ClearErrors()
3442
})
3543

3644
Describe("virtual storage", func() {
37-
Context("virtual storage without id", func() {
45+
BeforeEach(func() {
46+
cliCommand.VirtualServerManager = fakeVSManager
47+
})
48+
Context("User Input Checks", func() {
3849
It("return error", func() {
3950
err := testhelpers.RunCobraCommand(cliCommand.Command)
4051
Expect(err).To(HaveOccurred())
4152
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
4253
})
43-
})
44-
45-
Context("virtual storage with wrong id", func() {
4654
It("return error", func() {
4755
err := testhelpers.RunCobraCommand(cliCommand.Command, "abcd")
4856
Expect(err).To(HaveOccurred())
4957
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Virtual server ID'. It must be a positive integer."))
5058
})
5159
})
5260

53-
Context("virtual storage ISCSI with server fails", func() {
54-
BeforeEach(func() {
61+
Context("API Errors", func() {
62+
It("Failed to get ISCSI Storage", func() {
5563
fakeVSManager.GetStorageDetailsReturns([]datatypes.Network_Storage{}, errors.New("Internal server error"))
56-
})
57-
It("return error", func() {
5864
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
5965
Expect(err).To(HaveOccurred())
6066
Expect(err.Error()).To(ContainSubstring("Failed to get iscsi storage detail for the virtual server 1234."))
6167
Expect(err.Error()).To(ContainSubstring("Internal server error"))
6268
})
63-
})
64-
65-
Context("virtual storage credentials with server fails", func() {
66-
BeforeEach(func() {
69+
It("virtual storage credentials with server fails", func() {
6770
fakeVSManager.GetStorageCredentialsReturns(datatypes.Network_Storage_Allowed_Host{}, errors.New("Internal server error"))
68-
})
69-
It("return error", func() {
7071
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
7172
Expect(err).To(HaveOccurred())
7273
Expect(err.Error()).To(ContainSubstring("Failed to get the storage credential detail for the virtual server 1234."))
7374
Expect(err.Error()).To(ContainSubstring("Internal server error"))
7475
})
75-
})
76-
77-
Context("virtual portable storage with server fails", func() {
78-
BeforeEach(func() {
76+
It("virtual portable storage with server fails", func() {
7977
fakeVSManager.GetPortableStorageReturns([]datatypes.Virtual_Disk_Image{}, errors.New("Internal server error"))
80-
})
81-
It("return error", func() {
8278
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
8379
Expect(err).To(HaveOccurred())
8480
Expect(err.Error()).To(ContainSubstring("Failed to get the portable storage detail for the virtual server 1234."))
8581
Expect(err.Error()).To(ContainSubstring("Internal server error"))
8682
})
87-
})
88-
89-
Context("virtual local disks with server fails", func() {
90-
BeforeEach(func() {
83+
It("virtual local disks with server fails", func() {
9184
fakeVSManager.GetLocalDisksReturns([]datatypes.Virtual_Guest_Block_Device{}, errors.New("Internal server error"))
92-
})
93-
It("return error", func() {
9485
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
9586
Expect(err).To(HaveOccurred())
9687
Expect(err.Error()).To(ContainSubstring("Failed to get the local disks detail for the virtual server 1234."))
9788
Expect(err.Error()).To(ContainSubstring("Internal server error"))
9889
})
90+
9991
})
10092

93+
10194
Context("hardware iscsi", func() {
10295
BeforeEach(func() {
10396
fakeVSManager.GetStorageDetailsReturns([]datatypes.Network_Storage{
@@ -196,4 +189,14 @@ var _ = Describe("virtual storage", func() {
196189
})
197190
})
198191
})
192+
Describe("virtual storage with fixtures", func() {
193+
Context("Issues943", func() {
194+
It("Successful", func() {
195+
err := testhelpers.RunCobraCommand(cliCommand.Command, "934")
196+
Expect(err).NotTo(HaveOccurred())
197+
Expect(fakeUI.Outputs()).To(ContainSubstring("Disk"))
198+
})
199+
})
200+
})
201+
199202
})
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[
2+
{
3+
"capacity": 10,
4+
"createDate": "2025-11-01T03:15:06-07:00",
5+
"description": "poc-classic-to-vpc - Disk 3",
6+
"id": 22222,
7+
"modifyDate": "2025-11-01T05:34:26-07:00",
8+
"name": "poc-classic-to-vpc - Disk 3",
9+
"parentId": null,
10+
"storageRepositoryId": 333333,
11+
"typeId": 241,
12+
"units": "GB",
13+
"uuid": "123123123-c79f-42a6-82dc-b894474bf77c",
14+
"billingItem": {
15+
"allowCancellationFlag": 1,
16+
"associatedBillingItemId": "1259099304",
17+
"cancellationDate": null,
18+
"categoryCode": "guest_disk1",
19+
"createDate": "2025-11-01T03:15:02-07:00",
20+
"cycleStartDate": null,
21+
"description": "10 GB (SAN)",
22+
"id": 44444,
23+
"lastBillDate": "2025-11-01T03:15:02-07:00",
24+
"modifyDate": null,
25+
"nextBillDate": "2025-11-30T00:00:00-06:00",
26+
"orderItemId": 5555,
27+
"packageId": 198,
28+
"parentId": null,
29+
"recurringMonths": null,
30+
"serviceProviderId": null,
31+
"location": {
32+
"id": 1854895,
33+
"longName": "Dallas 13",
34+
"name": "dal13",
35+
"statusId": 2,
36+
"locationStatus": {
37+
"id": 2,
38+
"status": "Active"
39+
}
40+
},
41+
"resourceTableId": 123123
42+
}
43+
},
44+
{
45+
"capacity": 10,
46+
"createDate": "2025-11-02T03:40:01-06:00",
47+
"description": "poc-classic-to-vpc - Disk 4",
48+
"id": 234234,
49+
"modifyDate": "2025-11-02T03:41:32-06:00",
50+
"name": "poc-classic-to-vpc - Disk 4",
51+
"parentId": null,
52+
"storageRepositoryId": 234234,
53+
"typeId": 241,
54+
"units": "GB",
55+
"uuid": "28690a15-d67f-4326-a39a-472e1813cebf",
56+
"billingItem": {
57+
"allowCancellationFlag": 1,
58+
"associatedBillingItemId": "1259099304",
59+
"cancellationDate": null,
60+
"categoryCode": "guest_disk2",
61+
"createDate": "2025-11-02T03:39:57-06:00",
62+
"cycleStartDate": null,
63+
"description": "10 GB (SAN)",
64+
"id": 234234,
65+
"lastBillDate": "2025-11-02T03:39:57-06:00",
66+
"modifyDate": null,
67+
"nextBillDate": "2025-11-30T00:00:00-06:00",
68+
"orderItemId": 234234234,
69+
"packageId": 198,
70+
"parentId": null,
71+
"recurringMonths": null,
72+
"serviceProviderId": null,
73+
"location": {
74+
"id": 1854895,
75+
"longName": "Dallas 13",
76+
"name": "dal13",
77+
"statusId": 2,
78+
"locationStatus": {
79+
"id": 2,
80+
"status": "Active"
81+
}
82+
},
83+
"resourceTableId": 34535345
84+
}
85+
}
86+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"accountId": 2222222,
3+
"credentialId": 3333333,
4+
"id": 4444444,
5+
"name": "iqn.2025-10.com.ibm:ibm02su1123-v45667",
6+
"resourceTableId": 5555555,
7+
"resourceTableName": "VIRTUAL_GUEST",
8+
"credential": {
9+
"accountId": "1041833",
10+
"createDate": "2025-10-23T05:19:29-07:00",
11+
"id": 234234234,
12+
"modifyDate": null,
13+
"nasCredentialTypeId": 2,
14+
"password": "xxx",
15+
"username": "IBM02XXX-VS123"
16+
}
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"capacityGb": 20,
4+
"id": 345345,
5+
"username": "IBM0934",
6+
"allowedVirtualGuests": [
7+
{
8+
"id": 567567,
9+
"datacenter": {
10+
"id": 234234,
11+
"longName": "Dallas 13",
12+
"name": "dal13",
13+
"statusId": 2,
14+
"locationStatus": {
15+
"id": 2,
16+
"status": "Active"
17+
}
18+
}
19+
}
20+
],
21+
"serviceResourceBackendIpAddress": "111.22.444.153"
22+
}
23+
]

0 commit comments

Comments
 (0)