blob: f86f9adedd3d9fd6b64f117e7d82f3ce24ccd5bc [file] [log] [blame]
Jamie Hannaford4c2a1f22014-10-23 17:31:55 +02001// +build acceptance blockstorage volumes
2
Jamie Hannafordaf209d12014-10-22 12:37:48 +02003package v1
Jamie Hannaford48a80ce2014-10-23 14:49:51 +02004
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 os "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
10 "github.com/rackspace/gophercloud/pagination"
11 "github.com/rackspace/gophercloud/rackspace/blockstorage/v1/volumes"
12 th "github.com/rackspace/gophercloud/testhelper"
13)
14
15func TestVolumes(t *testing.T) {
16 client := setup(t)
17
18 t.Logf("Listing volumes")
19 testVolumeList(t, client)
20
21 t.Logf("Creating volume")
22 volumeID := testVolumeCreate(t, client)
23
24 t.Logf("Getting volume %s", volumeID)
25 testVolumeGet(t, client, volumeID)
26
27 t.Logf("Updating volume %s", volumeID)
28 testVolumeUpdate(t, client, volumeID)
29
30 t.Logf("Deleting volume %s", volumeID)
31 testVolumeDelete(t, client, volumeID)
32}
33
34func testVolumeList(t *testing.T, client *gophercloud.ServiceClient) {
35 volumes.List(client).EachPage(func(page pagination.Page) (bool, error) {
36 vList, err := volumes.ExtractVolumes(page)
37 th.AssertNoErr(t, err)
38
39 for _, v := range vList {
40 t.Logf("Volume: ID [%s] Name [%s] Type [%s] Created [%s]", v.ID, v.Name,
41 v.VolumeType, v.CreatedAt)
42 }
43
44 return true, nil
45 })
46}
47
48func testVolumeCreate(t *testing.T, client *gophercloud.ServiceClient) string {
49 vol, err := volumes.Create(client, os.CreateOpts{Size: 75}).Extract()
50 th.AssertNoErr(t, err)
51 t.Logf("Created volume: ID [%s] Size [%s]", vol.ID, vol.Size)
52 return vol.ID
53}
54
55func testVolumeGet(t *testing.T, client *gophercloud.ServiceClient, id string) {
56 vol, err := volumes.Get(client, id).Extract()
57 th.AssertNoErr(t, err)
58 t.Logf("Created volume: ID [%s] Size [%s]", vol.ID, vol.Size)
59}
60
61func testVolumeUpdate(t *testing.T, client *gophercloud.ServiceClient, id string) {
62 vol, err := volumes.Update(client, id, volumes.UpdateOpts{Name: "new_name"}).Extract()
63 th.AssertNoErr(t, err)
64 t.Logf("Created volume: ID [%s] Name [%s]", vol.ID, vol.Name)
65}
66
67func testVolumeDelete(t *testing.T, client *gophercloud.ServiceClient, id string) {
Jamie Hannaforde4e6dfe2014-10-27 11:50:29 +010068 res := volumes.Delete(client, id)
69 th.AssertNoErr(t, res.Err)
Jamie Hannaford48a80ce2014-10-23 14:49:51 +020070 t.Logf("Deleted volume %s", id)
71}