diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index 282a56e16..2103cc973 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -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 diff --git a/lib/vagrant/action/vm/export.rb b/lib/vagrant/action/vm/export.rb index cbb56e80a..a4ff8c90e 100644 --- a/lib/vagrant/action/vm/export.rb +++ b/lib/vagrant/action/vm/export.rb @@ -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 diff --git a/lib/vagrant/commands/package.rb b/lib/vagrant/commands/package.rb index f934840f0..bdca30f97 100644 --- a/lib/vagrant/commands/package.rb +++ b/lib/vagrant/commands/package.rb @@ -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 diff --git a/test/vagrant/action/vm/export_test.rb b/test/vagrant/action/vm/export_test.rb index 4ab58996a..a13f0bc18 100644 --- a/test/vagrant/action/vm/export_test.rb +++ b/test/vagrant/action/vm/export_test.rb @@ -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 diff --git a/test/vagrant/commands/package_test.rb b/test/vagrant/commands/package_test.rb index f10f98c76..2b8cd2413 100644 --- a/test/vagrant/commands/package_test.rb +++ b/test/vagrant/commands/package_test.rb @@ -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 diff --git a/vagrant.gemspec b/vagrant.gemspec index 4ad27f5b1..81c8c5bbc 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -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",