diff options
| author | Daniel Pittman <daniel@rimspace.net> | 2011-02-03 15:36:50 -0800 |
|---|---|---|
| committer | Daniel Pittman <daniel@rimspace.net> | 2011-02-03 15:36:50 -0800 |
| commit | 4ff5769119aefafa33e05449ebcfac78ba0c0fe0 (patch) | |
| tree | b49232a64521a0de647300fa44f75cda70d1f525 | |
| parent | 0502c557cbe8dc0d039e05ff5940a9e3b7e5c150 (diff) | |
| download | puppet-4ff5769119aefafa33e05449ebcfac78ba0c0fe0.tar.gz puppet-4ff5769119aefafa33e05449ebcfac78ba0c0fe0.tar.xz puppet-4ff5769119aefafa33e05449ebcfac78ba0c0fe0.zip | |
(#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.
| -rw-r--r-- | lib/puppet/application.rb | 9 | ||||
| -rwxr-xr-x | spec/unit/application_spec.rb | 42 |
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 |
