blob: 2949d5660a8682da26874b7863e5d81fb0fc299a [file] [log] [blame]
Sylvain Baubeaufdd34592014-02-20 18:40:10 +01001# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
2#
3# Author: Sylvain Baubeau <sylvain.baubeau@enovance.com>
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17from tempest.api.volume import base
18from tempest import test
19
20QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes']
21QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use']
22
23
24class VolumeQuotasAdminTestJSON(base.BaseVolumeV1AdminTest):
25 _interface = "json"
Matt Riedemann5349cfd2014-03-12 07:38:55 -070026 force_tenant_isolation = True
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010027
28 @classmethod
29 def setUpClass(cls):
30 super(VolumeQuotasAdminTestJSON, cls).setUpClass()
31 cls.admin_volume_client = cls.os_adm.volumes_client
32 cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get(
33 'tenantId')
34
35 @test.attr(type='gate')
36 def test_list_quotas(self):
37 resp, quotas = self.quotas_client.get_quota_set(self.demo_tenant_id)
38 self.assertEqual(200, resp.status)
39 for key in QUOTA_KEYS:
40 self.assertIn(key, quotas)
41
42 @test.attr(type='gate')
43 def test_list_default_quotas(self):
44 resp, quotas = self.quotas_client.get_default_quota_set(
45 self.demo_tenant_id)
46 self.assertEqual(200, resp.status)
47 for key in QUOTA_KEYS:
48 self.assertIn(key, quotas)
49
50 @test.attr(type='gate')
51 def test_update_all_quota_resources_for_tenant(self):
52 # Admin can update all the resource quota limits for a tenant
53 resp, default_quota_set = self.quotas_client.get_default_quota_set(
54 self.demo_tenant_id)
55 new_quota_set = {'gigabytes': 1009,
56 'volumes': 11,
57 'snapshots': 11}
58
59 # Update limits for all quota resources
60 resp, quota_set = self.quotas_client.update_quota_set(
61 self.demo_tenant_id,
62 **new_quota_set)
63
Cory Stone2cb18262014-03-19 14:14:03 -050064 cleanup_quota_set = dict(
65 (k, v) for k, v in default_quota_set.iteritems()
66 if k in QUOTA_KEYS)
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010067 self.addCleanup(self.quotas_client.update_quota_set,
Cory Stone2cb18262014-03-19 14:14:03 -050068 self.demo_tenant_id, **cleanup_quota_set)
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010069 self.assertEqual(200, resp.status)
Sean Dague27a8c562014-03-19 07:46:42 -040070 # test that the specific values we set are actually in
71 # the final result. There is nothing here that ensures there
72 # would be no other values in there.
73 self.assertDictContainsSubset(new_quota_set, quota_set)
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010074
75 @test.attr(type='gate')
76 def test_show_quota_usage(self):
77 resp, quota_usage = self.quotas_client.get_quota_usage(self.adm_tenant)
78 self.assertEqual(200, resp.status)
79 for key in QUOTA_KEYS:
80 self.assertIn(key, quota_usage)
81 for usage_key in QUOTA_USAGE_KEYS:
82 self.assertIn(usage_key, quota_usage[key])
83
84 @test.attr(type='gate')
85 def test_quota_usage(self):
86 resp, quota_usage = self.quotas_client.get_quota_usage(
87 self.demo_tenant_id)
88
89 volume = self.create_volume(size=1)
90 self.addCleanup(self.admin_volume_client.delete_volume,
91 volume['id'])
92
93 resp, new_quota_usage = self.quotas_client.get_quota_usage(
94 self.demo_tenant_id)
95
96 self.assertEqual(200, resp.status)
97 self.assertEqual(quota_usage['volumes']['in_use'] + 1,
98 new_quota_usage['volumes']['in_use'])
99
100 self.assertEqual(quota_usage['gigabytes']['in_use'] + 1,
101 new_quota_usage['gigabytes']['in_use'])
102
103
104class VolumeQuotasAdminTestXML(VolumeQuotasAdminTestJSON):
105 _interface = "xml"