summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-11-15 21:29:18 -0600
committerLuke Kanies <luke@madstop.com>2007-11-15 21:29:18 -0600
commit9290cc89a2206fb5204578f8e91208857a48b147 (patch)
tree60eccb1ac688e6a9ca618155cdc141a23e6f6498
parentffb4c2dbc7314b364d25e4f7be599ef05b767b44 (diff)
downloadpuppet-9290cc89a2206fb5204578f8e91208857a48b147.tar.gz
puppet-9290cc89a2206fb5204578f8e91208857a48b147.tar.xz
puppet-9290cc89a2206fb5204578f8e91208857a48b147.zip
Modifying how default resources are created; they are now
added to the configuration by the master client, rather than by the creating types.
-rw-r--r--lib/puppet/network/client/master.rb21
-rwxr-xr-xlib/puppet/type/pfilebucket.rb8
-rwxr-xr-xlib/puppet/type/schedule.rb25
-rwxr-xr-xspec/unit/network/client/master.rb21
4 files changed, 43 insertions, 32 deletions
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb
index 2b0c99d33..691681f9e 100644
--- a/lib/puppet/network/client/master.rb
+++ b/lib/puppet/network/client/master.rb
@@ -49,15 +49,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
Puppet.settings[:dynamicfacts].split(/\s*,\s*/).collect { |fact| fact.downcase }
end
- # Add our default resources to the configuration.
- def add_default_resources(configuration)
- # First create the default scheduling objects
- Puppet::Type.type(:schedule).add_default_schedules(configuration)
-
- # And filebuckets
- Puppet::Type.type(:filebucket).add_default_filebucket(configuration)
- end
-
# Cache the config
def cache(text)
Puppet.info "Caching configuration at %s" % self.cachefile
@@ -558,6 +549,18 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
private
+ # Add our default resources to the configuration.
+ def add_default_resources(configuration)
+ # These are the only two resource types with default resources.
+ # We should probably iterate across all of them, but I think that's
+ # unnecessarily expensive at this point.
+ [:schedule, :filebucket].each do |resource_type|
+ Puppet::Type.type(resource_type).create_default_resources.each do |resource|
+ configuration.add_resource(resource) unless configuration.resource(resource_type, resource.title)
+ end
+ end
+ end
+
# Use our cached config, optionally specifying whether this is
# necessary because of a failure.
def use_cached_config(because_of_failure = false)
diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb
index 065d07fcb..5ce81858b 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -64,11 +64,9 @@ module Puppet
end
# Create a default filebucket.
- def self.add_default_bucket(configuration)
- unless configuration.resource(:filebucket, "puppet")
- Puppet.debug "Creating default local filebucket"
- configuration.create :filebucket, :name => "puppet", :path => Puppet[:clientbucketdir]
- end
+ def self.create_default_resources
+ Puppet.debug "Creating default local filebucket"
+ self.create :name => "puppet", :path => Puppet[:clientbucketdir]
end
def self.instances
diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb
index 9772762bb..72d649584 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -311,27 +311,24 @@ module Puppet
[]
end
- def self.add_default_schedules(configuration)
+ def self.create_default_schedules
Puppet.debug "Creating default schedules"
resources = []
# Create our default schedule
- unless configuration.resource(:schedule, "puppet")
- configuration.create(:schedule,
- :name => "puppet",
- :period => :hourly,
- :repeat => "2"
- )
- end
+ resources << self.create(
+ :name => "puppet",
+ :period => :hourly,
+ :repeat => "2"
+ )
# And then one for every period
@parameters.find { |p| p.name == :period }.values.each { |value|
- unless configuration.resource(:schedule, value.to_s)
- configuraiton.create(:schedule,
- :name => value.to_s,
- :period => value
- )
- end
+ resources << self.create(:schedule,
+ :name => value.to_s,
+ :period => value
+ )
}
+ resources
end
def match?(previous = nil, now = nil)
diff --git a/spec/unit/network/client/master.rb b/spec/unit/network/client/master.rb
index 68bb21d5e..8354b5521 100755
--- a/spec/unit/network/client/master.rb
+++ b/spec/unit/network/client/master.rb
@@ -424,8 +424,13 @@ describe Puppet::Network::Client::Master, " when adding default resources" do
it "should add the default schedules" do
config = mock 'config'
- Puppet::Type.type(:schedule).expects(:add_default_schedules).with(config)
- Puppet::Type.type(:filebucket).stubs(:add_default_filebucket)
+ one = stub 'one', :title => "one"
+ two = stub 'two', :title => "two"
+ Puppet::Type.type(:schedule).expects(:create_default_resources).with().returns([one, two])
+ config.expects(:add_resource).with(one)
+ config.expects(:add_resource).with(two)
+ config.stubs(:resource).returns(false)
+ Puppet::Type.type(:filebucket).stubs(:create_default_resources).returns([])
Puppet::Network::Client::Master.publicize_methods :add_default_resources do
@client.add_default_resources(config)
end
@@ -433,10 +438,18 @@ describe Puppet::Network::Client::Master, " when adding default resources" do
it "should add the default filebucket" do
config = mock 'config'
- Puppet::Type.type(:schedule).stubs(:add_default_schedules)
- Puppet::Type.type(:filebucket).expects(:add_default_filebucket).with(config)
+ Puppet::Type.type(:schedule).stubs(:create_default_resources).returns([])
+ one = stub 'one', :title => "one"
+ two = stub 'two', :title => "two"
+ Puppet::Type.type(:filebucket).expects(:create_default_resources).with().returns([one, two])
+ config.expects(:add_resource).with(one)
+ config.expects(:add_resource).with(two)
+ config.stubs(:resource).returns(false)
Puppet::Network::Client::Master.publicize_methods :add_default_resources do
@client.add_default_resources(config)
end
end
+
+ it "should only add default resources if no similarly named resource does not exist" do
+ end
end