Jon Perritt | ee6074f | 2014-04-30 18:42:32 -0500 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package openstack |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | blockstorage "github.com/rackspace/gophercloud/openstack/blockstorage/v1" |
| 8 | "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes" |
| 9 | "github.com/rackspace/gophercloud/openstack/identity" |
| 10 | "github.com/rackspace/gophercloud/openstack/utils" |
| 11 | "os" |
| 12 | "testing" |
| 13 | ) |
| 14 | |
| 15 | func getClient() (*blockstorage.Client, error) { |
| 16 | ao, err := utils.AuthOptions() |
| 17 | if err != nil { |
| 18 | return nil, err |
| 19 | } |
| 20 | |
| 21 | r, err := identity.Authenticate(ao) |
| 22 | if err != nil { |
| 23 | return nil, err |
| 24 | } |
| 25 | |
| 26 | sc, err := identity.GetServiceCatalog(r) |
| 27 | if err != nil { |
| 28 | return nil, err |
| 29 | } |
| 30 | |
| 31 | ces, err := sc.CatalogEntries() |
| 32 | if err != nil { |
| 33 | return nil, err |
| 34 | } |
| 35 | |
| 36 | var eps []identity.Endpoint |
| 37 | for _, ce := range ces { |
| 38 | if ce.Type == "volume" { |
| 39 | eps = ce.Endpoints |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | region := os.Getenv("OS_REGION_NAME") |
| 44 | rep := "" |
| 45 | for _, ep := range eps { |
| 46 | if ep.Region == region { |
| 47 | rep = ep.PublicURL |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | client := blockstorage.NewClient(rep, r, ao) |
| 52 | |
| 53 | return client, nil |
| 54 | |
| 55 | } |
| 56 | |
| 57 | func TestVolumes(t *testing.T) { |
| 58 | client, err := getClient() |
| 59 | if err != nil { |
| 60 | t.Error(err) |
| 61 | return |
| 62 | } |
Jon Perritt | 70dd47d | 2014-05-01 13:51:53 -0500 | [diff] [blame^] | 63 | nv, err := volumes.Create(client, volumes.CreateOpts{ |
Jon Perritt | 3baca06 | 2014-04-30 23:33:04 -0500 | [diff] [blame] | 64 | "size": 1, |
| 65 | "display_name": "test-volume", |
Jon Perritt | ee6074f | 2014-04-30 18:42:32 -0500 | [diff] [blame] | 66 | }) |
| 67 | if err != nil { |
| 68 | t.Error(err) |
| 69 | return |
| 70 | } |
Jon Perritt | 70dd47d | 2014-05-01 13:51:53 -0500 | [diff] [blame^] | 71 | |
Jon Perritt | e77b9b2 | 2014-05-01 13:11:12 -0500 | [diff] [blame] | 72 | defer func() { |
| 73 | err = volumes.Delete(client, volumes.DeleteOpts{ |
Jon Perritt | 70dd47d | 2014-05-01 13:51:53 -0500 | [diff] [blame^] | 74 | "id": nv.Id, |
Jon Perritt | e77b9b2 | 2014-05-01 13:11:12 -0500 | [diff] [blame] | 75 | }) |
| 76 | }() |
Jon Perritt | 70dd47d | 2014-05-01 13:51:53 -0500 | [diff] [blame^] | 77 | |
| 78 | gv, err := volumes.Get(client, volumes.GetOpts{ |
| 79 | "id": nv.Id, |
| 80 | }) |
| 81 | if err != nil { |
| 82 | t.Error(err) |
| 83 | return |
| 84 | } |
| 85 | fmt.Printf("%+v\n", gv) |
Jon Perritt | ee6074f | 2014-04-30 18:42:32 -0500 | [diff] [blame] | 86 | } |