[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:15:53 UTC 2011


The following commit has been merged in the experimental branch:
commit ab541fa0976bdce395a072bf0c391146b99d4219
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Fri Apr 15 15:18:13 2011 -0700

    (#7059) Use option hooks for the indirector terminus option.
    
    We used to open-code terminus setting, which had a bunch of duplicate code.
    Now, instead, we use the option hooks, resulting in the same behaviour with
    much less code.
    
    Paired-With: Max Martin <max at puppetlabs.com>

diff --git a/lib/puppet/face/indirector.rb b/lib/puppet/face/indirector.rb
index f48611e..6c7708b 100644
--- a/lib/puppet/face/indirector.rb
+++ b/lib/puppet/face/indirector.rb
@@ -5,6 +5,14 @@ class Puppet::Face::Indirector < Puppet::Face
   option "--terminus TERMINUS" do
     desc "REVISIT: You can select a terminus, which has some bigger effect
 that we should describe in this file somehow."
+
+    before_action do |action, args, options|
+      set_terminus(options[:terminus])
+    end
+
+    after_action do |action, args, options|
+      indirection.reset_terminus_class
+    end
   end
 
   def self.indirections
@@ -17,7 +25,6 @@ that we should describe in this file somehow."
 
   def call_indirection_method(method, *args)
     options = args.last
-    options.has_key?(:terminus) and set_terminus(options[:terminus])
 
     begin
       result = indirection.__send__(method, *args)
@@ -26,7 +33,6 @@ that we should describe in this file somehow."
       raise "Could not call '#{method}' on '#{indirection_name}': #{detail}"
     end
 
-    indirection.reset_terminus_class
     return result
   end
 
@@ -49,16 +55,11 @@ that we should describe in this file somehow."
   # Print the configuration for the current terminus class
   action :info do
     when_invoked 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
 
diff --git a/spec/unit/application/indirection_base_spec.rb b/spec/unit/application/indirection_base_spec.rb
index 63ab11e..5774038 100755
--- a/spec/unit/application/indirection_base_spec.rb
+++ b/spec/unit/application/indirection_base_spec.rb
@@ -23,12 +23,11 @@ describe Puppet::Application::IndirectionBase do
   it "should accept a terminus command line option" do
     # It would be nice not to have to stub this, but whatever... writing an
     # entire indirection stack would cause us more grief. --daniel 2011-03-31
-    terminus = mock("test indirection terminus")
+    terminus = stub_everything("test indirection terminus")
     Puppet::Indirector::Indirection.expects(:instance).
-      with(:testindirection).twice.returns()
+      with(:testindirection).returns(terminus)
 
-    subject.command_line.
-      instance_variable_set('@args', %w{--terminus foo save})
+    subject.command_line.instance_variable_set('@args', %w{--terminus foo save})
 
     # Not a very nice thing. :(
     $stderr.stubs(:puts)

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list