From 97facb08fd908e517abc987d44c789c4fe9ad06d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 3 Jun 2010 20:34:02 -0700 Subject: [PATCH] Do not reload VM and everything if no forwarded ports were destroyed --- lib/vagrant/actions/vm/forward_ports.rb | 10 ++++++---- test/vagrant/actions/vm/forward_ports_test.rb | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/actions/vm/forward_ports.rb b/lib/vagrant/actions/vm/forward_ports.rb index c0d9ad784..f3423f161 100644 --- a/lib/vagrant/actions/vm/forward_ports.rb +++ b/lib/vagrant/actions/vm/forward_ports.rb @@ -67,10 +67,12 @@ module Vagrant end def clear - logger.info "Deleting any previously set forwarded ports..." - fp = @runner.vm.forwarded_ports.dup - fp.collect { |p| p.destroy } - @runner.reload! + if runner.vm.forwarded_ports.length > 0 + logger.info "Deleting any previously set forwarded ports..." + fp = runner.vm.forwarded_ports.dup + fp.collect { |p| p.destroy } + runner.reload! + end end def forward_ports diff --git a/test/vagrant/actions/vm/forward_ports_test.rb b/test/vagrant/actions/vm/forward_ports_test.rb index 47071ef4d..0a79ee962 100644 --- a/test/vagrant/actions/vm/forward_ports_test.rb +++ b/test/vagrant/actions/vm/forward_ports_test.rb @@ -164,9 +164,15 @@ class ForwardPortsActionTest < Test::Unit::TestCase forwarded_ports << port end - @vm.expects(:forwarded_ports).returns(forwarded_ports) + @vm.stubs(:forwarded_ports).returns(forwarded_ports) @runner.expects(:reload!) @action.clear end + + should "do nothing if there are no forwarded ports" do + @vm.stubs(:forwarded_ports).returns([]) + @runner.expects(:reload!).never + @action.clear + end end end