Skip to content

Commit 995c465

Browse files
committed
Avoid retrieving ports if network list is empty
In ``QoSPlugin._get_ports_with_policy``, if the network IDs list is empty, the SQLAlchemy throws the following warning: SELECT statement has a cartesian product between FROM element(s) "subports_1", "ports", "portnumaaffinitypolicies_1", "testportextensions_1", "portuplinkstatuspropagation_1", "portdataplanestatuses_1", "standardattributes_2", "portdeviceprofiles_1", "ml2_port_bindings_1", "portsecuritybindings_1", "portdnses_1", "securitygroupportbindings_1", "qos_network_policy_bindings_1", "qos_port_policy_bindings_1", "trunks_1", "standardattributes_1" and FROM element "networks". Apply join condition(s) between each element to resolve. This patch avoids this query by checking the network IDs list. If the list is empty, the expected port list will be too. This is also a small optimization because we are skipping the port query. This patch is also applying the same logic to the second query in this method. Closes-Bug: #2018000 Change-Id: Ia5380bc78cc1d0136e11cc4692069279419e285e (cherry picked from commit 9ac59e4)
1 parent 28dd08a commit 995c465

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

neutron/services/qos/qos_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def _extend_port_resource_request_bulk(ports_res, noop):
366366
def _get_ports_with_policy(self, context, policy):
367367
networks_ids = policy.get_bound_networks()
368368
ports_with_net_policy = ports_object.Port.get_objects(
369-
context, network_id=networks_ids)
369+
context, network_id=networks_ids) if networks_ids else []
370370

371371
# Filter only this ports which don't have overwritten policy
372372
ports_with_net_policy = [
@@ -376,7 +376,7 @@ def _get_ports_with_policy(self, context, policy):
376376

377377
ports_ids = policy.get_bound_ports()
378378
ports_with_policy = ports_object.Port.get_objects(
379-
context, id=ports_ids)
379+
context, id=ports_ids) if ports_ids else []
380380
return list(set(ports_with_policy + ports_with_net_policy))
381381

382382
def _validate_create_port_callback(self, resource, event, trigger,

0 commit comments

Comments
 (0)