blob: 11025a053cc4e81aaf54ff08411646588539d6dd [file] [log] [blame]
Jon Perrittee6074f2014-04-30 18:42:32 -05001// +build acceptance
2
3package openstack
4
5import (
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
15func 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
57func TestVolumes(t *testing.T) {
58 client, err := getClient()
59 if err != nil {
60 t.Error(err)
61 return
62 }
Jon Perritt70dd47d2014-05-01 13:51:53 -050063 nv, err := volumes.Create(client, volumes.CreateOpts{
Jon Perritt3baca062014-04-30 23:33:04 -050064 "size": 1,
65 "display_name": "test-volume",
Jon Perrittee6074f2014-04-30 18:42:32 -050066 })
67 if err != nil {
68 t.Error(err)
69 return
70 }
Jon Perritt70dd47d2014-05-01 13:51:53 -050071
Jon Perritte77b9b22014-05-01 13:11:12 -050072 defer func() {
73 err = volumes.Delete(client, volumes.DeleteOpts{
Jon Perritt70dd47d2014-05-01 13:51:53 -050074 "id": nv.Id,
Jon Perritte77b9b22014-05-01 13:11:12 -050075 })
76 }()
Jon Perritt70dd47d2014-05-01 13:51:53 -050077
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 Perrittee6074f2014-04-30 18:42:32 -050086}