forked from dell/gounity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume_test.go
367 lines (300 loc) · 10.5 KB
/
volume_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
Copyright © 2019 Dell Inc. or its subsidiaries. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package gounity
import (
"context"
"fmt"
"testing"
"time"
)
var (
volName string
cloneVolumeName string
volID string
cloneVolumeID string
hostIOLimitID string
)
func TestVolume(t *testing.T) {
now := time.Now()
timeStamp := now.Format("20060102150405")
volName = "Unit-test-vol-" + timeStamp
cloneVolumeName = "Unit-test-clone-vol-" + timeStamp
ctx = context.Background()
findHostIOLimitByNameTest(t)
createLunTest(t)
findVolumeByNameTest(t)
findVolumeByIDTest(t)
listVolumesTest(t)
exportVolumeTest(t)
unexportVolumeTest(t)
expandVolumeTest(t)
createCloneFromVolumeTest(t)
modifyVolumeExportTest(t)
deleteVolumeTest(t)
getMaxVolumeSizeTest(t)
// creteLunThinCloneTest(t) - Will be added to snapshot_test
}
func findHostIOLimitByNameTest(t *testing.T) {
fmt.Println("Begin - Find Host IO Limit by Name Test")
if testConf.hostIOLimitName != "" {
hostIOLimit, err := testConf.volumeAPI.FindHostIOLimitByName(ctx, testConf.hostIOLimitName)
fmt.Println("hostIOLimit:", prettyPrintJSON(hostIOLimit), "Error:", err)
hostIOLimitID = hostIOLimit.IoLimitPolicyContent.ID
// Negative case
hostIOTemp := "dummy_hostio_1"
_, err = testConf.volumeAPI.FindHostIOLimitByName(ctx, hostIOTemp)
if err == nil {
t.Fatalf("Find Host IO Limit negative case failed: %v", err)
}
hostIOTemp = ""
_, err = testConf.volumeAPI.FindHostIOLimitByName(ctx, hostIOTemp)
if err == nil {
t.Fatalf("Find Host IO Limit with empty name case failed: %v", err)
}
fmt.Println("Find Host IO Limit by Name Test - Successful")
} else {
fmt.Println("Skipping Host IO Limit by Name Test - Parameter not configured")
}
}
func createLunTest(t *testing.T) {
fmt.Println("Begin - Create LUN Test")
_, err := testConf.volumeAPI.CreateLun(ctx, volName, testConf.poolID, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err != nil {
t.Fatalf("Create LUN failed: %v", err)
}
// Negative cases
volNameTemp := ""
_, err = testConf.volumeAPI.CreateLun(ctx, volNameTemp, testConf.poolID, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err == nil {
t.Fatalf("Create LUN with empty name case failed: %v", err)
}
volNameTemp = "vol-name-max-length-12345678901234567890123456789012345678901234567890"
_, err = testConf.volumeAPI.CreateLun(ctx, volNameTemp, testConf.poolID, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err == nil {
t.Fatalf("Create LUN exceeding max name length case failed: %v", err)
}
poolIDTemp := "dummy_pool_1"
_, err = testConf.volumeAPI.CreateLun(ctx, volName, poolIDTemp, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err == nil {
t.Fatalf("Create LUN with invalid pool name case failed: %v", err)
}
_, err = testConf.volumeAPI.CreateLun(ctx, volName, testConf.poolID, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err == nil {
t.Fatalf("Create LUN with same name case failed: %v", err)
}
fmt.Println("Create LUN Test - Successful")
}
func findVolumeByNameTest(t *testing.T) {
fmt.Println("Begin - Find Volume By Name Test")
vol, err := testConf.volumeAPI.FindVolumeByName(ctx, volName)
fmt.Println("Find volume by Name:", prettyPrintJSON(vol), err)
if err != nil {
t.Fatalf("Find volume by Name failed: %v", err)
}
volID = vol.VolumeContent.ResourceID
// Negative cases
volNameTemp := ""
_, err = testConf.volumeAPI.FindVolumeByName(ctx, volNameTemp)
if err == nil {
t.Fatalf("Find volume by Name with empty name case failed: %v", err)
}
volNameTemp = "dummy_volume_1"
_, err = testConf.volumeAPI.FindVolumeByName(ctx, volNameTemp)
if err == nil {
t.Fatalf("Find volume by Name with invalid name case failed: %v", err)
}
fmt.Println("Find Volume by Name Test - Successful")
}
func findVolumeByIDTest(t *testing.T) {
fmt.Println("Begin - Find Volume By Name Test")
vol, err := testConf.volumeAPI.FindVolumeByID(ctx, volID)
fmt.Println("Find volume by Name:", prettyPrintJSON(vol), err)
if err != nil {
t.Fatalf("Find volume by Id failed: %v", err)
}
// Negative cases
volIDTemp := ""
_, err = testConf.volumeAPI.FindVolumeByID(ctx, volIDTemp)
if err == nil {
t.Fatalf("Find volume by Id with empty Id case failed: %v", err)
}
volIDTemp = "dummy_vol_sv_1"
_, err = testConf.volumeAPI.FindVolumeByID(ctx, volIDTemp)
if err == nil {
t.Fatalf("Find volume by Id with invalid Id case failed: %v", err)
}
fmt.Println("Find Volume by Id Test - Successful")
}
func listVolumesTest(t *testing.T) {
fmt.Println("Begin - List Volumes Test")
vols, _, err := testConf.volumeAPI.ListVolumes(ctx, 11, 10)
fmt.Println("List volumes count: ", len(vols))
if len(vols) <= 10 {
fmt.Println("List volume success")
} else {
t.Fatalf("List volumes failed: %v", err)
}
fmt.Println("List Volume Test - Successful")
}
func exportVolumeTest(t *testing.T) {
fmt.Println("Begin - Export Volume Test")
host, err := testConf.hostAPI.FindHostByName(ctx, testConf.nodeHostName)
if err != nil {
t.Fatalf("Find Host failed: %v", err)
}
err = testConf.volumeAPI.ExportVolume(ctx, volID, host.HostContent.ID)
if err != nil {
t.Fatalf("ExportVolume failed: %v", err)
}
// Negative case for Delete Volume
err = testConf.volumeAPI.DeleteVolume(ctx, volID)
if err == nil {
t.Fatalf("Delete volume on exported volume case failed: %v", err)
}
fmt.Println("Export Volume Test - Successful")
}
func unexportVolumeTest(t *testing.T) {
fmt.Println("Begin - Unexport Volume Test")
err := testConf.volumeAPI.UnexportVolume(ctx, volID)
if err != nil {
t.Fatalf("UnExportVolume failed: %v", err)
}
fmt.Println("Unexport Volume Test - Successful")
}
func expandVolumeTest(t *testing.T) {
fmt.Println("Begin - Expand Volume Test")
err := testConf.volumeAPI.ExpandVolume(ctx, volID, 5368709120)
if err != nil {
t.Fatalf("Expand volume failed: %v", err)
}
err = testConf.volumeAPI.ExpandVolume(ctx, volID, 5368709120)
if err != nil {
t.Fatalf("Expand volume with same size failed: %v", err)
}
// Negative cases
volIDTemp := "dummy_vol_sv_1"
err = testConf.volumeAPI.ExpandVolume(ctx, volIDTemp, 5368709120)
if err == nil {
t.Fatalf("Expand volume with invalid Id case failed: %v", err)
}
err = testConf.volumeAPI.ExpandVolume(ctx, volID, 4368709120)
if err == nil {
t.Fatalf("Expand volume with smaller size case failed: %v", err)
}
fmt.Println("Expand Volume Test - Successful")
}
func createCloneFromVolumeTest(t *testing.T) {
fmt.Println("Begin - Create clone from Volume Test")
_, err := testConf.volumeAPI.CreateCloneFromVolume(ctx, cloneVolumeName, volID)
if err != nil {
t.Fatalf("Clone volume failed: %v", err)
}
vol, err := testConf.volumeAPI.FindVolumeByName(ctx, cloneVolumeName)
fmt.Println("Find volume by Name:", prettyPrintJSON(vol), err)
if err != nil {
t.Fatalf("Find volume by Name failed: %v", err)
}
cloneVolumeID = vol.VolumeContent.ResourceID
// Negative Test Case
// Creating clone with same name
_, err = testConf.volumeAPI.CreateCloneFromVolume(ctx, cloneVolumeName, volID)
if err == nil {
t.Fatalf("Clone volume with a same existing volume name test case failed: %v", err)
}
// Creating clone with invalid volume ID
volIDTemp := "dummy-vol-1"
_, err = testConf.volumeAPI.CreateCloneFromVolume(ctx, cloneVolumeName, volIDTemp)
if err == nil {
t.Fatalf("Clone volume with invalid volume ID test case failed: %v", err)
}
fmt.Println("Create clone from Volume Test - Successful")
}
func modifyVolumeExportTest(t *testing.T) {
fmt.Println("Begin - Modify Volume Export Test")
hostIDList := []string{}
for _, hostName := range testConf.hostList {
host, err := testConf.hostAPI.FindHostByName(ctx, hostName)
if err != nil {
t.Fatalf("Find host by name %s failed. Error: %v", hostName, err)
}
hostIDList = append(hostIDList, host.HostContent.ID)
}
err := testConf.volumeAPI.ModifyVolumeExport(ctx, volID, hostIDList)
if err != nil {
t.Fatalf("Modify Volume Export failed: %v", err)
}
// Modify Volume name
volName = volName + "_renamed"
err = testConf.volumeAPI.RenameVolume(ctx, volName, volID)
if err != nil {
t.Fatalf("Rename existing volume failed. Error: %v", err)
}
// Negative Test case
volIDTemp := "dummy_vol_1"
err = testConf.volumeAPI.RenameVolume(ctx, volName, volIDTemp)
if err == nil {
t.Fatalf("Rename existing volume failed. Error: %v", err)
}
// Unexport volume from host
err = testConf.volumeAPI.UnexportVolume(ctx, volID)
if err != nil {
t.Fatalf("Unexport volume failed. Error: %v", err)
}
fmt.Println("Modify Volume Export Test Successful")
}
func deleteVolumeTest(t *testing.T) {
fmt.Println("Begin - Delete Volume Test")
// Deletion of volume, Volume won't get deleted as clone exists
err := testConf.volumeAPI.DeleteVolume(ctx, volID)
if err != nil {
t.Fatalf("Delete volume failed: %v", err)
}
// Deletion of clone and volume
err = testConf.volumeAPI.DeleteVolume(ctx, cloneVolumeID)
if err != nil {
t.Fatalf("Delete volume failed: %v", err)
}
// Negative cases
volIDTemp := ""
err = testConf.volumeAPI.DeleteVolume(ctx, volIDTemp)
if err == nil {
t.Fatalf("Delete volume with empty Id case failed: %v", err)
}
volIDTemp = "dummy_vol_sv_1"
err = testConf.volumeAPI.DeleteVolume(ctx, volIDTemp)
if err == nil {
t.Fatalf("Delete volume with invalid Id case failed: %v", err)
}
fmt.Println("Delete Volume Test - Successful")
}
func getMaxVolumeSizeTest(t *testing.T) {
fmt.Println("Begin - Get Max Volume Size")
// Positive case
systemLimitID := "Limit_MaxLUNSize"
_, err := testConf.volumeAPI.GetMaxVolumeSize(ctx, systemLimitID)
if err != nil {
t.Fatalf("Get maximum volume size failed: %v", err)
}
// Negative cases
systemLimitID = ""
_, err = testConf.volumeAPI.GetMaxVolumeSize(ctx, systemLimitID)
if err == nil {
t.Fatalf("Get maximum volume size with empty systemLimitID case failed: %v", err)
}
systemLimitID = "dummy_name"
_, err = testConf.volumeAPI.GetMaxVolumeSize(ctx, systemLimitID)
if err == nil {
t.Fatalf("Get maximum volume size with invalid systemLimitID case failed: %v", err)
}
fmt.Println("Get Max Volume Size - Successful")
}