Default user_id when not specified in check_num_instances_quota
The Quotas.check_deltas method needs a user_id keyword arg in order to
scope a quota check to a particular user. However, when we call
check_num_instances_quota we don't pass a project_id or user_id because
at the time of the quota check, we have not yet created an instance
record and thus will not use that to determine the appropriate project
and user.
Instead, we should rely on the RequestContext.project_id and
RequestContext.user_id as defaults in this case, but
check_num_instances_quota only defaults project_id and not user_id.
check_num_instances_quota should also default user_id to the
RequestContext.user_id when user_id is not explicitly passed.
check_num_instances_quota should also check whether any per-user quota
limits are defined for instance-related resources before passing along
the user_id to scope resource counting and limit checking. Counting
resources across a user is costly, so we should avoid it if it's not
needed.
Reviewed: https:/ /review. opendev. org/748550 /git.openstack. org/cgit/ openstack/ nova/commit/ ?id=4c11d5467a3 0506a82dd5d32dd 22b8958a187c0b
Committed: https:/
Submitter: Zuul
Branch: master
commit 4c11d5467a30506 a82dd5d32dd22b8 958a187c0b
Author: melanie witt <email address hidden>
Date: Thu Aug 27 23:34:18 2020 +0000
Default user_id when not specified in check_num_ instances_ quota
The Quotas.check_deltas method needs a user_id keyword arg in order to num_instances_ quota we don't pass a project_id or user_id because
scope a quota check to a particular user. However, when we call
check_
at the time of the quota check, we have not yet created an instance
record and thus will not use that to determine the appropriate project
and user.
Instead, we should rely on the RequestContext. project_ id and ext.user_ id as defaults in this case, but num_instances_ quota only defaults project_id and not user_id.
RequestCont
check_
check_ num_instances_ quota should also default user_id to the ext.user_ id when user_id is not explicitly passed.
RequestCont
check_ num_instances_ quota should also check whether any per-user quota
limits are defined for instance-related resources before passing along
the user_id to scope resource counting and limit checking. Counting
resources across a user is costly, so we should avoid it if it's not
needed.
Closes-Bug: #1893284
Change-Id: I3cfb1edc30b0bd a4671e0d2cc2a89 93055dcc9ff