-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsr_nfs_test.go
112 lines (102 loc) · 2.56 KB
/
sr_nfs_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
package testGoSDK
import (
"fmt"
"strings"
"testing"
"time"
"xenapi"
)
func TestNFSSRCreateAndDestroy(t *testing.T) {
if *NFS_SERVER_FLAG == "" || *NFS_PATH_FLAG == "" {
t.Log("NFS server or path is not provided, skipping NFS SR test")
t.Fail()
return
}
// Choose the first host
hostRefs, err := xenapi.Host.GetAll(session)
if err != nil {
t.Log(err)
t.Fail()
return
}
hostName, err := xenapi.Host.GetNameLabel(session, hostRefs[0])
if err != nil {
t.Log(err)
t.Fail()
return
}
t.Log("Got host :", hostName)
// Create config parameter for shared storage on nfs server
var deviceConfig = make(map[string]string)
deviceConfig["server"] = *NFS_SERVER_FLAG
deviceConfig["serverpath"] = *NFS_PATH_FLAG
t.Log("Creating a shared storage SR ...")
var srRefNew xenapi.SRRef
srRefNew, err = xenapi.SR.Create(session, hostRefs[0], deviceConfig, 100000, "NFS SR created by sr_nfs_test.go",
fmt.Sprintf("[%s:%s] Created at %s", *NFS_SERVER_FLAG, *NFS_PATH_FLAG, time.Now().String()), "nfs", "unused",
true, make(map[string]string))
if err != nil {
t.Log(err)
t.Fail()
return
}
err = WaitForSRReady(session, srRefNew)
if err != nil {
t.Log(err)
t.Fail()
return
}
err = xenapi.SR.SetNameDescription(session, srRefNew, "New description")
if err != nil {
t.Log(err)
t.Fail()
return
}
t.Log("Now unplugging PBDs")
pbdRefs, err := xenapi.SR.GetPBDs(session, srRefNew)
if err != nil {
t.Log(err)
t.Fail()
return
}
for _, pbdRef := range pbdRefs {
pbdRecord, err := xenapi.PBD.GetRecord(session, pbdRef)
if err != nil {
t.Log(err)
t.Fail()
return
}
if pbdRecord.CurrentlyAttached {
err = xenapi.PBD.Unplug(session, pbdRef)
if err != nil {
t.Log(err)
t.Fail()
return
}
}
}
t.Log("Now destroying the newly-created SR")
err = xenapi.SR.Destroy(session, srRefNew)
if err != nil {
t.Log(err)
t.Fail()
return
}
// try a couple of erroneous calls to generate exceptions
t.Log("Trying to create one with bad device_config")
_, err = xenapi.SR.Create(session, hostRefs[0], make(map[string]string), 100000, "bad_device_config",
"description", "nfs", "contenttype", true, make(map[string]string))
if err == nil || !strings.Contains(err.Error(), "missing") {
t.Log(err)
t.Fail()
return
}
t.Log("Trying to create one with a bad 'type' field")
_, err = xenapi.SR.Create(session, hostRefs[0], make(map[string]string), 100000, "bad_sr_type",
"description", "made_up", "", true, make(map[string]string))
if err == nil || !strings.Contains(err.Error(), "made_up") {
t.Log(err)
t.Fail()
return
}
}