summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlib/puppet/type/filebucket.rb15
-rw-r--r--lib/puppet/type/pfile.rb18
-rwxr-xr-xtest/types/tc_filebucket.rb78
3 files changed, 91 insertions, 20 deletions
diff --git a/lib/puppet/type/filebucket.rb b/lib/puppet/type/filebucket.rb
index 537f3983b..16a323960 100755
--- a/lib/puppet/type/filebucket.rb
+++ b/lib/puppet/type/filebucket.rb
@@ -1,6 +1,7 @@
-#!/usr/local/bin/ruby -w
# An interface for managing filebuckets from puppet
+# $Id$
+
require 'puppet/filebucket'
module Puppet
@@ -20,10 +21,10 @@ module Puppet
@name = :filebucket
@namevar = :name
- @@buckets = {}
-
+ # get the actual filebucket object
def self.bucket(name)
- @@buckets[name]
+ oname, object = @objects.find { |oname, o| oname == name }
+ return object.bucket
end
def initialize(hash)
@@ -55,12 +56,10 @@ module Puppet
)
end
end
-
- @@buckets[self.name] = @bucket
end
- end # Puppet::Type::Service
- end # Puppet::Type
+ end
+ end
end
# $Id$
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 5dc27290b..dad42c019 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -732,21 +732,27 @@ module Puppet
:source,
:filebucket
]
+
@paramdoc[:path] = "The path to the file to manage. Must be fully
qualified."
+
@paramdoc[:backup] = "Whether files should be backed up before
- being replaced. If a *filebucket* is specified, files will be
+ being replaced. If a ``filebucket`` is specified, files will be
backed up there; else, they will be backed up in the same directory
- with a *.puppet-bak* extension."
+ with a ``.puppet-bak`` extension."
+
@paramdoc[:linkmaker] = "An internal parameter used by the *symlink*
type to do recursive link creation."
+
@paramdoc[:recurse] = "Whether and how deeply to do recursive
management. **false**/*true*/*inf*/*number*"
+
@paramdoc[:source] = "Where to retrieve the contents of the files.
Currently only supports local copying, but will eventually
support multiple protocols for copying. Arguments are specified
using either a full local path or using a URI (currently only
*file* is supported as a protocol)."
+
@paramdoc[:filebucket] = "A repository for backing up files, including
over the network. Currently non-functional."
@@ -829,6 +835,14 @@ module Puppet
end
end
+ def paramfilebucket=(name)
+ if bucket = Puppet::Type::PFileBucket.bucket(name)
+ @parameters[:filebucket] = bucket
+ else
+ raise Puppet::Error.new("Could not find filebucket %s" % name)
+ end
+ end
+
def newchild(path, hash = {})
if path =~ %r{^#{File::SEPARATOR}}
raise Puppet::DevError.new(
diff --git a/test/types/tc_filebucket.rb b/test/types/tc_filebucket.rb
index e9644912d..b8568ae77 100755
--- a/test/types/tc_filebucket.rb
+++ b/test/types/tc_filebucket.rb
@@ -24,6 +24,20 @@ class TestFileBucket < Test::Unit::TestCase
return file
end
+ def mkbucket(name,path)
+ bucket = nil
+ assert_nothing_raised {
+ bucket = Puppet::Type::PFileBucket.new(
+ :name => name,
+ :path => path
+ )
+ }
+
+ @@tmpfiles.push path
+
+ return bucket
+ end
+
def mktestfile
# because luke's home directory is on nfs, it can't be used for testing
# as root
@@ -69,14 +83,7 @@ class TestFileBucket < Test::Unit::TestCase
def test_simplebucket
name = "yayness"
- assert_nothing_raised {
- Puppet::Type::PFileBucket.new(
- :name => name,
- :path => "/tmp/filebucket"
- )
- }
-
- @@tmpfiles.push "/tmp/filebucket"
+ mkbucket("yayness", "/tmp/filebucket")
bucket = nil
assert_nothing_raised {
@@ -85,8 +92,6 @@ class TestFileBucket < Test::Unit::TestCase
assert_instance_of(FileBucket::Dipper, bucket)
- Puppet.debug(bucket)
-
md5 = nil
newpath = "/tmp/passwd"
system("cp /etc/passwd %s" % newpath)
@@ -114,4 +119,57 @@ class TestFileBucket < Test::Unit::TestCase
assert_equal(md5, newmd5)
end
+
+ def test_fileswithbuckets
+ name = "yayness"
+ mkbucket("yayness", "/tmp/filebucket")
+
+ bucket = nil
+ assert_nothing_raised {
+ bucket = Puppet::Type::PFileBucket.bucket(name)
+ }
+
+ file = mktestfile()
+ assert_nothing_raised {
+ file[:filebucket] = name
+ }
+
+ opath = "/tmp/anotherbuckettest"
+ system("cp /etc/passwd %s" % opath)
+
+ origmd5 = File.open(file.name) { |f| newmd5 = Digest::MD5.hexdigest(f.read) }
+
+ file[:source] = opath
+ assert_nothing_raised {
+ file[:backup] = true
+ }
+
+ comp = newcomp("yaytest", file)
+
+ trans = nil
+ assert_nothing_raised {
+ trans = comp.evaluate
+ }
+ events = nil
+ assert_nothing_raised {
+ events = trans.evaluate.collect { |e| e.event }
+ }
+
+ # so, we've now replaced the file with the opath file
+ assert_equal(
+ File.open(opath) { |f| newmd5 = Digest::MD5.hexdigest(f.read) },
+ File.open(file.name) { |f| newmd5 = Digest::MD5.hexdigest(f.read) }
+ )
+
+ assert_nothing_raised {
+ bucket.restore(file.name, origmd5)
+ }
+
+ assert_equal(
+ origmd5,
+ File.open(file.name) { |f| newmd5 = Digest::MD5.hexdigest(f.read) }
+ )
+
+
+ end
end