diff --git a/app/models/miq_product_feature.rb b/app/models/miq_product_feature.rb index a716b035ef2..d98fd1fd88e 100644 --- a/app/models/miq_product_feature.rb +++ b/app/models/miq_product_feature.rb @@ -107,6 +107,18 @@ def self.invalidate_caches @detail = nil end + # invalidate feature cache on this server and others + # + # called when data in the features change (typically tenant data). + # This then uses the queue to tell other servers they need to update as well. + def self.invalidate_caches_queue + invalidate_caches + MiqQueue.broadcast( + :class_name => name, + :method_name => "invalidate_caches" + ) + end + def self.features @feature_cache ||= begin # create hash with parent identifier and details diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 06c742d4730..78c37e3ab33 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -62,7 +62,8 @@ class Tenant < ApplicationRecord virtual_column :display_type, :type => :string before_save :nil_blanks - after_create :create_tenant_group, :create_miq_product_features_for_tenant_nodes + after_save -> { MiqProductFeature.invalidate_caches } + after_create :create_tenant_group, :create_miq_product_features_for_tenant_nodes, :update_miq_product_features_for_tenant_nodes def self.scope_by_tenant? true @@ -318,6 +319,10 @@ def create_miq_product_features_for_tenant_nodes MiqProductFeature.seed_single_tenant_miq_product_features(self) end + def update_miq_product_features_for_tenant_nodes + MiqProductFeature.invalidate_caches_queue + end + def destroy_with_subtree subtree.sort_by(&:depth).reverse.each(&:destroy) end diff --git a/spec/models/host_spec.rb b/spec/models/host_spec.rb index d3bcb2059b7..af0d2243814 100644 --- a/spec/models/host_spec.rb +++ b/spec/models/host_spec.rb @@ -140,6 +140,7 @@ it "policy passes" do expect_any_instance_of(described_class).to receive(:ipmi_power_on) + MiqQueue.delete_all @host.start status, message, result = MiqQueue.first.deliver MiqQueue.first.delivered(status, message, result)