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

Commit 8840db2

Browse files
author
Bogdan Irimie
authored
(FACT-2562) Correctly load custom and external fact directories (#458)
* (FACT-2562) Remove reset from to_hash. Save external and custom facts in options. * (FACT-2562) Read custom and external facts from options instead of LegacyFacter. * (FACT-2562) Fix tests. * (FACT-2562) Update tests description.
1 parent b4917e6 commit 8840db2

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

lib/facter.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def fact(user_query)
131131
# @api public
132132
def reset
133133
LegacyFacter.reset
134+
Options[:custom_dir] = []
135+
Options[:external_dir] = []
134136
LegacyFacter.search(*Options.custom_dir)
135137
LegacyFacter.search_external(Options.external_dir)
136138
nil
@@ -145,6 +147,7 @@ def reset
145147
#
146148
# @api public
147149
def search(*dirs)
150+
Options[:custom_dir] += dirs
148151
LegacyFacter.search(*dirs)
149152
end
150153

@@ -156,6 +159,7 @@ def search(*dirs)
156159
#
157160
# @api public
158161
def search_external(dirs)
162+
Options[:external_dir] += dirs
159163
LegacyFacter.search_external(dirs)
160164
end
161165

@@ -165,7 +169,7 @@ def search_external(dirs)
165169
#
166170
# @api public
167171
def search_external_path
168-
LegacyFacter.search_external_path
172+
Options.external_dir
169173
end
170174

171175
# Returns the registered search directories for custom facts.
@@ -174,7 +178,7 @@ def search_external_path
174178
#
175179
# @api public
176180
def search_path
177-
LegacyFacter.search_path
181+
Options.custom_dir
178182
end
179183

180184
# Gets a hash mapping fact names to their values
@@ -186,7 +190,6 @@ def search_path
186190
def to_hash
187191
log_blocked_facts
188192

189-
reset
190193
resolved_facts = Facter::FactManager.instance.resolve_facts
191194
Facter::SessionCache.invalidate_all_caches
192195
Facter::FactCollection.new.build_fact_collection!(resolved_facts)

lib/framework/core/fact_loaders/external_fact_loader.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def all_facts
1919
# The search paths must be set before creating the fact collection.
2020
# If we set them after, they will not be visible.
2121
def load_search_paths
22+
LegacyFacter.reset_search_path!
2223
LegacyFacter.search(*Options.custom_dir) if Options.custom_dir?
2324
LegacyFacter.search_external(Options.external_dir) if Options.external_dir?
2425
end

spec/facter/facter_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@
285285
end
286286

287287
describe '#search_path' do
288-
it 'sends call to LegacyFacter' do
289-
expect(LegacyFacter).to receive(:search_path).once
288+
it 'sends call to Facter::Options' do
289+
expect(Facter::Options).to receive(:custom_dir).once
290290
Facter.search_path
291291
end
292292
end
@@ -301,8 +301,8 @@
301301
end
302302

303303
describe '#search_external_path' do
304-
it 'sends call to LegacyFacter' do
305-
expect(LegacyFacter).to receive(:search_external_path).once
304+
it 'sends call to Facter::Options' do
305+
expect(Facter::Options).to receive(:external_dir).once
306306
Facter.search_external_path
307307
end
308308
end

0 commit comments

Comments
 (0)