Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add last known good fact hash and handle empty results from facter

  • Loading branch information...
commit afafddf517f108c1d8bd4f4027b2cdcacda04cf9 1 parent 9d47e20
R.I.Pienaar ripienaar authored
Showing with 17 additions and 3 deletions.
  1. +17 −3 facts/facter/facter.rb
20 facts/facter/facter.rb
View
@@ -20,6 +20,7 @@ module Facts
class Facter<Base
@@last_facts_load = 0
@@facts = {}
+ @@last_good_facts = {}
def get_facts
config = Config.instance
@@ -29,7 +30,7 @@ def get_facts
cache_time = config.pluginconf["facter.cache_time"] || 300
logger.debug("Have FACTERLIB: #{ENV['FACTERLIB']}")
- logger.debug("Last facts load time i #{@@last_facts_load} cache time is #{cache_time}")
+ logger.debug("Last facts load time is #{@@last_facts_load} cache time is #{cache_time}")
Thread.exclusive do
begin
@@ -48,14 +49,27 @@ def get_facts
private
def reload_facts
- @@last_facts_load = Time.now.to_i
::Facter.reset
@@facts = {}
- ::Facter.to_hash.each_pair do |key,value|
+ facts = ::Facter.to_hash
+ Log.instance.info("Loaded #{facts.keys.size} facts from Facter")
+
+ facts.each_pair do |key,value|
@@facts[key] = value.to_s
end
+
+ # Somehow, sometimes, we get empty fact hashes?
+ if @@facts.empty?
+ Log.instance.error("Got empty facts, resetting to last known good")
+
+ @@facts = @last_good_facts.clone
+ else
+ @@last_good_facts = @@facts.clone
+ end
+
+ @@last_facts_load = Time.now.to_i
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.