Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 1 | // +build acceptance blockstorage |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "os" |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 7 | "testing" |
| 8 | |
| 9 | "github.com/rackspace/gophercloud" |
| 10 | "github.com/rackspace/gophercloud/openstack" |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 11 | "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes" |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 12 | "github.com/rackspace/gophercloud/pagination" |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 13 | th "github.com/rackspace/gophercloud/testhelper" |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 14 | ) |
| 15 | |
Jon Perritt | 46be1a1 | 2014-11-03 09:18:24 -0600 | [diff] [blame] | 16 | func newClient(t *testing.T) (*gophercloud.ServiceClient, error) { |
Jamie Hannaford | 390555a | 2014-10-22 17:04:03 +0200 | [diff] [blame] | 17 | ao, err := openstack.AuthOptionsFromEnv() |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 18 | th.AssertNoErr(t, err) |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 19 | |
| 20 | client, err := openstack.AuthenticatedClient(ao) |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 21 | th.AssertNoErr(t, err) |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 22 | |
| 23 | return openstack.NewBlockStorageV1(client, gophercloud.EndpointOpts{ |
| 24 | Region: os.Getenv("OS_REGION_NAME"), |
| 25 | }) |
| 26 | } |
| 27 | |
| 28 | func TestVolumes(t *testing.T) { |
Jon Perritt | 46be1a1 | 2014-11-03 09:18:24 -0600 | [diff] [blame] | 29 | client, err := newClient(t) |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 30 | th.AssertNoErr(t, err) |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 31 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 32 | cv, err := volumes.Create(client, &volumes.CreateOpts{ |
| 33 | Size: 1, |
| 34 | Name: "gophercloud-test-volume", |
| 35 | }).Extract() |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 36 | th.AssertNoErr(t, err) |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 37 | defer func() { |
| 38 | err = volumes.WaitForStatus(client, cv.ID, "available", 60) |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 39 | th.AssertNoErr(t, err) |
Jon Perritt | ba2395e | 2014-10-27 15:23:21 -0500 | [diff] [blame] | 40 | err = volumes.Delete(client, cv.ID).ExtractErr() |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 41 | th.AssertNoErr(t, err) |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 42 | }() |
Jon Perritt | 3db65cd | 2014-09-17 18:32:43 -0500 | [diff] [blame] | 43 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 44 | _, err = volumes.Update(client, cv.ID, &volumes.UpdateOpts{ |
Jon Perritt | 97347a0 | 2014-09-21 13:34:48 -0500 | [diff] [blame] | 45 | Name: "gophercloud-updated-volume", |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 46 | }).Extract() |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 47 | th.AssertNoErr(t, err) |
Jon Perritt | 97347a0 | 2014-09-21 13:34:48 -0500 | [diff] [blame] | 48 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 49 | v, err := volumes.Get(client, cv.ID).Extract() |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 50 | th.AssertNoErr(t, err) |
Ash Wilson | 9a9f5bc | 2014-10-24 14:55:40 -0400 | [diff] [blame] | 51 | t.Logf("Got volume: %+v\n", v) |
Jon Perritt | 9b2bf7d | 2014-09-18 18:47:51 -0500 | [diff] [blame] | 52 | |
Jon Perritt | 97347a0 | 2014-09-21 13:34:48 -0500 | [diff] [blame] | 53 | if v.Name != "gophercloud-updated-volume" { |
| 54 | t.Errorf("Unable to update volume: Expected name: gophercloud-updated-volume\nActual name: %s", v.Name) |
| 55 | } |
| 56 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 57 | err = volumes.List(client, &volumes.ListOpts{Name: "gophercloud-updated-volume"}).EachPage(func(page pagination.Page) (bool, error) { |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 58 | vols, err := volumes.ExtractVolumes(page) |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 59 | th.CheckEquals(t, 1, len(vols)) |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 60 | return true, err |
| 61 | }) |
jrperritt | 0bfb099 | 2014-10-28 10:38:07 -0500 | [diff] [blame] | 62 | th.AssertNoErr(t, err) |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 63 | } |