Skip to content

Commit 65416f3

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "compute/v2 limits_absolute resource"
2 parents 0f49898 + 747c18c commit 65416f3

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
import six
14+
15+
from openstack.compute import compute_service
16+
from openstack import resource
17+
18+
19+
class LimitsAbsolute(resource.Resource):
20+
resource_key = 'limits_absolute'
21+
resources_key = 'limits_absolutes'
22+
base_path = '/limits'
23+
service = compute_service.ComputeService()
24+
25+
# capabilities
26+
allow_list = True
27+
28+
# Properties
29+
name = resource.prop('name')
30+
value = resource.prop('value')
31+
32+
@classmethod
33+
def list(cls, session, path_args=None, **params):
34+
url = cls.base_path
35+
resp = session.get(url, service=cls.service, params=params).body
36+
resp = resp['limits']['absolute']
37+
return [cls.existing(name=key, value=value)
38+
for key, value in six.iteritems(resp)]
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
import mock
14+
import six
15+
import testtools
16+
17+
from openstack.compute.v2 import limits_absolute
18+
19+
IDENTIFIER = 'IDENTIFIER'
20+
EXAMPLE = {
21+
'name': 'maxImageMeta',
22+
'value': '2',
23+
}
24+
FAKE_RESPONSES = {
25+
"limits": {
26+
"absolute": {
27+
"maxImageMeta": 128,
28+
"maxPersonality": 5,
29+
"maxPersonalitySize": 10240,
30+
"maxSecurityGroupRules": 20,
31+
"maxSecurityGroups": 10,
32+
"maxServerMeta": 128,
33+
"maxTotalCores": 20,
34+
"maxTotalFloatingIps": 10,
35+
"maxTotalInstances": 10,
36+
"maxTotalKeypairs": 100,
37+
"maxTotalRAMSize": 51200,
38+
}
39+
}
40+
}
41+
42+
43+
class TestLimitsAbsolute(testtools.TestCase):
44+
45+
def test_basic(self):
46+
sot = limits_absolute.LimitsAbsolute()
47+
self.assertEqual('limits_absolute', sot.resource_key)
48+
self.assertEqual('limits_absolutes', sot.resources_key)
49+
self.assertEqual('/limits', sot.base_path)
50+
self.assertEqual('compute', sot.service.service_type)
51+
self.assertFalse(sot.allow_create)
52+
self.assertFalse(sot.allow_retrieve)
53+
self.assertFalse(sot.allow_update)
54+
self.assertFalse(sot.allow_delete)
55+
self.assertTrue(sot.allow_list)
56+
57+
def test_make_it(self):
58+
sot = limits_absolute.LimitsAbsolute(EXAMPLE)
59+
self.assertEqual(EXAMPLE['name'], sot.name)
60+
self.assertEqual(EXAMPLE['value'], sot.value)
61+
62+
def test_list(self):
63+
resp = mock.Mock()
64+
resp.body = FAKE_RESPONSES
65+
sess = mock.Mock()
66+
sess.get = mock.MagicMock()
67+
sess.get.return_value = resp
68+
sot = limits_absolute.LimitsAbsolute()
69+
70+
resp = sot.list(sess)
71+
72+
url = '/limits'
73+
sess.get.assert_called_with(url, service=sot.service, params={})
74+
absolute = FAKE_RESPONSES['limits']['absolute']
75+
cnt = 0
76+
for key, value in six.iteritems(absolute):
77+
self.assertEqual(key, resp[cnt].name)
78+
self.assertEqual(value, resp[cnt].value)
79+
cnt = cnt + 1

0 commit comments

Comments
 (0)