All provisioners are now RVM-friendly

This commit is contained in:
Mitchell Hashimoto 2011-01-12 16:57:19 -08:00
parent 93d241f4ce
commit 2a5070dad7
10 changed files with 27 additions and 35 deletions

View File

@ -10,11 +10,9 @@ module Vagrant
def verify_binary(binary) def verify_binary(binary)
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
ssh.shell do |sh| # Checks for the existence of chef binary and error if it
# Checks for the existence of chef binary and error if it # doesn't exist.
# doesn't exist. ssh.exec!("sudo -i which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary)
sh.execute("which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary)
end
end end
end end

View File

@ -70,7 +70,7 @@ module Vagrant
end end
def run_chef_client 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") env.ui.info I18n.t("vagrant.provisioners.chef.running_client")
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|

View File

@ -60,7 +60,7 @@ module Vagrant
end end
def run_chef_solo 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") env.ui.info I18n.t("vagrant.provisioners.chef.running_solo")
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|

View File

@ -43,9 +43,7 @@ module Vagrant
def verify_binary(binary) def verify_binary(binary)
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
ssh.shell do |sh| ssh.exec!("sudo -i which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary)
sh.execute("which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary)
end
end end
end end
@ -75,11 +73,11 @@ module Vagrant
env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet") env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet")
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
ssh.shell do |sh| ssh.exec! "sudo -i 'cd #{config.pp_path}; puppet #{options}'" do |ch, type, data|
sh.execute "sudo -i 'cd #{config.pp_path}; puppet #{options}'" do |process| if type == :exit_status
process.on_output do |p, data| ssh.check_exit_status(data, command)
env.ui.info(data) else
end env.ui.info(data)
end end
end end
end end

View File

@ -26,9 +26,9 @@ module Vagrant
def verify_binary(binary) def verify_binary(binary)
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
# Checks for the existence of puppetd binary and error if it ssh.shell do |sh|
# doesn't exist. sh.execute("sudo -i which #{binary}", :error_class => PuppetServerError, :_key => :puppetd_not_detected, :binary => binary)
ssh.exec!("which #{binary}", :error_class => PuppetServerError, :_key => :puppetd_not_detected, :binary => binary) end
end end
end end
@ -41,14 +41,14 @@ module Vagrant
cn = env.config.vm.box cn = env.config.vm.box
end 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") env.ui.info I18n.t("vagrant.provisioners.puppet_server.running_puppetd")
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
ssh.exec!(command) do |channel, type, data| ssh.exec!(command) do |channel, type, data|
ssh.check_exit_status(data, command) if type == :exit_status 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 end
end end

View File

@ -145,7 +145,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
end end
should "cd into the provisioning directory and run chef client" do 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 @action.run_chef_client
end end

View File

@ -206,7 +206,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
end end
should "cd into the provisioning directory and run chef solo" do 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 @action.run_chef_solo
end end

View File

@ -111,14 +111,12 @@ class ChefProvisionerTest < Test::Unit::TestCase
context "verifying binary" do context "verifying binary" do
setup do setup do
@ssh = mock("ssh") @ssh = mock("ssh")
@shell = mock("shell")
@ssh.stubs(:shell).yields(@shell)
@vm.ssh.stubs(:execute).yields(@ssh) @vm.ssh.stubs(:execute).yields(@ssh)
end end
should "verify binary exists" do should "verify binary exists" do
binary = "foo" binary = "foo"
@shell.expects(:execute).with("which #{binary}", anything) @ssh.expects(:exec!).with("sudo -i which #{binary}", anything)
@action.verify_binary(binary) @action.verify_binary(binary)
end end
end end

View File

@ -24,12 +24,14 @@ class PuppetServerProvisionerTest < Test::Unit::TestCase
context "verifying binary" do context "verifying binary" do
setup do setup do
@ssh = mock("ssh") @ssh = mock("ssh")
@shell = mock("shell")
@ssh.stubs(:shell).yields(@shell)
@vm.ssh.stubs(:execute).yields(@ssh) @vm.ssh.stubs(:execute).yields(@ssh)
end end
should "verify binary exists" do should "verify binary exists" do
binary = "foo" binary = "foo"
@ssh.expects(:exec!).with("which #{binary}", anything) @shell.expects(:execute).with("sudo -i which #{binary}", anything)
@action.verify_binary(binary) @action.verify_binary(binary)
end end
end end
@ -42,19 +44,19 @@ class PuppetServerProvisionerTest < Test::Unit::TestCase
end end
should "run the puppetd client" do 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 @action.run_puppetd_client
end end
should "run puppetd with given options when given as an array" do should "run puppetd with given options when given as an array" do
@config.options = ["--modulepath", "modules", "--verbose"] @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 @action.run_puppetd_client
end end
should "run puppetd with the options when given as a string" do should "run puppetd with the options when given as a string" do
@config.options = "--modulepath modules --verbose" @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 @action.run_puppetd_client
end end

View File

@ -64,15 +64,13 @@ class PuppetProvisionerTest < Test::Unit::TestCase
context "verifying binary" do context "verifying binary" do
setup do setup do
@shell = mock("shell")
@ssh = mock("ssh") @ssh = mock("ssh")
@ssh.stubs(:shell).yields(@shell)
@vm.ssh.stubs(:execute).yields(@ssh) @vm.ssh.stubs(:execute).yields(@ssh)
end end
should "verify binary exists" do should "verify binary exists" do
binary = "foo" binary = "foo"
@shell.expects(:execute).with("which #{binary}", anything) @ssh.expects(:exec!).with("sudo -i which #{binary}", anything)
@action.verify_binary(binary) @action.verify_binary(binary)
end end
end end
@ -111,13 +109,11 @@ class PuppetProvisionerTest < Test::Unit::TestCase
context "running puppet client" do context "running puppet client" do
setup do setup do
@ssh = mock("ssh") @ssh = mock("ssh")
@shell = mock("shell")
@ssh.stubs(:shell).yields(@shell)
@vm.ssh.stubs(:execute).yields(@ssh) @vm.ssh.stubs(:execute).yields(@ssh)
end end
def expect_puppet_command(command) 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 end
should "cd into the pp_path directory and run puppet" do should "cd into the pp_path directory and run puppet" do