blob: d9e73e98d984751b517dd10349ea33d8dcf2edd6 [file] [log] [blame]
Joe Topjian713e51a2016-07-25 19:06:25 +00001// +build acceptance compute quotasets
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -06002
3package v2
4
5import (
Joe Topjian713e51a2016-07-25 19:06:25 +00006 "fmt"
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -06007 "testing"
8
jrperritt3d966162016-06-06 14:08:54 -05009 "github.com/gophercloud/gophercloud"
Joe Topjian1c15e3f2016-08-08 10:48:38 -060010 "github.com/gophercloud/gophercloud/acceptance/clients"
jrperritt3d966162016-06-06 14:08:54 -050011 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
12 "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060013)
14
Joe Topjian713e51a2016-07-25 19:06:25 +000015func TestQuotasetGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060016 client, err := clients.NewComputeV2Client()
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060017 if err != nil {
18 t.Fatalf("Unable to create a compute client: %v", err)
19 }
20
Joe Topjian1c15e3f2016-08-08 10:48:38 -060021 identityClient, err := clients.NewIdentityV2Client()
Joe Topjian713e51a2016-07-25 19:06:25 +000022 if err != nil {
23 t.Fatalf("Unable to get a new identity client: %v", err)
24 }
25
26 tenantID, err := getTenantID(t, identityClient)
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060027 if err != nil {
28 t.Fatal(err)
29 }
30
Joe Topjian713e51a2016-07-25 19:06:25 +000031 quotaSet, err := quotasets.Get(client, tenantID).Extract()
32 if err != nil {
33 t.Fatal(err)
34 }
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060035
Joe Topjian1c15e3f2016-08-08 10:48:38 -060036 PrintQuotaSet(t, quotaSet)
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060037}
38
Joe Topjian713e51a2016-07-25 19:06:25 +000039func 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 Kirkwooded3f5fd2016-03-16 12:41:47 -060044
Joe Topjian713e51a2016-07-25 19:06:25 +000045 allTenants, err := tenants.ExtractTenants(allPages)
46 if err != nil {
47 t.Fatalf("Unable to extract tenants: %v", err)
48 }
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060049
Joe Topjian713e51a2016-07-25 19:06:25 +000050 for _, tenant := range allTenants {
51 return tenant.ID, nil
52 }
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060053
Joe Topjian713e51a2016-07-25 19:06:25 +000054 return "", fmt.Errorf("Unable to get tenant ID")
55}