From 7d73bec776cbecf97bb6d282fce96d4e5a591d4b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 12 Sep 2010 16:31:38 -0600 Subject: [PATCH] Disable networks only if VM is created --- lib/vagrant/action/vm/disable_networks.rb | 20 ++++++++++--------- .../action/vm/disable_networks_test.rb | 9 +++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/vagrant/action/vm/disable_networks.rb b/lib/vagrant/action/vm/disable_networks.rb index 2ba272e62..c6e0244bf 100644 --- a/lib/vagrant/action/vm/disable_networks.rb +++ b/lib/vagrant/action/vm/disable_networks.rb @@ -10,18 +10,20 @@ module Vagrant end def call(env) - logged = false + if env["vm"].created? + logged = false - env["vm"].vm.network_adapters.each do |adapter| - next if adapter.attachment_type != :host_only + env["vm"].vm.network_adapters.each do |adapter| + next if adapter.attachment_type != :host_only - if !logged - env.ui.info "vagrant.actions.vm.disable_networks.disabling" - logged = true + if !logged + env.ui.info "vagrant.actions.vm.disable_networks.disabling" + logged = true + end + + adapter.enabled = false + adapter.save end - - adapter.enabled = false - adapter.save end @app.call(env) diff --git a/test/vagrant/action/vm/disable_networks_test.rb b/test/vagrant/action/vm/disable_networks_test.rb index 63c9e6fae..c8604fb1f 100644 --- a/test/vagrant/action/vm/disable_networks_test.rb +++ b/test/vagrant/action/vm/disable_networks_test.rb @@ -9,6 +9,7 @@ class DisableNetworksVMActionTest < Test::Unit::TestCase @env.env.stubs(:vm).returns(@vm) @internal_vm = mock("internal") + @vm.stubs(:created?).returns(true) @vm.stubs(:vm).returns(@internal_vm) @internal_vm.stubs(:network_adapters).returns([]) @@ -27,6 +28,14 @@ class DisableNetworksVMActionTest < Test::Unit::TestCase @internal_vm.network_adapters << adapter end + should "do nothing if VM is not created" do + @vm.stubs(:created?).returns(false) + @vm.expects(:vm).never + + @app.expects(:call).with(@env).once + @instance.call(@env) + end + should "remove all network adapters and continue chain" do mock_adapter(:bridged) mock_adapter(:host_only)