diff --git a/lib/vagrant/provisioners/puppet.rb b/lib/vagrant/provisioners/puppet.rb index 33b85cfce..a1aa02383 100644 --- a/lib/vagrant/provisioners/puppet.rb +++ b/lib/vagrant/provisioners/puppet.rb @@ -43,7 +43,9 @@ module Vagrant def verify_binary(binary) vm.ssh.execute do |ssh| - ssh.exec!("which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary) + ssh.shell do |sh| + sh.execute("which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary) + end end end @@ -66,16 +68,19 @@ module Vagrant end def run_puppet_client - options = config.options - options = options.join(" ") if options.is_a?(Array) - command = "cd #{config.pp_path} && sudo -E puppet #{options} #{@manifest}" + options = [config.options].flatten + options << @manifest + options = options.join(" ") env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet") vm.ssh.execute do |ssh| - ssh.exec!(command) do |channel, type, data| - ssh.check_exit_status(data, command) if type == :exit_status - env.ui.info("#{data}: #{type}") if type != :exit_status + ssh.shell do |sh| + sh.execute "sudo -i 'cd #{config.pp_path}; puppet #{options}'" do |process| + process.on_output do |p, data| + env.ui.info(data) + end + end end end end diff --git a/test/vagrant/provisioners/puppet_test.rb b/test/vagrant/provisioners/puppet_test.rb index a73e682d4..27d9b2fed 100644 --- a/test/vagrant/provisioners/puppet_test.rb +++ b/test/vagrant/provisioners/puppet_test.rb @@ -64,13 +64,15 @@ class PuppetProvisionerTest < Test::Unit::TestCase context "verifying binary" do setup do + @shell = mock("shell") @ssh = mock("ssh") + @ssh.stubs(:shell).yields(@shell) @vm.ssh.stubs(:execute).yields(@ssh) end should "verify binary exists" do binary = "foo" - @ssh.expects(:exec!).with("which #{binary}", anything) + @shell.expects(:execute).with("which #{binary}", anything) @action.verify_binary(binary) end end @@ -109,29 +111,29 @@ class PuppetProvisionerTest < Test::Unit::TestCase context "running puppet client" do setup do @ssh = mock("ssh") + @shell = mock("shell") + @ssh.stubs(:shell).yields(@shell) @vm.ssh.stubs(:execute).yields(@ssh) end + def expect_puppet_command(command) + @shell.expects(:execute).with("sudo -i 'cd #{@config.pp_path}; #{command}'") + end + should "cd into the pp_path directory and run puppet" do - @ssh.expects(:exec!).with("cd #{@config.pp_path} && sudo -E puppet #{@manifest}").once + expect_puppet_command("puppet #{@manifest}") @action.run_puppet_client end should "cd into the pp_path directory and run puppet with given options when given as an array" do @config.options = ["--modulepath", "modules", "--verbose"] - @ssh.expects(:exec!).with("cd #{@config.pp_path} && sudo -E puppet --modulepath modules --verbose #{@manifest}").once + expect_puppet_command("puppet --modulepath modules --verbose #{@manifest}") @action.run_puppet_client end should "cd into the pp_path directory and run puppet with the options when given as a string" do @config.options = "--modulepath modules --verbose" - @ssh.expects(:exec!).with("cd #{@config.pp_path} && sudo -E puppet --modulepath modules --verbose #{@manifest}").once - @action.run_puppet_client - end - - should "check the exit status if that is given" do - @ssh.stubs(:exec!).yields(nil, :exit_status, :foo) - @ssh.expects(:check_exit_status).with(:foo, anything).once + expect_puppet_command("puppet --modulepath modules --verbose #{@manifest}") @action.run_puppet_client end end