Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 1 | // +build acceptance blockstorage |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 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 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/acceptance/tools" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots" |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 11 | ) |
| 12 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 13 | func TestSnapshotsList(t *testing.T) { |
| 14 | client, err := clients.NewBlockStorageV1Client() |
| 15 | if err != nil { |
| 16 | t.Fatalf("Unable to create a blockstorage client: %v", err) |
| 17 | } |
Jon Perritt | d4788f9 | 2014-09-24 12:05:27 -0500 | [diff] [blame] | 18 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 19 | allPages, err := snapshots.List(client, snapshots.ListOpts{}).AllPages() |
| 20 | if err != nil { |
| 21 | t.Fatalf("Unable to retrieve snapshots: %v", err) |
| 22 | } |
Jon Perritt | 46be1a1 | 2014-11-03 09:18:24 -0600 | [diff] [blame] | 23 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 24 | allSnapshots, err := snapshots.ExtractSnapshots(allPages) |
| 25 | if err != nil { |
| 26 | t.Fatalf("Unable to extract snapshots: %v", err) |
| 27 | } |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 28 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 29 | for _, snapshot := range allSnapshots { |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 30 | tools.PrintResource(t, snapshot) |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 31 | } |
| 32 | } |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 33 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 34 | func TestSnapshotsCreateDelete(t *testing.T) { |
| 35 | client, err := clients.NewBlockStorageV1Client() |
| 36 | if err != nil { |
| 37 | t.Fatalf("Unable to create a blockstorage client: %v", err) |
| 38 | } |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 39 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 40 | volume, err := CreateVolume(t, client) |
| 41 | if err != nil { |
| 42 | t.Fatalf("Unable to create volume: %v", err) |
| 43 | } |
| 44 | defer DeleteVolume(t, client, volume) |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 45 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 46 | snapshot, err := CreateSnapshot(t, client, volume) |
| 47 | if err != nil { |
| 48 | t.Fatalf("Unable to create snapshot: %v", err) |
| 49 | } |
| 50 | defer DeleteSnapshotshot(t, client, snapshot) |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 51 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 52 | newSnapshot, err := snapshots.Get(client, snapshot.ID).Extract() |
| 53 | if err != nil { |
| 54 | t.Errorf("Unable to retrieve snapshot: %v", err) |
| 55 | } |
Jon Perritt | 57ba763 | 2014-10-02 20:32:22 -0500 | [diff] [blame] | 56 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 57 | tools.PrintResource(t, newSnapshot) |
Jon Perritt | d039957 | 2014-09-22 18:03:02 -0500 | [diff] [blame] | 58 | } |