diff options
| author | Luke Kanies <luke@madstop.com> | 2005-08-23 21:23:57 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-08-23 21:23:57 +0000 |
| commit | 5b20c92ff322ba1886209f788ce6a7df05315cf5 (patch) | |
| tree | 8b75ab42323ef07de4a5cab6182b4c8eff8eb5da | |
| parent | ba51e700ace1b34b2dbb06bc61287be184fe46ec (diff) | |
| download | puppet-5b20c92ff322ba1886209f788ce6a7df05315cf5.tar.gz puppet-5b20c92ff322ba1886209f788ce6a7df05315cf5.tar.xz puppet-5b20c92ff322ba1886209f788ce6a7df05315cf5.zip | |
Have done a significant reorganization of how clients work, also, along with some interesting trouble shooting on components
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@585 980ebf18-57e1-0310-9a29-db15c13687c0
| -rwxr-xr-x | bin/puppet | 7 | ||||
| -rw-r--r-- | lib/puppet.rb | 31 | ||||
| -rw-r--r-- | lib/puppet/client.rb | 360 | ||||
| -rw-r--r-- | lib/puppet/server.rb | 2 | ||||
| -rwxr-xr-x | lib/puppet/server/filebucket.rb | 174 | ||||
| -rw-r--r-- | lib/puppet/server/servlet.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/type/component.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/type/pfile.rb | 3 | ||||
| -rwxr-xr-x | lib/puppet/type/pfilebucket.rb | 4 | ||||
| -rw-r--r-- | test/client/tc_client.rb | 8 | ||||
| -rwxr-xr-x | test/executables/tc_puppetbin.rb | 3 | ||||
| -rwxr-xr-x | test/executables/tc_puppetd.rb | 3 | ||||
| -rwxr-xr-x | test/executables/tc_puppetmasterd.rb | 3 | ||||
| -rwxr-xr-x | test/language/tc_snippets.rb | 4 | ||||
| -rw-r--r-- | test/server/tc_bucket.rb | 109 | ||||
| -rwxr-xr-x | test/server/tc_fileserver.rb | 14 | ||||
| -rw-r--r-- | test/server/tc_master.rb | 8 | ||||
| -rw-r--r-- | test/server/tc_server.rb | 4 | ||||
| -rwxr-xr-x | test/types/tc_component.rb | 66 | ||||
| -rwxr-xr-x | test/types/tc_exec.rb | 11 | ||||
| -rwxr-xr-x | test/types/tc_filebucket.rb | 2 | ||||
| -rwxr-xr-x | test/types/tc_filesources.rb | 2 |
22 files changed, 407 insertions, 416 deletions
diff --git a/bin/puppet b/bin/puppet index 094cefd0a..1580cb196 100755 --- a/bin/puppet +++ b/bin/puppet @@ -103,7 +103,7 @@ if logfile end begin - server = Puppet::Master.new( + server = Puppet::Server::Master.new( :File => ARGV.shift, :Local => true ) @@ -113,8 +113,8 @@ rescue => detail end begin - client = Puppet::Client.new( - :Server => server + client = Puppet::Client::MasterClient.new( + :Master => server ) rescue => detail $stderr.puts detail @@ -123,6 +123,7 @@ end begin client.getconfig + client.config rescue => detail $stderr.puts detail exit(1) diff --git a/lib/puppet.rb b/lib/puppet.rb index 64a3821a9..ba432f492 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -190,19 +190,24 @@ module Puppet # XXX this should all be done using puppet objects, not using # normal mkdir def self.recmkdir(dir,mode = 0755) - tmp = dir.sub(/^\//,'') - path = [File::SEPARATOR] - tmp.split(File::SEPARATOR).each { |dir| - path.push dir - if ! FileTest.exist?(File.join(path)) - Dir.mkdir(File.join(path), mode) - elsif FileTest.directory?(File.join(path)) - next - else FileTest.exist?(File.join(path)) - raise "Cannot create %s: basedir %s is a file" % - [dir, File.join(path)] - end - } + if FileTest.exist?(dir) + return false + else + tmp = dir.sub(/^\//,'') + path = [File::SEPARATOR] + tmp.split(File::SEPARATOR).each { |dir| + path.push dir + if ! FileTest.exist?(File.join(path)) + Dir.mkdir(File.join(path), mode) + elsif FileTest.directory?(File.join(path)) + next + else FileTest.exist?(File.join(path)) + raise "Cannot create %s: basedir %s is a file" % + [dir, File.join(path)] + end + } + return true + end end end diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index bc5869a76..ee2645852 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -40,6 +40,7 @@ module Puppet interface.methods.each { |ary| method = ary[0] + Puppet.info "Defining %s.%s" % [namespace, method] self.send(:define_method,method) { |*args| #Puppet.info "peer cert is %s" % @http.peer_cert #Puppet.info "cert is %s" % @http.cert @@ -113,18 +114,19 @@ module Puppet end end + # FIXME this still isn't a good design, because none of the handlers overlap + # so i could just as easily include them all in the main module + # but at least it's better organized for now class Client include Puppet - include Puppet::Daemon - attr_accessor :local, :secureinit - def Client.facts - facts = {} - Facter.each { |name,fact| - facts[name] = fact.downcase - } + # FIXME the cert stuff should only come up with networking, so it + # should be in the network client, not the normal client + include Puppet::Daemon + attr_reader :local, :secureinit - facts + class << self + attr_reader :drivername end def initialize(hash) @@ -145,186 +147,254 @@ module Puppet @cache = true end + driverparam = self.class.drivername if hash.include?(:Server) - case hash[:Server] - when String: - if $noclientnetworking - raise NetworkClientError.new("Networking not available: %s" % - $nonetworking) - end - - args = {} - [:Port, :Server].each { |arg| - if hash.include?(:Port) - args[arg] = hash[arg] - end - } + if $noclientnetworking + raise NetworkClientError.new("Networking not available: %s" % + $nonetworking) + end - if self.readcert - args[:Certificate] = @cert - args[:Key] = @key - args[:CAFile] = @cacertfile + args = {} + [:Port, :Server].each { |arg| + if hash.include?(:Port) + args[arg] = hash[arg] end + } - @driver = Puppet::NetworkClient.new(args) - @local = false - when Puppet::Server::Master: - @driver = hash[:Server] - @local = true - else - raise ClientError.new("Server must be a hostname or a " + - "Puppet::Server::Master object") + if self.readcert + args[:Certificate] = @cert + args[:Key] = @key + args[:CAFile] = @cacertfile end + + @driver = Puppet::NetworkClient.new(args) + @local = false + elsif hash.include?(driverparam) + @driver = hash[driverparam] + @local = true else - raise ClientError.new("Must pass :Server to client") + raise ClientError, "%s must be passed a Server or %s" % + [self.class, driverparam] end end - def getconfig - #client.loadproperty('files/sslclient.properties') - Puppet.debug("getting config") + class MasterClient < Puppet::Client + @drivername = :Master - facts = Client.facts + def self.facts + facts = {} + Facter.each { |name,fact| + facts[name] = fact.downcase + } - unless facts.length > 0 - raise Puppet::ClientError.new( - "Could not retrieve any facts" - ) + facts end - objects = nil - if @local - objects = @driver.getconfig(facts) + def getconfig + #client.loadproperty('files/sslclient.properties') + Puppet.debug("getting config") + + facts = self.class.facts - if objects == "" - raise Puppet::Error, "Could not retrieve configuration" + unless facts.length > 0 + raise Puppet::ClientError.new( + "Could not retrieve any facts" + ) end - else - textfacts = CGI.escape(Marshal::dump(facts)) - # error handling for this is done in the network client - textobjects = @driver.getconfig(textfacts) + objects = nil + if @local + objects = @driver.getconfig(facts) - unless textobjects == "" - begin - textobjects = CGI.unescape(textobjects) - rescue => detail - raise Puppet::Error, "Could not CGI.unescape configuration" + if objects == "" + raise Puppet::Error, "Could not retrieve configuration" end - end + else + textfacts = CGI.escape(Marshal::dump(facts)) - if @cache - if textobjects == "" - if FileTest.exists?(Puppet[:localconfig]) - textobjects = File.read(Puppet[:localconfig]) - else - raise Puppet::Error.new( - "Cannot connect to server and there is no cached configuration" - ) + # error handling for this is done in the network client + textobjects = @driver.getconfig(textfacts) + + unless textobjects == "" + begin + textobjects = CGI.unescape(textobjects) + rescue => detail + raise Puppet::Error, "Could not CGI.unescape configuration" end - else - # we store the config so that if we can't connect next time, we - # can just run against the most recently acquired copy - confdir = File.dirname(Puppet[:localconfig]) - unless FileTest.exists?(confdir) - Puppet.recmkdir(confdir, 0770) + end + + if @cache + if textobjects == "" + if FileTest.exists?(Puppet[:localconfig]) + textobjects = File.read(Puppet[:localconfig]) + else + raise Puppet::Error.new( + "Cannot connect to server and there is no cached configuration" + ) + end + else + # we store the config so that if we can't connect next time, we + # can just run against the most recently acquired copy + confdir = File.dirname(Puppet[:localconfig]) + unless FileTest.exists?(confdir) + Puppet.recmkdir(confdir, 0770) + end + File.open(Puppet[:localconfig], "w", 0660) { |f| + f.print textobjects + } end - File.open(Puppet[:localconfig], "w", 0660) { |f| - f.print textobjects - } + elsif textobjects == "" + raise Puppet::Error, "Could not retrieve configuration" + end + + begin + objects = Marshal::load(textobjects) + rescue => detail + raise Puppet::Error.new("Could not understand configuration") end - elsif textobjects == "" - raise Puppet::Error, "Could not retrieve configuration" end + if objects.is_a?(Puppet::TransBucket) + @objects = objects + else + Puppet.warning objects.inspect + raise NetworkClientError.new(objects.class) + end + end + # this method is how the client receives the tree of Transportable + # objects + # for now, just descend into the tree and perform and necessary + # manipulations + def config + unless defined? @objects + raise Puppet::Error, "Cannot config; objects not defined" + end + Puppet.debug("Calling config") + + # XXX this is kind of a problem; if the user changes the state file + # after this, then we have to reload the file and everything... begin - objects = Marshal::load(textobjects) + Puppet::Storage.init + Puppet::Storage.load rescue => detail - raise Puppet::Error.new("Could not understand configuration") + Puppet.err "Corrupt state file %s" % Puppet[:checksumfile] + begin + File.unlink(Puppet[:checksumfile]) + retry + rescue => detail + raise Puppet::Error.new("Cannot remove %s: %s" % + [Puppet[statefile], detail]) + end end + + container = @objects.to_type + #if @local + # container = @objects.to_type + #else + # container = Marshal::load(@objects).to_type + #end + + # this is a gross hack... but i don't see a good way around it + # set all of the variables to empty + Puppet::Transaction.init + + # for now we just evaluate the top-level container, but eventually + # there will be schedules and such associated with each object, + # and probably with the container itself + transaction = container.evaluate + #transaction = Puppet::Transaction.new(objects) + transaction.toplevel = true + transaction.evaluate + Puppet::Metric.gather + Puppet::Metric.tally + if Puppet[:rrdgraph] == true + Metric.store + Metric.graph + end + Puppet::Storage.store + + return transaction end - if objects.is_a?(Puppet::TransBucket) - @objects = objects - else - Puppet.warning objects.inspect - raise NetworkClientError.new(objects.class) + + def initcerts + unless self.readcert + unless self.requestcert + return nil + end + end + + unless @driver + return true + end + + Puppet.info "setting cert and key and such" + @driver.cert = @cert + @driver.key = @key + @driver.ca_file = @cacertfile end end - # this method is how the client receives the tree of Transportable - # objects - # for now, just descend into the tree and perform and necessary - # manipulations - def config - unless defined? @objects - raise Puppet::Error, "Cannot config; objects not defined" - end - Puppet.debug("Calling config") - - # XXX this is kind of a problem; if the user changes the state file - # after this, then we have to reload the file and everything... - begin - Puppet::Storage.init - Puppet::Storage.load - rescue => detail - Puppet.err "Corrupt state file %s" % Puppet[:checksumfile] - begin - File.unlink(Puppet[:checksumfile]) - retry - rescue => detail - raise Puppet::Error.new("Cannot remove %s: %s" % - [Puppet[statefile], detail]) + class Dipper < Puppet::Client + @drivername = :Bucket + + def initialize(hash = {}) + if hash.include?(:Path) + bucket = Puppet::Server::FileBucket.new( + :Bucket => hash[:Path] + ) + hash.delete(:Path) + hash[:Bucket] = bucket end + + super(hash) end - container = @objects.to_type - #if @local - # container = @objects.to_type - #else - # container = Marshal::load(@objects).to_type - #end - - # this is a gross hack... but i don't see a good way around it - # set all of the variables to empty - Puppet::Transaction.init - - # for now we just evaluate the top-level container, but eventually - # there will be schedules and such associated with each object, - # and probably with the container itself - transaction = container.evaluate - #transaction = Puppet::Transaction.new(objects) - transaction.toplevel = true - transaction.evaluate - Puppet::Metric.gather - Puppet::Metric.tally - if Puppet[:rrdgraph] == true - Metric.store - Metric.graph + def backup(file) + unless FileTest.exists?(file) + raise(BucketError, "File %s does not exist" % file, caller) + end + contents = File.open(file) { |of| of.read } + + string = Base64.encode64(contents) + #puts "string is created" + + sum = @driver.addfile(string,file) + #puts "file %s is added" % file + return sum end - Puppet::Storage.store - return transaction - #self.shutdown - end + def restore(file,sum) + restore = true + if FileTest.exists?(file) + contents = File.open(file) { |of| of.read } - def initcerts - unless self.readcert - unless self.requestcert + cursum = Digest::MD5.hexdigest(contents) + + # if the checksum has changed... + # this might be extra effort + if cursum == sum + restore = false + end + end + + if restore + #puts "Restoring %s" % file + newcontents = Base64.decode64(@driver.getfile(sum)) + newsum = Digest::MD5.hexdigest(newcontents) + File.open(file,File::WRONLY|File::TRUNC) { |of| + of.print(newcontents) + } + #puts "Done" + return newsum + else return nil end - end - unless @driver - return true end - - Puppet.info "setting cert and key and such" - @driver.cert = @cert - @driver.key = @key - @driver.ca_file = @cacertfile end + end - #--------------------------------------------------------------- +#--------------------------------------------------------------- end # $Id$ diff --git a/lib/puppet/server.rb b/lib/puppet/server.rb index c3ba0b394..47b53a27b 100644 --- a/lib/puppet/server.rb +++ b/lib/puppet/server.rb @@ -26,6 +26,7 @@ module Puppet #--------------------------------------------------------------- if $noservernetworking Puppet.err "Could not create server: %s" % $noservernetworking + class Server; end else class Server < WEBrick::HTTPServer include Puppet::Daemon @@ -154,3 +155,4 @@ require 'puppet/server/master' require 'puppet/server/ca' require 'puppet/server/fileserver' require 'puppet/server/filebucket' +require 'puppet/client' diff --git a/lib/puppet/server/filebucket.rb b/lib/puppet/server/filebucket.rb index f0e717146..fa02d967a 100755 --- a/lib/puppet/server/filebucket.rb +++ b/lib/puppet/server/filebucket.rb @@ -15,37 +15,26 @@ require 'facter' require 'digest/md5' require 'base64' -class BucketError < RuntimeError; end +module Puppet +class Server + class BucketError < RuntimeError; end + class FileBucket < Handler + DEFAULTPORT = 8139 + + @interface = XMLRPC::Service::Interface.new("puppetbucket") { |iface| + iface.add_method("string addfile(string, string)") + iface.add_method("string getfile(string)") + } -module FileBucket - DEFAULTPORT = 8139 - # this doesn't work for relative paths - def FileBucket.mkdir(dir) - if FileTest.exist?(dir) - return false - else - tmp = dir.sub(/^\//,'') - path = [File::SEPARATOR] - tmp.split(File::SEPARATOR).each { |dir| - path.push dir - unless FileTest.exist?(File.join(path)) - Dir.mkdir(File.join(path)) - end - } - return true + # this doesn't work for relative paths + def FileBucket.paths(base,md5) + return [ + File.join(base, md5), + File.join(base, md5, "contents"), + File.join(base, md5, "paths") + ] end - end - def FileBucket.paths(base,md5) - return [ - File.join(base, md5), - File.join(base, md5, "contents"), - File.join(base, md5, "paths") - ] - end - - #--------------------------------------------------------------- - class Bucket def initialize(hash) # build our AST @@ -67,12 +56,11 @@ module FileBucket end end - # XXX this should really be done using Puppet::Type instances... - FileBucket.mkdir(@bucket) + Puppet.recmkdir(@bucket) end # accept a file from a client - def addfile(string,path) + def addfile(string,path, request = nil) #puts "entering addfile" contents = Base64.decode64(string) #puts "string is decoded" @@ -83,7 +71,7 @@ module FileBucket bpath, bfile, pathpath = FileBucket.paths(@bucket,md5) # if it's a new directory... - if FileBucket.mkdir(bpath) + if Puppet.recmkdir(bpath) # ...then just create the file #puts "creating file" File.open(bfile, File::WRONLY|File::CREAT) { |of| @@ -141,7 +129,7 @@ module FileBucket return md5 end - def getfile(md5) + def getfile(md5, request = nil) bpath, bfile, bpaths = FileBucket.paths(@bucket,md5) unless FileTest.exists?(bfile) @@ -155,123 +143,7 @@ module FileBucket return Base64.encode64(contents) end - - private - - def on_init - @default_namespace = 'urn:filebucket-server' - add_method(self, 'addfile', 'string', 'path') - add_method(self, 'getfile', 'md5') - end - - def cert(filename) - OpenSSL::X509::Certificate.new(File.open(File.join(@dir, filename)) { |f| - f.read - }) - end - - def key(filename) - OpenSSL::PKey::RSA.new(File.open(File.join(@dir, filename)) { |f| - f.read - }) - end - - end - #--------------------------------------------------------------- - - class BucketWebserver < WEBrick::HTTPServer - def initialize(hash) - unless hash.include?(:Port) - hash[:Port] = FileBucket::DEFAULTPORT - end - servlet = XMLRPC::WEBrickServlet.new - @bucket = FileBucket::Bucket.new(hash) - #puts @bucket - servlet.add_handler("bucket",@bucket) - super - - self.mount("/RPC2", servlet) - end + #--------------------------------------------------------------- end - - class BucketClient < XMLRPC::Client - @@methods = [ :addfile, :getfile ] - - @@methods.each { |method| - self.send(:define_method,method) { |*args| - begin - call("bucket.%s" % method.to_s,*args) - rescue => detail - #puts detail - end - } - } - - def initialize(hash) - hash[:Path] ||= "/RPC2" - hash[:Server] ||= "localhost" - hash[:Port] ||= FileBucket::DEFAULTPORT - super(hash[:Server],hash[:Path],hash[:Port]) - end - end - - class Dipper - def initialize(hash) - if hash.include?(:Server) - @bucket = FileBucket::BucketClient.new( - :Server => hash[:Server] - ) - elsif hash.include?(:Bucket) - @bucket = hash[:Bucket] - elsif hash.include?(:Path) - @bucket = FileBucket::Bucket.new( - :Path => hash[:Path] - ) - end - end - - def backup(file) - unless FileTest.exists?(file) - raise(BucketError, "File %s does not exist" % file, caller) - end - contents = File.open(file) { |of| of.read } - - string = Base64.encode64(contents) - #puts "string is created" - - sum = @bucket.addfile(string,file) - #puts "file %s is added" % file - return sum - end - - def restore(file,sum) - restore = true - if FileTest.exists?(file) - contents = File.open(file) { |of| of.read } - - cursum = Digest::MD5.hexdigest(contents) - - # if the checksum has changed... - # this might be extra effort - if cursum == sum - restore = false - end - end - - if restore - #puts "Restoring %s" % file - newcontents = Base64.decode64(@bucket.getfile(sum)) - newsum = Digest::MD5.hexdigest(newcontents) - File.open(file,File::WRONLY|File::TRUNC) { |of| - of.print(newcontents) - } - #puts "Done" - return newsum - else - return nil - end - - end - end - #--------------------------------------------------------------- +end end diff --git a/lib/puppet/server/servlet.rb b/lib/puppet/server/servlet.rb index 4db9f6c0e..70f47a069 100644 --- a/lib/puppet/server/servlet.rb +++ b/lib/puppet/server/servlet.rb @@ -38,6 +38,7 @@ class Server obj.call(*args) rescue => detail Puppet.warning obj.inspect + Puppet.warning args.inspect Puppet.err "Could not call: %s" % detail.to_s end } @@ -49,7 +50,7 @@ class Server Puppet.info "client cert is %s" % @request.client_cert end if @request.server_cert - Puppet.info "server cert is %s" % @request.server_cert + #Puppet.info "server cert is %s" % @request.server_cert end #p @request begin diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index a996bd591..f34e238b0 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -33,7 +33,7 @@ module Puppet end def self.recurse(obj, inlist, list) - return if list.include?(obj.object_id) + return if inlist.include?(obj.object_id) obj.eachdependency { |req| self.recurse(req, inlist, list) } diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index 3c233e79e..cb68ee347 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -217,7 +217,7 @@ module Puppet self.is = sum # if we don't have a 'should' value, then go ahead and mark it - if @should == -2 + if ! defined? @should or @should == -2 @should = sum self.updatesum end @@ -240,6 +240,7 @@ module Puppet self.retrieve if @is == @should + Puppet.debug "Checksum is already in sync" return nil end #Puppet.debug "%s(%s): after refresh, is '%s'" % diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb index da931244c..c5d1eeb22 100755 --- a/lib/puppet/type/pfilebucket.rb +++ b/lib/puppet/type/pfilebucket.rb @@ -33,7 +33,7 @@ module Puppet if @parameters.include?(:server) @parameters[:port] ||= FileBucket::DEFAULTPORT begin - @bucket = FileBucket::Dipper.new( + @bucket = Puppet::Client::Dipper.new( :Server => @parameters[:server], :Port => @parameters[:port] ) @@ -45,7 +45,7 @@ module Puppet else @parameters[:path] ||= Puppet[:bucketdir] begin - @bucket = FileBucket::Dipper.new( + @bucket = Puppet::Client::Dipper.new( :Path => @parameters[:path] ) rescue => detail diff --git a/test/client/tc_client.rb b/test/client/tc_client.rb index f82240225..5823e6e32 100644 --- a/test/client/tc_client.rb +++ b/test/client/tc_client.rb @@ -1,8 +1,7 @@ if __FILE__ == $0 $:.unshift '..' $:.unshift '../../lib' - $:.unshift '../../../../language/trunk/lib' - $puppetbase = "../../../../language/trunk/" + $puppetbase = "../.." end require 'puppet' @@ -62,7 +61,10 @@ class TestClient < Test::Unit::TestCase @@tmppids << spid client = nil assert_nothing_raised { - client = Puppet::Client.new(:Server => "localhost", :Port => port) + client = Puppet::Client::MasterClient.new( + :Server => "localhost", + :Port => port + ) } assert_nothing_raised { client.initcerts diff --git a/test/executables/tc_puppetbin.rb b/test/executables/tc_puppetbin.rb index b42f5aa6a..d1261dad7 100755 --- a/test/executables/tc_puppetbin.rb +++ b/test/executables/tc_puppetbin.rb @@ -1,7 +1,6 @@ if __FILE__ == $0 $:.unshift '../../lib' - $:.unshift '../../../../library/trunk/lib/' - $:.unshift '../../../../library/trunk/test/' + $:.unshift '..' $puppetbase = "../.." end diff --git a/test/executables/tc_puppetd.rb b/test/executables/tc_puppetd.rb index 38467332d..235db386f 100755 --- a/test/executables/tc_puppetd.rb +++ b/test/executables/tc_puppetd.rb @@ -1,7 +1,6 @@ if __FILE__ == $0 $:.unshift '../../lib' - $:.unshift '../../../../library/trunk/lib/' - $:.unshift '../../../../library/trunk/test/' + $:.unshift '..' $puppetbase = "../.." end diff --git a/test/executables/tc_puppetmasterd.rb b/test/executables/tc_puppetmasterd.rb index 5ef802151..44aa03da4 100755 --- a/test/executables/tc_puppetmasterd.rb +++ b/test/executables/tc_puppetmasterd.rb @@ -1,7 +1,6 @@ if __FILE__ == $0 $:.unshift '../../lib' - $:.unshift '../../../../library/trunk/lib/' - $:.unshift '../../../../library/trunk/test/' + $:.unshift '..' $puppetbase = "../.." end diff --git a/test/language/tc_snippets.rb b/test/language/tc_snippets.rb index d1aaa023c..b207d8a92 100755 --- a/test/language/tc_snippets.rb +++ b/test/language/tc_snippets.rb @@ -300,8 +300,8 @@ class TestSnippets < Test::Unit::TestCase :File => File.join($snippetbase, file), :Local => true ) - client = Puppet::Client.new( - :Server => server, + client = Puppet::Client::MasterClient.new( + :Master => server, :Cache => false ) diff --git a/test/server/tc_bucket.rb b/test/server/tc_bucket.rb index c4ad3d774..79d8afcd0 100644 --- a/test/server/tc_bucket.rb +++ b/test/server/tc_bucket.rb @@ -13,22 +13,7 @@ require 'puppettest.rb' require 'base64' # $Id$ - - -$external = true -if ARGV[1] and ARGV[1] == "external" - $external = true -else - # default to external - #$external = false -end class TestBucket < Test::Unit::TestCase - def debug(string) - if $debug - puts([Time.now,string].join(" ")) - end - end - def filelist files = [] #/etc/passwd /etc/syslog.conf /etc/hosts @@ -57,21 +42,32 @@ class TestBucket < Test::Unit::TestCase end def setup + if __FILE__ == $0 + Puppet[:loglevel] = :debug + end + @bucket = File::SEPARATOR + File.join("tmp","filebuckettesting") + + @@tmppids = [] + @@tmpfiles = [@bucket] end def teardown - system("rm -rf %s" % @bucket) - if defined? $pid - system("kill -9 #{$pid} 2>/dev/null") - end + @@tmpfiles.each { |file| + if FileTest.exists?(file) + system("rm -rf %s" % file) + end + } + @@tmppids.each { |pid| + system("kill -INT %s" % pid) + } end def test_localserver files = filelist() server =nil assert_nothing_raised { - server = FileBucket::Bucket.new( + server = Puppet::Server::FileBucket.new( :Bucket => @bucket ) } @@ -99,21 +95,21 @@ class TestBucket < Test::Unit::TestCase files = filelist() tmpdir = File.join(@bucket,"tmpfiledir") - FileBucket.mkdir(tmpdir) + Puppet.recmkdir(tmpdir) - server = nil + bucket = nil client = nil threads = [] assert_nothing_raised { - server = FileBucket::Bucket.new( + bucket = Puppet::Server::FileBucket.new( :Bucket => @bucket ) } #sleep(30) assert_nothing_raised { - client = FileBucket::Dipper.new( - :Bucket => server + client = Puppet::Client::Dipper.new( + :Bucket => bucket ) } files.each { |file| @@ -172,43 +168,31 @@ class TestBucket < Test::Unit::TestCase files = filelist() tmpdir = File.join(@bucket,"tmpfiledir") - FileBucket.mkdir(tmpdir) + Puppet.recmkdir(tmpdir) server = nil client = nil - port = FileBucket::DEFAULTPORT + port = Puppet::Server::FileBucket::DEFAULTPORT serverthread = nil - pid = nil - if $external - $pid = fork { - server = FileBucket::BucketWebserver.new( - :Bucket => @bucket, - :Port => port - ) - trap(:INT) { server.shutdown } - trap(:TERM) { server.shutdown } - server.start - } - sleep 3 - #puts "pid is %s" % pid - #exit - else - assert_nothing_raised { - server = FileBucket::BucketWebserver.new( - :Bucket => @bucket, - :Port => port - ) - } - assert_nothing_raised() { - trap(:INT) { server.shutdown } - serverthread = Thread.new { - server.start + pid = fork { + server = Puppet::Server.new( + :Port => port, + :Handlers => { + :CA => {}, # so that certs autogenerate + :FileBucket => { + :Bucket => @bucket, + } } - } - end + ) + trap(:INT) { server.shutdown } + trap(:TERM) { server.shutdown } + server.start + } + @@tmppids << pid + sleep 3 assert_nothing_raised { - client = FileBucket::Dipper.new( + client = Puppet::Client::Dipper.new( :Server => "localhost", :Port => port ) @@ -266,18 +250,9 @@ class TestBucket < Test::Unit::TestCase assert(tsum == csum) } - if $external - unless $pid - raise "Uh, we don't have a child pid" - end - system("kill %s" % $pid) - else - server.shutdown - - # make sure everything's complete before we stop - assert_nothing_raised() { - serverthread.join(60) - } + unless pid + raise "Uh, we don't have a child pid" end + system("kill %s" % pid) end end diff --git a/test/server/tc_fileserver.rb b/test/server/tc_fileserver.rb index 692981fe3..b82778f19 100755 --- a/test/server/tc_fileserver.rb +++ b/test/server/tc_fileserver.rb @@ -399,7 +399,11 @@ class TestFileServer < TestPuppet :Port => port, :Handlers => { :CA => {}, # so that certs autogenerate - :Status => nil + :FileServer => { + :Mount => { + + } + } } ) @@ -419,14 +423,6 @@ class TestFileServer < TestPuppet client = XMLRPC::Client.new("localhost", "/RPC2", port, nil, nil, nil, nil, true, 3) } - retval = nil - - assert_nothing_raised() { - Puppet.notice "calling status" - retval = client.call("status.status") - } - - assert_equal(1, retval) end end diff --git a/test/server/tc_master.rb b/test/server/tc_master.rb index fce6ea925..9a5f2fdbb 100644 --- a/test/server/tc_master.rb +++ b/test/server/tc_master.rb @@ -62,8 +62,8 @@ class TestMaster < Test::Unit::TestCase ) } assert_nothing_raised() { - client = Puppet::Client.new( - :Server => master + client = Puppet::Client::MasterClient.new( + :Master => master ) } @@ -102,8 +102,8 @@ class TestMaster < Test::Unit::TestCase ) } assert_nothing_raised() { - client = Puppet::Client.new( - :Server => master + client = Puppet::Client::MasterClient.new( + :Master => master ) } diff --git a/test/server/tc_server.rb b/test/server/tc_server.rb index d75d981ae..50c5a6cec 100644 --- a/test/server/tc_server.rb +++ b/test/server/tc_server.rb @@ -236,7 +236,7 @@ class TestServer < Test::Unit::TestCase # first use a puppet client object assert_nothing_raised() { - client = Puppet::Client.new( + client = Puppet::Client::MasterClient.new( :Server => "localhost", :Port => port ) @@ -255,7 +255,7 @@ class TestServer < Test::Unit::TestCase } retval = nil - facts = CGI.escape(Marshal.dump(Puppet::Client.facts)) + facts = CGI.escape(Marshal.dump(Puppet::Client::MasterClient.facts)) assert_nothing_raised() { Puppet.notice "calling status" retval = client.call("puppetmaster.getconfig", facts) diff --git a/test/types/tc_component.rb b/test/types/tc_component.rb index bd8b21a40..728c19b73 100755 --- a/test/types/tc_component.rb +++ b/test/types/tc_component.rb @@ -104,4 +104,70 @@ class TestComponent < TestPuppet } } end + + def test_correctsorting + tmpfile = "/tmp/comptesting" + @@tmpfiles.push tmpfile + trans = nil + cmd = nil + File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of| + of.puts rand(100) + } + file = Puppet::Type::PFile.new( + :path => tmpfile, + :checksum => "md5" + ) + assert_nothing_raised { + cmd = Puppet::Type::Exec.new( + :command => "pwd", + :path => "/usr/bin:/bin:/usr/sbin:/sbin", + :subscribe => [[file.class.name,file.name]], + :refreshonly => true + ) + } + + order = nil + assert_nothing_raised { + order = Puppet::Type::Component.sort([file, cmd]) + } + + [cmd, file].each { |obj| + assert_equal(1, order.find_all { |o| o.name == obj.name }.length) + } + end + + def test_correctflattening + tmpfile = "/tmp/comptesting" + @@tmpfiles.push tmpfile + trans = nil + cmd = nil + File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of| + of.puts rand(100) + } + file = Puppet::Type::PFile.new( + :path => tmpfile, + :checksum => "md5" + ) + assert_nothing_raised { + cmd = Puppet::Type::Exec.new( + :command => "pwd", + :path => "/usr/bin:/bin:/usr/sbin:/sbin", + :subscribe => [[file.class.name,file.name]], + :refreshonly => true + ) + } + + comp = Puppet::Type::Component.new(:name => "RefreshTest") + [file,cmd].each { |obj| + comp.push obj + } + objects = nil + assert_nothing_raised { + objects = comp.flatten + } + + [cmd, file].each { |obj| + assert_equal(1, objects.find_all { |o| o.name == obj.name }.length) + } + end end diff --git a/test/types/tc_exec.rb b/test/types/tc_exec.rb index cfd06d495..bdfebc267 100755 --- a/test/types/tc_exec.rb +++ b/test/types/tc_exec.rb @@ -166,10 +166,11 @@ class TestExec < Test::Unit::TestCase cmd = Puppet::Type::Exec.new( :command => "pwd", :path => "/usr/bin:/bin:/usr/sbin:/sbin", - :require => [[file.class.name,file.name]], + :subscribe => [[file.class.name,file.name]], :refreshonly => true ) } + comp = Puppet::Type::Component.new(:name => "RefreshTest") [file,cmd].each { |obj| comp.push obj @@ -177,6 +178,9 @@ class TestExec < Test::Unit::TestCase events = nil assert_nothing_raised { trans = comp.evaluate + + sum = file.state(:checksum) + assert_equal(sum.is, sum.should) events = trans.evaluate.collect { |event| event.event } @@ -190,9 +194,8 @@ class TestExec < Test::Unit::TestCase } assert_nothing_raised { trans = comp.evaluate - events = trans.evaluate.collect { |event| - event.event - } + sum = file.state(:checksum) + events = trans.evaluate.collect { |event| event.event } } # verify that only the file_changed event was kicked off, not the diff --git a/test/types/tc_filebucket.rb b/test/types/tc_filebucket.rb index 091ff3af3..5fc8e2d6e 100755 --- a/test/types/tc_filebucket.rb +++ b/test/types/tc_filebucket.rb @@ -90,7 +90,7 @@ class TestFileBucket < Test::Unit::TestCase bucket = Puppet::Type::PFileBucket.bucket(name) } - assert_instance_of(FileBucket::Dipper, bucket) + assert_instance_of(Puppet::Client::Dipper, bucket) md5 = nil newpath = "/tmp/passwd" diff --git a/test/types/tc_filesources.rb b/test/types/tc_filesources.rb index ae94b7f0f..ffd07a749 100755 --- a/test/types/tc_filesources.rb +++ b/test/types/tc_filesources.rb @@ -12,7 +12,7 @@ require 'puppettest' # $Id$ -class TestFile < Test::Unit::TestCase +class TestFileSources < Test::Unit::TestCase include FileTesting # hmmm # this is complicated, because we store references to the created |
