diff --git a/lib/vagrant/actions/vm/forward_ports.rb b/lib/vagrant/actions/vm/forward_ports.rb index 70b3fc4c1..c1517f911 100644 --- a/lib/vagrant/actions/vm/forward_ports.rb +++ b/lib/vagrant/actions/vm/forward_ports.rb @@ -7,7 +7,7 @@ module Vagrant next if !vm.running? || vm.uuid == @runner.uuid vm.forwarded_ports.each do |fp| - Vagrant.config.vm.forwarded_ports.each do |name, options| + @runner.env.config.vm.forwarded_ports.each do |name, options| if fp.hostport.to_s == options[:hostport].to_s raise ActionException.new(:vm_port_collision, :name => name, :hostport => fp.hostport.to_s, :guestport => options[:guestport].to_s) end @@ -29,7 +29,7 @@ module Vagrant def forward_ports logger.info "Forwarding ports..." - Vagrant.config.vm.forwarded_ports.each do |name, options| + @runner.env.config.vm.forwarded_ports.each do |name, options| logger.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}" port = VirtualBox::ForwardedPort.new port.name = name diff --git a/lib/vagrant/commands.rb b/lib/vagrant/commands.rb index ade5971d1..3112e196d 100644 --- a/lib/vagrant/commands.rb +++ b/lib/vagrant/commands.rb @@ -72,14 +72,14 @@ msg # provisioning the instance with chef. {up} also starts the instance, # running it in the background. def up - Env.load! + env = Environment.load! - if Env.persisted_vm + if env.vm logger.info "VM already created. Starting VM if its not already running..." - Env.persisted_vm.start + env.vm.start else - Env.require_box - VM.execute!(Actions::VM::Up) + env.require_box + env.create_vm.execute!(Actions::VM::Up) end end diff --git a/test/vagrant/actions/vm/forward_ports_test.rb b/test/vagrant/actions/vm/forward_ports_test.rb index 7dbfd3e83..fa73a6846 100644 --- a/test/vagrant/actions/vm/forward_ports_test.rb +++ b/test/vagrant/actions/vm/forward_ports_test.rb @@ -20,10 +20,12 @@ class ForwardPortsActionTest < Test::Unit::TestCase vms = [@vm] VirtualBox::VM.stubs(:all).returns(vms) - mock_config do |config| + @env = mock_environment do |config| config.vm.forwarded_ports.clear config.vm.forward_port("ssh", 22, 2222) end + + @mock_vm.stubs(:env).returns(@env) end should "ignore vms which aren't running" do @@ -71,7 +73,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase should "create a port forwarding for the VM" do forwarded_ports = mock("forwarded_ports") - Vagrant.config.vm.forwarded_ports.each do |name, opts| + @mock_vm.env.config.vm.forwarded_ports.each do |name, opts| forwarded_ports.expects(:<<).with do |port| assert_equal name, port.name assert_equal opts[:hostport], port.hostport diff --git a/test/vagrant/commands_test.rb b/test/vagrant/commands_test.rb index b4a0416a3..61fba7a55 100644 --- a/test/vagrant/commands_test.rb +++ b/test/vagrant/commands_test.rb @@ -54,30 +54,33 @@ class CommandsTest < Test::Unit::TestCase context "up" do setup do - Vagrant::Env.stubs(:persisted_vm).returns(nil) - Vagrant::VM.stubs(:execute!) - Vagrant::Env.stubs(:require_box) + @new_vm = mock("vm") + @new_vm.stubs(:execute!) + + @env.stubs(:vm).returns(nil) + @env.stubs(:require_box) + @env.stubs(:create_vm).returns(@new_vm) end should "require load the environment" do - Vagrant::Env.expects(:load!).once + Vagrant::Environment.expects(:load!).once.returns(@env) Vagrant::Commands.up end should "require a box" do - Vagrant::Env.expects(:require_box).once + @env.expects(:require_box).once Vagrant::Commands.up end should "call the up action on VM if it doesn't exist" do - Vagrant::VM.expects(:execute!).with(Vagrant::Actions::VM::Up).once + @new_vm.expects(:execute!).with(Vagrant::Actions::VM::Up).once Vagrant::Commands.up end should "call start on the persisted vm if it exists" do - Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm) + @env.stubs(:vm).returns(@persisted_vm) @persisted_vm.expects(:start).once - Vagrant::VM.expects(:execute!).never + @env.expects(:create_vm).never Vagrant::Commands.up end end