summaryrefslogtreecommitdiff
path: root/neutron
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <ralonsoh@redhat.com>2023-04-28 16:34:22 +0200
committerRodolfo Alonso Hernandez <ralonsoh@redhat.com>2023-04-28 16:40:04 +0200
commit9ac59e4b4a3b40861308c71bbacc379dacb2bd20 (patch)
treee248c96b46aebb967a82b646fe6bfba00a52aeaa /neutron
parent1ee0e3858829b260dabda5192ef819708bd034e6 (diff)
downloadneutron-9ac59e4b4a3b40861308c71bbacc379dacb2bd20.tar.gz
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
Diffstat (limited to 'neutron')
-rw-r--r--neutron/services/qos/qos_plugin.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/neutron/services/qos/qos_plugin.py b/neutron/services/qos/qos_plugin.py
index 776dae6da2..d4f5d5038e 100644
--- a/neutron/services/qos/qos_plugin.py
+++ b/neutron/services/qos/qos_plugin.py
@@ -323,7 +323,7 @@ class QoSPlugin(qos.QoSPluginBase):
def _get_ports_with_policy(self, context, policy):
networks_ids = policy.get_bound_networks()
ports_with_net_policy = ports_object.Port.get_objects(
- context, network_id=networks_ids)
+ context, network_id=networks_ids) if networks_ids else []
# Filter only this ports which don't have overwritten policy
ports_with_net_policy = [
@@ -333,7 +333,7 @@ class QoSPlugin(qos.QoSPluginBase):
ports_ids = policy.get_bound_ports()
ports_with_policy = ports_object.Port.get_objects(
- context, id=ports_ids)
+ context, id=ports_ids) if ports_ids else []
return list(set(ports_with_policy + ports_with_net_policy))
def _validate_create_port_callback(self, resource, event, trigger,