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 6, 2020
1 parent f56f6d4 commit 817e4a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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
7 changes: 5 additions & 2 deletions app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ 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
before_destroy :ensure_can_be_destroyed

def self.scope_by_tenant?
Expand Down Expand Up @@ -318,6 +317,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

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 @@ -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 817e4a7

Please sign in to comment.