From f68fe0045d3519d545d8e63b7ee470ece74fcc3f Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 23 Aug 2005 16:55:24 +0000 Subject: moving all server handlers into a specific server subdirectory git-svn-id: https://reductivelabs.com/svn/puppet/trunk@579 980ebf18-57e1-0310-9a29-db15c13687c0 --- test/bucket/tc_bucket.rb | 284 ---------------------------------------- test/executables/tc_puppetca.rb | 7 +- test/language/tc_snippets.rb | 2 +- test/other/tc_selector.rb | 37 ------ test/server/tc_bucket.rb | 283 +++++++++++++++++++++++++++++++++++++++ test/server/tc_ca.rb | 13 +- test/server/tc_fileserver.rb | 36 +++-- test/server/tc_master.rb | 18 +-- test/server/tc_server.rb | 18 +-- 9 files changed, 315 insertions(+), 383 deletions(-) delete mode 100644 test/bucket/tc_bucket.rb delete mode 100644 test/other/tc_selector.rb create mode 100644 test/server/tc_bucket.rb (limited to 'test') diff --git a/test/bucket/tc_bucket.rb b/test/bucket/tc_bucket.rb deleted file mode 100644 index 3aa045fc1..000000000 --- a/test/bucket/tc_bucket.rb +++ /dev/null @@ -1,284 +0,0 @@ -if __FILE__ == $0 - $:.unshift '../../lib' - $:.unshift '../../../../library/trunk/lib/' - $:.unshift '../../../../library/trunk/test/' - $puppetbase = "../.." - $debug = true -else - $debug = false -end - -require 'puppet/filebucket' -require 'test/unit' -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 - %w{ - who /tmp/bigfile sh uname /etc/passwd /etc/syslog.conf /etc/hosts - }.each { |file| - if file =~ /^\// - if FileTest.exists?(file) - files.push file - end - else - begin - path = %x{which #{file}} - rescue => detail - #STDERR.puts "Could not search for binaries: %s" % detail - next - end - - if path != "" - files.push path.chomp - end - end - } - - return files - end - - def setup - @bucket = File::SEPARATOR + File.join("tmp","filebuckettesting") - end - - def teardown - system("rm -rf %s" % @bucket) - if defined? $pid - system("kill -9 #{$pid} 2>/dev/null") - end - end - - def test_localserver - files = filelist() - server =nil - assert_nothing_raised { - server = FileBucket::Bucket.new( - :Bucket => @bucket - ) - } - files.each { |file| - contents = File.open(file) { |of| of.read } - - md5 = nil - assert_nothing_raised { - #STDERR.puts("adding %s" % file) if $debug - md5 = server.addfile(Base64.encode64(contents),file) - } - newcontents = nil - assert_nothing_raised { - #STDERR.puts("getting %s" % file) if $debug - newcontents = Base64.decode64(server.getfile(md5)) - } - - assert( - contents == newcontents - ) - } - end - - def test_localboth - files = filelist() - - tmpdir = File.join(@bucket,"tmpfiledir") - FileBucket.mkdir(tmpdir) - - server = nil - client = nil - threads = [] - assert_nothing_raised { - server = FileBucket::Bucket.new( - :Bucket => @bucket - ) - } - - #sleep(30) - assert_nothing_raised { - client = FileBucket::Dipper.new( - :Bucket => server - ) - } - files.each { |file| - name = File.basename(file) - tmppath = File.join(tmpdir,name) - - # copy the files to our tmp directory so we can modify them... - #STDERR.puts("copying %s" % file) if $debug - File.open(tmppath,File::WRONLY|File::TRUNC|File::CREAT) { |wf| - File.open(file) { |rf| - wf.print(rf.read) - } - } - - assert(FileTest.exists?(tmppath)) - - osum = nil - tsum = nil - nsum = nil - assert_nothing_raised { - #STDERR.puts("backing up %s" % file) if $debug - osum = client.backup(file) - } - assert_nothing_raised { - #STDERR.puts("backing up %s" % tmppath) if $debug - tsum = client.backup(tmppath) - } - - assert(tsum == osum) - - File.open(tmppath,File::WRONLY|File::TRUNC) { |wf| - wf.print "This is some test text\n" - } - assert_nothing_raised { - #STDERR.puts("backing up %s" % tmppath) if $debug - nsum = client.backup(tmppath) - } - - assert(tsum != nsum) - - assert_nothing_raised { - #STDERR.puts("restoring %s" % tmppath) if $debug - nsum = client.restore(tmppath,tsum) - } - - contents = File.open(tmppath) { |rf| - #STDERR.puts("reading %s" % tmppath) if $debug - rf.read - } - csum = Digest::MD5.hexdigest(contents) - assert(tsum == csum) - } - end - - def test_webxmlmix - files = filelist() - - tmpdir = File.join(@bucket,"tmpfiledir") - FileBucket.mkdir(tmpdir) - - server = nil - client = nil - port = 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 - } - } - end - - assert_nothing_raised { - client = FileBucket::Dipper.new( - :Server => "localhost", - :Port => port - ) - } - files.each { |file| - name = File.basename(file) - tmppath = File.join(tmpdir,name) - - # copy the files to our tmp directory so we can modify them... - #STDERR.puts("copying %s" % file) if $debug - File.open(tmppath,File::WRONLY|File::TRUNC|File::CREAT) { |wf| - File.open(file) { |rf| - wf.print(rf.read) - } - } - - assert(FileTest.exists?(tmppath)) - - osum = nil - tsum = nil - nsum = nil - assert_nothing_raised { - #STDERR.puts("backing up %s" % file) if $debug - osum = client.backup(file) - } - assert_nothing_raised { - #STDERR.puts("backing up %s" % tmppath) if $debug - tsum = client.backup(tmppath) - } - - assert(tsum == osum) - - File.open(tmppath,File::WRONLY|File::TRUNC) { |wf| - wf.print "This is some test text\n" - } - assert_nothing_raised { - #STDERR.puts("backing up %s" % tmppath) if $debug - nsum = client.backup(tmppath) - } - - assert(tsum != nsum) - - assert_nothing_raised { - #STDERR.puts("restoring %s" % tmppath) if $debug - nsum = client.restore(tmppath,tsum) - } - - assert_equal(tsum, nsum) - - contents = File.open(tmppath) { |rf| - #STDERR.puts("reading %s" % tmppath) if $debug - rf.read - } - csum = Digest::MD5.hexdigest(contents) - 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) - } - end - end -end diff --git a/test/executables/tc_puppetca.rb b/test/executables/tc_puppetca.rb index e657de483..6f799c670 100755 --- a/test/executables/tc_puppetca.rb +++ b/test/executables/tc_puppetca.rb @@ -1,7 +1,6 @@ if __FILE__ == $0 $:.unshift '../../lib' - $:.unshift '../../../../library/trunk/lib/' - $:.unshift '../../../../library/trunk/test/' + $:.unshift '..' $puppetbase = "../.." end @@ -54,7 +53,7 @@ class TestPuppetCA < Test::Unit::TestCase @@tmpfiles << Puppet[:ssldir] Puppet[:autosign] = false assert_nothing_raised { - ca = Puppet::CA.new() + ca = Puppet::Server::CA.new() } #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] #system("find %s" % Puppet[:ssldir]) @@ -70,7 +69,7 @@ class TestPuppetCA < Test::Unit::TestCase output = nil assert_nothing_raised { - output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]} 2>&1}.chomp.split("\n") + output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]} 2>&1}.chomp.split("\n").reject { |line| line =~ /warning:/ } # stupid ssl.rb } #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] #system("find %s" % Puppet[:ssldir]) diff --git a/test/language/tc_snippets.rb b/test/language/tc_snippets.rb index da1172f63..d1aaa023c 100755 --- a/test/language/tc_snippets.rb +++ b/test/language/tc_snippets.rb @@ -296,7 +296,7 @@ class TestSnippets < Test::Unit::TestCase testname = ("test_" + mname).intern self.send(:define_method, testname) { # first parse the file - server = Puppet::Master.new( + server = Puppet::Server::Master.new( :File => File.join($snippetbase, file), :Local => true ) diff --git a/test/other/tc_selector.rb b/test/other/tc_selector.rb deleted file mode 100644 index 47e0d9ff5..000000000 --- a/test/other/tc_selector.rb +++ /dev/null @@ -1,37 +0,0 @@ -if __FILE__ == $0 - $:.unshift '..' - $:.unshift '../../lib' - $puppetbase = "../../../../language/trunk" -end - -require 'puppet/selector' -require 'facter' -require 'test/unit' - -# $Id$ - -class TestSelector < Test::Unit::TestCase - def setup - @os = Facter["operatingsystem"].value - @hostname = Facter["hostname"].value - - Puppet[:loglevel] = :debug if __FILE__ == $0 - end - - def test_values - selector = nil - assert_nothing_raised() { - selector = Puppet::Selector.new { |select| - select.add("value1") { - Facter["hostname"].value == @hostname - } - } - } - - assert_equal( - "value1", - selector.evaluate() - ) - - end -end diff --git a/test/server/tc_bucket.rb b/test/server/tc_bucket.rb new file mode 100644 index 000000000..c4ad3d774 --- /dev/null +++ b/test/server/tc_bucket.rb @@ -0,0 +1,283 @@ +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '..' + $puppetbase = "../.." + $debug = true +else + $debug = false +end + +require 'puppet' +require 'test/unit' +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 + %w{ + who /tmp/bigfile sh uname /etc/passwd /etc/syslog.conf /etc/hosts + }.each { |file| + if file =~ /^\// + if FileTest.exists?(file) + files.push file + end + else + begin + path = %x{which #{file}} + rescue => detail + #STDERR.puts "Could not search for binaries: %s" % detail + next + end + + if path != "" + files.push path.chomp + end + end + } + + return files + end + + def setup + @bucket = File::SEPARATOR + File.join("tmp","filebuckettesting") + end + + def teardown + system("rm -rf %s" % @bucket) + if defined? $pid + system("kill -9 #{$pid} 2>/dev/null") + end + end + + def test_localserver + files = filelist() + server =nil + assert_nothing_raised { + server = FileBucket::Bucket.new( + :Bucket => @bucket + ) + } + files.each { |file| + contents = File.open(file) { |of| of.read } + + md5 = nil + assert_nothing_raised { + #STDERR.puts("adding %s" % file) if $debug + md5 = server.addfile(Base64.encode64(contents),file) + } + newcontents = nil + assert_nothing_raised { + #STDERR.puts("getting %s" % file) if $debug + newcontents = Base64.decode64(server.getfile(md5)) + } + + assert( + contents == newcontents + ) + } + end + + def test_localboth + files = filelist() + + tmpdir = File.join(@bucket,"tmpfiledir") + FileBucket.mkdir(tmpdir) + + server = nil + client = nil + threads = [] + assert_nothing_raised { + server = FileBucket::Bucket.new( + :Bucket => @bucket + ) + } + + #sleep(30) + assert_nothing_raised { + client = FileBucket::Dipper.new( + :Bucket => server + ) + } + files.each { |file| + name = File.basename(file) + tmppath = File.join(tmpdir,name) + + # copy the files to our tmp directory so we can modify them... + #STDERR.puts("copying %s" % file) if $debug + File.open(tmppath,File::WRONLY|File::TRUNC|File::CREAT) { |wf| + File.open(file) { |rf| + wf.print(rf.read) + } + } + + assert(FileTest.exists?(tmppath)) + + osum = nil + tsum = nil + nsum = nil + assert_nothing_raised { + #STDERR.puts("backing up %s" % file) if $debug + osum = client.backup(file) + } + assert_nothing_raised { + #STDERR.puts("backing up %s" % tmppath) if $debug + tsum = client.backup(tmppath) + } + + assert(tsum == osum) + + File.open(tmppath,File::WRONLY|File::TRUNC) { |wf| + wf.print "This is some test text\n" + } + assert_nothing_raised { + #STDERR.puts("backing up %s" % tmppath) if $debug + nsum = client.backup(tmppath) + } + + assert(tsum != nsum) + + assert_nothing_raised { + #STDERR.puts("restoring %s" % tmppath) if $debug + nsum = client.restore(tmppath,tsum) + } + + contents = File.open(tmppath) { |rf| + #STDERR.puts("reading %s" % tmppath) if $debug + rf.read + } + csum = Digest::MD5.hexdigest(contents) + assert(tsum == csum) + } + end + + def test_webxmlmix + files = filelist() + + tmpdir = File.join(@bucket,"tmpfiledir") + FileBucket.mkdir(tmpdir) + + server = nil + client = nil + port = 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 + } + } + end + + assert_nothing_raised { + client = FileBucket::Dipper.new( + :Server => "localhost", + :Port => port + ) + } + files.each { |file| + name = File.basename(file) + tmppath = File.join(tmpdir,name) + + # copy the files to our tmp directory so we can modify them... + #STDERR.puts("copying %s" % file) if $debug + File.open(tmppath,File::WRONLY|File::TRUNC|File::CREAT) { |wf| + File.open(file) { |rf| + wf.print(rf.read) + } + } + + assert(FileTest.exists?(tmppath)) + + osum = nil + tsum = nil + nsum = nil + assert_nothing_raised { + #STDERR.puts("backing up %s" % file) if $debug + osum = client.backup(file) + } + assert_nothing_raised { + #STDERR.puts("backing up %s" % tmppath) if $debug + tsum = client.backup(tmppath) + } + + assert(tsum == osum) + + File.open(tmppath,File::WRONLY|File::TRUNC) { |wf| + wf.print "This is some test text\n" + } + assert_nothing_raised { + #STDERR.puts("backing up %s" % tmppath) if $debug + nsum = client.backup(tmppath) + } + + assert(tsum != nsum) + + assert_nothing_raised { + #STDERR.puts("restoring %s" % tmppath) if $debug + nsum = client.restore(tmppath,tsum) + } + + assert_equal(tsum, nsum) + + contents = File.open(tmppath) { |rf| + #STDERR.puts("reading %s" % tmppath) if $debug + rf.read + } + csum = Digest::MD5.hexdigest(contents) + 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) + } + end + end +end diff --git a/test/server/tc_ca.rb b/test/server/tc_ca.rb index 9fb579638..e3f768b39 100644 --- a/test/server/tc_ca.rb +++ b/test/server/tc_ca.rb @@ -1,12 +1,11 @@ if __FILE__ == $0 $:.unshift '../../lib' - $:.unshift '../../../../library/trunk/lib/' - $:.unshift '../../../../library/trunk/test/' + $:.unshift '..' $puppetbase = "../.." end require 'puppet' -require 'puppet/ca' +require 'puppet/server/ca' require 'puppet/sslcertificates' require 'openssl' require 'test/unit' @@ -54,7 +53,7 @@ class TestCA < Test::Unit::TestCase ca = nil assert_nothing_raised { - ca = Puppet::CA.new() + ca = Puppet::Server::CA.new() } key = nil @@ -106,7 +105,7 @@ class TestCA < Test::Unit::TestCase ca = nil caserv = nil assert_nothing_raised { - caserv = Puppet::CA.new() + caserv = Puppet::Server::CA.new() } assert_nothing_raised { ca = caserv.ca @@ -163,7 +162,7 @@ class TestCA < Test::Unit::TestCase caserv = nil assert_nothing_raised { - caserv = Puppet::CA.new() + caserv = Puppet::Server::CA.new() } key = nil @@ -212,7 +211,7 @@ class TestCA < Test::Unit::TestCase caserv = nil file = File.join($puppetbase, "examples", "code", "head") assert_nothing_raised { - caserv = Puppet::CA.new() + caserv = Puppet::Server::CA.new() } assert(caserv.autosign?("hostmatch.domain.com")) diff --git a/test/server/tc_fileserver.rb b/test/server/tc_fileserver.rb index ad9b6298c..93b31db58 100755 --- a/test/server/tc_fileserver.rb +++ b/test/server/tc_fileserver.rb @@ -4,14 +4,12 @@ if __FILE__ == $0 end $:.unshift '../lib' - $:.unshift '../../../library/trunk/lib/' - $:.unshift '../../../library/trunk/test/' $puppetbase = ".." end require 'puppet' -require 'puppet/fileserver' +require 'puppet/server/fileserver' require 'test/unit' require 'puppettest.rb' @@ -34,24 +32,24 @@ class TestFileServer < TestPuppet def test_namefailures server = nil assert_nothing_raised { - server = Puppet::FileServer.new( + server = Puppet::Server::FileServer.new( :Local => true ) } - assert_raise(Puppet::FileServerError) { + assert_raise(Puppet::Server::FileServerError) { server.mount("/tmp", "invalid+name") } - assert_raise(Puppet::FileServerError) { + assert_raise(Puppet::Server::FileServerError) { server.mount("/tmp", "invalid-name") } - assert_raise(Puppet::FileServerError) { + assert_raise(Puppet::Server::FileServerError) { server.mount("/tmp", "invalid name") } - assert_raise(Puppet::FileServerError) { + assert_raise(Puppet::Server::FileServerError) { server.mount("/tmp", "") } end @@ -69,10 +67,10 @@ class TestFileServer < TestPuppet } file = nil - checks = Puppet::FileServer::CHECKPARAMS + checks = Puppet::Server::FileServer::CHECKPARAMS assert_nothing_raised { - server = Puppet::FileServer.new( + server = Puppet::Server::FileServer.new( :Local => true ) } @@ -114,7 +112,7 @@ class TestFileServer < TestPuppet file = nil assert_nothing_raised { - server = Puppet::FileServer.new( + server = Puppet::Server::FileServer.new( :Local => true ) } @@ -165,10 +163,10 @@ class TestFileServer < TestPuppet } file = nil - checks = Puppet::FileServer::CHECKPARAMS + checks = Puppet::Server::FileServer::CHECKPARAMS assert_nothing_raised { - server = Puppet::FileServer.new( + server = Puppet::Server::FileServer.new( :Local => true ) } @@ -200,7 +198,7 @@ class TestFileServer < TestPuppet def test_mountroot server = nil assert_nothing_raised { - server = Puppet::FileServer.new( + server = Puppet::Server::FileServer.new( :Local => true ) } @@ -230,7 +228,7 @@ class TestFileServer < TestPuppet def test_recursionlevels server = nil assert_nothing_raised { - server = Puppet::FileServer.new( + server = Puppet::Server::FileServer.new( :Local => true ) } @@ -275,7 +273,7 @@ class TestFileServer < TestPuppet def test_listedpath server = nil assert_nothing_raised { - server = Puppet::FileServer.new( + server = Puppet::Server::FileServer.new( :Local => true ) } @@ -312,7 +310,7 @@ class TestFileServer < TestPuppet def test_widelists server = nil assert_nothing_raised { - server = Puppet::FileServer.new( + server = Puppet::Server::FileServer.new( :Local => true ) } @@ -354,10 +352,10 @@ class TestFileServer < TestPuppet } file = nil - checks = Puppet::FileServer::CHECKPARAMS + checks = Puppet::Server::FileServer::CHECKPARAMS assert_nothing_raised { - server = Puppet::FileServer.new( + server = Puppet::Server::FileServer.new( :Local => true ) } diff --git a/test/server/tc_master.rb b/test/server/tc_master.rb index be61b232b..fce6ea925 100644 --- a/test/server/tc_master.rb +++ b/test/server/tc_master.rb @@ -1,27 +1,15 @@ if __FILE__ == $0 if Dir.getwd =~ /test\/server$/ Dir.chdir("..") - #puts "Unfortunately, you must be in the test dir to run this test." - #puts "Yes, I know it's different than all of the others." - #exit end $:.unshift '../lib' - $:.unshift '../../../library/trunk/lib/' - $:.unshift '../../../library/trunk/test/' $puppetbase = ".." end -#if __FILE__ == $0 -# $:.unshift '../../lib' -# $:.unshift '../../../../library/trunk/lib/' -# $:.unshift '../../../../library/trunk/test/' -# $puppetbase = "../.." -#end - require 'puppet' -require 'puppet/master' +require 'puppet/server' require 'puppet/client' require 'test/unit' require 'puppettest.rb' @@ -68,7 +56,7 @@ class TestMaster < Test::Unit::TestCase master = nil assert_nothing_raised() { # this is the default server setup - master = Puppet::Master.new( + master = Puppet::Server::Master.new( :File => file, :Local => true ) @@ -108,7 +96,7 @@ class TestMaster < Test::Unit::TestCase master = nil assert_nothing_raised() { # this is the default server setup - master = Puppet::Master.new( + master = Puppet::Server::Master.new( :File => file, :Local => true ) diff --git a/test/server/tc_server.rb b/test/server/tc_server.rb index d3a4ea305..d75d981ae 100644 --- a/test/server/tc_server.rb +++ b/test/server/tc_server.rb @@ -1,26 +1,12 @@ if __FILE__ == $0 $:.unshift '../../lib' - $:.unshift '../../../../library/trunk/lib/' - $:.unshift '../../../../library/trunk/test/' + $:.unshift '..' $puppetbase = "../.." end -#if __FILE__ == $0 -# $:.unshift '../lib' -# $:.unshift '../../../library/trunk/lib/' -# $:.unshift '../../../library/trunk/test/' -# $puppetbase = ".." -# -# -# if Dir.getwd !~ /test$/ -# puts "Unfortunately, you must be in the test dir to run this test." -# puts "Yes, I know it's different than all of the others." -# exit -# end -#end require 'puppet' require 'cgi' -require 'puppet/server' +#require 'puppet/server' require 'facter' require 'puppet/client' require 'xmlrpc/client' -- cgit