ForwardPort action converted to new environment

This commit is contained in:
Mitchell Hashimoto 2010-03-19 16:16:03 -07:00
parent b5daf5ae86
commit e1c4f91664
4 changed files with 22 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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