Customize action

This commit is contained in:
Mitchell Hashimoto 2010-07-04 09:18:34 +02:00
parent 67729304a2
commit 12117d6349
3 changed files with 48 additions and 0 deletions

View File

@ -7,6 +7,7 @@ module Vagrant
def self.builtin!
up = Builder.new do
use VM::Import
use VM::Customize
end
register :up, up

View File

@ -0,0 +1,21 @@
module Vagrant
class Action
module VM
class Customize
def initialize(app, env)
@app = app
end
def call(env)
if !env.env.config.vm.proc_stack.empty?
env.logger.info "Running any VM customizations..."
env.env.config.vm.run_procs!(env["vm"])
env["vm"].save
end
@app.call(env)
end
end
end
end
end

View File

@ -0,0 +1,26 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class CustomizeVMActionTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::VM::Customize
@app, @env = mock_action_data
@instance = @klass.new(@app, @env)
@vm = mock("vm")
@env["vm"] = @vm
end
should "not run anything if no customize blocks exist" do
@vm.expects(:save).never
@app.expects(:call).with(@env).once
@instance.call(@env)
end
should "run the VM customization procs then save the VM" do
@env.env.config.vm.customize { |vm| }
@env.env.config.vm.expects(:run_procs!).with(@vm)
@vm.expects(:save).once
@app.expects(:call).with(@env).once
@instance.call(@env)
end
end