Add `--no-provision` flag to `vagrant up`. Refactor the way action options work a bit. [closes GH-87]
This commit is contained in:
parent
c16df0d26a
commit
455a44cc5d
|
@ -26,6 +26,9 @@ module Vagrant
|
|||
# The {Runner runner} which is executing the action
|
||||
attr_reader :runner
|
||||
|
||||
# Any options which are passed into the initializer as a hash.
|
||||
attr_reader :options
|
||||
|
||||
# Included so subclasses don't need to include it themselves.
|
||||
include Vagrant::Util
|
||||
|
||||
|
@ -40,8 +43,9 @@ module Vagrant
|
|||
# Initialization of the action, passing any arguments which may have
|
||||
# been given to the {Runner runner}. This method can be used by subclasses
|
||||
# to save any of the configuration options which are passed in.
|
||||
def initialize(runner, *args)
|
||||
def initialize(runner, options=nil)
|
||||
@runner = runner
|
||||
@options = options || {}
|
||||
end
|
||||
|
||||
# This method is called once per action, allowing the action
|
||||
|
|
|
@ -2,18 +2,11 @@ module Vagrant
|
|||
module Actions
|
||||
module VM
|
||||
class Halt < Base
|
||||
attr_reader :force
|
||||
|
||||
def initialize(vm, force=nil)
|
||||
super
|
||||
@force = force
|
||||
end
|
||||
|
||||
def execute!
|
||||
raise ActionException.new(:vm_not_running) unless @runner.vm.running?
|
||||
|
||||
@runner.invoke_around_callback(:halt) do
|
||||
@runner.system.halt if !force
|
||||
@runner.system.halt if !options[:force]
|
||||
|
||||
if @runner.vm.state(true) != :powered_off
|
||||
logger.info "Forcing shutdown of VM..."
|
||||
|
|
|
@ -2,20 +2,16 @@ module Vagrant
|
|||
module Actions
|
||||
module VM
|
||||
class Package < Base
|
||||
attr_accessor :out_path
|
||||
attr_accessor :include_files
|
||||
attr_reader :export_action
|
||||
|
||||
def initialize(vm, out_path = nil, include_files = nil, *args)
|
||||
def initialize(*args)
|
||||
super
|
||||
@out_path = out_path || "package"
|
||||
@include_files = include_files || []
|
||||
@temp_path = nil
|
||||
end
|
||||
|
||||
def prepare
|
||||
# Verify the existance of all the additional files, if any
|
||||
@include_files.each do |file|
|
||||
include_files.each do |file|
|
||||
raise ActionException.new(:package_include_file_doesnt_exist, :filename => file) unless File.exists?(file)
|
||||
end
|
||||
|
||||
|
@ -28,6 +24,14 @@ module Vagrant
|
|||
compress
|
||||
end
|
||||
|
||||
def out_path
|
||||
options[:output] || "package"
|
||||
end
|
||||
|
||||
def include_files
|
||||
options[:include] || []
|
||||
end
|
||||
|
||||
def tar_path
|
||||
File.join(FileUtils.pwd, "#{out_path}#{@runner.env.config.package.extension}")
|
||||
end
|
||||
|
|
|
@ -8,11 +8,11 @@ module Vagrant
|
|||
steps = [Boot]
|
||||
if !@runner.vm || !@runner.vm.saved?
|
||||
steps.unshift([Customize, ForwardPorts, SharedFolders])
|
||||
steps << Provision if !@runner.env.config.vm.provisioner.nil? && !@runner.created?
|
||||
steps << Provision if !@runner.env.config.vm.provisioner.nil? && options[:provision]
|
||||
end
|
||||
|
||||
steps.flatten.each do |action_klass|
|
||||
@runner.add_action(action_klass)
|
||||
@runner.add_action(action_klass, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ module Vagrant
|
|||
steps.insert(0, MoveHardDrive) if @runner.env.config.vm.hd_location
|
||||
|
||||
steps.each do |action_klass|
|
||||
@runner.add_action(action_klass)
|
||||
@runner.add_action(action_klass, options)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
if vm.created?
|
||||
vm.halt(options[:force])
|
||||
vm.halt(options)
|
||||
else
|
||||
vm.env.logger.info "VM '#{name}' not created. Ignoring."
|
||||
end
|
||||
|
|
|
@ -58,7 +58,7 @@ module Vagrant
|
|||
return # for tests
|
||||
end
|
||||
|
||||
vm.package(options[:output], options[:include])
|
||||
vm.package(options)
|
||||
end
|
||||
|
||||
def options_spec(opts)
|
||||
|
|
|
@ -31,7 +31,14 @@ module Vagrant
|
|||
end
|
||||
|
||||
def options_spec(opts)
|
||||
opts.banner = "Usage: vagrant up"
|
||||
opts.banner = "Usage: vagrant up [--no-provision]"
|
||||
|
||||
# Defaults
|
||||
options[:provision] = true
|
||||
|
||||
opts.on("--no-provision", "Do not provision during this up.") do |v|
|
||||
options[:provision] = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -93,14 +93,14 @@ module Vagrant
|
|||
@vm = VirtualBox::VM.find(@vm.uuid)
|
||||
end
|
||||
|
||||
def package(out_path, include_files=[])
|
||||
add_action(Actions::VM::Export)
|
||||
add_action(Actions::VM::Package, out_path, include_files)
|
||||
def package(options=nil)
|
||||
add_action(Actions::VM::Export, options)
|
||||
add_action(Actions::VM::Package, options)
|
||||
execute!
|
||||
end
|
||||
|
||||
def up
|
||||
execute!(Actions::VM::Up)
|
||||
def up(options=nil)
|
||||
execute!(Actions::VM::Up, options)
|
||||
end
|
||||
|
||||
def start
|
||||
|
@ -109,8 +109,8 @@ module Vagrant
|
|||
execute!(Actions::VM::Start)
|
||||
end
|
||||
|
||||
def halt(force=false)
|
||||
execute!(Actions::VM::Halt, force)
|
||||
def halt(options=nil)
|
||||
execute!(Actions::VM::Halt, options)
|
||||
end
|
||||
|
||||
def reload
|
||||
|
|
|
@ -2,12 +2,15 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|||
|
||||
class PackageActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing", [])
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package)
|
||||
end
|
||||
|
||||
context "initialization" do
|
||||
def get_action(*args)
|
||||
runner, vm, action = mock_action(Vagrant::Actions::VM::Package, *args)
|
||||
def get_action(output, include_files)
|
||||
runner, vm, action = mock_action(Vagrant::Actions::VM::Package, {
|
||||
:output => output,
|
||||
:include => include_files
|
||||
})
|
||||
return action
|
||||
end
|
||||
|
||||
|
@ -35,6 +38,31 @@ class PackageActionTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "out path" do
|
||||
should "be the specified output file if given" do
|
||||
result = mock("result")
|
||||
@action.options[:output] = result
|
||||
assert_equal result, @action.out_path
|
||||
end
|
||||
|
||||
should "default to 'package'" do
|
||||
@action.options[:output] = nil
|
||||
assert_equal "package", @action.out_path
|
||||
end
|
||||
end
|
||||
|
||||
context "include files" do
|
||||
should "specified array if given" do
|
||||
@action.options[:include] = [1,2,3]
|
||||
assert_equal @action.options[:include], @action.include_files
|
||||
end
|
||||
|
||||
should "be an empty array by default" do
|
||||
@action.options[:include] = nil
|
||||
assert_equal [], @action.include_files
|
||||
end
|
||||
end
|
||||
|
||||
context "tar path" do
|
||||
should "be the temporary directory with the name and extension attached" do
|
||||
pwd = "foo"
|
||||
|
@ -185,7 +213,9 @@ class PackageActionTest < Test::Unit::TestCase
|
|||
context "checking include files" do
|
||||
setup do
|
||||
@include_files = ['fooiest', 'booiest']
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing", @include_files)
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, {
|
||||
:include => @include_files
|
||||
})
|
||||
@runner.stubs(:find_action).returns("foo")
|
||||
end
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|||
class StartActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Start)
|
||||
|
||||
@action.options[:provision] = true
|
||||
end
|
||||
|
||||
context "sub-actions" do
|
||||
|
@ -17,7 +19,7 @@ class StartActionTest < Test::Unit::TestCase
|
|||
def setup_action_expectations
|
||||
default_seq = sequence("default_seq")
|
||||
@default_order.flatten.each do |action|
|
||||
@runner.expects(:add_action).with(action).once.in_sequence(default_seq)
|
||||
@runner.expects(:add_action).with(action, @action.options).once.in_sequence(default_seq)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,15 +51,5 @@ class StartActionTest < Test::Unit::TestCase
|
|||
setup_action_expectations
|
||||
@action.prepare
|
||||
end
|
||||
|
||||
should "not add provisioning if enabled but already created" do
|
||||
@runner.stubs(:created?).returns(true)
|
||||
@vm.env.config.vm.provisioner = :chef_solo
|
||||
|
||||
@runner.stubs(:vm).returns(nil)
|
||||
@default_order.unshift([Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders])
|
||||
setup_action_expectations
|
||||
@action.prepare
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ class UpActionTest < Test::Unit::TestCase
|
|||
def setup_action_expectations
|
||||
default_seq = sequence("default_seq")
|
||||
@default_order.each do |action|
|
||||
@runner.expects(:add_action).with(action).once.in_sequence(default_seq)
|
||||
@runner.expects(:add_action).with(action, @action.options).once.in_sequence(default_seq)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -31,13 +31,13 @@ class CommandsHaltTest < Test::Unit::TestCase
|
|||
|
||||
should "halt if its created" do
|
||||
@foo_vm.stubs(:created?).returns(true)
|
||||
@foo_vm.expects(:halt).with(false).once
|
||||
@foo_vm.expects(:halt).with(:force => false).once
|
||||
@instance.execute(["foo"])
|
||||
end
|
||||
|
||||
should "halt and force if specified" do
|
||||
@foo_vm.stubs(:created?).returns(true)
|
||||
@foo_vm.expects(:halt).with(true).once
|
||||
@foo_vm.expects(:halt).with(:force => true).once
|
||||
@instance.execute(["foo", "--force"])
|
||||
end
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ class CommandsPackageTest < Test::Unit::TestCase
|
|||
@options[:output] = "foo.box"
|
||||
@options[:include] = :bar
|
||||
|
||||
@vm.expects(:package).with(@options[:output], @options[:include]).once
|
||||
@vm.expects(:package).with(@options).once
|
||||
@instance.package_vm(@vm)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -153,31 +153,30 @@ class VMTest < Test::Unit::TestCase
|
|||
|
||||
context "packaging" do
|
||||
should "queue up the actions and execute" do
|
||||
out_path = mock("out_path")
|
||||
action_seq = sequence("actions")
|
||||
@vm.expects(:add_action).with(Vagrant::Actions::VM::Export).once.in_sequence(action_seq)
|
||||
@vm.expects(:add_action).with(Vagrant::Actions::VM::Package, out_path, []).once.in_sequence(action_seq)
|
||||
action_seq = sequence("action_seq")
|
||||
@vm.expects(:add_action).with(Vagrant::Actions::VM::Export, nil).once.in_sequence(action_seq)
|
||||
@vm.expects(:add_action).with(Vagrant::Actions::VM::Package, nil).once.in_sequence(action_seq)
|
||||
@vm.expects(:execute!).in_sequence(action_seq)
|
||||
@vm.package(out_path)
|
||||
@vm.package
|
||||
end
|
||||
end
|
||||
|
||||
context "upping" do
|
||||
should "execute the up action" do
|
||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Up).once
|
||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Up, nil).once
|
||||
@vm.up
|
||||
end
|
||||
end
|
||||
|
||||
context "halting" do
|
||||
should "execute the halt action" do
|
||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Halt, false).once
|
||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Halt, nil).once
|
||||
@vm.halt
|
||||
end
|
||||
|
||||
should "force if specified" do
|
||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Halt, true).once
|
||||
@vm.halt(true)
|
||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Halt, {:foo => :bar}).once
|
||||
@vm.halt({:foo => :bar})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Mitchell Hashimoto", "John Bender"]
|
||||
s.date = %q{2010-05-25}
|
||||
s.date = %q{2010-05-26}
|
||||
s.default_executable = %q{vagrant}
|
||||
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
|
||||
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]
|
||||
|
|
Loading…
Reference in New Issue