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" |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 11 | ) |
| 12 | |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 13 | func TestSnapshots(t *testing.T) { |
Jon Perritt | d4788f9 | 2014-09-24 12:05:27 -0500 | [diff] [blame] | 14 | |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 15 | client, err := newClient() |
| 16 | if err != nil { |
| 17 | t.Fatalf("Failed to create Block Storage v1 client: %v", err) |
| 18 | } |
| 19 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 20 | v, err := volumes.Create(client, &volumes.CreateOpts{ |
| 21 | Name: "gophercloud-test-volume", |
| 22 | Size: 1, |
| 23 | }).Extract() |
| 24 | if err != nil { |
| 25 | t.Fatalf("Failed to create volume: %v\n", err) |
| 26 | } |
| 27 | |
| 28 | err = volumes.WaitForStatus(client, v.ID, "available", 120) |
| 29 | if err != nil { |
| 30 | t.Fatalf("Failed to create volume: %v\n", err) |
| 31 | } |
| 32 | |
| 33 | t.Logf("Created volume: %v\n", v) |
| 34 | |
| 35 | ss, err := snapshots.Create(client, &snapshots.CreateOpts{ |
Jon Perritt | d4788f9 | 2014-09-24 12:05:27 -0500 | [diff] [blame] | 36 | Name: "gophercloud-test-snapshot", |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 37 | VolumeID: v.ID, |
| 38 | }).Extract() |
| 39 | if err != nil { |
| 40 | t.Fatalf("Failed to create snapshot: %v\n", err) |
| 41 | } |
| 42 | |
| 43 | err = snapshots.WaitForStatus(client, ss.ID, "available", 120) |
| 44 | if err != nil { |
| 45 | t.Fatalf("Failed to create snapshot: %v\n", err) |
| 46 | } |
| 47 | |
| 48 | t.Logf("Created snapshot: %+v\n", ss) |
| 49 | |
Jon Perritt | 1f61778 | 2014-10-27 11:37:39 -0500 | [diff] [blame] | 50 | err = snapshots.Delete(client, ss.ID).Extract() |
| 51 | if err != nil { |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 52 | t.Fatalf("Failed to delete snapshot: %v", err) |
| 53 | } |
| 54 | |
| 55 | err = gophercloud.WaitFor(120, func() (bool, error) { |
| 56 | _, err := snapshots.Get(client, ss.ID).Extract() |
| 57 | if err != nil { |
| 58 | return true, nil |
| 59 | } |
| 60 | |
| 61 | return false, nil |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 62 | }) |
| 63 | if err != nil { |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 64 | t.Fatalf("Failed to delete snapshot: %v", err) |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 67 | t.Log("Deleted snapshot\n") |
| 68 | |
Jon Perritt | 1f61778 | 2014-10-27 11:37:39 -0500 | [diff] [blame] | 69 | err = volumes.Delete(client, v.ID).Extract() |
| 70 | if err != nil { |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 71 | t.Errorf("Failed to delete volume: %v", err) |
Jon Perritt | 56d43b2 | 2014-09-22 20:47:11 -0500 | [diff] [blame] | 72 | } |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 73 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 74 | err = gophercloud.WaitFor(120, func() (bool, error) { |
| 75 | _, err := volumes.Get(client, v.ID).Extract() |
| 76 | if err != nil { |
| 77 | return true, nil |
| 78 | } |
Jon Perritt | d4788f9 | 2014-09-24 12:05:27 -0500 | [diff] [blame] | 79 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 80 | return false, nil |
| 81 | }) |
| 82 | if err != nil { |
| 83 | t.Errorf("Failed to delete volume: %v", err) |
| 84 | } |
Jon Perritt | d746863 | 2014-09-22 21:58:59 -0500 | [diff] [blame] | 85 | |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 86 | t.Log("Deleted volume\n") |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 87 | } |