1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from tempest.lib import exceptions
from openstackclient.tests.functional import base
class QuotaTests(base.TestCase):
"""Functional tests for quota
Note that for 'set' tests use different quotas for each API in different
test runs as these may run in parallel and otherwise step on each other.
"""
PROJECT_NAME = None
@classmethod
def setUpClass(cls):
super(QuotaTests, cls).setUpClass()
cls.haz_network = cls.is_service_enabled('network')
cls.PROJECT_NAME = cls.get_openstack_configuration_value(
'auth.project_name'
)
def test_quota_list_details_compute(self):
expected_headers = ["Resource", "In Use", "Reserved", "Limit"]
cmd_output = self.openstack(
'quota list --detail --compute',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
resources = []
for row in cmd_output:
row_headers = [str(r) for r in row.keys()]
self.assertEqual(sorted(expected_headers), sorted(row_headers))
resources.append(row['Resource'])
# Ensure that returned quota is compute quota
self.assertIn("instances", resources)
# and that there is no network quota here
self.assertNotIn("networks", resources)
def test_quota_list_details_network(self):
expected_headers = ["Resource", "In Use", "Reserved", "Limit"]
cmd_output = self.openstack(
'quota list --detail --network',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
resources = []
for row in cmd_output:
row_headers = [str(r) for r in row.keys()]
self.assertEqual(sorted(expected_headers), sorted(row_headers))
resources.append(row['Resource'])
# Ensure that returned quota is network quota
self.assertIn("networks", resources)
# and that there is no compute quota here
self.assertNotIn("instances", resources)
def test_quota_list_network_option(self):
if not self.haz_network:
self.skipTest("No Network service present")
self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
cmd_output = self.openstack(
'quota list --network',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
self.assertEqual(
40,
cmd_output[0]["Networks"],
)
def test_quota_list_compute_option(self):
self.openstack('quota set --instances 30 ' + self.PROJECT_NAME)
cmd_output = self.openstack(
'quota list --compute',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
self.assertEqual(
30,
cmd_output[0]["Instances"],
)
def test_quota_list_volume_option(self):
self.openstack('quota set --volumes 20 ' + self.PROJECT_NAME)
cmd_output = self.openstack(
'quota list --volume',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
self.assertEqual(
20,
cmd_output[0]["Volumes"],
)
def test_quota_set_project(self):
"""Test quota set, show"""
network_option = ""
if self.haz_network:
network_option = "--routers 21 "
self.openstack(
'quota set --cores 31 --backups 41 '
+ network_option
+ self.PROJECT_NAME
)
cmd_output = self.openstack(
'quota show ' + self.PROJECT_NAME,
parse_output=True,
)
cmd_output = {x['Resource']: x['Limit'] for x in cmd_output}
self.assertIsNotNone(cmd_output)
self.assertEqual(
31,
cmd_output["cores"],
)
self.assertEqual(
41,
cmd_output["backups"],
)
if self.haz_network:
self.assertEqual(
21,
cmd_output["routers"],
)
# Check default quotas
cmd_output = self.openstack(
'quota show --default',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
# We don't necessarily know the default quotas, we're checking the
# returned attributes
cmd_output = {x['Resource']: x['Limit'] for x in cmd_output}
self.assertTrue(cmd_output["cores"] >= 0)
self.assertTrue(cmd_output["backups"] >= 0)
if self.haz_network:
self.assertTrue(cmd_output["routers"] >= 0)
def test_quota_set_class(self):
self.openstack(
'quota set --key-pairs 33 --snapshots 43 ' + '--class default'
)
cmd_output = self.openstack(
'quota show --class default',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
cmd_output = {x['Resource']: x['Limit'] for x in cmd_output}
self.assertEqual(
33,
cmd_output["key-pairs"],
)
self.assertEqual(
43,
cmd_output["snapshots"],
)
# Check default quota class
cmd_output = self.openstack(
'quota show --class',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
# We don't necessarily know the default quotas, we're checking the
# returned attributes
cmd_output = {x['Resource']: x['Limit'] for x in cmd_output}
self.assertTrue(cmd_output["key-pairs"] >= 0)
self.assertTrue(cmd_output["snapshots"] >= 0)
def _restore_quota_limit(self, resource, limit, project):
self.openstack('quota set --%s %s %s' % (resource, limit, project))
def test_quota_network_set_with_no_force(self):
if not self.haz_network:
self.skipTest('No Network service present')
if not self.is_extension_enabled('quota-check-limit'):
self.skipTest('No "quota-check-limit" extension present')
cmd_output = self.openstack(
'quota list --network',
parse_output=True,
)
self.addCleanup(
self._restore_quota_limit,
'network',
cmd_output[0]['Networks'],
self.PROJECT_NAME,
)
self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
cmd_output = self.openstack(
'quota list --network',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
self.assertEqual(40, cmd_output[0]['Networks'])
# That will ensure we have at least two networks in the system.
for _ in range(2):
self.openstack(
'network create --project %s %s'
% (self.PROJECT_NAME, uuid.uuid4().hex)
)
self.assertRaises(
exceptions.CommandFailed,
self.openstack,
'quota set --networks 1 --no-force ' + self.PROJECT_NAME,
)
def test_quota_network_set_with_force(self):
self.skipTest('story 2010110')
if not self.haz_network:
self.skipTest('No Network service present')
# NOTE(ralonsoh): the Neutron support for the flag "check-limit" was
# added with the extension "quota-check-limit". The flag "force" was
# added too in order to change the behaviour of Neutron quota engine
# and mimic the Nova one: by default the engine will check the resource
# usage before setting the new limit; with "force", this check will be
# skipped (in Yoga, this behaviour is still NOT the default in
# Neutron).
if not self.is_extension_enabled('quota-check-limit'):
self.skipTest('No "quota-check-limit" extension present')
cmd_output = self.openstack(
'quota list --network',
parse_output=True,
)
self.addCleanup(
self._restore_quota_limit,
'network',
cmd_output[0]['Networks'],
self.PROJECT_NAME,
)
self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
cmd_output = self.openstack(
'quota list --network',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
self.assertEqual(40, cmd_output[0]['Networks'])
# That will ensure we have at least two networks in the system.
for _ in range(2):
self.openstack(
'network create --project %s %s'
% (self.PROJECT_NAME, uuid.uuid4().hex)
)
self.openstack('quota set --networks 1 --force ' + self.PROJECT_NAME)
cmd_output = self.openstack(
'quota list --network',
parse_output=True,
)
self.assertIsNotNone(cmd_output)
self.assertEqual(1, cmd_output[0]['Networks'])
|