Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

(FACT-2562) Correctly load custom and external fact directories #458

Merged
merged 4 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/facter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -145,6 +147,7 @@ def reset
#
# @api public
def search(*dirs)
Options[:custom_dir] += dirs
LegacyFacter.search(*dirs)
end

Expand All @@ -156,6 +159,7 @@ def search(*dirs)
#
# @api public
def search_external(dirs)
Options[:external_dir] += dirs
LegacyFacter.search_external(dirs)
end

Expand All @@ -165,7 +169,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.
Expand All @@ -174,7 +178,7 @@ def search_external_path
#
# @api public
def search_path
LegacyFacter.search_path
Options.custom_dir
end

# Gets a hash mapping fact names to their values
Expand All @@ -186,7 +190,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)
Expand Down
1 change: 1 addition & 0 deletions lib/framework/core/fact_loaders/external_fact_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/facter/facter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@
end

describe '#search_path' do
it 'sends call to LegacyFacter' do
expect(LegacyFacter).to receive(:search_path).once
it 'sends call to Facter::Options' do
expect(Facter::Options).to receive(:custom_dir).once
Facter.search_path
end
end
Expand All @@ -301,8 +301,8 @@
end

describe '#search_external_path' do
it 'sends call to LegacyFacter' do
expect(LegacyFacter).to receive(:search_external_path).once
it 'sends call to Facter::Options' do
expect(Facter::Options).to receive(:external_dir).once
Facter.search_external_path
end
end
Expand Down