Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 1 | // +build acceptance compute |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 8 | "github.com/gophercloud/gophercloud" |
| 9 | "github.com/gophercloud/gophercloud/openstack" |
| 10 | "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets" |
| 11 | "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants" |
| 12 | "github.com/gophercloud/gophercloud/pagination" |
| 13 | th "github.com/gophercloud/gophercloud/testhelper" |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 14 | ) |
| 15 | |
| 16 | func TestGetQuotaset(t *testing.T) { |
| 17 | client, err := newClient() |
| 18 | if err != nil { |
| 19 | t.Fatalf("Unable to create a compute client: %v", err) |
| 20 | } |
| 21 | |
| 22 | idclient := openstack.NewIdentityV2(client.ProviderClient) |
| 23 | quotaset, err := quotasets.Get(client, findTenant(t, idclient)).Extract() |
| 24 | if err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | |
| 28 | t.Logf("QuotaSet details:\n") |
| 29 | t.Logf(" instances=[%d]\n", quotaset.Instances) |
| 30 | t.Logf(" cores=[%d]\n", quotaset.Cores) |
| 31 | t.Logf(" ram=[%d]\n", quotaset.Ram) |
| 32 | t.Logf(" key_pairs=[%d]\n", quotaset.KeyPairs) |
| 33 | t.Logf(" metadata_items=[%d]\n", quotaset.MetadataItems) |
| 34 | t.Logf(" security_groups=[%d]\n", quotaset.SecurityGroups) |
| 35 | t.Logf(" security_group_rules=[%d]\n", quotaset.SecurityGroupRules) |
| 36 | t.Logf(" fixed_ips=[%d]\n", quotaset.FixedIps) |
| 37 | t.Logf(" floating_ips=[%d]\n", quotaset.FloatingIps) |
| 38 | t.Logf(" injected_file_content_bytes=[%d]\n", quotaset.InjectedFileContentBytes) |
| 39 | t.Logf(" injected_file_path_bytes=[%d]\n", quotaset.InjectedFilePathBytes) |
| 40 | t.Logf(" injected_files=[%d]\n", quotaset.InjectedFiles) |
| 41 | |
| 42 | } |
| 43 | |
| 44 | func findTenant(t *testing.T, client *gophercloud.ServiceClient) string { |
| 45 | var tenantID string |
| 46 | err := tenants.List(client, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 47 | tenantList, err := tenants.ExtractTenants(page) |
| 48 | th.AssertNoErr(t, err) |
| 49 | |
| 50 | for _, t := range tenantList { |
| 51 | tenantID = t.ID |
| 52 | break |
| 53 | } |
| 54 | |
| 55 | return true, nil |
| 56 | }) |
| 57 | th.AssertNoErr(t, err) |
| 58 | |
| 59 | return tenantID |
| 60 | } |