diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-19 01:42:10 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-19 01:42:10 +0000 |
commit | 5f7ae353a0ca9cadaf8fdc8803e1227ee6583d25 (patch) | |
tree | 840d708a742ab0234be7f55f3cf478a526a5f6a3 | |
parent | a2a9d93fd3f9de6d4c6d13ca8d99c2d496a39e40 (diff) | |
download | puppet-5f7ae353a0ca9cadaf8fdc8803e1227ee6583d25.tar.gz puppet-5f7ae353a0ca9cadaf8fdc8803e1227ee6583d25.tar.xz puppet-5f7ae353a0ca9cadaf8fdc8803e1227ee6583d25.zip |
Fixing #519. The facts are now cached in the state file and changes to them force a recompile.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2303 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | lib/puppet/network/client/master.rb | 13 | ||||
-rwxr-xr-x | test/network/client/master.rb | 29 |
3 files changed, 45 insertions, 0 deletions
@@ -1,4 +1,7 @@ 0.22.2 (grover) + Facts are now cached in the state file, and when they change the configuration + is always recompiled. (#519) + Added 'ignoreimport' setting for use in commit hooks. This causes the parser to ignore import statements so a single file can be parse-checked. (#544) diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb index 7553a62c7..506ed09e8 100644 --- a/lib/puppet/network/client/master.rb +++ b/lib/puppet/network/client/master.rb @@ -127,10 +127,22 @@ class Puppet::Network::Client::Master < Puppet::Network::Client end end + # Have the facts changed since we last compiled? + def facts_changed? + oldfacts = Puppet::Util::Storage.cache(:configuration)[:facts] + newfacts = self.class.facts + if oldfacts == newfacts + return false + else + return true + end + end + # Check whether our configuration is up to date def fresh? return false if Puppet[:ignorecache] return false unless self.compile_time + return false if self.facts_changed? # We're willing to give a 2 second drift if @driver.freshness - @compile_time.to_i < 1 @@ -570,6 +582,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client fromcache = true else @compile_time = Time.now + Puppet::Util::Storage.cache(:configuration)[:facts] = facts Puppet::Util::Storage.cache(:configuration)[:compile_time] = @compile_time end diff --git a/test/network/client/master.rb b/test/network/client/master.rb index 593c331ce..12f25820a 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -567,6 +567,35 @@ end assert(! @logs.detect { |l| l.message =~ /Could not load/}, "Tried to load cache when it is non-existent") end + + # #519 - cache the facts so that we notice if they change. + def test_factchanges_cause_recompile + $value = "one" + Facter.add(:testfact) do + setcode { $value } + end + assert_equal("one", Facter.value(:testfact), "fact was not set correctly") + master = mkclient + master.local = false + driver = master.send(:instance_variable_get, "@driver") + driver.local = false + + assert_nothing_raised("Could not compile config") do + master.getconfig + end + + $value = "two" + Facter.clear + Facter.loadfacts + Facter.add(:testfact) do + setcode { $value } + end + assert_equal("two", Facter.value(:testfact), "fact did not change") + + assert(master.facts_changed?, "master does not think facts changed") + assert(! master.fresh?, "master is considered fresh after facts changed") + + end end # $Id$ |