diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-09 22:51:55 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-09 22:51:55 +0000 |
| commit | b5344f2acbf447be853af78f34a4b1562ae060f2 (patch) | |
| tree | 01094480b5eaa63e3792b9b489b102dbab3793e7 | |
| parent | 8f9264bcc30312cc927eac72c66415eae7b69e88 (diff) | |
| download | puppet-b5344f2acbf447be853af78f34a4b1562ae060f2.tar.gz puppet-b5344f2acbf447be853af78f34a4b1562ae060f2.tar.xz puppet-b5344f2acbf447be853af78f34a4b1562ae060f2.zip | |
Fixing the problem reported by Adnet Ghislain where facts do not load on later runs.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1757 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/puppet/client/master.rb | 19 | ||||
| -rw-r--r-- | test/client/master.rb | 19 | ||||
| -rw-r--r-- | test/lib/puppettest.rb | 2 |
3 files changed, 26 insertions, 14 deletions
diff --git a/lib/puppet/client/master.rb b/lib/puppet/client/master.rb index 8d7721ae5..0763cdfe1 100644 --- a/lib/puppet/client/master.rb +++ b/lib/puppet/client/master.rb @@ -539,9 +539,10 @@ class Puppet::Client::MasterClient < Puppet::Client # Retrieve facts from the central server. def self.getfacts - # First clear all existing definitions. + # Clear all existing definitions. Facter.clear + # Download the new facts path = Puppet[:factpath].split(":") files = [] download(:dest => Puppet[:factdest], :source => Puppet[:factsource], @@ -553,18 +554,8 @@ class Puppet::Client::MasterClient < Puppet::Client end - Facter.clear - files.each do |file| - begin - Puppet.info "Loading fact %s" % - File.basename(File.basename(file)).sub(".rb",'') - load file - rescue => detail - Puppet.warning "Could not reload fact %s: %s" % - [file, detail] - end - end ensure + # Reload everything. if Facter.respond_to? :loadfacts Facter.loadfacts elsif Facter.respond_to? :load @@ -573,6 +564,10 @@ class Puppet::Client::MasterClient < Puppet::Client raise Puppet::Error, "You must upgrade your version of Facter to use centralized facts" end + + # This loads all existing facts and any new ones. We have to remove and + # reload because there's no way to unload specific facts. + loadfacts() end # Retrieve the plugins from the central server. We only have to load the diff --git a/test/client/master.rb b/test/client/master.rb index c2277b8e4..096918918 100644 --- a/test/client/master.rb +++ b/test/client/master.rb @@ -190,6 +190,7 @@ end def test_getfacts Puppet[:factsource] = tempfile() Dir.mkdir(Puppet[:factsource]) + hostname = Facter.value(:hostname) myfact = File.join(Puppet[:factsource], "myfact.rb") File.open(myfact, "w") do |f| @@ -207,7 +208,9 @@ end assert(File.exists?(destfile), "Did not get fact") - assert_equal("yayness", Facter["myfact"].value, + assert_equal(hostname, Facter.value(:hostname), + "Lost value to hostname") + assert_equal("yayness", Facter.value(:myfact), "Did not get correct fact value") # Now modify the file and make sure the type is replaced @@ -222,8 +225,20 @@ end Puppet::Client::MasterClient.getfacts } - assert_equal("funtest", Facter["myfact"].value, + assert_equal("funtest", Facter.value(:myfact), "Did not reload fact") + assert_equal(hostname, Facter.value(:hostname), + "Lost value to hostname") + + # Now run it again and make sure the fact still loads + assert_nothing_raised { + Puppet::Client::MasterClient.getfacts + } + + assert_equal("funtest", Facter.value(:myfact), + "Did not reload fact") + assert_equal(hostname, Facter.value(:hostname), + "Lost value to hostname") end # Make sure we load all facts on startup. diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index e5192ccc7..c8c8b077d 100644 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -81,6 +81,8 @@ module PuppetTest $user = nonrootuser().uid.to_s $group = nonrootgroup().gid.to_s end + + Puppet.config.clear Puppet[:user] = $user Puppet[:group] = $group |
