ForwardPort action converted to new environment
This commit is contained in:
parent
b5daf5ae86
commit
e1c4f91664
|
@ -7,7 +7,7 @@ module Vagrant
|
||||||
next if !vm.running? || vm.uuid == @runner.uuid
|
next if !vm.running? || vm.uuid == @runner.uuid
|
||||||
|
|
||||||
vm.forwarded_ports.each do |fp|
|
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
|
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)
|
raise ActionException.new(:vm_port_collision, :name => name, :hostport => fp.hostport.to_s, :guestport => options[:guestport].to_s)
|
||||||
end
|
end
|
||||||
|
@ -29,7 +29,7 @@ module Vagrant
|
||||||
def forward_ports
|
def forward_ports
|
||||||
logger.info "Forwarding 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]}"
|
logger.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}"
|
||||||
port = VirtualBox::ForwardedPort.new
|
port = VirtualBox::ForwardedPort.new
|
||||||
port.name = name
|
port.name = name
|
||||||
|
|
|
@ -72,14 +72,14 @@ msg
|
||||||
# provisioning the instance with chef. {up} also starts the instance,
|
# provisioning the instance with chef. {up} also starts the instance,
|
||||||
# running it in the background.
|
# running it in the background.
|
||||||
def up
|
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..."
|
logger.info "VM already created. Starting VM if its not already running..."
|
||||||
Env.persisted_vm.start
|
env.vm.start
|
||||||
else
|
else
|
||||||
Env.require_box
|
env.require_box
|
||||||
VM.execute!(Actions::VM::Up)
|
env.create_vm.execute!(Actions::VM::Up)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,12 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
vms = [@vm]
|
vms = [@vm]
|
||||||
VirtualBox::VM.stubs(:all).returns(vms)
|
VirtualBox::VM.stubs(:all).returns(vms)
|
||||||
|
|
||||||
mock_config do |config|
|
@env = mock_environment do |config|
|
||||||
config.vm.forwarded_ports.clear
|
config.vm.forwarded_ports.clear
|
||||||
config.vm.forward_port("ssh", 22, 2222)
|
config.vm.forward_port("ssh", 22, 2222)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@mock_vm.stubs(:env).returns(@env)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "ignore vms which aren't running" do
|
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
|
should "create a port forwarding for the VM" do
|
||||||
forwarded_ports = mock("forwarded_ports")
|
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|
|
forwarded_ports.expects(:<<).with do |port|
|
||||||
assert_equal name, port.name
|
assert_equal name, port.name
|
||||||
assert_equal opts[:hostport], port.hostport
|
assert_equal opts[:hostport], port.hostport
|
||||||
|
|
|
@ -54,30 +54,33 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "up" do
|
context "up" do
|
||||||
setup do
|
setup do
|
||||||
Vagrant::Env.stubs(:persisted_vm).returns(nil)
|
@new_vm = mock("vm")
|
||||||
Vagrant::VM.stubs(:execute!)
|
@new_vm.stubs(:execute!)
|
||||||
Vagrant::Env.stubs(:require_box)
|
|
||||||
|
@env.stubs(:vm).returns(nil)
|
||||||
|
@env.stubs(:require_box)
|
||||||
|
@env.stubs(:create_vm).returns(@new_vm)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "require load the environment" do
|
should "require load the environment" do
|
||||||
Vagrant::Env.expects(:load!).once
|
Vagrant::Environment.expects(:load!).once.returns(@env)
|
||||||
Vagrant::Commands.up
|
Vagrant::Commands.up
|
||||||
end
|
end
|
||||||
|
|
||||||
should "require a box" do
|
should "require a box" do
|
||||||
Vagrant::Env.expects(:require_box).once
|
@env.expects(:require_box).once
|
||||||
Vagrant::Commands.up
|
Vagrant::Commands.up
|
||||||
end
|
end
|
||||||
|
|
||||||
should "call the up action on VM if it doesn't exist" do
|
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
|
Vagrant::Commands.up
|
||||||
end
|
end
|
||||||
|
|
||||||
should "call start on the persisted vm if it exists" do
|
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
|
@persisted_vm.expects(:start).once
|
||||||
Vagrant::VM.expects(:execute!).never
|
@env.expects(:create_vm).never
|
||||||
Vagrant::Commands.up
|
Vagrant::Commands.up
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue