1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5#      http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13"""
14test_quotas
15----------------------------------
16
17Functional tests for `shade` quotas methods.
18"""
19
20from openstack.tests.functional import base
21
22
23class TestComputeQuotas(base.BaseFunctionalTest):
24
25    def test_quotas(self):
26        '''Test quotas functionality'''
27        quotas = self.operator_cloud.get_compute_quotas('demo')
28        cores = quotas['cores']
29        self.operator_cloud.set_compute_quotas('demo', cores=cores + 1)
30        self.assertEqual(
31            cores + 1,
32            self.operator_cloud.get_compute_quotas('demo')['cores'])
33        self.operator_cloud.delete_compute_quotas('demo')
34        self.assertEqual(
35            cores, self.operator_cloud.get_compute_quotas('demo')['cores'])
36
37
38class TestVolumeQuotas(base.BaseFunctionalTest):
39
40    def setUp(self):
41        super(TestVolumeQuotas, self).setUp()
42        if not self.operator_cloud.has_service('volume'):
43            self.skipTest('volume service not supported by cloud')
44
45    def test_quotas(self):
46        '''Test quotas functionality'''
47        quotas = self.operator_cloud.get_volume_quotas('demo')
48        volumes = quotas['volumes']
49        self.operator_cloud.set_volume_quotas('demo', volumes=volumes + 1)
50        self.assertEqual(
51            volumes + 1,
52            self.operator_cloud.get_volume_quotas('demo')['volumes'])
53        self.operator_cloud.delete_volume_quotas('demo')
54        self.assertEqual(
55            volumes,
56            self.operator_cloud.get_volume_quotas('demo')['volumes'])
57
58
59class TestNetworkQuotas(base.BaseFunctionalTest):
60
61    def setUp(self):
62        super(TestNetworkQuotas, self).setUp()
63        if not self.operator_cloud.has_service('network'):
64            self.skipTest('network service not supported by cloud')
65
66    def test_quotas(self):
67        '''Test quotas functionality'''
68        quotas = self.operator_cloud.get_network_quotas('demo')
69        network = quotas['network']
70        self.operator_cloud.set_network_quotas('demo', network=network + 1)
71        self.assertEqual(
72            network + 1,
73            self.operator_cloud.get_network_quotas('demo')['network'])
74        self.operator_cloud.delete_network_quotas('demo')
75        self.assertEqual(
76            network,
77            self.operator_cloud.get_network_quotas('demo')['network'])
78
79    def test_get_quotas_details(self):
80        expected_keys = ['limit', 'used', 'reserved']
81        '''Test getting details about quota usage'''
82        quota_details = self.operator_cloud.get_network_quotas(
83            'demo', details=True)
84        for quota_values in quota_details.values():
85            for expected_key in expected_keys:
86                self.assertTrue(expected_key in quota_values.keys())
87