Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame] | 1 | // +build acceptance compute quotasets |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame] | 6 | "fmt" |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 7 | "testing" |
| 8 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud" |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/acceptance/clients" |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 11 | "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets" |
| 12 | "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants" |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 13 | ) |
| 14 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame] | 15 | func TestQuotasetGet(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 16 | client, err := clients.NewComputeV2Client() |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 17 | if err != nil { |
| 18 | t.Fatalf("Unable to create a compute client: %v", err) |
| 19 | } |
| 20 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 21 | identityClient, err := clients.NewIdentityV2Client() |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame] | 22 | if err != nil { |
| 23 | t.Fatalf("Unable to get a new identity client: %v", err) |
| 24 | } |
| 25 | |
| 26 | tenantID, err := getTenantID(t, identityClient) |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 27 | if err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame] | 31 | quotaSet, err := quotasets.Get(client, tenantID).Extract() |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 35 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 36 | PrintQuotaSet(t, quotaSet) |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 37 | } |
| 38 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame] | 39 | func getTenantID(t *testing.T, client *gophercloud.ServiceClient) (string, error) { |
| 40 | allPages, err := tenants.List(client, nil).AllPages() |
| 41 | if err != nil { |
| 42 | t.Fatalf("Unable to get list of tenants: %v", err) |
| 43 | } |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 44 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame] | 45 | allTenants, err := tenants.ExtractTenants(allPages) |
| 46 | if err != nil { |
| 47 | t.Fatalf("Unable to extract tenants: %v", err) |
| 48 | } |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 49 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame] | 50 | for _, tenant := range allTenants { |
| 51 | return tenant.ID, nil |
| 52 | } |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 53 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame] | 54 | return "", fmt.Errorf("Unable to get tenant ID") |
| 55 | } |