Skip to content

Commit

Permalink
Tenant changes changes miq product features on all servers
Browse files Browse the repository at this point in the history
miq product features contain tenant data. So we want to update the product features data
on all servers when a tenant changes

This allows us to remove special logic from the front end.

ManageIQ/manageiq-ui-classic#7430
  • Loading branch information
kbrock committed Nov 12, 2020
1 parent 92cb362 commit c7aa203
Show file tree
Hide file tree
Showing 3 changed files with 18 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 @@ -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
Expand Down
6 changes: 5 additions & 1 deletion app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Tenant < ApplicationRecord

before_save :nil_blanks
after_save -> { MiqProductFeature.invalidate_caches }
after_create :create_tenant_group, :create_miq_product_features_for_tenant_nodes
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 +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
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 @@ -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)
Expand Down

0 comments on commit c7aa203

Please sign in to comment.