From 817e4a72209158bf3ac806642264e38cac88b604 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Mon, 2 Nov 2020 14:38:29 -0500 Subject: [PATCH] Tenant changes changes miq product features on all servers 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. https://github.com/ManageIQ/manageiq-ui-classic/pull/7430 --- app/models/miq_product_feature.rb | 12 ++++++++++++ app/models/tenant.rb | 7 +++++-- spec/models/host_spec.rb | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/models/miq_product_feature.rb b/app/models/miq_product_feature.rb index a716b035ef27..d98fd1fd88e0 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 3e1b38118f50..8e7abd2cbf99 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -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? @@ -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, diff --git a/spec/models/host_spec.rb b/spec/models/host_spec.rb index d3bcb2059b7b..af0d2243814d 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)