summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-07-31 02:59:25 +0000
committerLuke Kanies <luke@madstop.com>2005-07-31 02:59:25 +0000
commite041c8a800f61db4ec87f375de77ac4784ff039c (patch)
tree4fa267d7ffc83a677e4a9bb7ddf048ba42c003ea /test
parentcf37c06dbbde7ceb21691e6d90067eae8cfcfadd (diff)
downloadpuppet-e041c8a800f61db4ec87f375de77ac4784ff039c.tar.gz
puppet-e041c8a800f61db4ec87f375de77ac4784ff039c.tar.xz
puppet-e041c8a800f61db4ec87f375de77ac4784ff039c.zip
basic filebucketing is now working
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@479 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rw-r--r--test/bucket/tc_bucket.rb284
-rw-r--r--test/types/tc_file.rb8
-rwxr-xr-xtest/types/tc_filebucket.rb117
3 files changed, 405 insertions, 4 deletions
diff --git a/test/bucket/tc_bucket.rb b/test/bucket/tc_bucket.rb
new file mode 100644
index 000000000..3aa045fc1
--- /dev/null
+++ b/test/bucket/tc_bucket.rb
@@ -0,0 +1,284 @@
+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/types/tc_file.rb b/test/types/tc_file.rb
index c646e6272..740f6394c 100644
--- a/test/types/tc_file.rb
+++ b/test/types/tc_file.rb
@@ -24,7 +24,7 @@ class TestFile < Test::Unit::TestCase
return file
end
- def testfile
+ def mktestfile
# because luke's home directory is on nfs, it can't be used for testing
# as root
tmpfile = tempfile()
@@ -68,7 +68,7 @@ class TestFile < Test::Unit::TestCase
end
def test_zzowner
- file = testfile()
+ file = mktestfile()
users = {}
count = 0
@@ -152,7 +152,7 @@ class TestFile < Test::Unit::TestCase
end
def test_group
- file = testfile()
+ file = mktestfile()
[%x{groups}.chomp.split(/ /), Process.groups].flatten.each { |group|
assert_nothing_raised() {
file[:group] = group
@@ -224,7 +224,7 @@ class TestFile < Test::Unit::TestCase
end
def test_modes
- file = testfile
+ file = mktestfile
[0644,0755,0777,0641].each { |mode|
assert_nothing_raised() {
file[:mode] = mode
diff --git a/test/types/tc_filebucket.rb b/test/types/tc_filebucket.rb
new file mode 100755
index 000000000..e9644912d
--- /dev/null
+++ b/test/types/tc_filebucket.rb
@@ -0,0 +1,117 @@
+if __FILE__ == $0
+ $:.unshift '..'
+ $:.unshift '../../lib'
+ $puppetbase = "../../../../language/trunk"
+end
+
+require 'puppet'
+require 'test/unit'
+require 'fileutils'
+require 'puppettest'
+
+# $Id$
+
+class TestFileBucket < Test::Unit::TestCase
+ include FileTesting
+ # hmmm
+ # this is complicated, because we store references to the created
+ # objects in a central store
+ def mkfile(hash)
+ file = nil
+ assert_nothing_raised {
+ file = Puppet::Type::PFile.new(hash)
+ }
+ return file
+ end
+
+ def mktestfile
+ # because luke's home directory is on nfs, it can't be used for testing
+ # as root
+ tmpfile = tempfile()
+ File.open(tmpfile, "w") { |f| f.puts rand(100) }
+ @@tmpfiles.push tmpfile
+ mkfile(:name => tmpfile)
+ end
+
+ def setup
+ @@tmpfiles = []
+ Puppet[:loglevel] = :debug if __FILE__ == $0
+ Puppet[:statefile] = "/var/tmp/puppetstate"
+ begin
+ initstorage
+ rescue
+ system("rm -rf %s" % Puppet[:statefile])
+ end
+ end
+
+ def teardown
+ clearstorage
+ Puppet::Type.allclear
+ @@tmpfiles.each { |file|
+ if FileTest.exists?(file)
+ system("chmod -R 755 %s" % file)
+ system("rm -rf %s" % file)
+ end
+ }
+ @@tmpfiles.clear
+ system("rm -f %s" % Puppet[:statefile])
+ end
+
+ def initstorage
+ Puppet::Storage.init
+ Puppet::Storage.load
+ end
+
+ def clearstorage
+ Puppet::Storage.store
+ Puppet::Storage.clear
+ end
+
+ def test_simplebucket
+ name = "yayness"
+ assert_nothing_raised {
+ Puppet::Type::PFileBucket.new(
+ :name => name,
+ :path => "/tmp/filebucket"
+ )
+ }
+
+ @@tmpfiles.push "/tmp/filebucket"
+
+ bucket = nil
+ assert_nothing_raised {
+ bucket = Puppet::Type::PFileBucket.bucket(name)
+ }
+
+ assert_instance_of(FileBucket::Dipper, bucket)
+
+ Puppet.debug(bucket)
+
+ md5 = nil
+ newpath = "/tmp/passwd"
+ system("cp /etc/passwd %s" % newpath)
+ assert_nothing_raised {
+ md5 = bucket.backup(newpath)
+ }
+
+ assert(md5)
+
+ newmd5 = nil
+
+ File.open(newpath, "w") { |f| f.puts ";lkjasdf;lkjasdflkjwerlkj134lkj" }
+
+ assert_nothing_raised {
+ newmd5 = bucket.backup(newpath)
+ }
+
+ assert(md5 != newmd5)
+
+ assert_nothing_raised {
+ bucket.restore(newpath, md5)
+ }
+
+ File.open(newpath) { |f| newmd5 = Digest::MD5.hexdigest(f.read) }
+
+ assert_equal(md5, newmd5)
+ end
+end