|
16 | 16 |
|
17 | 17 | from oslo_config import cfg
|
18 | 18 | from oslo_limit import exception as limit_exceptions
|
| 19 | +from oslo_limit import fixture as limit_fixture |
19 | 20 | from oslo_limit import limit
|
20 | 21 | from oslo_utils.fixture import uuidsentinel as uuids
|
21 | 22 |
|
@@ -309,3 +310,44 @@ def test_enforce_num_instances_and_flavor_placement_fail(self, mock_limit):
|
309 | 310 |
|
310 | 311 | expected = str(mock_enforcer.enforce.side_effect)
|
311 | 312 | self.assertEqual(expected, str(e))
|
| 313 | + |
| 314 | + |
| 315 | +class GetLegacyLimitsTest(test.NoDBTestCase): |
| 316 | + def setUp(self): |
| 317 | + super(GetLegacyLimitsTest, self).setUp() |
| 318 | + self.new = {"servers": 1, "class:VCPU": 2, "class:MEMORY_MB": 3} |
| 319 | + self.legacy = {"instances": 1, "cores": 2, "ram": 3} |
| 320 | + self.resources = ["servers", "class:VCPU", "class:MEMORY_MB"] |
| 321 | + self.resources.sort() |
| 322 | + self.flags(driver=limit_utils.UNIFIED_LIMITS_DRIVER, group="quota") |
| 323 | + |
| 324 | + def test_convert_keys_to_legacy_name(self): |
| 325 | + limits = placement_limits._convert_keys_to_legacy_name(self.new) |
| 326 | + self.assertEqual(self.legacy, limits) |
| 327 | + |
| 328 | + def test_get_legacy_default_limits(self): |
| 329 | + reglimits = {'servers': 1, 'class:VCPU': 2} |
| 330 | + self.useFixture(limit_fixture.LimitFixture(reglimits, {})) |
| 331 | + limits = placement_limits.get_legacy_default_limits() |
| 332 | + self.assertEqual({'cores': 2, 'instances': 1, 'ram': 0}, limits) |
| 333 | + |
| 334 | + def test_get_legacy_project_limits(self): |
| 335 | + reglimits = {'servers': 5, 'class:MEMORY_MB': 7} |
| 336 | + projlimits = {uuids.project_id: {'servers': 1}} |
| 337 | + self.useFixture(limit_fixture.LimitFixture(reglimits, projlimits)) |
| 338 | + limits = placement_limits.get_legacy_project_limits(uuids.project_id) |
| 339 | + self.assertEqual({'instances': 1, 'cores': 0, 'ram': 7}, limits) |
| 340 | + |
| 341 | + @mock.patch.object(report.SchedulerReportClient, |
| 342 | + "get_usages_counts_for_limits") |
| 343 | + @mock.patch.object(objects.InstanceMappingList, "get_counts") |
| 344 | + @mock.patch.object(quota, "is_qfd_populated") |
| 345 | + def test_get_legacy_counts(self, mock_qfd, mock_counts, mock_placement): |
| 346 | + mock_qfd.return_value = True |
| 347 | + mock_counts.return_value = {"project": {"instances": 1}} |
| 348 | + mock_placement.return_value = { |
| 349 | + "VCPU": 2, "CUSTOM_BAREMETAL": 2, "MEMORY_MB": 3, |
| 350 | + } |
| 351 | + counts = placement_limits.get_legacy_counts( |
| 352 | + "context", uuids.project_id) |
| 353 | + self.assertEqual(self.legacy, counts) |
0 commit comments