blob: 9edf31af1454598c2ad8749b1aa686a53864a06f [file] [log] [blame]
feiskycf0c7fe2015-11-05 22:06:17 +08001// +build acceptance blockstorage
2
3package v2
4
5import (
6 "os"
7 "testing"
8
jrperritt9b7b9e62016-07-11 22:30:50 -05009 "github.com/gophercloud/gophercloud"
10 "github.com/gophercloud/gophercloud/openstack"
11 "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
12 "github.com/gophercloud/gophercloud/pagination"
13 th "github.com/gophercloud/gophercloud/testhelper"
feiskycf0c7fe2015-11-05 22:06:17 +080014)
15
16func newClient(t *testing.T) (*gophercloud.ServiceClient, error) {
17 ao, err := openstack.AuthOptionsFromEnv()
18 th.AssertNoErr(t, err)
19
20 client, err := openstack.AuthenticatedClient(ao)
21 th.AssertNoErr(t, err)
22
23 return openstack.NewBlockStorageV2(client, gophercloud.EndpointOpts{
24 Region: os.Getenv("OS_REGION_NAME"),
25 })
26}
27
28func TestVolumes(t *testing.T) {
29 client, err := newClient(t)
30 th.AssertNoErr(t, err)
31
32 cv, err := volumes.Create(client, &volumes.CreateOpts{
33 Size: 1,
34 Name: "blockv2-volume",
35 }).Extract()
36 th.AssertNoErr(t, err)
37 defer func() {
38 err = volumes.WaitForStatus(client, cv.ID, "available", 60)
39 th.AssertNoErr(t, err)
40 err = volumes.Delete(client, cv.ID).ExtractErr()
41 th.AssertNoErr(t, err)
42 }()
43
44 _, err = volumes.Update(client, cv.ID, &volumes.UpdateOpts{
45 Name: "blockv2-updated-volume",
46 }).Extract()
47 th.AssertNoErr(t, err)
48
49 v, err := volumes.Get(client, cv.ID).Extract()
50 th.AssertNoErr(t, err)
51 t.Logf("Got volume: %+v\n", v)
52
53 if v.Name != "blockv2-updated-volume" {
54 t.Errorf("Unable to update volume: Expected name: blockv2-updated-volume\nActual name: %s", v.Name)
55 }
56
57 err = volumes.List(client, &volumes.ListOpts{Name: "blockv2-updated-volume"}).EachPage(func(page pagination.Page) (bool, error) {
58 vols, err := volumes.ExtractVolumes(page)
59 th.CheckEquals(t, 1, len(vols))
60 return true, err
61 })
62 th.AssertNoErr(t, err)
63}