summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_limits.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_limits.py')
-rw-r--r--novaclient/tests/unit/v2/test_limits.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_limits.py b/novaclient/tests/unit/v2/test_limits.py
new file mode 100644
index 0000000..94a62c5
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_limits.py
@@ -0,0 +1,88 @@
1#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13
14from novaclient.tests.unit.fixture_data import client
15from novaclient.tests.unit.fixture_data import limits as data
16from novaclient.tests.unit import utils
17from novaclient.v2 import limits
18
19
20class LimitsTest(utils.FixturedTestCase):
21
22 client_fixture_class = client.V1
23 data_fixture_class = data.Fixture
24
25 def test_get_limits(self):
26 obj = self.cs.limits.get()
27 self.assert_called('GET', '/limits')
28 self.assertIsInstance(obj, limits.Limits)
29
30 def test_get_limits_for_a_tenant(self):
31 obj = self.cs.limits.get(tenant_id=1234)
32 self.assert_called('GET', '/limits?tenant_id=1234')
33 self.assertIsInstance(obj, limits.Limits)
34
35 def test_absolute_limits(self):
36 obj = self.cs.limits.get()
37
38 expected = (
39 limits.AbsoluteLimit("maxTotalRAMSize", 51200),
40 limits.AbsoluteLimit("maxServerMeta", 5),
41 limits.AbsoluteLimit("maxImageMeta", 5),
42 limits.AbsoluteLimit("maxPersonality", 5),
43 limits.AbsoluteLimit("maxPersonalitySize", 10240),
44 )
45
46 abs_limits = list(obj.absolute)
47 self.assertEqual(len(abs_limits), len(expected))
48
49 for limit in abs_limits:
50 self.assertTrue(limit in expected)
51
52 def test_absolute_limits_reserved(self):
53 obj = self.cs.limits.get(reserved=True)
54
55 expected = (
56 limits.AbsoluteLimit("maxTotalRAMSize", 51200),
57 limits.AbsoluteLimit("maxServerMeta", 5),
58 limits.AbsoluteLimit("maxImageMeta", 5),
59 limits.AbsoluteLimit("maxPersonality", 5),
60 limits.AbsoluteLimit("maxPersonalitySize", 10240),
61 )
62
63 self.assert_called('GET', '/limits?reserved=1')
64 abs_limits = list(obj.absolute)
65 self.assertEqual(len(abs_limits), len(expected))
66
67 for limit in abs_limits:
68 self.assertTrue(limit in expected)
69
70 def test_rate_limits(self):
71 obj = self.cs.limits.get()
72
73 expected = (
74 limits.RateLimit('POST', '*', '.*', 10, 2, 'MINUTE',
75 '2011-12-15T22:42:45Z'),
76 limits.RateLimit('PUT', '*', '.*', 10, 2, 'MINUTE',
77 '2011-12-15T22:42:45Z'),
78 limits.RateLimit('DELETE', '*', '.*', 100, 100, 'MINUTE',
79 '2011-12-15T22:42:45Z'),
80 limits.RateLimit('POST', '*/servers', '^/servers', 25, 24, 'DAY',
81 '2011-12-15T22:42:45Z'),
82 )
83
84 rate_limits = list(obj.rate)
85 self.assertEqual(len(rate_limits), len(expected))
86
87 for limit in rate_limits:
88 self.assertTrue(limit in expected)