[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

Markus Roberts Markus at reality.com
Wed Jul 14 10:37:51 UTC 2010


The following commit has been merged in the upstream branch:
commit 793d7b7cfd2bb1d61a0c0686dc1f8533c8ab13d9
Author: Nick Lewis <nick at puppetlabs.com>
Date:   Mon Jul 12 16:23:35 2010 -0700

    [#4213] -o option for setting onetime now works properly
    
    When onetime was moved to global defaults, it broke the option handler
    using it in agent to manage waitforcert length. Additionally, it
    caused --onetime and -o to behave differently. This patch removes
    the ordinary option handler defined in agent and moves the logic
    for waitforcert to the one location it's used.

diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb
index b90bdd4..f0e7f4d 100644
--- a/lib/puppet/application/agent.rb
+++ b/lib/puppet/application/agent.rb
@@ -5,7 +5,7 @@ class Puppet::Application::Agent < Puppet::Application
   should_parse_config
   run_mode :agent
 
-  attr_accessor :explicit_waitforcert, :args, :agent, :daemon, :host
+  attr_accessor :args, :agent, :daemon, :host
 
   def preinit
     # Do an initial trap, so that cancels don't get a stack trace.
@@ -15,7 +15,7 @@ class Puppet::Application::Agent < Puppet::Application
     end
 
     {
-      :waitforcert => 120,  # Default to checking for certs every 5 minutes
+      :waitforcert => nil,
       :detailed_exitcodes => false,
       :verbose => false,
       :debug => false,
@@ -32,7 +32,6 @@ class Puppet::Application::Agent < Puppet::Application
       options[opt] = val
     end
 
-    @explicit_waitforcert = false
     @args = {}
     require 'puppet/daemon'
     @daemon = Puppet::Daemon.new
@@ -62,11 +61,6 @@ class Puppet::Application::Agent < Puppet::Application
     options[:client] = false
   end
 
-  option("--onetime", "-o") do |arg|
-    Puppet[:onetime] = true
-    options[:waitforcert] = 0 unless @explicit_waitforcert
-  end
-
   option("--detailed-exitcodes") do |arg|
     options[:detailed_exitcodes] = true
   end
@@ -83,7 +77,6 @@ class Puppet::Application::Agent < Puppet::Application
 
   option("--waitforcert WAITFORCERT", "-w") do |arg|
     options[:waitforcert] = arg.to_i
-    @explicit_waitforcert = true
   end
 
   option("--port PORT","-p") do |arg|
@@ -149,7 +142,6 @@ class Puppet::Application::Agent < Puppet::Application
     options[:verbose] = true
     Puppet[:onetime] = true
     options[:detailed_exitcodes] = true
-    options[:waitforcert] = 0 unless @explicit_waitforcert
   end
 
   # Handle the logging settings.
@@ -196,6 +188,12 @@ class Puppet::Application::Agent < Puppet::Application
     @daemon.server = server
   end
 
+  def setup_host
+    @host = Puppet::SSL::Host.new
+    waitforcert = options[:waitforcert] || (Puppet[:onetime] ? 0 : 120)
+    cert = @host.wait_for_cert(waitforcert) unless options[:fingerprint]
+  end
+
   def setup
     setup_test if options[:test]
 
@@ -252,8 +250,7 @@ class Puppet::Application::Agent < Puppet::Application
     # waitforcert happens.
     @daemon.daemonize if Puppet[:daemonize]
 
-    @host = Puppet::SSL::Host.new
-    cert = @host.wait_for_cert(options[:waitforcert]) unless options[:fingerprint]
+    setup_host
 
     @objects = []
 
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 0af40f2..84e2d93 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -54,10 +54,11 @@ module Puppet
       "Whether Puppet should manage the owner, group, and mode of files
       it uses internally"
       ],
-    :onetime => [false,
-      "Run the configuration once, rather than as a long-running
-      daemon. This is useful for interactively running puppetd."
-      ],
+    :onetime => {:default => false,
+      :desc => "Run the configuration once, rather than as a long-running
+      daemon. This is useful for interactively running puppetd.",
+      :short => 'o'
+      },
     :path => {:default => "none",
       :desc => "The shell search path.  Defaults to whatever is inherited
         from the parent process.",
diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb
index 079e0ad..54726c1 100755
--- a/spec/unit/application/agent_spec.rb
+++ b/spec/unit/application/agent_spec.rb
@@ -59,12 +59,6 @@ describe Puppet::Application::Agent do
       @puppetd.preinit
     end
 
-    it "should set waitforcert to 120" do
-      @puppetd.preinit
-
-      @puppetd.options[:waitforcert].should == 120
-    end
-
     it "should init client to true" do
       @puppetd.preinit
 
@@ -124,21 +118,22 @@ describe Puppet::Application::Agent do
       @puppetd.options[:client].should be_false
     end
 
-    it "should set onetime to true with --onetime" do
-      @puppetd.handle_onetime(nil)
-      Puppet[:onetime].should be_true
+    it "should set waitforcert to 0 with --onetime and if --waitforcert wasn't given" do
+      Puppet[:onetime] = true
+      Puppet::SSL::Host.any_instance.expects(:wait_for_cert).with(0)
+      @puppetd.setup_host
     end
 
-    it "should set waitforcert to 0 with --onetime and if --waitforcert wasn't given" do
-      @puppetd.explicit_waitforcert = false
-      @puppetd.handle_onetime(nil)
-      @puppetd.options[:waitforcert].should == 0
+    it "should use supplied waitforcert when --onetime is specified" do
+      Puppet[:onetime] = true
+      @puppetd.handle_waitforcert(60)
+      Puppet::SSL::Host.any_instance.expects(:wait_for_cert).with(60)
+      @puppetd.setup_host
     end
 
-    it "should not reset waitforcert with --onetime when --waitforcert is used" do
-      @puppetd.explicit_waitforcert = true
-      @puppetd.handle_onetime(nil)
-      @puppetd.options[:waitforcert].should_not == 0
+    it "should use a default value for waitforcert when --onetime and --waitforcert are not specified" do
+      Puppet::SSL::Host.any_instance.expects(:wait_for_cert).with(120)
+      @puppetd.setup_host
     end
 
     it "should set the log destination with --logdest" do
@@ -168,13 +163,6 @@ describe Puppet::Application::Agent do
       @puppetd.handle_waitforcert("42")
     end
 
-    it "should mark explicit_waitforcert to true with --waitforcert" do
-      @puppetd.options.stubs(:[]=)
-
-      @puppetd.handle_waitforcert("42")
-      @puppetd.explicit_waitforcert.should be_true
-    end
-
     it "should set args[:Port] with --port" do
       @puppetd.handle_port("42")
       @puppetd.args[:Port].should == "42"
@@ -226,10 +214,6 @@ describe Puppet::Application::Agent do
         @puppetd.options.expects(:[]=).with(:detailed_exitcodes,true)
         @puppetd.setup_test
       end
-      it "should set waitforcert to 0" do
-        @puppetd.options.expects(:[]=).with(:waitforcert,0)
-        @puppetd.setup_test
-      end
     end
 
     it "should call setup_logs" do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list