|
14 | 14 | # under the License.
|
15 | 15 | import copy
|
16 | 16 | import mock
|
| 17 | +from oslo_limit import fixture as limit_fixture |
17 | 18 | import webob
|
18 | 19 |
|
19 | 20 | from nova.api.openstack.compute import quota_classes \
|
20 | 21 | as quota_classes_v21
|
21 | 22 | from nova import exception
|
| 23 | +from nova.limit import local as local_limit |
22 | 24 | from nova import objects
|
23 | 25 | from nova import test
|
24 | 26 | from nova.tests.unit.api.openstack import fakes
|
@@ -262,3 +264,108 @@ def test_update_v257(self, mock_update):
|
262 | 264 |
|
263 | 265 | class UnifiedLimitsQuotaClassesTest(NoopQuotaClassesTest):
|
264 | 266 | quota_driver = "nova.quota.UnifiedLimitsDriver"
|
| 267 | + |
| 268 | + def setUp(self): |
| 269 | + super(UnifiedLimitsQuotaClassesTest, self).setUp() |
| 270 | + # Set server_groups so all config options get a different value |
| 271 | + # but we also test as much as possible with the default config |
| 272 | + self.flags(driver="nova.quota.UnifiedLimitsDriver", group='quota') |
| 273 | + reglimits = {local_limit.SERVER_METADATA_ITEMS: 128, |
| 274 | + local_limit.INJECTED_FILES: 5, |
| 275 | + local_limit.INJECTED_FILES_CONTENT: 10 * 1024, |
| 276 | + local_limit.INJECTED_FILES_PATH: 255, |
| 277 | + local_limit.KEY_PAIRS: 100, |
| 278 | + local_limit.SERVER_GROUPS: 12, |
| 279 | + local_limit.SERVER_GROUP_MEMBERS: 10} |
| 280 | + self.useFixture(limit_fixture.LimitFixture(reglimits, {})) |
| 281 | + |
| 282 | + def test_show_v21(self): |
| 283 | + req = fakes.HTTPRequest.blank("") |
| 284 | + response = self.controller.show(req, "test_class") |
| 285 | + expected_response = { |
| 286 | + 'quota_class_set': { |
| 287 | + 'id': 'test_class', |
| 288 | + 'cores': -1, |
| 289 | + 'fixed_ips': -1, |
| 290 | + 'floating_ips': -1, |
| 291 | + 'ram': -1, |
| 292 | + 'injected_file_content_bytes': 10240, |
| 293 | + 'injected_file_path_bytes': 255, |
| 294 | + 'injected_files': 5, |
| 295 | + 'instances': -1, |
| 296 | + 'key_pairs': 100, |
| 297 | + 'metadata_items': 128, |
| 298 | + 'security_group_rules': -1, |
| 299 | + 'security_groups': -1, |
| 300 | + } |
| 301 | + } |
| 302 | + self.assertEqual(expected_response, response) |
| 303 | + |
| 304 | + def test_show_v257(self): |
| 305 | + req = fakes.HTTPRequest.blank("", version='2.57') |
| 306 | + response = self.controller.show(req, "default") |
| 307 | + expected_response = { |
| 308 | + 'quota_class_set': { |
| 309 | + 'id': 'default', |
| 310 | + 'cores': -1, |
| 311 | + 'instances': -1, |
| 312 | + 'ram': -1, |
| 313 | + 'key_pairs': 100, |
| 314 | + 'metadata_items': 128, |
| 315 | + 'server_group_members': 10, |
| 316 | + 'server_groups': 12, |
| 317 | + } |
| 318 | + } |
| 319 | + self.assertEqual(expected_response, response) |
| 320 | + |
| 321 | + def test_update_still_rejects_badrequests(self): |
| 322 | + req = fakes.HTTPRequest.blank("") |
| 323 | + body = {'quota_class_set': {'instances': 50, 'cores': 50, |
| 324 | + 'ram': 51200, 'unsupported': 12}} |
| 325 | + self.assertRaises(exception.ValidationError, self.controller.update, |
| 326 | + req, 'test_class', body=body) |
| 327 | + |
| 328 | + @mock.patch.object(objects.Quotas, "update_class") |
| 329 | + def test_update_v21(self, mock_update): |
| 330 | + req = fakes.HTTPRequest.blank("") |
| 331 | + body = {'quota_class_set': {'ram': 51200}} |
| 332 | + response = self.controller.update(req, 'default', body=body) |
| 333 | + expected_response = { |
| 334 | + 'quota_class_set': { |
| 335 | + 'cores': -1, |
| 336 | + 'fixed_ips': -1, |
| 337 | + 'floating_ips': -1, |
| 338 | + 'injected_file_content_bytes': 10240, |
| 339 | + 'injected_file_path_bytes': 255, |
| 340 | + 'injected_files': 5, |
| 341 | + 'instances': -1, |
| 342 | + 'key_pairs': 100, |
| 343 | + 'metadata_items': 128, |
| 344 | + 'ram': -1, |
| 345 | + 'security_group_rules': -1, |
| 346 | + 'security_groups': -1 |
| 347 | + } |
| 348 | + } |
| 349 | + self.assertEqual(expected_response, response) |
| 350 | + # TODO(johngarbutt) we should be proxying to keystone |
| 351 | + self.assertEqual(0, mock_update.call_count) |
| 352 | + |
| 353 | + @mock.patch.object(objects.Quotas, "update_class") |
| 354 | + def test_update_v257(self, mock_update): |
| 355 | + req = fakes.HTTPRequest.blank("", version='2.57') |
| 356 | + body = {'quota_class_set': {'ram': 51200}} |
| 357 | + response = self.controller.update(req, 'default', body=body) |
| 358 | + expected_response = { |
| 359 | + 'quota_class_set': { |
| 360 | + 'cores': -1, |
| 361 | + 'instances': -1, |
| 362 | + 'ram': -1, |
| 363 | + 'key_pairs': 100, |
| 364 | + 'metadata_items': 128, |
| 365 | + 'server_group_members': 10, |
| 366 | + 'server_groups': 12, |
| 367 | + } |
| 368 | + } |
| 369 | + self.assertEqual(expected_response, response) |
| 370 | + # TODO(johngarbutt) we should be proxying to keystone |
| 371 | + self.assertEqual(0, mock_update.call_count) |
0 commit comments