blob: 354537187a64f977a24e561b5a57f53b8f265f71 [file] [log] [blame]
Joe Topjian68bed5f2016-08-10 15:30:57 -06001// +build acceptance blockstorage
Jon Perrittd0399572014-09-22 18:03:02 -05002
Jon Perrittb71a28a2014-09-17 18:16:32 -05003package v1
Jon Perrittd0399572014-09-22 18:03:02 -05004
5import (
Jon Perrittd0399572014-09-22 18:03:02 -05006 "testing"
Jon Perrittd0399572014-09-22 18:03:02 -05007
Joe Topjian68bed5f2016-08-10 15:30:57 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
Joe Topjian66a046c2017-01-19 22:07:26 -07009 "github.com/gophercloud/gophercloud/acceptance/tools"
Jon Perritt27249f42016-02-18 10:35:59 -060010 "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots"
Jon Perrittd0399572014-09-22 18:03:02 -050011)
12
Joe Topjian68bed5f2016-08-10 15:30:57 -060013func 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 Perrittd4788f92014-09-24 12:05:27 -050018
Joe Topjian68bed5f2016-08-10 15:30:57 -060019 allPages, err := snapshots.List(client, snapshots.ListOpts{}).AllPages()
20 if err != nil {
21 t.Fatalf("Unable to retrieve snapshots: %v", err)
22 }
Jon Perritt46be1a12014-11-03 09:18:24 -060023
Joe Topjian68bed5f2016-08-10 15:30:57 -060024 allSnapshots, err := snapshots.ExtractSnapshots(allPages)
25 if err != nil {
26 t.Fatalf("Unable to extract snapshots: %v", err)
27 }
Jon Perritt57ba7632014-10-02 20:32:22 -050028
Joe Topjian68bed5f2016-08-10 15:30:57 -060029 for _, snapshot := range allSnapshots {
Joe Topjian66a046c2017-01-19 22:07:26 -070030 tools.PrintResource(t, snapshot)
Joe Topjian68bed5f2016-08-10 15:30:57 -060031 }
32}
Jon Perritt57ba7632014-10-02 20:32:22 -050033
Joe Topjian68bed5f2016-08-10 15:30:57 -060034func 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 Perritt57ba7632014-10-02 20:32:22 -050039
Joe Topjian68bed5f2016-08-10 15:30:57 -060040 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 Perritt57ba7632014-10-02 20:32:22 -050045
Joe Topjian68bed5f2016-08-10 15:30:57 -060046 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 Perritt57ba7632014-10-02 20:32:22 -050051
Joe Topjian68bed5f2016-08-10 15:30:57 -060052 newSnapshot, err := snapshots.Get(client, snapshot.ID).Extract()
53 if err != nil {
54 t.Errorf("Unable to retrieve snapshot: %v", err)
55 }
Jon Perritt57ba7632014-10-02 20:32:22 -050056
Joe Topjian66a046c2017-01-19 22:07:26 -070057 tools.PrintResource(t, newSnapshot)
Jon Perrittd0399572014-09-22 18:03:02 -050058}