blob: 60b85634310653b2d967f818ecfcc8fd78f0f196 [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"
jrperritt3d966162016-06-06 14:08:54 -050010 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
11 "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060012)
13
Joe Topjian713e51a2016-07-25 19:06:25 +000014func TestQuotasetGet(t *testing.T) {
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060015 client, err := newClient()
16 if err != nil {
17 t.Fatalf("Unable to create a compute client: %v", err)
18 }
19
Joe Topjian713e51a2016-07-25 19:06:25 +000020 identityClient, err := newIdentityClient()
21 if err != nil {
22 t.Fatalf("Unable to get a new identity client: %v", err)
23 }
24
25 tenantID, err := getTenantID(t, identityClient)
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060026 if err != nil {
27 t.Fatal(err)
28 }
29
Joe Topjian713e51a2016-07-25 19:06:25 +000030 quotaSet, err := quotasets.Get(client, tenantID).Extract()
31 if err != nil {
32 t.Fatal(err)
33 }
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060034
Joe Topjian713e51a2016-07-25 19:06:25 +000035 printQuotaSet(t, quotaSet)
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060036}
37
Joe Topjian713e51a2016-07-25 19:06:25 +000038func getTenantID(t *testing.T, client *gophercloud.ServiceClient) (string, error) {
39 allPages, err := tenants.List(client, nil).AllPages()
40 if err != nil {
41 t.Fatalf("Unable to get list of tenants: %v", err)
42 }
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060043
Joe Topjian713e51a2016-07-25 19:06:25 +000044 allTenants, err := tenants.ExtractTenants(allPages)
45 if err != nil {
46 t.Fatalf("Unable to extract tenants: %v", err)
47 }
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060048
Joe Topjian713e51a2016-07-25 19:06:25 +000049 for _, tenant := range allTenants {
50 return tenant.ID, nil
51 }
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060052
Joe Topjian713e51a2016-07-25 19:06:25 +000053 return "", fmt.Errorf("Unable to get tenant ID")
54}
55
56func printQuotaSet(t *testing.T, quotaSet *quotasets.QuotaSet) {
57 t.Logf("instances: %d\n", quotaSet.Instances)
58 t.Logf("cores: %d\n", quotaSet.Cores)
59 t.Logf("ram: %d\n", quotaSet.Ram)
60 t.Logf("key_pairs: %d\n", quotaSet.KeyPairs)
61 t.Logf("metadata_items: %d\n", quotaSet.MetadataItems)
62 t.Logf("security_groups: %d\n", quotaSet.SecurityGroups)
63 t.Logf("security_group_rules: %d\n", quotaSet.SecurityGroupRules)
64 t.Logf("fixed_ips: %d\n", quotaSet.FixedIps)
65 t.Logf("floating_ips: %d\n", quotaSet.FloatingIps)
66 t.Logf("injected_file_content_bytes: %d\n", quotaSet.InjectedFileContentBytes)
67 t.Logf("injected_file_path_bytes: %d\n", quotaSet.InjectedFilePathBytes)
68 t.Logf("injected_files: %d\n", quotaSet.InjectedFiles)
Dan Kirkwooded3f5fd2016-03-16 12:41:47 -060069}