Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 531e0cc

Browse files
author
Jamie Hannaford
committed
fix acceptance tests and prevent decoding empty responses
1 parent 99c3580 commit 531e0cc

File tree

3 files changed

+69
-17
lines changed

3 files changed

+69
-17
lines changed

acceptance/openstack/blockstorage/v2/extensions/volumeactions_test.go

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ func TestVolumeAttach(t *testing.T) {
2929
client, err := newClient(t)
3030
th.AssertNoErr(t, err)
3131

32+
t.Logf("Creating volume")
3233
cv, err := volumes.Create(client, &volumes.CreateOpts{
3334
Size: 1,
3435
Name: "blockv2-volume",
3536
}).Extract()
3637
th.AssertNoErr(t, err)
38+
3739
defer func() {
3840
err = volumes.WaitForStatus(client, cv.ID, "available", 60)
3941
th.AssertNoErr(t, err)
42+
43+
t.Logf("Deleting volume")
4044
err = volumes.Delete(client, cv.ID).ExtractErr()
4145
th.AssertNoErr(t, err)
4246
}()
@@ -49,48 +53,97 @@ func TestVolumeAttach(t *testing.T) {
4953
t.Fatal("Environment variable OS_INSTANCE_ID is required")
5054
}
5155

52-
_, err = volumeactions.Attach(client, cv.ID, &volumeactions.AttachOpts{
56+
t.Logf("Attaching volume")
57+
err = volumeactions.Attach(client, cv.ID, &volumeactions.AttachOpts{
5358
MountPoint: "/mnt",
5459
Mode: "rw",
5560
InstanceUUID: instanceID,
56-
}).Extract()
61+
}).ExtractErr()
5762
th.AssertNoErr(t, err)
5863

5964
err = volumes.WaitForStatus(client, cv.ID, "in-use", 60)
6065
th.AssertNoErr(t, err)
6166

62-
_, err = volumeactions.Detach(client, cv.ID).Extract()
67+
t.Logf("Detaching volume")
68+
err = volumeactions.Detach(client, cv.ID).ExtractErr()
6369
th.AssertNoErr(t, err)
6470
}
6571

6672
func TestVolumeReserve(t *testing.T) {
6773
client, err := newClient(t)
6874
th.AssertNoErr(t, err)
6975

76+
t.Logf("Creating volume")
7077
cv, err := volumes.Create(client, &volumes.CreateOpts{
7178
Size: 1,
7279
Name: "blockv2-volume",
7380
}).Extract()
7481
th.AssertNoErr(t, err)
82+
7583
defer func() {
7684
err = volumes.WaitForStatus(client, cv.ID, "available", 60)
7785
th.AssertNoErr(t, err)
86+
87+
t.Logf("Deleting volume")
7888
err = volumes.Delete(client, cv.ID).ExtractErr()
7989
th.AssertNoErr(t, err)
8090
}()
8191

8292
err = volumes.WaitForStatus(client, cv.ID, "available", 60)
8393
th.AssertNoErr(t, err)
8494

85-
_, err = volumeactions.Reserve(client, cv.ID).Extract()
95+
t.Logf("Reserving volume")
96+
err = volumeactions.Reserve(client, cv.ID).ExtractErr()
8697
th.AssertNoErr(t, err)
8798

8899
err = volumes.WaitForStatus(client, cv.ID, "attaching", 60)
89100
th.AssertNoErr(t, err)
90101

91-
_, err = volumeactions.Unreserve(client, cv.ID).Extract()
102+
t.Logf("Unreserving volume")
103+
err = volumeactions.Unreserve(client, cv.ID).ExtractErr()
104+
th.AssertNoErr(t, err)
105+
106+
err = volumes.WaitForStatus(client, cv.ID, "available", 60)
107+
th.AssertNoErr(t, err)
108+
}
109+
110+
func TestVolumeConns(t *testing.T) {
111+
client, err := newClient(t)
112+
th.AssertNoErr(t, err)
113+
114+
t.Logf("Creating volume")
115+
cv, err := volumes.Create(client, &volumes.CreateOpts{
116+
Size: 1,
117+
Name: "blockv2-volume",
118+
}).Extract()
92119
th.AssertNoErr(t, err)
93120

121+
defer func() {
122+
err = volumes.WaitForStatus(client, cv.ID, "available", 60)
123+
th.AssertNoErr(t, err)
124+
125+
t.Logf("Deleting volume")
126+
err = volumes.Delete(client, cv.ID).ExtractErr()
127+
th.AssertNoErr(t, err)
128+
}()
129+
94130
err = volumes.WaitForStatus(client, cv.ID, "available", 60)
95131
th.AssertNoErr(t, err)
132+
133+
connOpts := &volumeactions.ConnectorOpts{
134+
IP: "127.0.0.1",
135+
Host: "stack",
136+
Initiator: "iqn.1994-05.com.redhat:17cf566367d2",
137+
Multipath: false,
138+
Platform: "x86_64",
139+
OSType: "linux2",
140+
}
141+
142+
t.Logf("Initializing connection")
143+
_, err = volumeactions.InitializeConnection(client, cv.ID, connOpts).Extract()
144+
th.AssertNoErr(t, err)
145+
146+
t.Logf("Terminating connection")
147+
err = volumeactions.TerminateConnection(client, cv.ID, connOpts).ExtractErr()
148+
th.AssertNoErr(t, err)
96149
}

openstack/blockstorage/v2/extensions/volumeactions/requests.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func Attach(client *gophercloud.ServiceClient, id string, opts AttachOptsBuilder
6262
return res
6363
}
6464

65-
_, res.Err = client.Post(attachURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
65+
_, res.Err = client.Post(attachURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
6666
OkCodes: []int{202},
6767
})
6868

@@ -76,7 +76,7 @@ func Detach(client *gophercloud.ServiceClient, id string) DetachResult {
7676
v := make(map[string]interface{})
7777
reqBody := map[string]interface{}{"os-detach": v}
7878

79-
_, res.Err = client.Post(detachURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
79+
_, res.Err = client.Post(detachURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
8080
OkCodes: []int{202},
8181
})
8282

@@ -90,7 +90,7 @@ func Reserve(client *gophercloud.ServiceClient, id string) ReserveResult {
9090
v := make(map[string]interface{})
9191
reqBody := map[string]interface{}{"os-reserve": v}
9292

93-
_, res.Err = client.Post(reserveURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
93+
_, res.Err = client.Post(reserveURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
9494
OkCodes: []int{200, 201, 202},
9595
})
9696

@@ -104,7 +104,7 @@ func Unreserve(client *gophercloud.ServiceClient, id string) UnreserveResult {
104104
v := make(map[string]interface{})
105105
reqBody := map[string]interface{}{"os-unreserve": v}
106106

107-
_, res.Err = client.Post(unreserveURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
107+
_, res.Err = client.Post(unreserveURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
108108
OkCodes: []int{200, 201, 202},
109109
})
110110

@@ -193,8 +193,8 @@ func TerminateConnection(client *gophercloud.ServiceClient, id string, opts *Con
193193

194194
reqBody := map[string]interface{}{"os-terminate_connection": connctorMap}
195195

196-
_, res.Err = client.Post(teminateConnectionURL(client, id), reqBody, &res.Body, &gophercloud.RequestOpts{
197-
OkCodes: []int{200, 201, 202},
196+
_, res.Err = client.Post(teminateConnectionURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
197+
OkCodes: []int{202},
198198
})
199199

200200
return res

openstack/blockstorage/v2/extensions/volumeactions/results.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ type commonResult struct {
1111

1212
// AttachResult contains the response body and error from a Get request.
1313
type AttachResult struct {
14-
commonResult
14+
gophercloud.ErrResult
1515
}
1616

1717
// DetachResult contains the response body and error from a Get request.
1818
type DetachResult struct {
19-
commonResult
19+
gophercloud.ErrResult
2020
}
2121

2222
// ReserveResult contains the response body and error from a Get request.
2323
type ReserveResult struct {
24-
commonResult
24+
gophercloud.ErrResult
2525
}
2626

2727
// UnreserveResult contains the response body and error from a Get request.
2828
type UnreserveResult struct {
29-
commonResult
29+
gophercloud.ErrResult
3030
}
3131

3232
// InitializeConnectionResult contains the response body and error from a Get request.
@@ -36,7 +36,7 @@ type InitializeConnectionResult struct {
3636

3737
// TerminateConnectionResult contains the response body and error from a Get request.
3838
type TerminateConnectionResult struct {
39-
commonResult
39+
gophercloud.ErrResult
4040
}
4141

4242
// Extract will get the Volume object out of the commonResult object.
@@ -46,7 +46,6 @@ func (r commonResult) Extract() (map[string]interface{}, error) {
4646
}
4747

4848
var res map[string]interface{}
49-
5049
err := mapstructure.Decode(r.Body, &res)
5150

5251
return res, err

0 commit comments

Comments
 (0)