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