From 431dd0ed82c0656895b117cac2561b69bae8838c Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Wed, 28 Feb 2018 16:35:02 +0100 Subject: [PATCH 1/2] Do not change passed extra attributes Do not change passed extra attributes, since that could affect another inventory collections --- .../network_manager.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection_default/network_manager.rb b/app/models/manager_refresh/inventory_collection_default/network_manager.rb index 38ccab5285f..8f2246f6b27 100644 --- a/app/models/manager_refresh/inventory_collection_default/network_manager.rb +++ b/app/models/manager_refresh/inventory_collection_default/network_manager.rb @@ -8,7 +8,7 @@ def cloud_subnet_network_ports(extra_attributes = {}) :parent_inventory_collections => [:vms, :network_ports, :load_balancers], } - extra_attributes[:targeted_arel] = lambda do |inventory_collection| + attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.cloud_subnet_network_ports.references(:network_ports).where( :network_ports => {:ems_ref => manager_uuids} @@ -114,7 +114,7 @@ def load_balancer_pools(extra_attributes = {}) } } - extra_attributes[:targeted_arel] = lambda do |inventory_collection| + attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_pools.where(:ems_ref => manager_uuids) end @@ -132,10 +132,10 @@ def load_balancer_pool_members(extra_attributes = {}) } } - extra_attributes[:targeted_arel] = lambda do |inventory_collection| + attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_pool_members - .joins(:load_balancer_pool_member_pools => :load_balancer_pool) + .joins(:load_balancer_pool_member_pools => :load_balancler_pool) .where(:load_balancer_pool_member_pools => {'load_balancer_pools' => {:ems_ref => manager_uuids}}) .distinct end @@ -151,7 +151,7 @@ def load_balancer_pool_member_pools(extra_attributes = {}) :parent_inventory_collections => [:load_balancers] } - extra_attributes[:targeted_arel] = lambda do |inventory_collection| + attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_pool_member_pools .references(:load_balancer_pools) @@ -173,7 +173,7 @@ def load_balancer_listeners(extra_attributes = {}) } } - extra_attributes[:targeted_arel] = lambda do |inventory_collection| + attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_listeners.joins(:load_balancer).where( :load_balancers => {:ems_ref => manager_uuids} @@ -191,7 +191,7 @@ def load_balancer_listener_pools(extra_attributes = {}) :parent_inventory_collections => [:load_balancers] } - extra_attributes[:targeted_arel] = lambda do |inventory_collection| + attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_listener_pools.joins(:load_balancer_pool).where( :load_balancer_pools => {:ems_ref => manager_uuids} @@ -211,7 +211,7 @@ def load_balancer_health_checks(extra_attributes = {}) } } - extra_attributes[:targeted_arel] = lambda do |inventory_collection| + attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_health_checks.where(:ems_ref => manager_uuids) end @@ -227,7 +227,7 @@ def load_balancer_health_check_members(extra_attributes = {}) :parent_inventory_collections => [:load_balancers], } - extra_attributes[:targeted_arel] = lambda do |inventory_collection| + attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_health_check_members.references(:load_balancer_health_checks).where( :load_balancer_health_checks => {:ems_ref => manager_uuids} From 55c716363ffddcef8bd1c2f2ec82d17895488ea0 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Wed, 28 Feb 2018 17:04:40 +0100 Subject: [PATCH 2/2] Correct targeted_arel joined with load_balancer Correct targeted_arel joined with load_balancer. For AWS, it was ok to join to pool, which had the same ems_ref as lb. But for Azure, the pool has different ems_ref, so we need to correctly join every table to load_balancers table and filter there Partially fixes https://bugzilla.redhat.com/show_bug.cgi?id=1487602 --- app/models/load_balancer_pool.rb | 1 + .../network_manager.rb | 46 ++++++++++++------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app/models/load_balancer_pool.rb b/app/models/load_balancer_pool.rb index 76f1c7489ca..91da65474b3 100644 --- a/app/models/load_balancer_pool.rb +++ b/app/models/load_balancer_pool.rb @@ -8,6 +8,7 @@ class LoadBalancerPool < ApplicationRecord has_many :load_balancer_listener_pools, :dependent => :destroy has_many :load_balancer_listeners, :through => :load_balancer_listener_pools + has_many :load_balancers, :through => :load_balancer_listeners has_many :load_balancer_pool_member_pools, :dependent => :destroy has_many :load_balancer_pool_members, :through => :load_balancer_pool_member_pools diff --git a/app/models/manager_refresh/inventory_collection_default/network_manager.rb b/app/models/manager_refresh/inventory_collection_default/network_manager.rb index 8f2246f6b27..f30223c6cdb 100644 --- a/app/models/manager_refresh/inventory_collection_default/network_manager.rb +++ b/app/models/manager_refresh/inventory_collection_default/network_manager.rb @@ -116,7 +116,10 @@ def load_balancer_pools(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_pools.where(:ems_ref => manager_uuids) + inventory_collection.parent.load_balancer_pools + .joins(:load_balancers) + .where(:load_balancers => {:ems_ref => manager_uuids}) + .distinct end attributes.merge!(extra_attributes) @@ -135,9 +138,14 @@ def load_balancer_pool_members(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_pool_members - .joins(:load_balancer_pool_member_pools => :load_balancler_pool) - .where(:load_balancer_pool_member_pools => {'load_balancer_pools' => {:ems_ref => manager_uuids}}) - .distinct + .joins(:load_balancer_pool_member_pools => [:load_balancer_pool => :load_balancers]) + .where(:load_balancer_pool_member_pools => { + 'load_balancer_pools' => { + 'load_balancers' => { + :ems_ref => manager_uuids + } + } + }).distinct end attributes.merge!(extra_attributes) @@ -154,8 +162,8 @@ def load_balancer_pool_member_pools(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_pool_member_pools - .references(:load_balancer_pools) - .where(:load_balancer_pools => {:ems_ref => manager_uuids}) + .joins(:load_balancer_pool => :load_balancers) + .where(:load_balancer_pools => {'load_balancers' => {:ems_ref => manager_uuids}}) .distinct end @@ -175,9 +183,10 @@ def load_balancer_listeners(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_listeners.joins(:load_balancer).where( - :load_balancers => {:ems_ref => manager_uuids} - ) + inventory_collection.parent.load_balancer_listeners + .joins(:load_balancer) + .where(:load_balancers => {:ems_ref => manager_uuids}) + .distinct end attributes.merge!(extra_attributes) @@ -193,9 +202,10 @@ def load_balancer_listener_pools(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_listener_pools.joins(:load_balancer_pool).where( - :load_balancer_pools => {:ems_ref => manager_uuids} - ) + inventory_collection.parent.load_balancer_listener_pools + .joins(:load_balancer_pool => :load_balancers) + .where(:load_balancer_pools => {'load_balancers' => {:ems_ref => manager_uuids}}) + .distinct end attributes.merge!(extra_attributes) @@ -213,7 +223,10 @@ def load_balancer_health_checks(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_health_checks.where(:ems_ref => manager_uuids) + inventory_collection.parent.load_balancer_health_checks + .joins(:load_balancer) + .where(:load_balancers => {:ems_ref => manager_uuids}) + .distinct end attributes.merge!(extra_attributes) @@ -229,9 +242,10 @@ def load_balancer_health_check_members(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_health_check_members.references(:load_balancer_health_checks).where( - :load_balancer_health_checks => {:ems_ref => manager_uuids} - ) + inventory_collection.parent.load_balancer_health_check_members + .joins(:load_balancer_health_check => :load_balancer) + .where(:load_balancer_health_checks => {'load_balancers' => {:ems_ref => manager_uuids}}) + .distinct end attributes.merge!(extra_attributes)