Skip to content

Commit

Permalink
Merge pull request #20772 from kbrock/invalidate_all_caches
Browse files Browse the repository at this point in the history
Tenant changes changes miq product features on all servers

(cherry picked from commit c7836b2)
  • Loading branch information
Fryguy authored and simaishi committed Jan 7, 2021
1 parent 717da55 commit 4bebcc4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/models/miq_product_feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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
Expand Down
7 changes: 6 additions & 1 deletion app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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
Expand Down Expand Up @@ -319,6 +320,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
Expand Down
1 change: 1 addition & 0 deletions spec/models/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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)
Expand Down

0 comments on commit 4bebcc4

Please sign in to comment.