Boot action converted to new Environment

This commit is contained in:
Mitchell Hashimoto 2010-03-19 16:22:20 -07:00
parent d384408782
commit ae43f25cd2
2 changed files with 10 additions and 10 deletions

View File

@ -3,7 +3,7 @@ module Vagrant
module VM module VM
class Boot < Base class Boot < Base
def prepare def prepare
Vagrant.config.vm.share_folder("vagrant-root", Vagrant.config.vm.project_directory, Env.root_path) @runner.env.config.vm.share_folder("vagrant-root", @runner.env.config.vm.project_directory, @runner.env.root_path)
end end
def execute! def execute!
@ -27,10 +27,10 @@ module Vagrant
def wait_for_boot(sleeptime=5) def wait_for_boot(sleeptime=5)
logger.info "Waiting for VM to boot..." logger.info "Waiting for VM to boot..."
Vagrant.config[:ssh][:max_tries].to_i.times do |i| @runner.env.config.ssh.max_tries.to_i.times do |i|
logger.info "Trying to connect (attempt ##{i+1} of #{Vagrant.config[:ssh][:max_tries]})..." logger.info "Trying to connect (attempt ##{i+1} of #{Vagrant.config[:ssh][:max_tries]})..."
if Vagrant::SSH.up? if @runner.env.ssh.up?
logger.info "VM booted and ready for use!" logger.info "VM booted and ready for use!"
return true return true
end end

View File

@ -2,14 +2,14 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class BootActionTest < Test::Unit::TestCase class BootActionTest < Test::Unit::TestCase
setup do setup do
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Boot) @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Boot)
@mock_vm.stubs(:invoke_callback) @runner.stubs(:invoke_callback)
mock_config mock_config
end end
context "preparing" do context "preparing" do
should "add the root shared folder" do should "add the root shared folder" do
Vagrant.config.vm.expects(:share_folder).with("vagrant-root", Vagrant.config.vm.project_directory, Vagrant::Env.root_path).once @runner.env.config.vm.expects(:share_folder).with("vagrant-root", @runner.env.config.vm.project_directory, @runner.env.root_path).once
@action.prepare @action.prepare
end end
end end
@ -17,7 +17,7 @@ class BootActionTest < Test::Unit::TestCase
context "execution" do context "execution" do
should "invoke the 'boot' around callback" do should "invoke the 'boot' around callback" do
boot_seq = sequence("boot_seq") boot_seq = sequence("boot_seq")
@mock_vm.expects(:invoke_around_callback).with(:boot).once.in_sequence(boot_seq).yields @runner.expects(:invoke_around_callback).with(:boot).once.in_sequence(boot_seq).yields
@action.expects(:boot).in_sequence(boot_seq) @action.expects(:boot).in_sequence(boot_seq)
@action.expects(:wait_for_boot).returns(true).in_sequence(boot_seq) @action.expects(:wait_for_boot).returns(true).in_sequence(boot_seq)
@action.execute! @action.execute!
@ -42,13 +42,13 @@ class BootActionTest < Test::Unit::TestCase
context "waiting for boot" do context "waiting for boot" do
should "repeatedly ping the SSH port and return false with no response" do should "repeatedly ping the SSH port and return false with no response" do
seq = sequence('pings') seq = sequence('pings')
Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i - 1).returns(false).in_sequence(seq) @runner.env.ssh.expects(:up?).times(@runner.env.config.ssh.max_tries.to_i - 1).returns(false).in_sequence(seq)
Vagrant::SSH.expects(:up?).once.returns(true).in_sequence(seq) @runner.env.ssh.expects(:up?).once.returns(true).in_sequence(seq)
assert @action.wait_for_boot(0) assert @action.wait_for_boot(0)
end end
should "ping the max number of times then just return" do should "ping the max number of times then just return" do
Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i).returns(false) @runner.env.ssh.expects(:up?).times(Vagrant.config.ssh.max_tries.to_i).returns(false)
assert !@action.wait_for_boot(0) assert !@action.wait_for_boot(0)
end end
end end