summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--conf/redhat/puppet.spec2
-rw-r--r--lib/puppet.rb2
-rw-r--r--lib/puppet/client/dipper.rb2
-rwxr-xr-xlib/puppet/server/filebucket.rb16
-rw-r--r--lib/puppet/type/pfile.rb3
-rwxr-xr-xlib/puppet/type/pfilebucket.rb14
-rw-r--r--test/types/file.rb39
-rwxr-xr-xtest/types/filebucket.rb6
-rwxr-xr-xtest/types/filesources.rb121
9 files changed, 99 insertions, 106 deletions
diff --git a/conf/redhat/puppet.spec b/conf/redhat/puppet.spec
index 74955b79e..6aa415dd5 100644
--- a/conf/redhat/puppet.spec
+++ b/conf/redhat/puppet.spec
@@ -4,7 +4,7 @@
Summary: A network tool for managing many disparate systems
Name: puppet
-Version: 0.16.1
+Version: 0.16.2
Release: 1%{?dist}
License: GPL
Group: System Environment/Base
diff --git a/lib/puppet.rb b/lib/puppet.rb
index 213eb088e..6824c822f 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -14,7 +14,7 @@ require 'puppet/util'
#
# it's also a place to find top-level commands like 'debug'
module Puppet
- PUPPETVERSION = '0.16.1'
+ PUPPETVERSION = '0.16.2'
def Puppet.version
return PUPPETVERSION
diff --git a/lib/puppet/client/dipper.rb b/lib/puppet/client/dipper.rb
index bc85236a3..5965c6b7d 100644
--- a/lib/puppet/client/dipper.rb
+++ b/lib/puppet/client/dipper.rb
@@ -10,7 +10,7 @@ module Puppet
def initialize(hash = {})
if hash.include?(:Path)
bucket = Puppet::Server::FileBucket.new(
- :Bucket => hash[:Path]
+ :Path => hash[:Path]
)
hash.delete(:Path)
hash[:Bucket] = bucket
diff --git a/lib/puppet/server/filebucket.rb b/lib/puppet/server/filebucket.rb
index 8a4d1a0a4..d07fc93af 100755
--- a/lib/puppet/server/filebucket.rb
+++ b/lib/puppet/server/filebucket.rb
@@ -16,7 +16,7 @@ class Server
Puppet.config.setdefaults("filebucket",
:bucketdir => {
:default => "$vardir/bucket",
- :mode => 0770,
+ :mode => 0750,
:owner => "$user",
:group => "$group",
:desc => "Where FileBucket files are stored."
@@ -28,7 +28,7 @@ class Server
}
Puppet::Util.logmethods(self, true)
- attr_reader :name
+ attr_reader :name, :path
# this doesn't work for relative paths
def FileBucket.paths(base,md5)
@@ -48,19 +48,19 @@ class Server
end
if hash.include?(:Path)
- @bucket = hash[:Path]
+ @path = hash[:Path]
hash.delete(:Path)
else
if defined? Puppet
- @bucket = Puppet[:bucketdir]
+ @path = Puppet[:bucketdir]
else
- @bucket = File.expand_path("~/.filebucket")
+ @path = File.expand_path("~/.filebucket")
end
end
Puppet.config.use(:filebucket)
- @name = "filebucket[#{Puppet[:bucketdir]}]"
+ @name = "filebucket[#{@path}]"
end
# accept a file from a client
@@ -68,7 +68,7 @@ class Server
contents = Base64.decode64(string)
md5 = Digest::MD5.hexdigest(contents)
- bpath, bfile, pathpath = FileBucket.paths(@bucket,md5)
+ bpath, bfile, pathpath = FileBucket.paths(@path,md5)
# if it's a new directory...
if Puppet.recmkdir(bpath)
@@ -131,7 +131,7 @@ class Server
end
def getfile(md5, client = nil, clientip = nil)
- bpath, bfile, bpaths = FileBucket.paths(@bucket,md5)
+ bpath, bfile, bpaths = FileBucket.paths(@path,md5)
unless FileTest.exists?(bfile)
return false
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index a6b8c5a1f..08f003f8c 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -271,8 +271,7 @@ module Puppet
end
end
begin
- FileUtils.cp(file,
- file + backup)
+ FileUtils.cp(file, file + backup)
return true
rescue => detail
# since they said they want a backup, let's error out
diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb
index 15c968dcf..c337ffa77 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -2,8 +2,6 @@ require 'puppet/server/filebucket'
module Puppet
newtype(:filebucket) do
- attr_reader :bucket
-
@doc = "A repository for backing up files. If no filebucket is
defined, then files will be backed up in their current directory,
but the filebucket can be either a host- or site-global repository
@@ -42,6 +40,8 @@ module Puppet
desc "The path to the local filebucket. If this is
not specified, then the bucket is remote and *server* must be
specified."
+
+ defaultto { Puppet[:bucketdir] }
end
# get the actual filebucket object
@@ -57,9 +57,15 @@ module Puppet
self.collect do |obj| obj.name end
end
- def initialize(hash)
- super
+ def bucket
+ unless defined? @bucket
+ mkbucket()
+ end
+
+ @bucket
+ end
+ def mkbucket
if self[:server]
begin
@bucket = Puppet::Client::Dipper.new(
diff --git a/test/types/file.rb b/test/types/file.rb
index 28a12ab2f..04993db82 100644
--- a/test/types/file.rb
+++ b/test/types/file.rb
@@ -1077,6 +1077,45 @@ class TestFile < Test::Unit::TestCase
assert(FileTest.symlink?(link), "Did not make link")
assert_equal(File.join(source, "file"), File.readlink(link))
end
+
+ def test_backupmodes
+ file = tempfile()
+ newfile = tempfile()
+
+ File.open(file, "w", 0411) { |f| f.puts "yayness" }
+
+ obj = nil
+ assert_nothing_raised {
+ obj = Puppet::Type.type(:file).create(
+ :path => file, :content => "rahness\n"
+ )
+ }
+
+ assert_apply(obj)
+
+ backupfile = file + obj[:backup]
+ @@tmpfiles << backupfile
+ assert(FileTest.exists?(backupfile),
+ "Backup file %s does not exist" % backupfile)
+
+ assert_equal(0411, filemode(backupfile),
+ "File mode is wrong for backupfile")
+
+ bucket = "bucket"
+ bpath = tempfile()
+ Dir.mkdir(bpath)
+ Puppet::Type.type(:filebucket).create(
+ :name => bucket, :path => bpath
+ )
+
+ obj[:backup] = bucket
+ obj[:content] = "New content"
+ assert_apply(obj)
+
+ bucketedpath = File.join(bpath, "18cc17fa3047fcc691fdf49c0a7f539a", "contents")
+
+ assert_equal(0440, filemode(bucketedpath))
+ end
end
# $Id$
diff --git a/test/types/filebucket.rb b/test/types/filebucket.rb
index fa48c7d45..e7e7e3e73 100755
--- a/test/types/filebucket.rb
+++ b/test/types/filebucket.rb
@@ -68,7 +68,8 @@ class TestFileBucket < Test::Unit::TestCase
def test_simplebucket
name = "yayness"
- mkbucket(name, tempfile())
+ bucketpath = tempfile()
+ mkbucket(name, bucketpath)
bucket = nil
assert_nothing_raised {
@@ -87,6 +88,9 @@ class TestFileBucket < Test::Unit::TestCase
assert(md5)
+ assert(FileTest.directory?(File.join(bucketpath, md5)),
+ "MD5 directory does not exist")
+
newmd5 = nil
# Just in case the file isn't writable
diff --git a/test/types/filesources.rb b/test/types/filesources.rb
index c25081977..e4e59bb78 100755
--- a/test/types/filesources.rb
+++ b/test/types/filesources.rb
@@ -263,91 +263,6 @@ class TestFileSources < Test::Unit::TestCase
return file
end
- # test raw xmlrpc calls
- # this test is disabled because it requires way too much setup to get
- # the certificates correct
- def disabled_test_SimpleNetworkSources
- server = nil
- basedir = tempfile()
- @@tmpfiles << basedir
-
- mounts = {
- "/" => "root"
- }
-
- fileserverconf = mkfileserverconf(mounts)
-
- if File.exists?(basedir)
- system("rm -rf %s" % basedir)
- end
- Dir.mkdir(basedir)
-
- Puppet[:confdir] = basedir
- Puppet[:vardir] = basedir
- Puppet[:autosign] = true
-
- 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 => {
- :Config => fileserverconf
- }
- }
- )
-
- }
- 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, :skip, false, false)
- }
-
- assert_equal("/\tfile", list)
-
- assert_nothing_raised {
- list = client.call("fileserver.describe", rpath, :skip)
- }
-
- assert_match(/^\d+\tfile\t\d+\t\d+\t.+$/, list)
-
- assert_nothing_raised {
- list = client.call("fileserver.retrieve", rpath, :skip)
- }
-
- contents = File.read(tmpfile)
- assert_equal(contents, CGI.unescape(list))
-
- assert_nothing_raised {
- system("kill -INT %s" % serverpid)
- }
- end
-
def test_NetworkSources
server = nil
basedir = tempfile()
@@ -632,9 +547,39 @@ class TestFileSources < Test::Unit::TestCase
trans = comp.evaluate
trans.evaluate
}
- #assert(FileTest.symlink?(dest), "Destination is not a symlink")
- #assert_equal(File.readlink(link), File.readlink(dest),
- # "Link did not copy correctly")
+ end
+
+ def test_changes
+ source = tempfile()
+ dest = tempfile()
+
+ File.open(source, "w") { |f| f.puts "yay" }
+
+ obj = nil
+ assert_nothing_raised {
+ obj = Puppet.type(:file).create(
+ :name => dest,
+ :source => source
+ )
+ }
+
+ assert_events([:file_created], obj)
+ assert_equal(File.read(source), File.read(dest), "Files are not equal")
+ assert_events([], obj)
+
+ File.open(source, "w") { |f| f.puts "boo" }
+
+ assert_events([:file_changed], obj)
+ assert_equal(File.read(source), File.read(dest), "Files are not equal")
+ assert_events([], obj)
+
+ File.open(dest, "w") { |f| f.puts "kaboom" }
+
+ # There are two changes, because first the checksum is noticed, and
+ # then the source causes a change
+ assert_events([:file_changed, :file_changed], obj)
+ assert_equal(File.read(source), File.read(dest), "Files are not equal")
+ assert_events([], obj)
end
end