-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisks_test.go
95 lines (78 loc) · 2.47 KB
/
disks_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
package manager
import (
"fmt"
"math/rand"
"testing"
"time"
)
func TestDisksRoundtrip(t *testing.T) {
s := createTestSession(t)
defer s.Logout()
rand.Seed(time.Now().UTC().UnixNano())
pools, err := s.GetStoragePools()
if err != nil {
t.Fatalf("Failed retrieve storage pool list: %v", err)
}
if len(pools) <= 0 {
t.Fatalf("No storage pool found")
}
targets, err := s.GetISCSITargets()
if err != nil {
t.Fatalf("Failed retrieve iSCSI target list: %v", err)
}
if len(targets) <= 0 {
t.Fatalf("No iSCSI target found")
}
target := targets[0]
t.Logf("Using iSCSI Target: %v (#%v)", target.TargetIQN, target.TargetIndex)
for _, pool := range pools {
lunName := fmt.Sprintf("UnitTest_%v", 10000+rand.Int31n(89999))
t.Logf("Using LUN/volume name: %v", lunName)
// create the lun
var lun *LUN
t.Run(fmt.Sprintf("Test_Storage Pool %v_CreateLUN", pool.PoolID), func(t *testing.T) {
lun, err = s.CreateBlockBasedLUN(pool.PoolID, lunName, 1, LUNAllocateMode_Thin, true, 99)
if err != nil {
t.Fatalf("Failed to create LUN '%v': %v", lunName, err)
}
t.Logf("Created new LUN %v", lun.LUNIndex)
if lun.VolumeID != -1 {
t.Fatalf("Unexpected volume ID (should not exist, yet)")
}
if lun.LUNTargetList.SingleRow != nil {
t.Fatalf("Unexpected iSCSI target information (not assigned, yet)")
}
})
// wait for the volume
t.Run(fmt.Sprintf("Test_Storage Pool %v_WaitForVolume", pool.PoolID), func(t *testing.T) {
lun, err = s.WaitForLUNVolume(lun.LUNIndex)
if err != nil {
t.Fatalf("Failed to wait for volume of LUN '%v': %v", lunName, err)
}
})
// assign the LUN
t.Run(fmt.Sprintf("Test_Storage Pool %v_AssignToTarget", pool.PoolID), func(t *testing.T) {
err = s.AssignLUN(lun.LUNIndex, target.TargetIndex)
if err != nil {
t.Fatalf("Failed to assign LUN '%v' to iSCSI target '%v': %v", lunName, "xxxx", err)
}
})
// check the target
t.Run(fmt.Sprintf("Test_Storage Pool %v_CheckTarget", pool.PoolID), func(t *testing.T) {
lun, err = s.GetLUNByIndex(lun.LUNIndex)
if err != nil {
t.Fatalf("Failed to get LUN '%v' to iSCSI target '%v': %v", lunName, "xxxx", err)
}
if lun.LUNTargetList.SingleRow == nil {
t.Fatalf("Missing iSCSI target information")
}
})
// delete the lun
t.Run(fmt.Sprintf("Test_Storage Pool %v_DeleteLUN", pool.PoolID), func(t *testing.T) {
err := s.DeleteLUN(lun.LUNIndex)
if err != nil {
t.Fatalf("Failed to delete LUN '%v': %v", lunName, err)
}
})
}
}