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
(cherry picked from commit c7aa203)
  • Loading branch information
kbrock authored and mzazrivec committed Dec 18, 2020
1 parent 0b7fe68 commit 7ea05a6
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 @@ -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
6 changes: 5 additions & 1 deletion app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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 @@ -312,6 +312,10 @@ def destroy_with_subtree
subtree.sort_by(&:depth).reverse.each(&:destroy)
end

def update_miq_product_features_for_tenant_nodes
MiqProductFeature.invalidate_caches_queue
end

private

# when a root tenant has an attribute with a nil value,
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 7ea05a6

Please sign in to comment.