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
This commit is contained in:
Родитель
a2a9d93fd3
Коммит
5f7ae353a0
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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$
|
||||
|
|
Загрузка…
Ссылка в новой задаче