summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/application.rb9
-rwxr-xr-xspec/unit/application_spec.rb42
2 files changed, 48 insertions, 3 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 17ad69cee..b944a554e 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 c0f97336c..5a52c2d54 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