Skip to content

Commit 271bb48

Browse files
sahidslawqo
authored andcommitted
rbacs: filter out model that are already owned by context
Taking example of a network that have multiple rbacs. In a situation of selecting networks that are shared to a project. If we could could already match the one that are owned by the context we can expect les rbacs to scan. https://bugs.launchpad.net/neutron/+bug/1918145/comments/54 In an environement with about 200 00 rbacs and 200 networks this reduce time of the request from more than 50s to less than a second. Related-bug: #1918145 Signed-off-by: Sahid Orentino Ferdjaoui <[email protected]> Change-Id: I54808cbd4cdccfee97eb59053418f55ba57e11a6 Signed-off-by: Sahid Orentino Ferdjaoui <[email protected]> Change-Id: Ib155fbb3f6b325d10e3fbea201677dc218111c17 (cherry picked from commit e6de524)
1 parent e5e6749 commit 271bb48

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

neutron/db/external_net_db.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def _network_filter_hook(context, original_model, conditions):
5151
(rbac_model.target_project == context.tenant_id) |
5252
(rbac_model.target_project == '*'))
5353
conditions = expr.or_(tenant_allowed, *conditions)
54+
conditions = expr.or_(original_model.tenant_id == context.tenant_id,
55+
*conditions)
5456
return conditions
5557

5658

neutron/tests/unit/extensions/test_external_net.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,17 @@ def test_network_filter_hook_admin_context(self):
142142
def test_network_filter_hook_nonadmin_context(self):
143143
ctx = context.Context('edinson', 'cavani')
144144
model = models_v2.Network
145-
txt = ("networkrbacs.action = :action_1 AND "
145+
txt = ("networks.project_id = :project_id_1 OR "
146+
"networkrbacs.action = :action_1 AND "
146147
"networkrbacs.target_project = :target_project_1 OR "
147148
"networkrbacs.target_project = :target_project_2")
148149
conditions = external_net_db._network_filter_hook(ctx, model, [])
149150
self.assertEqual(conditions.__str__(), txt)
150151
# Try to concatenate conditions
151152
txt2 = (txt.replace('project_1', 'project_3').
152153
replace('project_2', 'project_4').
153-
replace('action_1', 'action_2'))
154+
replace('action_1', 'action_2').
155+
replace('project_id_1', 'project_id_2'))
154156
conditions = external_net_db._network_filter_hook(ctx, model,
155157
conditions)
156158
self.assertEqual(conditions.__str__(), "%s OR %s" % (txt, txt2))

0 commit comments

Comments
 (0)