diff options
author | John Garbutt <john@johngarbutt.com> | 2020-03-12 13:15:14 +0000 |
---|---|---|
committer | melanie witt <melwittt@gmail.com> | 2022-02-24 16:21:02 +0000 |
commit | ce4f796ec120462011e018f1d95d67658d443ed4 (patch) | |
tree | cff4dbd959bea51a411f18b985b5835539815444 /nova/tests/unit/test_quota.py | |
parent | 94f9e443f2bde7edf63676ad9a8b2eefd9b68692 (diff) | |
download | nova-ce4f796ec120462011e018f1d95d67658d443ed4.tar.gz |
Update limit APIs
Ensure the limit related APIs reflect the new reality of enforcing the
API and DB limits based on keystone. Do this by implementing the
get_project_quotas and get_user_quotas methods.
This still leaves get_settable_quotas and get_defaults that are needed to
fix the quota sets APIs.
Note: this will need to be updated again once we add limits for
cores, ram, instances, etc.
blueprint unified-limits-nova
Change-Id: I3c4c29740e6275449887c4136d2467eade04fb06
Diffstat (limited to 'nova/tests/unit/test_quota.py')
-rw-r--r-- | nova/tests/unit/test_quota.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/nova/tests/unit/test_quota.py b/nova/tests/unit/test_quota.py index 2fc683b846..e4ac094919 100644 --- a/nova/tests/unit/test_quota.py +++ b/nova/tests/unit/test_quota.py @@ -1966,6 +1966,38 @@ class UnifiedLimitsDriverTestCase(NoopQuotaDriverTestCase): local_limit.SERVER_GROUPS: 12, local_limit.SERVER_GROUP_MEMBERS: 10} self.useFixture(limit_fixture.LimitFixture(reglimits, {})) + self.expected_without_usages = { + 'cores': {'limit': -1}, + 'fixed_ips': {'limit': -1}, + 'floating_ips': {'limit': -1}, + 'injected_file_content_bytes': {'limit': 10240}, + 'injected_file_path_bytes': {'limit': 255}, + 'injected_files': {'limit': 5}, + 'instances': {'limit': -1}, + 'key_pairs': {'limit': 100}, + 'metadata_items': {'limit': 128}, + 'ram': {'limit': -1}, + 'security_group_rules': {'limit': -1}, + 'security_groups': {'limit': -1}, + 'server_group_members': {'limit': 10}, + 'server_groups': {'limit': 12} + } + self.expected_with_usages = { + 'cores': {'in_use': -1, 'limit': -1}, + 'fixed_ips': {'in_use': -1, 'limit': -1}, + 'floating_ips': {'in_use': -1, 'limit': -1}, + 'injected_file_content_bytes': {'in_use': 0, 'limit': 10240}, + 'injected_file_path_bytes': {'in_use': 0, 'limit': 255}, + 'injected_files': {'in_use': 0, 'limit': 5}, + 'instances': {'in_use': -1, 'limit': -1}, + 'key_pairs': {'in_use': 0, 'limit': 100}, + 'metadata_items': {'in_use': 0, 'limit': 128}, + 'ram': {'in_use': -1, 'limit': -1}, + 'security_group_rules': {'in_use': -1, 'limit': -1}, + 'security_groups': {'in_use': -1, 'limit': -1}, + 'server_group_members': {'in_use': 0, 'limit': 10}, + 'server_groups': {'in_use': 9, 'limit': 12} + } def test_get_class_quotas(self): result = self.driver.get_class_quotas( @@ -1988,6 +2020,39 @@ class UnifiedLimitsDriverTestCase(NoopQuotaDriverTestCase): } self.assertEqual(expected_limits, result) + @mock.patch.object(objects.InstanceGroupList, "get_counts") + def test_get_project_quotas(self, mock_count): + mock_count.return_value = {'project': {'server_groups': 9}} + result = self.driver.get_project_quotas( + None, quota.QUOTAS._resources, 'test_project') + self.assertEqual(self.expected_with_usages, result) + mock_count.assert_called_once_with(None, "test_project") + + @mock.patch.object(objects.InstanceGroupList, "get_counts") + def test_get_project_quotas_no_usages(self, mock_count): + result = self.driver.get_project_quotas( + None, quota.QUOTAS._resources, 'test_project', usages=False) + self.assertEqual(self.expected_without_usages, result) + # ensure usages not fetched when not required + self.assertEqual(0, mock_count.call_count) + + @mock.patch.object(objects.InstanceGroupList, "get_counts") + def test_get_user_quotas(self, mock_count): + mock_count.return_value = {'project': {'server_groups': 9}} + result = self.driver.get_user_quotas( + None, quota.QUOTAS._resources, 'test_project', 'fake_user') + self.assertEqual(self.expected_with_usages, result) + mock_count.assert_called_once_with(None, "test_project") + + @mock.patch.object(objects.InstanceGroupList, "get_counts") + def test_get_user_quotas_no_usages(self, mock_count): + result = self.driver.get_user_quotas( + None, quota.QUOTAS._resources, 'test_project', 'fake_user', + usages=False) + self.assertEqual(self.expected_without_usages, result) + # ensure usages not fetched when not required + self.assertEqual(0, mock_count.call_count) + @ddt.ddt class QuotaCountTestCase(test.NoDBTestCase): |