From 6d82cc4c391b7746bce44639cd333feae8047db6 Mon Sep 17 00:00:00 2001 From: Bogdan Irimie Date: Thu, 16 Apr 2020 14:58:56 +0300 Subject: [PATCH 1/4] (FACT-2562) Remove reset from to_hash. Save external and custom facts in options. --- custom_facts/my_custom_fact.rb | 4 ++-- lib/facter.rb | 7 ++++++- lib/framework/core/fact_loaders/external_fact_loader.rb | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/custom_facts/my_custom_fact.rb b/custom_facts/my_custom_fact.rb index efa252238..7d198d80f 100644 --- a/custom_facts/my_custom_fact.rb +++ b/custom_facts/my_custom_fact.rb @@ -3,7 +3,7 @@ Facter.add(:my_custom_fact) do has_weight(10_000) setcode do - # 'my_custom_fact' - Facter.value('os') + 'my_custom_fact' + # Facter.value('os') end end diff --git a/lib/facter.rb b/lib/facter.rb index 179d57b56..ce4ac9423 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -131,6 +131,8 @@ def fact(user_query) # @api public def reset LegacyFacter.reset + Options[:custom_dir] = [] + Options[:external_dir] = [] LegacyFacter.search(*Options.custom_dir) LegacyFacter.search_external(Options.external_dir) nil @@ -145,6 +147,7 @@ def reset # # @api public def search(*dirs) + Options[:custom_dir] += dirs LegacyFacter.search(*dirs) end @@ -156,6 +159,7 @@ def search(*dirs) # # @api public def search_external(dirs) + Options[:external_dir] += dirs LegacyFacter.search_external(dirs) end @@ -166,6 +170,7 @@ def search_external(dirs) # @api public def search_external_path LegacyFacter.search_external_path + Options.external_dir end # Returns the registered search directories for custom facts. @@ -174,6 +179,7 @@ def search_external_path # # @api public def search_path + Options.custom_dir LegacyFacter.search_path end @@ -186,7 +192,6 @@ def search_path def to_hash log_blocked_facts - reset resolved_facts = Facter::FactManager.instance.resolve_facts Facter::SessionCache.invalidate_all_caches Facter::FactCollection.new.build_fact_collection!(resolved_facts) diff --git a/lib/framework/core/fact_loaders/external_fact_loader.rb b/lib/framework/core/fact_loaders/external_fact_loader.rb index f8786b2c6..dd92a889e 100644 --- a/lib/framework/core/fact_loaders/external_fact_loader.rb +++ b/lib/framework/core/fact_loaders/external_fact_loader.rb @@ -19,6 +19,7 @@ def all_facts # The search paths must be set before creating the fact collection. # If we set them after, they will not be visible. def load_search_paths + LegacyFacter.reset_search_path! LegacyFacter.search(*Options.custom_dir) if Options.custom_dir? LegacyFacter.search_external(Options.external_dir) if Options.external_dir? end From 9bf58df48f57ee008e13075aef07b4ddb318354b Mon Sep 17 00:00:00 2001 From: Bogdan Irimie Date: Thu, 16 Apr 2020 15:48:36 +0300 Subject: [PATCH 2/4] (FACT-2562) Read custom and external facts from options instead of LegacyFacter. --- lib/facter.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/facter.rb b/lib/facter.rb index ce4ac9423..066a75c99 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -169,7 +169,6 @@ def search_external(dirs) # # @api public def search_external_path - LegacyFacter.search_external_path Options.external_dir end @@ -180,7 +179,6 @@ def search_external_path # @api public def search_path Options.custom_dir - LegacyFacter.search_path end # Gets a hash mapping fact names to their values From 7a45c2d44ed875dbc336bb55d2181eae0cf616c9 Mon Sep 17 00:00:00 2001 From: Bogdan Irimie Date: Thu, 16 Apr 2020 16:55:58 +0300 Subject: [PATCH 3/4] (FACT-2562) Fix tests. --- spec/facter/facter_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/facter/facter_spec.rb b/spec/facter/facter_spec.rb index 51b34906f..4afb513aa 100644 --- a/spec/facter/facter_spec.rb +++ b/spec/facter/facter_spec.rb @@ -286,7 +286,7 @@ describe '#search_path' do it 'sends call to LegacyFacter' do - expect(LegacyFacter).to receive(:search_path).once + expect(Facter::Options).to receive(:custom_dir).once Facter.search_path end end @@ -302,7 +302,7 @@ describe '#search_external_path' do it 'sends call to LegacyFacter' do - expect(LegacyFacter).to receive(:search_external_path).once + expect(Facter::Options).to receive(:external_dir).once Facter.search_external_path end end From 1b120677229284b945d09863ddcf784ff09c2f83 Mon Sep 17 00:00:00 2001 From: Bogdan Irimie Date: Tue, 21 Apr 2020 10:43:59 +0300 Subject: [PATCH 4/4] (FACT-2562) Update tests description. --- custom_facts/my_custom_fact.rb | 4 ++-- spec/facter/facter_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_facts/my_custom_fact.rb b/custom_facts/my_custom_fact.rb index 7d198d80f..efa252238 100644 --- a/custom_facts/my_custom_fact.rb +++ b/custom_facts/my_custom_fact.rb @@ -3,7 +3,7 @@ Facter.add(:my_custom_fact) do has_weight(10_000) setcode do - 'my_custom_fact' - # Facter.value('os') + # 'my_custom_fact' + Facter.value('os') end end diff --git a/spec/facter/facter_spec.rb b/spec/facter/facter_spec.rb index 4afb513aa..ee2af3532 100644 --- a/spec/facter/facter_spec.rb +++ b/spec/facter/facter_spec.rb @@ -285,7 +285,7 @@ end describe '#search_path' do - it 'sends call to LegacyFacter' do + it 'sends call to Facter::Options' do expect(Facter::Options).to receive(:custom_dir).once Facter.search_path end @@ -301,7 +301,7 @@ end describe '#search_external_path' do - it 'sends call to LegacyFacter' do + it 'sends call to Facter::Options' do expect(Facter::Options).to receive(:external_dir).once Facter.search_external_path end