summaryrefslogtreecommitdiff
path: root/nova/quota.py
diff options
context:
space:
mode:
authorChen <dstbtgagt@foxmail.com>2018-07-06 22:47:12 +0800
committerMatt Riedemann <mriedem.os@gmail.com>2018-07-06 16:57:31 -0400
commitbbee9a26a5c64a1463bd9a9f82d735ec17c62d52 (patch)
tree01d4a4a763a5fa8cb6f49d1fd23c43cea27ec6f0 /nova/quota.py
parentf9874e059df50dc81803fcfdfd1045cc09624894 (diff)
downloadnova-bbee9a26a5c64a1463bd9a9f82d735ec17c62d52.tar.gz
Fix server_group_members quota check
For example there are 3 instances in a server group (quota is 5). When doing multi-creating of 3 more instances in this group (would have 6 members), current quota checking scheme will fail to prevent this happening, which is not expected. This is due to the server_group_members quota check previously only counting group members that existed as instance records in cell databases and not accounting for build requests which are the temporary representation of the instance in the API database before the instance is scheduled to a cell. Co-Authored-By: Matt Riedemann <mriedem.os@gmail.com> Change-Id: If439f4486b8fe157c436c47aa408608e639a3e15 Closes-Bug: #1780373
Diffstat (limited to 'nova/quota.py')
-rw-r--r--nova/quota.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/nova/quota.py b/nova/quota.py
index c8e4ad3168..3a7336f334 100644
--- a/nova/quota.py
+++ b/nova/quota.py
@@ -1283,7 +1283,20 @@ def _server_group_count_members_by_user(context, group, user_id):
for greenthread in greenthreads:
found = greenthread.wait()
instances = instances + found
- return {'user': {'server_group_members': len(instances)}}
+ # Count build requests using the same filters to catch group members
+ # that are not yet creatd in a cell.
+ # NOTE(mriedem): BuildRequestList.get_by_filters is not very efficient for
+ # what we need and we can optimize this with a new query method.
+ build_requests = objects.BuildRequestList.get_by_filters(context, filters)
+ # Ignore any duplicates since build requests and instances can co-exist
+ # for a short window of time after the instance is created in a cell but
+ # before the build request is deleted.
+ instance_uuids = [inst.uuid for inst in instances]
+ count = len(instances)
+ for build_request in build_requests:
+ if build_request.instance_uuid not in instance_uuids:
+ count += 1
+ return {'user': {'server_group_members': count}}
def _fixed_ip_count(context, project_id):