diff options
author | Luke Kanies <luke@madstop.com> | 2008-03-18 16:35:06 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-03-18 16:35:06 -0500 |
commit | e81fc583f1f25241d91e2402b89a06026138a20c (patch) | |
tree | 4b41df56a26864e9e6963c31e8ae291fedfbc692 | |
parent | fca467da6013dfeb1015a82e178d0db241eaa54e (diff) | |
download | puppet-e81fc583f1f25241d91e2402b89a06026138a20c.tar.gz puppet-e81fc583f1f25241d91e2402b89a06026138a20c.tar.xz puppet-e81fc583f1f25241d91e2402b89a06026138a20c.zip |
Settings now (again?) do not use a section more than
once, which should make the system a bit more efficient.
-rw-r--r-- | lib/puppet/util/settings.rb | 21 | ||||
-rwxr-xr-x | spec/unit/util/settings.rb | 13 |
2 files changed, 26 insertions, 8 deletions
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index 366688944..383e31b69 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -225,6 +225,9 @@ class Puppet::Util::Settings # A central concept of a name. @name = nil + + # The list of sections we've used. + @used = [] end # Return a given object's file metadata. @@ -663,26 +666,28 @@ Generated on #{Time.now}. # you can 'use' a section as many times as you want. def use(*sections) @@sync.synchronize do # yay, thread-safe - unless defined? @used - @used = [] - end + sections = sections.reject { |s| @used.include?(s.to_sym) } + + return if sections.empty? bucket = to_transportable(*sections) begin - config = bucket.to_catalog - config.host_config = false - config.apply do |transaction| + catalog = bucket.to_catalog + raise "wtf?(%s)" % sections.inspect unless catalog + catalog.host_config = false + catalog.apply do |transaction| if failures = transaction.any_failed? raise "Could not configure for running; got %s failure(s)" % failures end end ensure - config.clear + # The catalog won't exist if there was an error creating it. + catalog.clear if catalog end sections.each { |s| @used << s } - @used.uniq + @used.uniq! end end diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb index 45183e2fa..fbd638663 100755 --- a/spec/unit/util/settings.rb +++ b/spec/unit/util/settings.rb @@ -633,6 +633,19 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d lambda { @settings.use(:mysection) }.should raise_error end + it "should do nothing if all specified sections have already been used" do + bucket = mock 'bucket' + catalog = mock 'catalog' + + @settings.expects(:to_transportable).once.returns(bucket) + bucket.expects(:to_catalog).returns catalog + catalog.stub_everything + + @settings.use(:whatever) + + @settings.use(:whatever) + end + it "should ignore file settings whose values are not strings" do @settings[:maindir] = false |