`vagrant up` process converted to new Environment
This commit is contained in:
parent
ae43f25cd2
commit
62de77132c
|
@ -6,7 +6,7 @@ module Vagrant
|
|||
logger.info "Running any VM customizations..."
|
||||
|
||||
# Run the customization procs over the VM
|
||||
Vagrant.config.vm.run_procs!(@runner.vm)
|
||||
@runner.env.config.vm.run_procs!(@runner.vm)
|
||||
|
||||
# Save the vm
|
||||
@runner.vm.save(true)
|
||||
|
|
|
@ -5,9 +5,9 @@ module Vagrant
|
|||
def execute!
|
||||
@runner.invoke_around_callback(:import) do
|
||||
Busy.busy do
|
||||
logger.info "Importing base VM (#{Vagrant::Env.box.ovf_file})..."
|
||||
logger.info "Importing base VM (#{@runner.env.box.ovf_file})..."
|
||||
# Use the first argument passed to the action
|
||||
@runner.vm = VirtualBox::VM.import(Vagrant::Env.box.ovf_file)
|
||||
@runner.vm = VirtualBox::VM.import(@runner.env.box.ovf_file)
|
||||
raise ActionException.new(:virtualbox_import_failure) unless @runner.vm
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,15 +4,15 @@ module Vagrant
|
|||
class Up < Base
|
||||
def prepare
|
||||
# If the dotfile is not a file, raise error
|
||||
if File.exist?(Env.dotfile_path) && !File.file?(Env.dotfile_path)
|
||||
if File.exist?(@runner.env.dotfile_path) && !File.file?(@runner.env.dotfile_path)
|
||||
raise ActionException.new(:dotfile_error)
|
||||
end
|
||||
|
||||
# Up is a "meta-action" so it really just queues up a bunch
|
||||
# of other actions in its place:
|
||||
steps = [Import, Customize, ForwardPorts, SharedFolders, Boot]
|
||||
steps << Provision if !Vagrant.config.vm.provisioner.nil?
|
||||
steps.insert(0, MoveHardDrive) if Vagrant.config.vm.hd_location
|
||||
steps << Provision if !@runner.env.config.vm.provisioner.nil?
|
||||
steps.insert(0, MoveHardDrive) if @runner.env.config.vm.hd_location
|
||||
|
||||
steps.each do |action_klass|
|
||||
@runner.add_action(action_klass)
|
||||
|
@ -26,12 +26,12 @@ module Vagrant
|
|||
|
||||
def persist
|
||||
logger.info "Persisting the VM UUID (#{@runner.uuid})..."
|
||||
Env.persist_vm(@runner)
|
||||
@runner.env.persist_vm
|
||||
end
|
||||
|
||||
def setup_mac_address
|
||||
logger.info "Matching MAC addresses..."
|
||||
@runner.vm.nics.first.macaddress = Vagrant.config[:vm][:base_mac]
|
||||
@runner.vm.nics.first.macaddress = @runner.env.config.vm.base_mac
|
||||
@runner.vm.save(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class CustomizeActionTest < Test::Unit::TestCase
|
|||
|
||||
context "executing" do
|
||||
should "run the VM customization procs then save the VM" do
|
||||
Vagrant.config.vm.expects(:run_procs!).with(@vm)
|
||||
@runner.env.config.vm.expects(:run_procs!).with(@vm)
|
||||
@vm.expects(:save).with(true).once
|
||||
@action.execute!
|
||||
end
|
||||
|
|
|
@ -2,12 +2,12 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|||
|
||||
class ImportActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@mock_vm, @vm, @import = mock_action(Vagrant::Actions::VM::Import)
|
||||
@runner, @vm, @import = mock_action(Vagrant::Actions::VM::Import)
|
||||
|
||||
@ovf_file = "foo"
|
||||
@box = mock("box")
|
||||
@box.stubs(:ovf_file).returns(@ovf_file)
|
||||
Vagrant::Env.stubs(:box).returns(@box)
|
||||
@runner.env.stubs(:box).returns(@box)
|
||||
|
||||
VirtualBox::VM.stubs(:import)
|
||||
end
|
||||
|
@ -18,7 +18,7 @@ class ImportActionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "invoke an around callback around the import" do
|
||||
@mock_vm.expects(:invoke_around_callback).with(:import).once
|
||||
@runner.expects(:invoke_around_callback).with(:import).once
|
||||
@import.execute!
|
||||
end
|
||||
|
||||
|
@ -28,7 +28,7 @@ class ImportActionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "raise an exception if import is nil" do
|
||||
@mock_vm.expects(:vm).returns(nil)
|
||||
@runner.expects(:vm).returns(nil)
|
||||
assert_raises(Vagrant::Actions::ActionException) {
|
||||
@import.execute!
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class ImportActionTest < Test::Unit::TestCase
|
|||
|
||||
should "set the resulting VM as the VM of the Vagrant VM object" do
|
||||
new_vm = mock("new_vm")
|
||||
@mock_vm.expects(:vm=).with(new_vm).once
|
||||
@runner.expects(:vm=).with(new_vm).once
|
||||
VirtualBox::VM.expects(:import).returns(new_vm).returns("foo")
|
||||
@import.execute!
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|||
|
||||
class UpActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Up)
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Up)
|
||||
mock_config
|
||||
end
|
||||
|
||||
|
@ -11,17 +11,20 @@ class UpActionTest < Test::Unit::TestCase
|
|||
File.stubs(:file?).returns(true)
|
||||
File.stubs(:exist?).returns(true)
|
||||
@default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
|
||||
|
||||
@dotfile_path = "foo"
|
||||
@runner.env.stubs(:dotfile_path).returns(@dotfile_path)
|
||||
end
|
||||
|
||||
def setup_action_expectations
|
||||
default_seq = sequence("default_seq")
|
||||
@default_order.each do |action|
|
||||
@mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
|
||||
@runner.expects(:add_action).with(action).once.in_sequence(default_seq)
|
||||
end
|
||||
end
|
||||
|
||||
should "raise an ActionException if a dotfile exists but is not a file" do
|
||||
File.expects(:file?).with(Vagrant::Env.dotfile_path).returns(false)
|
||||
File.expects(:file?).with(@runner.env.dotfile_path).returns(false)
|
||||
assert_raises(Vagrant::Actions::ActionException) {
|
||||
@action.prepare
|
||||
}
|
||||
|
@ -46,21 +49,27 @@ class UpActionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "add in the provisioning step if enabled" do
|
||||
mock_config do |config|
|
||||
env = mock_environment do |config|
|
||||
config.vm.provisioner = "foo"
|
||||
end
|
||||
|
||||
@runner.stubs(:env).returns(env)
|
||||
env.stubs(:dotfile_path).returns(@dotfile_path)
|
||||
|
||||
@default_order.push(Vagrant::Actions::VM::Provision)
|
||||
setup_action_expectations
|
||||
@action.prepare
|
||||
end
|
||||
|
||||
should "add in the action to move hard drive if config is set" do
|
||||
mock_config do |config|
|
||||
env = mock_environment do |config|
|
||||
File.expects(:directory?).with("foo").returns(true)
|
||||
config.vm.hd_location = "foo"
|
||||
end
|
||||
|
||||
@runner.stubs(:env).returns(env)
|
||||
env.stubs(:dotfile_path).returns(@dotfile_path)
|
||||
|
||||
@default_order.insert(0, Vagrant::Actions::VM::MoveHardDrive)
|
||||
setup_action_expectations
|
||||
@action.prepare
|
||||
|
@ -78,8 +87,8 @@ class UpActionTest < Test::Unit::TestCase
|
|||
|
||||
context "persisting" do
|
||||
should "persist the VM with Env" do
|
||||
@mock_vm.stubs(:uuid)
|
||||
Vagrant::Env.expects(:persist_vm).with(@mock_vm).once
|
||||
@runner.stubs(:uuid)
|
||||
@runner.env.expects(:persist_vm).once
|
||||
@action.persist
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue