diff options
| author | Luke Kanies <luke@madstop.com> | 2005-08-23 23:08:41 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-08-23 23:08:41 +0000 |
| commit | 583a9c6e2a7469e4ae3b72264010a5d8d0dab867 (patch) | |
| tree | 8cc76790c5c22516bff75f0aa821d1d3be128692 | |
| parent | 5b20c92ff322ba1886209f788ce6a7df05315cf5 (diff) | |
| download | puppet-583a9c6e2a7469e4ae3b72264010a5d8d0dab867.tar.gz puppet-583a9c6e2a7469e4ae3b72264010a5d8d0dab867.tar.xz puppet-583a9c6e2a7469e4ae3b72264010a5d8d0dab867.zip | |
remote filecopying now works
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@586 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/puppet/client.rb | 4 | ||||
| -rwxr-xr-x | lib/puppet/daemon.rb | 11 | ||||
| -rwxr-xr-x | lib/puppet/server/fileserver.rb | 93 | ||||
| -rw-r--r-- | lib/puppet/server/servlet.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/type/pfile.rb | 6 | ||||
| -rwxr-xr-x | test/server/tc_fileserver.rb | 38 | ||||
| -rwxr-xr-x | test/types/tc_filesources.rb | 137 |
7 files changed, 207 insertions, 90 deletions
diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index ee2645852..67307e621 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -111,6 +111,10 @@ module Puppet # from here, i need to add the key, cert, and ca cert # and reorgize how i start the client end + + def local + false + end end end diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb index 1cbb35ce5..837debd79 100755 --- a/lib/puppet/daemon.rb +++ b/lib/puppet/daemon.rb @@ -41,14 +41,21 @@ module Puppet def httplog args = [] # yuck; separate http logs + file = nil if self.is_a?(Puppet::Server) - args << Puppet[:masterhttplog] + file = Puppet[:masterhttplog] else - args << Puppet[:httplog] + file = Puppet[:httplog] end + + unless FileTest.exists?(File.dirname(file)) + Puppet.recmkdir(File.dirname(file)) + end + args << file if Puppet[:debug] args << WEBrick::Log::DEBUG end + log = WEBrick::Log.new(*args) return log diff --git a/lib/puppet/server/fileserver.rb b/lib/puppet/server/fileserver.rb index f13c3285f..96080920d 100755 --- a/lib/puppet/server/fileserver.rb +++ b/lib/puppet/server/fileserver.rb @@ -38,7 +38,7 @@ class Server return obj end - def describe(file) + def describe(file, request = nil) mount, path = splitpath(file) subdir = nil @@ -82,9 +82,22 @@ class Server else @local = false end + + if hash.include?(:Mount) + unless hash[:Mount].is_a?(Hash) + raise Puppet::DevError, "Invalid mount hash %s" % + hash[:Mount].inspect + end + + hash[:Mount].each { |dir, name| + if FileTest.exists?(dir) + self.mount(dir, name) + end + } + end end - def list(dir, recurse = false, sum = "md5") + def list(dir, recurse = false, sum = "md5", request = nil) mount, path = splitpath(dir) subdir = nil @@ -101,7 +114,7 @@ class Server #rmdir = File.dirname(File.join(@mounts[mount], path)) rmdir = nameswap(dir, mount) - desc = self.reclist(rmdir, subdir, recurse) + desc = reclist(rmdir, subdir, recurse) if desc.length == 0 Puppet.notice "Got no information on //%s/%s" % @@ -145,43 +158,7 @@ class Server end end - # recursive listing function - def reclist(root, path, recurse) - #desc = [obj.name.sub(%r{#{root}/?}, '')] - name = path.sub(root, '') - if name == "" - name = "/" - end - - if name == path - raise Puppet::FileServerError, "Could not match %s in %s" % - [root, path] - end - - desc = [name] - ftype = File.stat(path).ftype - - desc << ftype - if recurse.is_a?(Integer) - recurse -= 1 - end - - ary = [desc] - if recurse == true or (recurse.is_a?(Integer) and recurse > -1) - if ftype == "directory" - Dir.entries(path).each { |child| - next if child =~ /^\.\.?$/ - self.reclist(root, File.join(path, child), recurse).each { |cobj| - ary << cobj - } - } - end - end - - return ary.reject { |c| c.nil? } - end - - def retrieve(file) + def retrieve(file, request = nil) mount, path = splitpath(file) unless (@mounts.include?(mount)) @@ -219,6 +196,42 @@ class Server #newname end + # recursive listing function + def reclist(root, path, recurse) + #desc = [obj.name.sub(%r{#{root}/?}, '')] + name = path.sub(root, '') + if name == "" + name = "/" + end + + if name == path + raise Puppet::FileServerError, "Could not match %s in %s" % + [root, path] + end + + desc = [name] + ftype = File.stat(path).ftype + + desc << ftype + if recurse.is_a?(Integer) + recurse -= 1 + end + + ary = [desc] + if recurse == true or (recurse.is_a?(Integer) and recurse > -1) + if ftype == "directory" + Dir.entries(path).each { |child| + next if child =~ /^\.\.?$/ + reclist(root, File.join(path, child), recurse).each { |cobj| + ary << cobj + } + } + end + end + + return ary.reject { |c| c.nil? } + end + def splitpath(dir) # the dir is based on one of the mounts # so first retrieve the mount path diff --git a/lib/puppet/server/servlet.rb b/lib/puppet/server/servlet.rb index 70f47a069..b14efe645 100644 --- a/lib/puppet/server/servlet.rb +++ b/lib/puppet/server/servlet.rb @@ -72,17 +72,17 @@ class Server for name, obj in @handler if obj.kind_of? Proc unless methodname == name - Puppet.debug "obj is proc but %s != %s" % - [methodname, name] + #Puppet.debug "obj is proc but %s != %s" % + # [methodname, name] next end else unless methodname =~ /^#{name}(.+)$/ - Puppet.debug "methodname did not match" + #Puppet.debug "methodname did not match" next end unless obj.respond_to? $1 - Puppet.debug "methodname does not respond to %s" % $1 + #Puppet.debug "methodname does not respond to %s" % $1 next end obj = obj.method($1) diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index cb68ee347..cffa6a890 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -642,9 +642,8 @@ module Puppet def describe source = @source - - sourceobj, path = @parent.uri2obj(source) + sourceobj, path = @parent.uri2obj(source) server = sourceobj.server desc = server.describe(path) @@ -1300,7 +1299,8 @@ module Puppet tmp = uri.path if tmp =~ %r{^/(\w+)} sourceobj.mount = $1 - path = tmp.sub(%r{^/\w+},'') || "/" + path = tmp + #path = tmp.sub(%r{^/\w+},'') || "/" else raise Puppet::Error, "Invalid source path %s" % tmp end diff --git a/test/server/tc_fileserver.rb b/test/server/tc_fileserver.rb index b82778f19..a06e993d4 100755 --- a/test/server/tc_fileserver.rb +++ b/test/server/tc_fileserver.rb @@ -386,44 +386,6 @@ class TestFileServer < TestPuppet } } end - - def test_networksources - server = nil - Puppet[:ssldir] = "/tmp/serverconnecttesting" - Puppet[:autosign] = true - @@tmpfiles << "/tmp/serverconnecttesting" - serverpid = nil - port = 8080 - assert_nothing_raised() { - server = Puppet::Server.new( - :Port => port, - :Handlers => { - :CA => {}, # so that certs autogenerate - :FileServer => { - :Mount => { - - } - } - } - ) - - } - serverpid = fork { - assert_nothing_raised() { - #trap(:INT) { server.shutdown; Kernel.exit! } - trap(:INT) { server.shutdown } - server.start - } - } - @@tmppids << serverpid - - sleep(3) - client = nil - assert_nothing_raised() { - client = XMLRPC::Client.new("localhost", "/RPC2", port, nil, nil, - nil, nil, true, 3) - } - end end # $Id$ diff --git a/test/types/tc_filesources.rb b/test/types/tc_filesources.rb index ffd07a749..ed9a26f38 100755 --- a/test/types/tc_filesources.rb +++ b/test/types/tc_filesources.rb @@ -6,6 +6,7 @@ if __FILE__ == $0 end require 'puppet' +require 'cgi' require 'test/unit' require 'fileutils' require 'puppettest' @@ -36,6 +37,7 @@ class TestFileSources < Test::Unit::TestCase def setup @@tmpfiles = [] + @@tmppids = [] Puppet[:loglevel] = :debug if __FILE__ == $0 Puppet[:checksumfile] = File.join(Puppet[:statedir], "checksumtestfile") begin @@ -48,6 +50,9 @@ class TestFileSources < Test::Unit::TestCase def teardown clearstorage Puppet::Type.allclear + @@tmppids.each { |pid| + system("kill -INT %s" % pid) + } @@tmpfiles.each { |file| if FileTest.exists?(file) system("chmod -R 755 %s" % file) @@ -169,7 +174,7 @@ class TestFileSources < Test::Unit::TestCase Puppet::Type.allclear end - def run_complex_sources + def run_complex_sources(networked = false) path = "/tmp/ComplexSourcesTest" @@tmpfiles.push path @@ -185,7 +190,12 @@ class TestFileSources < Test::Unit::TestCase } todir = File.join(path, "todir") - recursive_source_test(fromdir, todir) + source = fromdir + if networked + source = "puppet://localhost/%s%s" % [networked, fromdir] + end + Puppet.warning "Source is %s" % source + recursive_source_test(source, todir) return [fromdir,todir] end @@ -233,7 +243,7 @@ class TestFileSources < Test::Unit::TestCase assert_trees_equal(fromdir,todir) end - def test_zzzsources_with_added_destfiles + def test_sources_with_added_destfiles fromdir, todir = run_complex_sources assert(FileTest.exists?(todir)) # and finally, add some new files @@ -299,4 +309,125 @@ class TestFileSources < Test::Unit::TestCase } assert(klass[file3]) end + + def test_zzSimpleNetworkSources + server = nil + basedir = "/tmp/networksourcetesting" + Dir.mkdir(basedir) + + Puppet[:puppetconf] = basedir + Puppet[:puppetvar] = basedir + Puppet[:autosign] = true + @@tmpfiles << basedir + + tmpname = "yaytesting" + tmpfile = File.join(basedir, tmpname) + File.open(tmpfile, "w") { |f| f.print rand(100) } + + port = 8765 + serverpid = nil + assert_nothing_raised() { + server = Puppet::Server.new( + :Port => port, + :Handlers => { + :CA => {}, # so that certs autogenerate + :FileServer => { + :Mount => { + "/" => "root" + } + } + } + ) + + } + serverpid = fork { + assert_nothing_raised() { + #trap(:INT) { server.shutdown; Kernel.exit! } + trap(:INT) { server.shutdown } + server.start + } + } + @@tmppids << serverpid + + client = nil + assert_nothing_raised() { + client = XMLRPC::Client.new("localhost", "/RPC2", port, nil, nil, + nil, nil, true, 3) + } + retval = nil + + sleep(1) + + list = nil + rpath = "/root%s" % tmpfile + assert_nothing_raised { + list = client.call("fileserver.list", rpath) + } + + assert_equal("/\tfile", list) + + assert_nothing_raised { + list = client.call("fileserver.describe", rpath) + } + + assert_match(/^\d+\tfile\t\d+\t\d+\t.+$/, list) + + assert_nothing_raised { + list = client.call("fileserver.retrieve", rpath) + } + + contents = File.read(tmpfile) + assert_equal(contents, CGI.unescape(list)) + + assert_nothing_raised { + system("kill -INT %s" % serverpid) + } + end + + def test_zzNetworkSources + server = nil + basedir = "/tmp/networksourcetesting" + Dir.mkdir(basedir) + + Puppet[:puppetconf] = basedir + Puppet[:puppetvar] = basedir + Puppet[:autosign] = true + @@tmpfiles << basedir + + Puppet[:masterport] = 8762 + + serverpid = nil + assert_nothing_raised() { + server = Puppet::Server.new( + :Handlers => { + :CA => {}, # so that certs autogenerate + :FileServer => { + :Mount => { + "/" => "root" + } + } + } + ) + + } + serverpid = fork { + assert_nothing_raised() { + #trap(:INT) { server.shutdown; Kernel.exit! } + trap(:INT) { server.shutdown } + server.start + } + } + @@tmppids << serverpid + + sleep(1) + + fromdir, todir = run_complex_sources("root") + assert_trees_equal(fromdir,todir) + recursive_source_test(fromdir, todir) + assert_trees_equal(fromdir,todir) + + assert_nothing_raised { + system("kill -INT %s" % serverpid) + } + end end |
