From 2a5070dad7cec0b475e0725deb734c12d1908432 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 12 Jan 2011 16:57:19 -0800 Subject: [PATCH] All provisioners are now RVM-friendly --- lib/vagrant/provisioners/chef.rb | 8 +++----- lib/vagrant/provisioners/chef_server.rb | 2 +- lib/vagrant/provisioners/chef_solo.rb | 2 +- lib/vagrant/provisioners/puppet.rb | 14 ++++++-------- lib/vagrant/provisioners/puppet_server.rb | 10 +++++----- test/vagrant/provisioners/chef_server_test.rb | 2 +- test/vagrant/provisioners/chef_solo_test.rb | 2 +- test/vagrant/provisioners/chef_test.rb | 4 +--- test/vagrant/provisioners/puppet_server_test.rb | 10 ++++++---- test/vagrant/provisioners/puppet_test.rb | 8 ++------ 10 files changed, 27 insertions(+), 35 deletions(-) diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 81728dfaf..acd9b8422 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -10,11 +10,9 @@ module Vagrant def verify_binary(binary) vm.ssh.execute do |ssh| - ssh.shell do |sh| - # Checks for the existence of chef binary and error if it - # doesn't exist. - sh.execute("which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary) - end + # Checks for the existence of chef binary and error if it + # doesn't exist. + ssh.exec!("sudo -i which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary) end end diff --git a/lib/vagrant/provisioners/chef_server.rb b/lib/vagrant/provisioners/chef_server.rb index 7502f60be..e605ffd74 100644 --- a/lib/vagrant/provisioners/chef_server.rb +++ b/lib/vagrant/provisioners/chef_server.rb @@ -70,7 +70,7 @@ module Vagrant end def run_chef_client - command = "cd #{config.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json" + command = "sudo -i 'cd #{config.provisioning_path} && chef-client -c client.rb -j dna.json'" env.ui.info I18n.t("vagrant.provisioners.chef.running_client") vm.ssh.execute do |ssh| diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index b0bae130d..9bf753eb6 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -60,7 +60,7 @@ module Vagrant end def run_chef_solo - command = "cd #{config.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json" + command = "sudo -i 'cd #{config.provisioning_path} && chef-solo -c solo.rb -j dna.json'" env.ui.info I18n.t("vagrant.provisioners.chef.running_solo") vm.ssh.execute do |ssh| diff --git a/lib/vagrant/provisioners/puppet.rb b/lib/vagrant/provisioners/puppet.rb index a1aa02383..9f6476f26 100644 --- a/lib/vagrant/provisioners/puppet.rb +++ b/lib/vagrant/provisioners/puppet.rb @@ -43,9 +43,7 @@ module Vagrant def verify_binary(binary) vm.ssh.execute do |ssh| - ssh.shell do |sh| - sh.execute("which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary) - end + ssh.exec!("sudo -i which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary) end end @@ -75,11 +73,11 @@ module Vagrant env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet") vm.ssh.execute do |ssh| - 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 + ssh.exec! "sudo -i 'cd #{config.pp_path}; puppet #{options}'" do |ch, type, data| + if type == :exit_status + ssh.check_exit_status(data, command) + else + env.ui.info(data) end end end diff --git a/lib/vagrant/provisioners/puppet_server.rb b/lib/vagrant/provisioners/puppet_server.rb index aa569c5aa..91c913366 100644 --- a/lib/vagrant/provisioners/puppet_server.rb +++ b/lib/vagrant/provisioners/puppet_server.rb @@ -26,9 +26,9 @@ module Vagrant def verify_binary(binary) vm.ssh.execute do |ssh| - # Checks for the existence of puppetd binary and error if it - # doesn't exist. - ssh.exec!("which #{binary}", :error_class => PuppetServerError, :_key => :puppetd_not_detected, :binary => binary) + ssh.shell do |sh| + sh.execute("sudo -i which #{binary}", :error_class => PuppetServerError, :_key => :puppetd_not_detected, :binary => binary) + end end end @@ -41,14 +41,14 @@ module Vagrant cn = env.config.vm.box end - command = "sudo -E puppetd #{options} --server #{config.puppet_server} --certname #{cn}" + command = "sudo -i puppetd #{options} --server #{config.puppet_server} --certname #{cn}" env.ui.info I18n.t("vagrant.provisioners.puppet_server.running_puppetd") 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 + env.ui.info(data) if type != :exit_status end end end diff --git a/test/vagrant/provisioners/chef_server_test.rb b/test/vagrant/provisioners/chef_server_test.rb index 45d6d9691..41d855fa1 100644 --- a/test/vagrant/provisioners/chef_server_test.rb +++ b/test/vagrant/provisioners/chef_server_test.rb @@ -145,7 +145,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase end should "cd into the provisioning directory and run chef client" do - @ssh.expects(:exec!).with("cd #{@config.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json").once + @ssh.expects(:exec!).with("sudo -i 'cd #{@config.provisioning_path} && chef-client -c client.rb -j dna.json'").once @action.run_chef_client end diff --git a/test/vagrant/provisioners/chef_solo_test.rb b/test/vagrant/provisioners/chef_solo_test.rb index 01cc95e4d..ebf92f6b6 100644 --- a/test/vagrant/provisioners/chef_solo_test.rb +++ b/test/vagrant/provisioners/chef_solo_test.rb @@ -206,7 +206,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase end should "cd into the provisioning directory and run chef solo" do - @ssh.expects(:exec!).with("cd #{@config.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json").once + @ssh.expects(:exec!).with("sudo -i 'cd #{@config.provisioning_path} && chef-solo -c solo.rb -j dna.json'").once @action.run_chef_solo end diff --git a/test/vagrant/provisioners/chef_test.rb b/test/vagrant/provisioners/chef_test.rb index 5c8f68da7..3ead19c81 100644 --- a/test/vagrant/provisioners/chef_test.rb +++ b/test/vagrant/provisioners/chef_test.rb @@ -111,14 +111,12 @@ class ChefProvisionerTest < Test::Unit::TestCase context "verifying binary" do setup do @ssh = mock("ssh") - @shell = mock("shell") - @ssh.stubs(:shell).yields(@shell) @vm.ssh.stubs(:execute).yields(@ssh) end should "verify binary exists" do binary = "foo" - @shell.expects(:execute).with("which #{binary}", anything) + @ssh.expects(:exec!).with("sudo -i which #{binary}", anything) @action.verify_binary(binary) end end diff --git a/test/vagrant/provisioners/puppet_server_test.rb b/test/vagrant/provisioners/puppet_server_test.rb index acf8e45a6..1d9da2fb2 100644 --- a/test/vagrant/provisioners/puppet_server_test.rb +++ b/test/vagrant/provisioners/puppet_server_test.rb @@ -24,12 +24,14 @@ class PuppetServerProvisionerTest < Test::Unit::TestCase context "verifying binary" do setup do @ssh = mock("ssh") + @shell = mock("shell") + @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("sudo -i which #{binary}", anything) @action.verify_binary(binary) end end @@ -42,19 +44,19 @@ class PuppetServerProvisionerTest < Test::Unit::TestCase end should "run the puppetd client" do - @ssh.expects(:exec!).with("sudo -E puppetd --server #{@config.puppet_server} --certname #{@cn}").once + @ssh.expects(:exec!).with("sudo -i puppetd --server #{@config.puppet_server} --certname #{@cn}").once @action.run_puppetd_client end should "run puppetd with given options when given as an array" do @config.options = ["--modulepath", "modules", "--verbose"] - @ssh.expects(:exec!).with("sudo -E puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once + @ssh.expects(:exec!).with("sudo -i puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once @action.run_puppetd_client end should "run puppetd with the options when given as a string" do @config.options = "--modulepath modules --verbose" - @ssh.expects(:exec!).with("sudo -E puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once + @ssh.expects(:exec!).with("sudo -i puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once @action.run_puppetd_client end diff --git a/test/vagrant/provisioners/puppet_test.rb b/test/vagrant/provisioners/puppet_test.rb index 27d9b2fed..88175cbbe 100644 --- a/test/vagrant/provisioners/puppet_test.rb +++ b/test/vagrant/provisioners/puppet_test.rb @@ -64,15 +64,13 @@ 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" - @shell.expects(:execute).with("which #{binary}", anything) + @ssh.expects(:exec!).with("sudo -i which #{binary}", anything) @action.verify_binary(binary) end end @@ -111,13 +109,11 @@ 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}'") + @ssh.expects(:exec!).with("sudo -i 'cd #{@config.pp_path}; #{command}'") end should "cd into the pp_path directory and run puppet" do