Power off during the package sequence if not already.

This commit is contained in:
Mitchell Hashimoto 2010-07-07 20:58:20 -07:00
parent b96acce79f
commit f45989d1d5
6 changed files with 24 additions and 12 deletions

View File

@ -77,6 +77,7 @@ module Vagrant
# package - Export and package the VM
package = Builder.new do
use Action[:halt]
use VM::Export
use VM::Package
end

View File

@ -10,6 +10,8 @@ module Vagrant
def call(env)
@env = env
return env.error!(:vm_power_off_to_package) if !@env["vm"].vm.powered_off?
setup_temp_dir
export

View File

@ -53,11 +53,6 @@ module Vagrant
end
def package_vm(vm)
if !vm.powered_off?
error_and_exit(:vm_power_off_to_package)
return # for tests
end
vm.package(options)
end

View File

@ -15,6 +15,10 @@ class ExportVMActionTest < Test::Unit::TestCase
end
context "calling" do
setup do
@internal_vm.stubs(:powered_off?).returns(true)
end
should "call the proper methods then continue chain" do
seq = sequence("seq")
@instance.expects(:setup_temp_dir).in_sequence(seq)
@ -23,6 +27,17 @@ class ExportVMActionTest < Test::Unit::TestCase
@instance.call(@env)
end
should "halt the chain if not powered off" do
@internal_vm.stubs(:powered_off?).returns(false)
@instance.expects(:setup_temp_dir).never
@instance.expects(:export).never
@app.expects(:call).with(@env).never
@instance.call(@env)
assert @env.error?
assert_equal :vm_power_off_to_package, @env.error.first
end
end
context "setting up the temporary directory" do

View File

@ -81,18 +81,11 @@ class CommandsPackageTest < Test::Unit::TestCase
context "packaging a VM" do
setup do
@vm = mock("vm")
@vm.stubs(:powered_off?).returns(true)
@options = {}
@instance.stubs(:options).returns(@options)
end
should "error and exit if VM is not powered off" do
@vm.stubs(:powered_off?).returns(false)
@instance.expects(:error_and_exit).with(:vm_power_off_to_package).once
@instance.package_vm(@vm)
end
should "package the VM with the proper arguments" do
@options[:output] = "foo.box"
@options[:include] = :bar

View File

@ -43,11 +43,13 @@ Gem::Specification.new do |s|
"lib/vagrant/action/vm/customize.rb",
"lib/vagrant/action/vm/destroy.rb",
"lib/vagrant/action/vm/destroy_unused_network_interfaces.rb",
"lib/vagrant/action/vm/export.rb",
"lib/vagrant/action/vm/forward_ports.rb",
"lib/vagrant/action/vm/halt.rb",
"lib/vagrant/action/vm/import.rb",
"lib/vagrant/action/vm/match_mac_address.rb",
"lib/vagrant/action/vm/network.rb",
"lib/vagrant/action/vm/package.rb",
"lib/vagrant/action/vm/persist.rb",
"lib/vagrant/action/vm/provision.rb",
"lib/vagrant/action/vm/resume.rb",
@ -141,11 +143,13 @@ Gem::Specification.new do |s|
"test/vagrant/action/vm/customize_test.rb",
"test/vagrant/action/vm/destroy_test.rb",
"test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb",
"test/vagrant/action/vm/export_test.rb",
"test/vagrant/action/vm/forward_ports_test.rb",
"test/vagrant/action/vm/halt_test.rb",
"test/vagrant/action/vm/import_test.rb",
"test/vagrant/action/vm/match_mac_address_test.rb",
"test/vagrant/action/vm/network_test.rb",
"test/vagrant/action/vm/package_test.rb",
"test/vagrant/action/vm/persist_test.rb",
"test/vagrant/action/vm/provision_test.rb",
"test/vagrant/action/vm/resume_test.rb",
@ -237,11 +241,13 @@ Gem::Specification.new do |s|
"test/vagrant/action/vm/customize_test.rb",
"test/vagrant/action/vm/destroy_test.rb",
"test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb",
"test/vagrant/action/vm/export_test.rb",
"test/vagrant/action/vm/forward_ports_test.rb",
"test/vagrant/action/vm/halt_test.rb",
"test/vagrant/action/vm/import_test.rb",
"test/vagrant/action/vm/match_mac_address_test.rb",
"test/vagrant/action/vm/network_test.rb",
"test/vagrant/action/vm/package_test.rb",
"test/vagrant/action/vm/persist_test.rb",
"test/vagrant/action/vm/provision_test.rb",
"test/vagrant/action/vm/resume_test.rb",