[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.5rc1-120-g2247c80

Daniel Pittman daniel at rimspace.net
Mon Feb 7 06:43:11 UTC 2011


The following commit has been merged in the upstream branch:
commit 4ff5769119aefafa33e05449ebcfac78ba0c0fe0
Author: Daniel Pittman <daniel at rimspace.net>
Date:   Thu Feb 3 15:36:50 2011 -0800

    (#5823) run mode can now be set dynamically...
    
    Third party scripts, and complex command line tools, depend on being able to
    configure the run_mode value at runtime, not just when they fire up.
    
    For better or worse we used to allow this sort of thing to work, but stopped,
    and we have no sane, safe and consensual alternative, so we broke a bunch of
    client code.
    
    This enables the feature again, but does not add any safety catch; you can now
    happily slice off your own feet with this, if you really want to.

diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 17ad69c..b944a55 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -264,9 +264,14 @@ class Application
   def initialize(command_line = nil)
     require 'puppet/util/command_line'
     @command_line = command_line || Puppet::Util::CommandLine.new
-    @run_mode = self.class.run_mode
+    set_run_mode self.class.run_mode
     @options = {}
 
+    require 'puppet'
+  end
+
+  def set_run_mode(mode)
+    @run_mode = mode
     $puppet_application_mode = @run_mode
     $puppet_application_name = name
 
@@ -281,8 +286,6 @@ class Application
       Puppet.settings.set_value(:rundir, Puppet.run_mode.run_dir, :mutable_defaults)
       Puppet.settings.set_value(:run_mode, Puppet.run_mode.name.to_s, :mutable_defaults)
     end
-
-    require 'puppet'
   end
 
   # This is the main application entry point
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index c0f9733..5a52c2d 100755
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -46,6 +46,48 @@ describe Puppet::Application do
     end
   end
 
+  it "should sadly and frighteningly allow run_mode to change at runtime" do
+    class TestApp < Puppet::Application
+      run_mode :master
+      def run_command
+        # This is equivalent to calling these methods externally to the
+        # instance, but since this is what "real world" code is likely to do
+        # (and we need the class anyway) we may as well test that. --daniel 2011-02-03
+        set_run_mode self.class.run_mode "agent"
+      end
+    end
+
+    Puppet[:run_mode].should == "user"
+
+    expect {
+      app = TestApp.new
+
+      Puppet[:run_mode].should == "master"
+
+      app.run
+
+      app.class.run_mode.name.should == :agent
+      $puppet_application_mode.name.should == :agent
+    }.should_not raise_error
+
+    Puppet[:run_mode].should == "agent"
+  end
+
+  it "it should not allow run mode to be set multiple times" do
+    pending "great floods of tears, you can do this right now" # --daniel 2011-02-03
+    app = Puppet::Application.new
+    expect {
+      app.set_run_mode app.class.run_mode "master"
+      $puppet_application_mode.name.should == :master
+      app.set_run_mode app.class.run_mode "agent"
+      $puppet_application_mode.name.should == :agent
+    }.should raise_error
+  end
+
+  it "should explode when an invalid run mode is set at runtime, for great victory"
+  # ...but you can, and while it will explode, that only happens too late for
+  # us to easily test. --daniel 2011-02-03
+
   it "should have a run entry-point" do
     @app.should respond_to(:run)
   end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list