[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.7-1-98-gf19c0e5

James Turnbull james at lovedthanlost.net
Wed Apr 8 21:48:04 UTC 2009


The following commit has been merged in the master branch:
commit 671d73c1f7799e685ab484c91b7f92d16e21e256
Author: Luke Kanies <luke at madstop.com>
Date:   Wed Jan 14 15:33:48 2009 -0600

    Prefetching, and thus purging, Nagios resources now works
    *only* if you use the default configuration file locations.
    
    In the end, this was a relatively minor change; most of the actual
    diff centers around making the code more readable so I could think
    my way into the fix, and adding tests for cases that were either
    untested or refactored slightly.
    
    Signed-off-by: Luke Kanies <luke at madstop.com>

diff --git a/CHANGELOG b/CHANGELOG
index b12b94d..1c796a7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,8 @@
 0.24.8
+    Fixed #1541 -  nagios objects write files to clientbucket on every change
+
+    Fixed #1542 - cannot purge nagios objects
+ 
     Fixing #1912 - gid still works with no 'should' value fixing ralsh issues
 
     Fixing the Rakefile to use 'git format-patch'
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb
index b4a4a3b..a4c4bc8 100755
--- a/lib/puppet/provider/parsedfile.rb
+++ b/lib/puppet/provider/parsedfile.rb
@@ -108,10 +108,11 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
 
     # Return a list of all of the records we can find.
     def self.instances
-        prefetch()
-        @records.find_all { |r| r[:record_type] == self.name }.collect { |r|
-            new(r)
-        }
+        targets.collect do |target|
+            prefetch_target(target)
+        end.flatten.reject { |r| skip_record?(r) }.collect do |record|
+            new(record)
+        end
     end
 
     # Override the default method with a lot more functionality.
@@ -171,31 +172,39 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
     # resource instance.
     def self.prefetch(resources = nil)
         # Reset the record list.
-        @records = []
-        targets(resources).each do |target|
-            @records += prefetch_target(target)
-        end
+        @records = prefetch_all_targets(resources)
 
-        if resources
-            matchers = resources.dup
-            @records.each do |record|
-                # Skip things like comments and blank lines
-                next if skip_record?(record)
+        match_providers_with_resources(resources)
+    end
 
-                if name = record[:name] and resource = resources[name]
+    def self.match_providers_with_resources(resources)
+        return unless resources
+        matchers = resources.dup
+        @records.each do |record|
+            # Skip things like comments and blank lines
+            next if skip_record?(record)
+
+            if name = record[:name] and resource = resources[name]
+                resource.provider = new(record)
+            elsif respond_to?(:match)
+                if resource = match(record, matchers)
+                    # Remove this resource from circulation so we don't unnecessarily try to match
+                    matchers.delete(resource.title)
+                    record[:name] = resource[:name]
                     resource.provider = new(record)
-                elsif respond_to?(:match)
-                    if resource = match(record, matchers)
-                        # Remove this resource from circulation so we don't unnecessarily try to match
-                        matchers.delete(resource.title)
-                        record[:name] = resource[:name]
-                        resource.provider = new(record)
-                    end
                 end
             end
         end
     end
 
+    def self.prefetch_all_targets(resources)
+        records = []
+        targets(resources).each do |target|
+            records += prefetch_target(target)
+        end
+        records
+    end
+
     # Prefetch an individual target.
     def self.prefetch_target(target)
         target_records = retrieve(target).each do |r|
@@ -217,6 +226,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
 
     # Is there an existing record with this name?
     def self.record?(name)
+        return nil unless @records
         @records.find { |r| r[:name] == name }
     end
 
@@ -367,4 +377,3 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
         end
     end
 end
-
diff --git a/lib/puppet/util/nagios_maker.rb b/lib/puppet/util/nagios_maker.rb
index a7aae4e..3163349 100644
--- a/lib/puppet/util/nagios_maker.rb
+++ b/lib/puppet/util/nagios_maker.rb
@@ -42,6 +42,7 @@ module Puppet::Util::NagiosMaker
 
         target = "/etc/nagios/#{full_name.to_s}.cfg"
         provider = type.provide(:naginator, :parent => Puppet::Provider::Naginator, :default_target => target) {}
+        provider.nagios_type
 
         type.desc "The Nagios type #{name.to_s}.  This resource type is autogenerated using the
             model developed in Naginator_, and all of the Nagios types are generated using the
@@ -51,6 +52,9 @@ module Puppet::Util::NagiosMaker
             files.  By default, the statements will be added to ``#{target}``, but
             you can send them to a different file by setting their ``target`` attribute.
 
+            You can purge Nagios resources using the ``resources`` type, but *only*
+            in the default file locations.  This is an architectural limitation.
+
             .. _naginator: http://reductivelabs.com/trac/naginator
         "
     end
diff --git a/spec/unit/provider/naginator.rb b/spec/unit/provider/naginator.rb
index c39a50c..d0d43aa 100644
--- a/spec/unit/provider/naginator.rb
+++ b/spec/unit/provider/naginator.rb
@@ -47,4 +47,12 @@ describe Puppet::Provider::Naginator do
     it "should be able to prefetch instance from configuration files" do
         @class.should respond_to(:prefetch)
     end
+
+    it "should be able to generate a list of instances" do
+        @class.should respond_to(:instances)
+    end
+
+    it "should never skip records" do
+        @class.should_not be_skip_record("foo")
+    end
 end
diff --git a/spec/unit/provider/parsedfile.rb b/spec/unit/provider/parsedfile.rb
new file mode 100755
index 0000000..05e9de3
--- /dev/null
+++ b/spec/unit/provider/parsedfile.rb
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/provider/parsedfile'
+
+# Most of the tests for this are still in test/ral/provider/parsedfile.rb.
+describe Puppet::Provider::ParsedFile do
+    before do
+        @class = Class.new(Puppet::Provider::ParsedFile)
+    end
+
+    describe "when looking up records loaded from disk" do
+        it "should return nil if no records have been loaded" do
+            @class.record?("foo").should be_nil
+        end
+    end
+
+    describe "when generating a list of instances" do
+        it "should return an instance for each record parsed from all of the registered targets" do
+            @class.expects(:targets).returns %w{/one /two}
+            @class.stubs(:skip_record?).returns false
+            one = [:uno1, :uno2]
+            two = [:dos1, :dos2]
+            @class.expects(:prefetch_target).with("/one").returns one
+            @class.expects(:prefetch_target).with("/two").returns two
+
+            results = []
+            (one + two).each do |inst|
+                results << inst.to_s + "_instance"
+                @class.expects(:new).with(inst).returns(results[-1])
+            end
+
+            @class.instances.should == results
+        end
+
+        it "should skip specified records" do
+            @class.expects(:targets).returns %w{/one}
+            @class.expects(:skip_record?).with(:uno).returns false
+            @class.expects(:skip_record?).with(:dos).returns true
+            one = [:uno, :dos]
+            @class.expects(:prefetch_target).returns one
+
+            @class.expects(:new).with(:uno).returns "eh"
+            @class.expects(:new).with(:dos).never
+
+            @class.instances
+        end
+    end
+end
diff --git a/spec/unit/util/nagios_maker.rb b/spec/unit/util/nagios_maker.rb
index b754394..1e1aefc 100755
--- a/spec/unit/util/nagios_maker.rb
+++ b/spec/unit/util/nagios_maker.rb
@@ -13,6 +13,9 @@ describe Puppet::Util::NagiosMaker do
 
         @nagtype = stub 'nagios type', :parameters => [], :namevar => :name
         Nagios::Base.stubs(:type).with(:test).returns(@nagtype)
+
+        @provider = stub 'provider', :nagios_type => nil
+        @type = stub 'type', :newparam => nil, :newproperty => nil, :provide => @provider, :desc => nil, :ensurable => nil
     end
 
     it "should be able to create a new nagios type" do
@@ -26,73 +29,59 @@ describe Puppet::Util::NagiosMaker do
     end
 
     it "should create a new RAL type with the provided name prefixed with 'nagios_'" do
-        type = stub 'type', :newparam => nil, :newproperty => nil, :ensurable => nil, :provide => nil, :desc => nil
-
-        Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+        Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
         @module.create_nagios_type(:test)
     end
 
     it "should mark the created type as ensurable" do
-        type = stub 'type', :newparam => nil, :newproperty => nil, :provide => nil, :desc => nil
+        @type.expects(:ensurable)
 
-        type.expects(:ensurable)
-
-        Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+        Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
         @module.create_nagios_type(:test)
     end
 
     it "should create a namevar parameter for the nagios type's name parameter" do
-        type = stub 'type', :newproperty => nil, :ensurable => nil, :provide => nil, :desc => nil
-
-        type.expects(:newparam).with(:name, :namevar => true)
+        @type.expects(:newparam).with(:name, :namevar => true)
 
-        Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+        Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
         @module.create_nagios_type(:test)
     end
 
     it "should create a property for all non-namevar parameters" do
-        type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil
-
         @nagtype.stubs(:parameters).returns([:one, :two])
 
-        type.expects(:newproperty).with(:one)
-        type.expects(:newproperty).with(:two)
-        type.expects(:newproperty).with(:target)
+        @type.expects(:newproperty).with(:one)
+        @type.expects(:newproperty).with(:two)
+        @type.expects(:newproperty).with(:target)
 
-        Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+        Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
         @module.create_nagios_type(:test)
     end
 
     it "should skip parameters that start with integers" do
-        type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil
-
         @nagtype.stubs(:parameters).returns(["2dcoords".to_sym, :other])
 
-        type.expects(:newproperty).with(:other)
-        type.expects(:newproperty).with(:target)
+        @type.expects(:newproperty).with(:other)
+        @type.expects(:newproperty).with(:target)
 
-        Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+        Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
         @module.create_nagios_type(:test)
     end
 
     it "should deduplicate the parameter list" do
-        type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil
-
         @nagtype.stubs(:parameters).returns([:one, :one])
 
-        type.expects(:newproperty).with(:one)
-        type.expects(:newproperty).with(:target)
+        @type.expects(:newproperty).with(:one)
+        @type.expects(:newproperty).with(:target)
 
-        Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+        Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
         @module.create_nagios_type(:test)
     end
 
     it "should create a target property" do
-        type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil
+        @type.expects(:newproperty).with(:target)
 
-        type.expects(:newproperty).with(:target)
-
-        Puppet::Type.expects(:newtype).with(:nagios_test).returns(type)
+        Puppet::Type.expects(:newtype).with(:nagios_test).returns(@type)
         @module.create_nagios_type(:test)
     end
 end
@@ -100,6 +89,7 @@ end
 describe Puppet::Util::NagiosMaker, " when creating the naginator provider" do
     before do
         @module = Puppet::Util::NagiosMaker
+        @provider = stub 'provider', :nagios_type => nil
 
         @nagtype = stub 'nagios type', :parameters => [], :namevar => :name
         Nagios::Base.stubs(:type).with(:test).returns(@nagtype)
@@ -109,19 +99,27 @@ describe Puppet::Util::NagiosMaker, " when creating the naginator provider" do
     end
 
     it "should add a naginator provider" do
-        @type.expects(:provide).with { |name, options| name == :naginator }
+        @type.expects(:provide).with { |name, options| name == :naginator }.returns @provider
 
         @module.create_nagios_type(:test)
     end
 
     it "should set Puppet::Provider::Naginator as the parent class of the provider" do
-        @type.expects(:provide).with { |name, options| options[:parent] == Puppet::Provider::Naginator }
+        @type.expects(:provide).with { |name, options| options[:parent] == Puppet::Provider::Naginator }.returns @provider
 
         @module.create_nagios_type(:test)
     end
 
     it "should use /etc/nagios/$name.cfg as the default target" do
-        @type.expects(:provide).with { |name, options| options[:default_target] == "/etc/nagios/nagios_test.cfg" }
+        @type.expects(:provide).with { |name, options| options[:default_target] == "/etc/nagios/nagios_test.cfg" }.returns @provider
+
+        @module.create_nagios_type(:test)
+    end
+
+    it "should trigger the lookup of the Nagios class" do
+        @type.expects(:provide).returns @provider
+
+        @provider.expects(:nagios_type)
 
         @module.create_nagios_type(:test)
     end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list