[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Daniel Pittman daniel at puppetlabs.com
Tue May 10 08:10:46 UTC 2011


The following commit has been merged in the experimental branch:
commit d328af73e688df136ee6fe10340adf7ba72b951e
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Fri Apr 1 12:46:12 2011 -0700

    (#6760) set terminus in indirector string base class.
    
    We now accept a terminus option to each invocation, and set the terminus based
    on that call.  This is probably incomplete, because it only sets the terminus
    when given, and doesn't try to reset it to the default afterwards.
    
    This also resets the terminus class after every invocation, to stop it leaking
    state across calls.  This make, sadly, have some effects if you are not just
    using the strings to invoke the terminus, but it beats having the strings
    broken as well...
    
    Reviewed-By: Pieter van de Bruggen <pieter at puppetlabs.com>

diff --git a/lib/puppet/string/indirector.rb b/lib/puppet/string/indirector.rb
index 48280cc..bb08153 100644
--- a/lib/puppet/string/indirector.rb
+++ b/lib/puppet/string/indirector.rb
@@ -2,7 +2,6 @@ require 'puppet'
 require 'puppet/string'
 
 class Puppet::String::Indirector < Puppet::String
-  warn "REVISIT: Need to redefine this to take arguments again, eh."
   option "--terminus TERMINUS" do
     desc "REVISIT: You can select a terminus, which has some bigger effect
 that we should describe in this file somehow."
@@ -16,6 +15,21 @@ that we should describe in this file somehow."
     Puppet::Indirector::Terminus.terminus_classes(indirection.to_sym).collect { |t| t.to_s }.sort
   end
 
+  def call_indirection_method(method, *args)
+    options = args.pop
+    options.has_key?(:terminus) and set_terminus(options[:terminus])
+
+    begin
+      result = indirection.__send__(method, *args)
+    rescue => detail
+      puts detail.backtrace if Puppet[:trace]
+      raise "Could not call '#{method}' on '#{indirection_name}': #{detail}"
+    end
+
+    indirection.reset_terminus_class
+    return result
+  end
+
   action :destroy do
     invoke { |*args| call_indirection_method(:destroy, *args) }
   end
@@ -35,11 +49,16 @@ that we should describe in this file somehow."
   # Print the configuration for the current terminus class
   action :info do
     invoke do |*args|
+      options = args.pop
+      options.has_key?(:terminus) and set_terminus(options[:terminus])
+
       if t = indirection.terminus_class
         puts "Run mode '#{Puppet.run_mode.name}': #{t}"
       else
         $stderr.puts "No default terminus class for run mode '#{Puppet.run_mode.name}'"
       end
+
+      indirection.reset_terminus_class
     end
   end
 
@@ -72,15 +91,4 @@ that we should describe in this file somehow."
       raise "Could not set '#{indirection.name}' terminus to '#{from}' (#{detail}); valid terminus types are #{self.class.terminus_classes(indirection.name).join(", ") }"
     end
   end
-
-  def call_indirection_method(method, *args)
-    begin
-      result = indirection.__send__(method, *args)
-    rescue => detail
-      puts detail.backtrace if Puppet[:trace]
-      raise "Could not call '#{method}' on '#{indirection_name}': #{detail}"
-    end
-
-    result
-  end
 end
diff --git a/spec/unit/application/indirection_base_spec.rb b/spec/unit/application/indirection_base_spec.rb
index f636613..66b3009 100755
--- a/spec/unit/application/indirection_base_spec.rb
+++ b/spec/unit/application/indirection_base_spec.rb
@@ -26,7 +26,7 @@ describe Puppet::Application::IndirectionBase do
     # entire indirection stack would cause us more grief. --daniel 2011-03-31
     terminus = mock("test indirection terminus")
     Puppet::Indirector::Indirection.expects(:instance).
-      with(:testindirection).returns()
+      with(:testindirection).twice.returns()
 
     subject.command_line.
       instance_variable_set('@args', %w{--terminus foo save})
diff --git a/spec/unit/string/indirector_spec.rb b/spec/unit/string/indirector_spec.rb
index da5f569..29e8e70 100755
--- a/spec/unit/string/indirector_spec.rb
+++ b/spec/unit/string/indirector_spec.rb
@@ -4,12 +4,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
 require 'puppet/string/indirector'
 
 describe Puppet::String::Indirector do
-  before do
-    @instance = Puppet::String::Indirector.new(:test, '0.0.1')
-
-    @indirection = stub 'indirection', :name => :stub_indirection
-
-    @instance.stubs(:indirection).returns @indirection
+  subject do
+    instance = Puppet::String::Indirector.new(:test, '0.0.1')
+    indirection = stub('indirection',
+                       :name => :stub_indirection,
+                       :reset_terminus_class => nil)
+    instance.stubs(:indirection).returns indirection
+    instance
   end
 
   it "should be able to return a list of indirections" do
@@ -34,8 +35,8 @@ describe Puppet::String::Indirector do
     end
 
     it "should call the indirection method when the '#{method}' action is invoked" do
-      @instance.indirection.expects(method).with(:test, "myargs", {})
-      @instance.send(method, :test, "myargs")
+      subject.indirection.expects(method).with(:test, "myargs")
+      subject.send(method, :test, "myargs")
     end
   end
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list