-
Notifications
You must be signed in to change notification settings - Fork 6
/
host_test.go
431 lines (353 loc) · 12.8 KB
/
host_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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
/*
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"
"github.com/dell/gounity/api"
"github.com/dell/gounity/types"
)
var (
hostName string
hostID string
hostIPPortID string
iqnInitiatorID string
wwnInitiatorPathID string
fcPortID string
iqnInitiator *types.HostInitiator
)
func TestHost(t *testing.T) {
now := time.Now()
timeStamp := now.Format("20060102150405")
hostName = "Unit-test-host-" + timeStamp
ctx = context.Background()
createHostTest(t)
findHostByNameTest(t)
createHostIPPortTest(t)
findHostIPPortByIDTest(t)
createHostInitiatorTest(t)
listHostInitiatorsTest(t)
findHostInitiatorByNameTest(t)
findHostInitiatorByIDTest(t)
modifyHostInitiatorTest(t)
modifyHostInitiatorByIDTest(t)
findHostInitiatorPathByIDTest(t)
findFcPortByIDTest(t)
findTenantsTest(t)
deleteHostTest(t)
}
func createHostTest(t *testing.T) {
fmt.Println("Begin - Create Host Test")
host, err := testConf.hostAPI.CreateHost(ctx, hostName, testConf.tenant)
if err != nil {
t.Fatalf("Create Host failed: %v", err)
}
hostID = host.HostContent.ID
// Negative test cases
hostNameTemp := ""
_, err = testConf.hostAPI.CreateHost(ctx, hostNameTemp, testConf.tenant)
if err == nil {
t.Fatalf("Create Host with empty hostName - Negative case failed")
}
tenantIDTemp := "tenant_invalid_1"
_, err = testConf.hostAPI.CreateHost(ctx, hostNameTemp, tenantIDTemp)
if err == nil {
t.Fatalf("Create Host with invalid tenant ID - Negative case failed")
}
fmt.Println("Create Host Test Successful")
}
func findHostByNameTest(t *testing.T) {
fmt.Println("Begin - Find Host by name Test")
_, err := testConf.hostAPI.FindHostByName(ctx, hostName)
if err != nil {
t.Fatalf("Find Host failed: %v", err)
}
// Negative test cases
hostNameTemp := ""
_, err = testConf.hostAPI.FindHostByName(ctx, hostNameTemp)
if err == nil {
t.Fatalf("Find Host with empty hostName - Negative case failed")
}
hostNameTemp = "dummy-host-1"
_, err = testConf.hostAPI.FindHostByName(ctx, hostNameTemp)
if err == nil {
t.Fatalf("Find Host with invalid hostName - Negative case failed")
}
fmt.Println("Find Host by name Successful")
}
func createHostIPPortTest(t *testing.T) {
fmt.Println("Begin - Create Host IP Port Test")
hostIPPort, err := testConf.hostAPI.CreateHostIPPort(ctx, hostID, testConf.nodeHostIP)
if err != nil {
t.Fatalf("CreateHostIPPort failed: %v", err)
}
hostIPPortID = hostIPPort.HostIPContent.ID
// Negative test cases
hostIDTemp := ""
_, err = testConf.hostAPI.CreateHostIPPort(ctx, hostIDTemp, testConf.nodeHostIP)
if err == nil {
t.Fatalf("Create Host IP Port with empty hostID - Negative case failed")
}
hostIDTemp = "Host_dummy_1"
_, err = testConf.hostAPI.CreateHostIPPort(ctx, hostIDTemp, testConf.nodeHostIP)
if err == nil {
t.Fatalf("Create Host IP Port with invalid hostID - Negative case failed")
}
fmt.Println("Create Host IP Port Test Successful")
}
func findHostIPPortByIDTest(t *testing.T) {
fmt.Println("Begin - Find Host IP Port Test")
_, err := testConf.hostAPI.FindHostIPPortByID(ctx, hostIPPortID)
if err != nil {
t.Fatalf("Find Host IP Port failed: %v", err)
}
// Negative test cases
hostIPPortIDTemp := "dummy-ip-port-id-1"
_, err = testConf.hostAPI.FindHostIPPortByID(ctx, hostIPPortIDTemp)
if err == nil {
t.Fatalf(" Find Host IP Port with invalid hostID - Negative case failed")
}
fmt.Println("Find Host IP Port Test Successful")
}
func createHostInitiatorTest(t *testing.T) {
fmt.Println("Begin - Create Host Initiator Test")
fmt.Println("WWNs: ", testConf.wwns)
for _, wwn := range testConf.wwns {
fmt.Printf("Adding new Initiator: %s to host: %s \n", hostName, wwn)
initiator, err := testConf.hostAPI.CreateHostInitiator(ctx, hostID, wwn, api.FCInitiatorType)
fmt.Println("CreateHostInitiator:", initiator, err)
if err != nil {
t.Fatalf("CreateHostInitiator %s Error: %v", wwn, err)
}
}
// Negative case
hostIDTemp := "host_dummy_1"
_, err := testConf.hostAPI.CreateHostInitiator(ctx, hostIDTemp, testConf.iqn, api.ISCSCIInitiatorType)
if err == nil {
t.Fatalf("Create Host Initiator Idempotency with invalid hostID - Negative case failed")
}
// Add Iqn
initiator, err := testConf.hostAPI.CreateHostInitiator(ctx, hostID, testConf.iqn, api.ISCSCIInitiatorType)
fmt.Println("CreateHostInitiator:", initiator, err)
if err != nil {
t.Fatalf("CreateHostInitiator %s Error: %v", testConf.iqn, err)
}
iqnInitiatorID = initiator.HostInitiatorContent.ID
// Test idempotency for parent host check
initiator, err = testConf.hostAPI.CreateHostInitiator(ctx, hostID, testConf.iqn, api.ISCSCIInitiatorType)
if err != nil {
t.Fatalf("CreateHostInitiator %s Error: %v", testConf.iqn, err)
}
// Negative test cases
hostIDTemp = ""
iqnTemp := ""
_, err = testConf.hostAPI.CreateHostInitiator(ctx, hostIDTemp, testConf.iqn, api.ISCSCIInitiatorType)
if err == nil {
t.Fatalf("Create Host Initiator with empty hostID - Negative case failed")
}
_, err = testConf.hostAPI.CreateHostInitiator(ctx, hostID, iqnTemp, api.ISCSCIInitiatorType)
if err == nil {
t.Fatalf("Create Host Initiator with empty iqn - Negative case failed")
}
// Test idempotency for parent host check
hostIDTemp = "host_dummy_1"
_, err = testConf.hostAPI.CreateHostInitiator(ctx, hostIDTemp, testConf.iqn, api.ISCSCIInitiatorType)
if err == nil {
t.Fatalf("Create Host Initiator Idempotency with invalid hostID - Negative case failed")
}
//@TODO: Cheack and add positive case to modify parent host
fmt.Println("Create Host Initiator Test Successful")
}
func listHostInitiatorsTest(t *testing.T) {
fmt.Println("Begin - List Host Initiators Test")
list, err := testConf.hostAPI.ListHostInitiators(ctx)
fmt.Println("List Host initiators", list, err)
if err != nil {
t.Fatalf("ListHostInitiators error: %v", err)
}
fmt.Println("List Host Initiators Test Successful")
}
func findHostInitiatorByNameTest(t *testing.T) {
fmt.Println("Begin - Find Host Initiator by Name Test")
initiator, err := testConf.hostAPI.FindHostInitiatorByName(ctx, testConf.iqn)
fmt.Println("FindHostInitiatorByName:", initiator, err)
if err != nil {
t.Fatalf("FindHostInitiatorByName %s Error: %v", testConf.iqn, err)
}
iqnInitiator = initiator
// Check if call for wwn is required
// Negative test cases
iqnTemp := ""
_, err = testConf.hostAPI.FindHostInitiatorByName(ctx, iqnTemp)
if err == nil {
t.Fatalf("Find Host Initiator with empty iqn - Negative case failed")
}
fmt.Println("Find Host Initiator by Name Test Successful")
}
func findHostInitiatorByIDTest(t *testing.T) {
fmt.Println("Begin - Find Host Initiator by Id Test")
// parameterize this
fcHostName := "lglal016"
host, err := testConf.hostAPI.FindHostByName(ctx, fcHostName)
if err != nil {
t.Fatalf("Find Host failed: %v", err)
}
for _, fcInitiator := range host.HostContent.FcInitiators {
initiatorID := fcInitiator.ID
initiator, err := testConf.hostAPI.FindHostInitiatorByID(ctx, initiatorID)
fmt.Println("FindHostInitiatorById:", initiator, err)
if err != nil {
t.Fatalf("FindHostInitiatorById %s Error: %v", initiatorID, err)
}
if len(initiator.HostInitiatorContent.Paths) > 0 {
wwnInitiatorPathID = initiator.HostInitiatorContent.Paths[0].ID
break
}
}
// Negative test cases
initiatorIDTemp := "dummy-ip-port-id-1"
_, err = testConf.hostAPI.FindHostInitiatorByID(ctx, initiatorIDTemp)
if err == nil {
t.Fatalf(" Find Host IP Port with invalid initiator ID - Negative case failed")
}
fmt.Println("Find Host Initiator by Id Test Successful")
}
func modifyHostInitiatorTest(t *testing.T) {
fmt.Println("Begin - Modify Host Initiator Test")
initiator, err := testConf.hostAPI.ModifyHostInitiator(ctx, hostID, iqnInitiator)
fmt.Println("ModifyHostInitiator:", initiator, err)
if err != nil {
t.Fatalf("ModifyHostInitiator %s Error: %v", iqnInitiatorID, err)
}
_, err = testConf.hostAPI.ModifyHostInitiator(ctx, hostID, nil)
if err == nil {
t.Fatalf("Modify Host initiator with nil initiator - Negative case failed")
}
hostIDTemp := "host_dummy_1"
_, err = testConf.hostAPI.ModifyHostInitiator(ctx, hostIDTemp, iqnInitiator)
if err == nil {
t.Fatalf("Modify Host initiator with invalid initiator - Negative case failed")
}
fmt.Println("Modify Host Initiator Test Successful")
}
func modifyHostInitiatorByIDTest(t *testing.T) {
fmt.Println("Begin - Modify Host Initiator By ID Test")
// parameterize this
fcHostName := "lglal016"
host, err := testConf.hostAPI.FindHostByName(ctx, fcHostName)
if err != nil {
t.Fatalf("Find Host failed: %v", err)
}
for _, fcInitiator := range host.HostContent.FcInitiators {
initiatorID := fcInitiator.ID
initiator, err := testConf.hostAPI.ModifyHostInitiatorByID(ctx, hostID, initiatorID)
fmt.Println("ModifyHostInitiator:", initiator, err)
if err != nil {
t.Fatalf("ModifyHostInitiator %s Error: %v", iqnInitiatorID, err)
}
}
for _, iscsiInitiator := range host.HostContent.IscsiInitiators {
initiatorID := iscsiInitiator.ID
initiator, err := testConf.hostAPI.ModifyHostInitiatorByID(ctx, hostID, initiatorID)
fmt.Println("ModifyHostInitiator:", initiator, err)
if err != nil {
t.Fatalf("ModifyHostInitiator %s Error: %v", iqnInitiatorID, err)
}
}
_, err = testConf.hostAPI.ModifyHostInitiatorByID(ctx, "", "")
if err == nil {
t.Fatalf("Modify Host initiator with nil initiator - Negative case failed")
}
hostIDTemp := "host_dummy_1"
_, err = testConf.hostAPI.ModifyHostInitiatorByID(ctx, hostIDTemp, "")
if err == nil {
t.Fatalf("Modify Host initiator with invalid initiator - Negative case failed")
}
fmt.Println("Modify Host Initiator By ID Test Successful")
}
func findHostInitiatorPathByIDTest(t *testing.T) {
fmt.Println("Begin - Find Initiator Path Test")
////initiatorPathID := iqnInitiator.HostInitiatorContent.Paths[0].ID
hostInitiatorPath, err := testConf.hostAPI.FindHostInitiatorPathByID(ctx, wwnInitiatorPathID)
if err != nil {
// Change to log if required for vm execution
t.Fatalf("Find Host Initiator Path failed: %v", err)
}
fcPortID = hostInitiatorPath.HostInitiatorPathContent.FcPortID.ID
// Negative test cases
initiatorPathIDTemp := "Host_initiator_path_dummy_1"
_, err = testConf.hostAPI.FindHostInitiatorPathByID(ctx, initiatorPathIDTemp)
if err == nil {
t.Fatalf("Find Host Initiator path with invalid Id - Negative case failed")
}
fmt.Println("Find Initiator Path Test Successful")
}
func findFcPortByIDTest(t *testing.T) {
fmt.Println("Begin - Find FC Port Test")
_, err := testConf.hostAPI.FindFcPortByID(ctx, fcPortID)
if err != nil {
// Change to log if required for vm execution
t.Fatalf("Find FC Port failed: %v", err)
}
// Negative test cases
fcPortIDTemp := "Fc_Port_dummy_1"
_, err = testConf.hostAPI.FindFcPortByID(ctx, fcPortIDTemp)
if err == nil {
t.Fatalf("Find FC Port with invalid Id - Negative case failed")
}
fmt.Println("Find FC Port Test Successful")
}
func findTenantsTest(t *testing.T) {
fmt.Println("Begin - Find Tenants Test")
_, err := testConf.hostAPI.FindTenants(ctx)
if err != nil {
t.Fatalf("Find Tenants failed: %v", err)
}
fmt.Println("Find Tenants Test Successful")
}
func deleteHostTest(t *testing.T) {
fmt.Println("Begin - Delete Host Test")
err := testConf.hostAPI.DeleteHost(ctx, hostName)
if err != nil {
t.Fatalf("Delete Host failed: %v", err)
}
hostNameTemp := ""
err = testConf.hostAPI.DeleteHost(ctx, hostNameTemp)
if err == nil {
t.Fatalf("Delete Host with empty hostName - Negative case failed")
}
hostNameTemp = "dummy-host-1"
err = testConf.hostAPI.DeleteHost(ctx, hostNameTemp)
if err == nil {
t.Fatalf("Delete Host with invalid hostName - Negative case failed")
}
// Create hosts with same name
hostNameTemp = "test_host_duplicate_names"
for apiCall := 0; apiCall < 2; apiCall++ {
_, err = testConf.hostAPI.CreateHost(ctx, hostNameTemp, "")
if err != nil {
t.Fatalf("Create Host failed: %v", err)
}
}
_, err = testConf.hostAPI.FindHostByName(ctx, hostNameTemp)
if err == nil {
t.Fatalf("Find Host with multiple instances with same name case failed: %v", err)
}
err = testConf.hostAPI.DeleteHost(ctx, hostNameTemp)
if err == nil {
t.Fatalf("Delete Host with multiple instances with same name case failed: %v", err)
}
fmt.Println("Delete Host Test Successful")
}