forked from dell/gounity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume_test.go
279 lines (216 loc) · 7.46 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
package gounity
import (
"context"
"fmt"
"testing"
"time"
)
var volName string
var cloneVolumeName string
var volID string
var cloneVolumeID string
var 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)
deleteVolumeTest(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
fmt.Println("Create clone from Volume Test - Successful")
}
func deleteVolumeTest(t *testing.T) {
fmt.Println("Begin - Delete Volume Test")
err := testConf.volumeAPI.DeleteVolume(ctx, cloneVolumeID)
if err != nil {
t.Fatalf("Delete volume failed: %v", err)
}
err = testConf.volumeAPI.DeleteVolume(ctx, volID)
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")
}