blob: 7741aa98416865759fc383996efb757a02215602 [file] [log] [blame]
Jon Perrittd0399572014-09-22 18:03:02 -05001// +build acceptance
2
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
Jon Perritt56d43b22014-09-22 20:47:11 -05008 "github.com/rackspace/gophercloud"
Jon Perritt57ba7632014-10-02 20:32:22 -05009 "github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots"
10 "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
jrperritt4508d5f2014-10-28 10:07:04 -050011 th "github.com/rackspace/gophercloud/testhelper"
Jon Perrittd0399572014-09-22 18:03:02 -050012)
13
Jon Perrittd0399572014-09-22 18:03:02 -050014func TestSnapshots(t *testing.T) {
Jon Perrittd4788f92014-09-24 12:05:27 -050015
Jon Perritt46be1a12014-11-03 09:18:24 -060016 client, err := newClient(t)
jrperritt4508d5f2014-10-28 10:07:04 -050017 th.AssertNoErr(t, err)
Jon Perritt46be1a12014-11-03 09:18:24 -060018
Jon Perritt57ba7632014-10-02 20:32:22 -050019 v, err := volumes.Create(client, &volumes.CreateOpts{
20 Name: "gophercloud-test-volume",
21 Size: 1,
22 }).Extract()
jrperritt4508d5f2014-10-28 10:07:04 -050023 th.AssertNoErr(t, err)
Jon Perritt57ba7632014-10-02 20:32:22 -050024
25 err = volumes.WaitForStatus(client, v.ID, "available", 120)
jrperritt4508d5f2014-10-28 10:07:04 -050026 th.AssertNoErr(t, err)
Jon Perritt57ba7632014-10-02 20:32:22 -050027
28 t.Logf("Created volume: %v\n", v)
29
30 ss, err := snapshots.Create(client, &snapshots.CreateOpts{
Jon Perrittd4788f92014-09-24 12:05:27 -050031 Name: "gophercloud-test-snapshot",
Jon Perritt57ba7632014-10-02 20:32:22 -050032 VolumeID: v.ID,
33 }).Extract()
jrperritt4508d5f2014-10-28 10:07:04 -050034 th.AssertNoErr(t, err)
Jon Perritt57ba7632014-10-02 20:32:22 -050035
36 err = snapshots.WaitForStatus(client, ss.ID, "available", 120)
jrperritt4508d5f2014-10-28 10:07:04 -050037 th.AssertNoErr(t, err)
Jon Perritt57ba7632014-10-02 20:32:22 -050038
39 t.Logf("Created snapshot: %+v\n", ss)
40
Jon Perrittba2395e2014-10-27 15:23:21 -050041 err = snapshots.Delete(client, ss.ID).ExtractErr()
jrperritt4508d5f2014-10-28 10:07:04 -050042 th.AssertNoErr(t, err)
Jon Perritt57ba7632014-10-02 20:32:22 -050043
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 Perrittd0399572014-09-22 18:03:02 -050051 })
jrperritt4508d5f2014-10-28 10:07:04 -050052 th.AssertNoErr(t, err)
Jon Perrittd0399572014-09-22 18:03:02 -050053
Jon Perritt57ba7632014-10-02 20:32:22 -050054 t.Log("Deleted snapshot\n")
55
Jon Perrittba2395e2014-10-27 15:23:21 -050056 err = volumes.Delete(client, v.ID).ExtractErr()
jrperritt4508d5f2014-10-28 10:07:04 -050057 th.AssertNoErr(t, err)
Jon Perrittd0399572014-09-22 18:03:02 -050058
Jon Perritt57ba7632014-10-02 20:32:22 -050059 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 Perrittd4788f92014-09-24 12:05:27 -050064
Jon Perritt57ba7632014-10-02 20:32:22 -050065 return false, nil
66 })
jrperritt4508d5f2014-10-28 10:07:04 -050067 th.AssertNoErr(t, err)
Jon Perrittd7468632014-09-22 21:58:59 -050068
Jon Perritt57ba7632014-10-02 20:32:22 -050069 t.Log("Deleted volume\n")
Jon Perrittd0399572014-09-22 18:03:02 -050070}