Update quotas to handle domain acting as project
The Keystone change Ib22a0f3007cb7ef6b4df6f48da5f4d018e905f55 sets the domain_id as the top-level parent project. However, since a domain is not a project and therefore has no effect on quota nesting, the domain "parent" should not be considered in the nested quota code. This patch updates the quota code to ignore the domain_id if it's present in the parent tree. Change-Id: I221cfc14b886ea9819e065d4c79e8c4bfc94df45 Closes-Bug: #1551911
This commit is contained in:
@@ -103,6 +103,19 @@ def get_volume_type_reservation(ctxt, volume, type_id,
|
||||
return reservations
|
||||
|
||||
|
||||
def _filter_domain_id_from_parents(domain_id, tree):
|
||||
"""Removes the domain_id from the tree if present"""
|
||||
new_tree = None
|
||||
if tree:
|
||||
parent, children = next(iter(tree.items()))
|
||||
# Don't add the domain id to the parents hierarchy
|
||||
if parent != domain_id:
|
||||
new_tree = {parent: _filter_domain_id_from_parents(domain_id,
|
||||
children)}
|
||||
|
||||
return new_tree
|
||||
|
||||
|
||||
def get_project_hierarchy(context, project_id, subtree_as_ids=False,
|
||||
parents_as_ids=False):
|
||||
"""A Helper method to get the project hierarchy.
|
||||
@@ -110,6 +123,8 @@ def get_project_hierarchy(context, project_id, subtree_as_ids=False,
|
||||
Along with hierarchical multitenancy in keystone API v3, projects can be
|
||||
hierarchically organized. Therefore, we need to know the project
|
||||
hierarchy, if any, in order to do nested quota operations properly.
|
||||
If the domain is being used as the top most parent, it is filtered out from
|
||||
the parent tree and parent_id.
|
||||
"""
|
||||
try:
|
||||
keystone = _keystone_client(context)
|
||||
@@ -118,11 +133,18 @@ def get_project_hierarchy(context, project_id, subtree_as_ids=False,
|
||||
project = keystone.projects.get(project_id,
|
||||
subtree_as_ids=subtree_as_ids,
|
||||
parents_as_ids=parents_as_ids)
|
||||
generic_project.parent_id = project.parent_id
|
||||
|
||||
generic_project.parent_id = None
|
||||
if project.parent_id != project.domain_id:
|
||||
generic_project.parent_id = project.parent_id
|
||||
|
||||
generic_project.subtree = (
|
||||
project.subtree if subtree_as_ids else None)
|
||||
generic_project.parents = (
|
||||
project.parents if parents_as_ids else None)
|
||||
|
||||
generic_project.parents = None
|
||||
if parents_as_ids:
|
||||
generic_project.parents = _filter_domain_id_from_parents(
|
||||
project.domain_id, project.parents)
|
||||
except exceptions.NotFound:
|
||||
msg = (_("Tenant ID: %s does not exist.") % project_id)
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
Reference in New Issue
Block a user