summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/client/master.rb37
-rw-r--r--lib/puppet/pgraph.rb7
-rwxr-xr-xlib/puppet/server/pelement.rb3
-rw-r--r--lib/puppet/transaction.rb11
-rw-r--r--lib/puppet/type/pfile.rb3
-rwxr-xr-xtest/client/master.rb103
-rwxr-xr-xtest/language/interpreter.rb2
-rwxr-xr-xtest/other/dsl.rb1
-rw-r--r--test/other/pgraph.rb12
-rwxr-xr-xtest/server/pelement.rb11
10 files changed, 161 insertions, 29 deletions
diff --git a/lib/puppet/client/master.rb b/lib/puppet/client/master.rb
index 97d224065..fb7922937 100644
--- a/lib/puppet/client/master.rb
+++ b/lib/puppet/client/master.rb
@@ -125,20 +125,16 @@ class Puppet::Client::MasterClient < Puppet::Client
ensure
Puppet::Storage.store
end
-
+
if Puppet[:report]
- begin
- report = transaction.report()
- if Puppet[:rrdgraph] == true
- report.graph()
- end
- reportclient().report(report)
- rescue => detail
- Puppet.err "Reporting failed: %s" % detail
- end
+ report(transaction)
end
return transaction
+ ensure
+ if defined? transaction and transaction
+ transaction.cleanup
+ end
end
# Cache the config
@@ -496,6 +492,8 @@ class Puppet::Client::MasterClient < Puppet::Client
private
+ # Download files from the remote server, returning a list of all
+ # changed files.
def self.download(args)
objects = Puppet::Type.type(:component).create(
:name => "#{args[:name]}_collector"
@@ -529,12 +527,16 @@ class Puppet::Client::MasterClient < Puppet::Client
# Now source all of the changed objects, but only source those
# that are top-level.
+ files = []
trans.changed?.find_all do |object|
- yield object
+ yield object if block_given?
+ files << object[:path]
end
+ trans.cleanup
# Now clean up after ourselves
objects.remove
+ files
end
# Retrieve facts from the central server.
@@ -610,6 +612,19 @@ class Puppet::Client::MasterClient < Puppet::Client
loaddir(dir, "fact")
end
end
+
+ # Send off the transaction report.
+ def report(transaction)
+ begin
+ report = transaction.report()
+ if Puppet[:rrdgraph] == true
+ report.graph()
+ end
+ reportclient().report(report)
+ rescue => detail
+ Puppet.err "Reporting failed: %s" % detail
+ end
+ end
def reportclient
unless defined? @reportclient
diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb
index bf156ed2d..d988ff36a 100644
--- a/lib/puppet/pgraph.rb
+++ b/lib/puppet/pgraph.rb
@@ -14,6 +14,13 @@ class Puppet::PGraph < GRATR::Digraph
# This is the type used for splicing.
attr_accessor :container_type
+ def clear
+ @vertex_dict.clear
+ if defined? @edge_number
+ @edge_number.clear
+ end
+ end
+
# The dependencies for a given resource.
def dependencies(resource)
tree_from_vertex(resource, :dfs).keys
diff --git a/lib/puppet/server/pelement.rb b/lib/puppet/server/pelement.rb
index 3001cd9a1..0c9537957 100755
--- a/lib/puppet/server/pelement.rb
+++ b/lib/puppet/server/pelement.rb
@@ -40,6 +40,9 @@ class Server::PElement < Server::Handler
# And then apply the configuration. This way we're reusing all
# the code in there. It should probably just be separated out, though.
transaction = client.apply
+
+ # And then clean up
+ component.remove
# It'd be nice to return some kind of report, but... at this point
# we have no such facility.
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index d6d1669a1..99b03b435 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -105,12 +105,16 @@ class Transaction
}.uniq
end
- # Do any necessary cleanup. Basically just removes any generated
- # resources.
+ # Do any necessary cleanup. If we don't get rid of the graphs, the
+ # contained resources might never get cleaned up.
def cleanup
@generated.each do |resource|
resource.remove
end
+ if defined? @relgraph
+ @relgraph.clear
+ end
+ @resources.clear
end
# See if the resource generates new resources at evaluation time.
@@ -210,8 +214,6 @@ class Transaction
# And then close the transaction log.
Puppet::Log.close(@report)
end
-
- cleanup()
Puppet.debug "Finishing transaction %s with %s changes" %
[self.object_id, @count]
@@ -235,7 +237,6 @@ class Transaction
# enough to check the immediate dependencies, which is why we use
# a tree from the reversed graph.
skip = false
- resource.info "checking for failed deps"
@relgraph.reversal.tree_from_vertex(resource, :dfs).keys.each do |dep|
if fails = failed?(dep)
resource.notice "Dependency %s[%s] has %s failures" %
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 24f961a62..0d69ffdda 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -174,6 +174,9 @@ module Puppet
# Autorequire any parent directories.
autorequire(:file) do
+ unless self[:path]
+ raise "no path for %s" % self.ref
+ end
File.dirname(self[:path])
end
diff --git a/test/client/master.rb b/test/client/master.rb
index f89d2cae8..9318fdcd6 100755
--- a/test/client/master.rb
+++ b/test/client/master.rb
@@ -9,6 +9,30 @@ require 'puppettest'
class TestMasterClient < Test::Unit::TestCase
include PuppetTest::ServerTest
+
+ class FakeTrans
+ def initialize
+ @counters = Hash.new { |h,k| h[k] = 0 }
+ end
+ [:evaluate, :report, :cleanup, :addtimes, :tags, :ignoreschedules].each do |m|
+ define_method(m.to_s + "=") do |*args|
+ @counters[m] += 1
+ end
+ define_method(m) do |*args|
+ @counters[m] += 1
+ end
+ define_method(m.to_s + "?") do
+ @counters[m]
+ end
+ end
+ end
+ class FakeComponent
+ attr_accessor :trans
+ def evaluate
+ @trans = FakeTrans.new
+ @trans
+ end
+ end
def mkmaster(file = nil)
master = nil
@@ -37,6 +61,73 @@ class TestMasterClient < Test::Unit::TestCase
return client
end
+
+ def mk_fake_client
+ server = Puppet::Server::Master.new :Code => ""
+ master = Puppet::Client::MasterClient.new :Server => server, :Local => true
+
+ # Now create some objects
+ objects = FakeComponent.new
+
+ master.send(:instance_variable_set, "@objects", objects)
+
+ class << master
+ def report(r)
+ @reported ||= 0
+ @reported += 1
+ end
+ def reported
+ @reported ||= 0
+ @reported
+ end
+ end
+ return master, objects
+ end
+
+ def test_apply
+ master, objects = mk_fake_client
+
+ check = Proc.new do |hash|
+ assert(objects.trans, "transaction was not created")
+ trans = objects.trans
+ hash[:yes].each do |m|
+ assert_equal(1, trans.send(m.to_s + "?"), "did not call #{m} enough times")
+ end
+ hash[:no].each do |m|
+ assert_equal(0, trans.send(m.to_s + "?"), "called #{m} too many times")
+ end
+ end
+
+ # First try it with no arguments
+ assert_nothing_raised do
+ master.apply
+ end
+ check.call :yes => %w{evaluate cleanup addtimes}, :no => %w{report tags ignoreschedules}
+ assert_equal(0, master.reported, "master sent report with reports disabled")
+
+
+ # Now enable reporting and make sure the report method gets called
+ Puppet[:report] = true
+ assert_nothing_raised do
+ master.apply
+ end
+ check.call :yes => %w{evaluate cleanup addtimes}, :no => %w{tags ignoreschedules}
+ assert_equal(1, master.reported, "master did not send report")
+
+ # Now try it with tags enabled
+ assert_nothing_raised do
+ master.apply("tags")
+ end
+ check.call :yes => %w{evaluate cleanup tags addtimes}, :no => %w{ignoreschedules}
+ assert_equal(2, master.reported, "master did not send report")
+
+ # and ignoreschedules
+ assert_nothing_raised do
+ master.apply("tags", true)
+ end
+ check.call :yes => %w{evaluate cleanup tags ignoreschedules addtimes}, :no => %w{}
+ assert_equal(3, master.reported, "master did not send report")
+ end
def test_disable
manifest = mktestmanifest
@@ -129,20 +220,24 @@ class TestMasterClient < Test::Unit::TestCase
}
end
+ # This method is supposed
def test_download
source = tempfile()
dest = tempfile()
sfile = File.join(source, "file")
+ dfile = File.join(dest, "file")
Dir.mkdir(source)
File.open(sfile, "w") {|f| f.puts "yay"}
files = []
assert_nothing_raised do
-
- Puppet::Client::Master.download(:dest => dest, :source => source, :name => "testing") do |path|
- files << path
- end
+ files = Puppet::Client::MasterClient.download(:dest => dest, :source => source, :name => "testing")
end
+
+ assert(FileTest.directory?(dest), "dest dir was not created")
+ assert(FileTest.file?(dfile), "dest file was not created")
+ assert_equal(File.read(sfile), File.read(dfile), "Dest file had incorrect contents")
+ assert_equal([dest, dfile].sort, files.sort, "Changed files were not returned correctly")
end
def test_getplugins
diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb
index 28c6d41a1..2fe9cc601 100755
--- a/test/language/interpreter.rb
+++ b/test/language/interpreter.rb
@@ -564,7 +564,7 @@ class TestInterpreter < Test::Unit::TestCase
assert(other, "Could not find class")
assert(interp.findclass("", "other::myclass"), "Could not find class")
assert_equal("other::myclass", other.fqname)
- assert_equal("other", other.namespace)
+ assert_equal("other::myclass", other.namespace)
assert_equal("myclass", other.type)
assert_equal(%w{something diff},
interp.findclass("other", "myclass").code.evaluate(:scope => scope))
diff --git a/test/other/dsl.rb b/test/other/dsl.rb
index bb7fc86cf..50eac4781 100755
--- a/test/other/dsl.rb
+++ b/test/other/dsl.rb
@@ -193,6 +193,7 @@ class TestDSL < Test::Unit::TestCase
end
def test_typemethods
+ Puppet::Type.loadall
filetype = Puppet::Type.type(:file)
path = tempfile()
diff --git a/test/other/pgraph.rb b/test/other/pgraph.rb
index 3dc232670..88f753131 100644
--- a/test/other/pgraph.rb
+++ b/test/other/pgraph.rb
@@ -14,6 +14,18 @@ class TestPGraph < Test::Unit::TestCase
Edge = Puppet::Relationship
+ def test_clear
+ graph = Puppet::PGraph.new
+ graph.add_edge!("a", "b")
+ graph.add_vertex! "c"
+ assert_nothing_raised do
+ graph.clear
+ end
+ assert(graph.vertices.empty?, "Still have vertices after clear")
+ assert(graph.edges.empty?, "still have edges after clear")
+ end
+
+
def test_matching_edges
graph = Puppet::PGraph.new
diff --git a/test/server/pelement.rb b/test/server/pelement.rb
index 24836e66c..c86dadc11 100755
--- a/test/server/pelement.rb
+++ b/test/server/pelement.rb
@@ -254,23 +254,16 @@ class TestPElementServer < Test::Unit::TestCase
Puppet::Type.type(:file).clear
- Puppet.err filetrans[:parent].inspect
-
- #p filetrans
-
bucket = Puppet::TransBucket.new
bucket.type = "file"
bucket.push filetrans
- #p bucket
-
oldbucket = bucket.dup
File.unlink(file)
assert_nothing_raised {
server.apply(bucket)
}
-
assert(FileTest.exists?(file), "File did not get recreated")
# Now try it as a "nonlocal" server
@@ -287,11 +280,13 @@ class TestPElementServer < Test::Unit::TestCase
Puppet.warning "YAML is broken on this machine"
return
end
- #puts Base64.decode64(yaml)
+ # puts Base64.decode64(yaml)
+ objects = nil
assert_nothing_raised("Could not reload yaml") {
YAML::load(Base64.decode64(yaml))
}
+ # The server is supposed to accept yaml and execute it.
assert_nothing_raised {
server.apply(yaml)
}