Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 3 | package v1 |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 4 | |
| 5 | import ( |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 6 | "testing" |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 7 | |
Jon Perritt | 56d43b2 | 2014-09-22 20:47:11 -0500 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud" |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots" |
| 10 | "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes" |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 11 | th "github.com/rackspace/gophercloud/testhelper" |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 12 | ) |
| 13 | |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 14 | func TestSnapshots(t *testing.T) { |
Jon Perritt | d4788f9 | 2014-09-24 12:05:27 -0500 | [diff] [blame] | 15 | |
Jon Perritt | 46be1a1 | 2014-11-03 09:18:24 -0600 | [diff] [blame] | 16 | client, err := newClient(t) |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 17 | th.AssertNoErr(t, err) |
Jon Perritt | 46be1a1 | 2014-11-03 09:18:24 -0600 | [diff] [blame] | 18 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 19 | v, err := volumes.Create(client, &volumes.CreateOpts{ |
| 20 | Name: "gophercloud-test-volume", |
| 21 | Size: 1, |
| 22 | }).Extract() |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 23 | th.AssertNoErr(t, err) |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 24 | |
| 25 | err = volumes.WaitForStatus(client, v.ID, "available", 120) |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 26 | th.AssertNoErr(t, err) |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 27 | |
| 28 | t.Logf("Created volume: %v\n", v) |
| 29 | |
| 30 | ss, err := snapshots.Create(client, &snapshots.CreateOpts{ |
Jon Perritt | d4788f9 | 2014-09-24 12:05:27 -0500 | [diff] [blame] | 31 | Name: "gophercloud-test-snapshot", |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 32 | VolumeID: v.ID, |
| 33 | }).Extract() |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 34 | th.AssertNoErr(t, err) |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 35 | |
| 36 | err = snapshots.WaitForStatus(client, ss.ID, "available", 120) |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 37 | th.AssertNoErr(t, err) |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 38 | |
| 39 | t.Logf("Created snapshot: %+v\n", ss) |
| 40 | |
Jon Perritt | ba2395e | 2014-10-27 15:23:21 -0500 | [diff] [blame] | 41 | err = snapshots.Delete(client, ss.ID).ExtractErr() |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 42 | th.AssertNoErr(t, err) |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 43 | |
| 44 | err = gophercloud.WaitFor(120, func() (bool, error) { |
| 45 | _, err := snapshots.Get(client, ss.ID).Extract() |
| 46 | if err != nil { |
| 47 | return true, nil |
| 48 | } |
| 49 | |
| 50 | return false, nil |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 51 | }) |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 52 | th.AssertNoErr(t, err) |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 53 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 54 | t.Log("Deleted snapshot\n") |
| 55 | |
Jon Perritt | ba2395e | 2014-10-27 15:23:21 -0500 | [diff] [blame] | 56 | err = volumes.Delete(client, v.ID).ExtractErr() |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 57 | th.AssertNoErr(t, err) |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 58 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 59 | err = gophercloud.WaitFor(120, func() (bool, error) { |
| 60 | _, err := volumes.Get(client, v.ID).Extract() |
| 61 | if err != nil { |
| 62 | return true, nil |
| 63 | } |
Jon Perritt | d4788f9 | 2014-09-24 12:05:27 -0500 | [diff] [blame] | 64 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 65 | return false, nil |
| 66 | }) |
jrperritt | 4508d5f | 2014-10-28 10:07:04 -0500 | [diff] [blame] | 67 | th.AssertNoErr(t, err) |
Jon Perritt | d746863 | 2014-09-22 21:58:59 -0500 | [diff] [blame] | 68 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 69 | t.Log("Deleted volume\n") |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 70 | } |