Skip to content

Commit c384824

Browse files
JohnGarbuttmelwitt
authored andcommitted
Update quota sets APIs
Ensure the limit related APIs reflect the new reality of enforcing the API and DB limits based on keystone only. For now we skip all updates to the DB, as none mean anything to the new code, as we only look at keystone now. Note: this will need to be updated again once we add limits for cores, ram, instances, etc. blueprint unified-limits-nova Change-Id: I5ef968395b4bdc6f190e239a19a723316b1d5baf
1 parent ce4f796 commit c384824

File tree

4 files changed

+110
-12
lines changed

4 files changed

+110
-12
lines changed

nova/api/openstack/compute/quota_sets.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import nova.conf
3030
from nova import exception
3131
from nova.i18n import _
32+
from nova.limit import utils as limit_utils
3233
from nova import objects
3334
from nova.policies import quota_sets as qs_policies
3435
from nova import quota
@@ -205,10 +206,16 @@ def _update(self, req, id, body, filtered_quotas):
205206
settable_quotas = QUOTAS.get_settable_quotas(context, project_id,
206207
user_id=user_id)
207208

209+
requested_quotas = body['quota_set'].items()
210+
if limit_utils.use_unified_limits():
211+
# NOTE(johngarbutt) currently all info comes from keystone
212+
# we don't update the database.
213+
requested_quotas = []
214+
208215
# NOTE(dims): Pass #1 - In this loop for quota_set.items(), we validate
209216
# min/max values and bail out if any of the items in the set is bad.
210217
valid_quotas = {}
211-
for key, value in body['quota_set'].items():
218+
for key, value in requested_quotas:
212219
if key == 'force' or (not value and value != 0):
213220
continue
214221
# validate whether already used and reserved exceeds the new
@@ -276,8 +283,12 @@ def delete(self, req, id):
276283
context.can(qs_policies.POLICY_ROOT % 'delete', {'project_id': id})
277284
params = urlparse.parse_qs(req.environ.get('QUERY_STRING', ''))
278285
user_id = params.get('user_id', [None])[0]
279-
if user_id:
280-
objects.Quotas.destroy_all_by_project_and_user(
281-
context, id, user_id)
282-
else:
283-
objects.Quotas.destroy_all_by_project(context, id)
286+
287+
# NOTE(johngarbutt) with unified limits we only use keystone, not the
288+
# db
289+
if not limit_utils.use_unified_limits():
290+
if user_id:
291+
objects.Quotas.destroy_all_by_project_and_user(
292+
context, id, user_id)
293+
else:
294+
objects.Quotas.destroy_all_by_project(context, id)

nova/quota.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,10 @@ def get_class_quotas(self, context, resources, quota_class):
801801
:param resources: A dictionary of the registered resources.
802802
:param quota_class: Placeholder, we always assume default quota class.
803803
"""
804+
# NOTE(johngarbutt): ignoring quota_class, as ignored in noop driver
805+
return self.get_defaults(context, resources)
804806

807+
def get_defaults(self, context, resources):
805808
local_limits = local_limit.get_legacy_default_limits()
806809
# TODO(melwitt): This is temporary when we are in a state where cores,
807810
# ram, and instances quota limits are not known/enforced with unified

nova/tests/unit/api/openstack/compute/test_quotas.py

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,7 @@ def test_update_v21(self, mock_create):
10121012
}
10131013
}
10141014
self.assertEqual(expected_response, response)
1015-
mock_create.assert_called_once_with(req.environ['nova.context'],
1016-
uuids.project_id, "server_groups",
1017-
2, user_id=None)
1015+
self.assertEqual(0, mock_create.call_count)
10181016

10191017
@mock.patch.object(objects.Quotas, "create_limit")
10201018
def test_update_v21_user(self, mock_create):
@@ -1040,6 +1038,75 @@ def test_update_v21_user(self, mock_create):
10401038
}
10411039
}
10421040
self.assertEqual(expected_response, response)
1043-
mock_create.assert_called_once_with(req.environ['nova.context'],
1044-
uuids.project_id, "key_pairs", 52,
1045-
user_id="42")
1041+
self.assertEqual(0, mock_create.call_count)
1042+
1043+
def test_defaults_v21(self):
1044+
req = fakes.HTTPRequest.blank("")
1045+
response = self.controller.defaults(req, uuids.project_id)
1046+
expected_response = {
1047+
'quota_set': {
1048+
'id': uuids.project_id,
1049+
'cores': -1,
1050+
'fixed_ips': -1,
1051+
'floating_ips': -1,
1052+
'injected_file_content_bytes': 10240,
1053+
'injected_file_path_bytes': 255,
1054+
'injected_files': 5,
1055+
'instances': -1,
1056+
'key_pairs': 100,
1057+
'metadata_items': 128,
1058+
'ram': -1,
1059+
'security_group_rules': -1,
1060+
'security_groups': -1,
1061+
'server_group_members': 10,
1062+
'server_groups': 12,
1063+
}
1064+
}
1065+
self.assertEqual(expected_response, response)
1066+
1067+
def test_defaults_v21_different_limit_values(self):
1068+
reglimits = {local_limit.SERVER_METADATA_ITEMS: 7,
1069+
local_limit.INJECTED_FILES: 6,
1070+
local_limit.INJECTED_FILES_CONTENT: 4,
1071+
local_limit.INJECTED_FILES_PATH: 5,
1072+
local_limit.KEY_PAIRS: 1,
1073+
local_limit.SERVER_GROUPS: 3,
1074+
local_limit.SERVER_GROUP_MEMBERS: 2}
1075+
self.useFixture(limit_fixture.LimitFixture(reglimits, {}))
1076+
1077+
req = fakes.HTTPRequest.blank("")
1078+
response = self.controller.defaults(req, uuids.project_id)
1079+
expected_response = {
1080+
'quota_set': {
1081+
'id': uuids.project_id,
1082+
'cores': -1,
1083+
'fixed_ips': -1,
1084+
'floating_ips': -1,
1085+
'injected_file_content_bytes': 4,
1086+
'injected_file_path_bytes': 5,
1087+
'injected_files': 6,
1088+
'instances': -1,
1089+
'key_pairs': 1,
1090+
'metadata_items': 7,
1091+
'ram': -1,
1092+
'security_group_rules': -1,
1093+
'security_groups': -1,
1094+
'server_group_members': 2,
1095+
'server_groups': 3,
1096+
}
1097+
}
1098+
self.assertEqual(expected_response, response)
1099+
1100+
@mock.patch('nova.objects.Quotas.destroy_all_by_project')
1101+
def test_quotas_delete(self, mock_destroy_all_by_project):
1102+
req = fakes.HTTPRequest.blank("")
1103+
self.controller.delete(req, "1234")
1104+
# Ensure destroy isn't called for unified limits
1105+
self.assertEqual(0, mock_destroy_all_by_project.call_count)
1106+
1107+
@mock.patch('nova.objects.Quotas.destroy_all_by_project_and_user')
1108+
def test_user_quotas_delete(self, mock_destroy_all_by_user):
1109+
req = fakes.HTTPRequest.blank("?user_id=42")
1110+
self.controller.delete(req, "1234")
1111+
# Ensure destroy isn't called for unified limits
1112+
self.assertEqual(0, mock_destroy_all_by_user.call_count)

nova/tests/unit/test_quota.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,23 @@ def setUp(self):
19661966
local_limit.SERVER_GROUPS: 12,
19671967
local_limit.SERVER_GROUP_MEMBERS: 10}
19681968
self.useFixture(limit_fixture.LimitFixture(reglimits, {}))
1969+
1970+
self.expected_without_dict = {
1971+
'cores': -1,
1972+
'fixed_ips': -1,
1973+
'floating_ips': -1,
1974+
'injected_file_content_bytes': 10240,
1975+
'injected_file_path_bytes': 255,
1976+
'injected_files': 5,
1977+
'instances': -1,
1978+
'key_pairs': 100,
1979+
'metadata_items': 128,
1980+
'ram': -1,
1981+
'security_group_rules': -1,
1982+
'security_groups': -1,
1983+
'server_group_members': 10,
1984+
'server_groups': 12,
1985+
}
19691986
self.expected_without_usages = {
19701987
'cores': {'limit': -1},
19711988
'fixed_ips': {'limit': -1},

0 commit comments

Comments
 (0)