blob: 531e14519c5f5cd60ad813116d8f1d3725fd84e5 [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
Andrea Frittoli86ad28d2014-03-20 10:09:12 +000032 cls.demo_tenant_id = cls.isolated_creds.get_primary_creds().tenant_id
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010033
34 @test.attr(type='gate')
35 def test_list_quotas(self):
36 resp, quotas = self.quotas_client.get_quota_set(self.demo_tenant_id)
37 self.assertEqual(200, resp.status)
38 for key in QUOTA_KEYS:
39 self.assertIn(key, quotas)
40
41 @test.attr(type='gate')
42 def test_list_default_quotas(self):
43 resp, quotas = self.quotas_client.get_default_quota_set(
44 self.demo_tenant_id)
45 self.assertEqual(200, resp.status)
46 for key in QUOTA_KEYS:
47 self.assertIn(key, quotas)
48
49 @test.attr(type='gate')
50 def test_update_all_quota_resources_for_tenant(self):
51 # Admin can update all the resource quota limits for a tenant
52 resp, default_quota_set = self.quotas_client.get_default_quota_set(
53 self.demo_tenant_id)
54 new_quota_set = {'gigabytes': 1009,
55 'volumes': 11,
56 'snapshots': 11}
57
58 # Update limits for all quota resources
59 resp, quota_set = self.quotas_client.update_quota_set(
60 self.demo_tenant_id,
61 **new_quota_set)
62
Cory Stone2cb18262014-03-19 14:14:03 -050063 cleanup_quota_set = dict(
64 (k, v) for k, v in default_quota_set.iteritems()
65 if k in QUOTA_KEYS)
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010066 self.addCleanup(self.quotas_client.update_quota_set,
Cory Stone2cb18262014-03-19 14:14:03 -050067 self.demo_tenant_id, **cleanup_quota_set)
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010068 self.assertEqual(200, resp.status)
Sean Dague27a8c562014-03-19 07:46:42 -040069 # test that the specific values we set are actually in
70 # the final result. There is nothing here that ensures there
71 # would be no other values in there.
72 self.assertDictContainsSubset(new_quota_set, quota_set)
Sylvain Baubeaufdd34592014-02-20 18:40:10 +010073
74 @test.attr(type='gate')
75 def test_show_quota_usage(self):
76 resp, quota_usage = self.quotas_client.get_quota_usage(self.adm_tenant)
77 self.assertEqual(200, resp.status)
78 for key in QUOTA_KEYS:
79 self.assertIn(key, quota_usage)
80 for usage_key in QUOTA_USAGE_KEYS:
81 self.assertIn(usage_key, quota_usage[key])
82
83 @test.attr(type='gate')
84 def test_quota_usage(self):
85 resp, quota_usage = self.quotas_client.get_quota_usage(
86 self.demo_tenant_id)
87
88 volume = self.create_volume(size=1)
89 self.addCleanup(self.admin_volume_client.delete_volume,
90 volume['id'])
91
92 resp, new_quota_usage = self.quotas_client.get_quota_usage(
93 self.demo_tenant_id)
94
95 self.assertEqual(200, resp.status)
96 self.assertEqual(quota_usage['volumes']['in_use'] + 1,
97 new_quota_usage['volumes']['in_use'])
98
99 self.assertEqual(quota_usage['gigabytes']['in_use'] + 1,
100 new_quota_usage['gigabytes']['in_use'])
101
102
103class VolumeQuotasAdminTestXML(VolumeQuotasAdminTestJSON):
104 _interface = "xml"