MAC address matching middleware

This commit is contained in:
Mitchell Hashimoto 2010-07-05 03:38:42 +02:00
parent 3e51a07a80
commit de772a01ce
3 changed files with 48 additions and 0 deletions

View File

@ -8,6 +8,7 @@ module Vagrant
up = Builder.new do
use VM::Import
use VM::Persist
use VM::MatchMACAddress
use VM::Customize
use VM::ForwardPorts
use VM::ShareFolders

View File

@ -0,0 +1,19 @@
module Vagrant
class Action
module VM
class MatchMACAddress
def initialize(app, env)
@app = app
end
def call(env)
env.logger.info "Matching MAC addresses..."
env["vm"].vm.network_adapters.first.mac_address = env.env.config.vm.base_mac
env["vm"].vm.save
@app.call(env)
end
end
end
end
end

View File

@ -0,0 +1,28 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class MatchMACAddressVMActionTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::VM::MatchMACAddress
@app, @env = mock_action_data
@vm = mock("vm")
@env["vm"] = @vm
@internal_vm = mock("internal")
@vm.stubs(:vm).returns(@internal_vm)
@instance = @klass.new(@app, @env)
end
should "match the mac addresses" do
nic = mock("nic")
nic.expects(:mac_address=).once
update_seq = sequence("update_seq")
@internal_vm.expects(:network_adapters).returns([nic]).once.in_sequence(update_seq)
@internal_vm.expects(:save).once.in_sequence(update_seq)
@app.expects(:call).with(@env).once.in_sequence(update_seq)
@instance.call(@env)
end
end