diff options
| author | Till Maas <opensource@till.name> | 2009-08-02 11:20:30 +0200 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-08-03 07:42:54 +1000 |
| commit | 266aafa6efa9dff5fb0b49ffdafc9372edcafdfe (patch) | |
| tree | fef3c920a0275cb040d13f778e543ff0e4994f7e | |
| parent | 1f8ef6086cc1bb27035cc2534fac781a0349bfb5 (diff) | |
| download | puppet-266aafa6efa9dff5fb0b49ffdafc9372edcafdfe.tar.gz puppet-266aafa6efa9dff5fb0b49ffdafc9372edcafdfe.tar.xz puppet-266aafa6efa9dff5fb0b49ffdafc9372edcafdfe.zip | |
default server in remote filebuckets
With the path parameter set to false, the server defaults
to Puppet[:server]. This allows to use a remote filebucket without
syncing the servername there with the one used on the config file.
To use the default server, this manifest can be used:
filebucket { main: path => false }
A related bug report is:
http://projects.reductivelabs.com/issues/2456
| -rwxr-xr-x | lib/puppet/type/filebucket.rb | 54 | ||||
| -rw-r--r-- | spec/unit/type/filebucket.rb | 30 | ||||
| -rw-r--r-- | test/lib/puppettest/testcase.rb | 1 |
3 files changed, 62 insertions, 23 deletions
diff --git a/lib/puppet/type/filebucket.rb b/lib/puppet/type/filebucket.rb index 6e8e38adc..f0d2c8e82 100755 --- a/lib/puppet/type/filebucket.rb +++ b/lib/puppet/type/filebucket.rb @@ -34,9 +34,10 @@ module Puppet end newparam(:server) do - desc "The server providing the filebucket. If this is - not specified, then the bucket is local and *path* must be - specified." + desc "The server providing the remote filebucket. If this is not + specified then *path* is checked. If it is set, then the + bucket is local. Otherwise the puppetmaster server specified + in the config or at the commandline is used." end newparam(:port) do @@ -48,8 +49,8 @@ module Puppet newparam(:path) do desc "The path to the local filebucket. If this is - not specified, then the bucket is remote and *server* must be - specified." + unset, then the bucket is remote. The parameter *server* must + can be specified to set the remote server." defaultto { Puppet[:clientbucketdir] } end @@ -72,30 +73,37 @@ module Puppet end def mkbucket + # Default is a local filebucket, if no server is given. + # If the default path has been removed, too, then + # the puppetmaster is used as default server + + type = "local" if self[:server] - begin - @bucket = Puppet::Network::Client.client(:Dipper).new( - :Server => self[:server], - :Port => self[:port] - ) - rescue => detail - self.fail( - "Could not create remote filebucket: %s" % detail - ) - end - else - begin + type = "remote" + server = self[:server] + elsif not self[:path] + type = "remote" + server = Puppet[:server] + end + + begin + if type == "local" @bucket = Puppet::Network::Client.client(:Dipper).new( :Path => self[:path] ) - rescue => detail - if Puppet[:trace] - puts detail.backtrace - end - self.fail( - "Could not create local filebucket: %s" % detail + else + @bucket = Puppet::Network::Client.client(:Dipper).new( + :Server => server, + :Port => self[:port] ) end + rescue => detail + if Puppet[:trace] + puts detail.backtrace + end + self.fail( + "Could not create %s filebucket: %s" % [type, detail] + ) end @bucket.name = self.name diff --git a/spec/unit/type/filebucket.rb b/spec/unit/type/filebucket.rb new file mode 100644 index 000000000..9a635d517 --- /dev/null +++ b/spec/unit/type/filebucket.rb @@ -0,0 +1,30 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Type.type(:filebucket) do + it "be local by default" do + bucket = Puppet::Type.type(:filebucket).new :name => "main" + + bucket.name.should == "main" + bucket.bucket.should be_instance_of(Puppet::Network::Client::Dipper) + bucket.bucket.local.should == true + end + + it "not be local if path is false" do + bucket = Puppet::Type.type(:filebucket).new :name => "main", :path => false + + bucket.name.should == "main" + bucket.bucket.should be_instance_of(Puppet::Network::Client::Dipper) + bucket.bucket.local.should_not == true + end + + it "not be local if a server is specified" do + bucket = Puppet::Type.type(:filebucket).new :name => "main", :server => "puppet" + + bucket.name.should == "main" + bucket.bucket.should be_instance_of(Puppet::Network::Client::Dipper) + bucket.bucket.local.should_not == true + end + +end diff --git a/test/lib/puppettest/testcase.rb b/test/lib/puppettest/testcase.rb index 9af0292b4..bd566dff2 100644 --- a/test/lib/puppettest/testcase.rb +++ b/test/lib/puppettest/testcase.rb @@ -5,6 +5,7 @@ require 'puppettest' require 'puppettest/runnable_test' +require 'test/unit' class PuppetTest::TestCase < Test::Unit::TestCase include PuppetTest |
