Disable networks only if VM is created
This commit is contained in:
parent
e11d3bd4f7
commit
7d73bec776
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue