From fddee1158d886edcbbf3b81c162a0d520611d47e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 19 Mar 2010 17:05:31 -0700 Subject: [PATCH] `vagrant package` now uses the environment --- lib/vagrant/actions/vm/export.rb | 4 ++-- lib/vagrant/actions/vm/package.rb | 2 +- lib/vagrant/commands.rb | 8 ++++---- lib/vagrant/environment.rb | 5 +++++ test/vagrant/actions/vm/export_test.rb | 6 +++--- test/vagrant/actions/vm/package_test.rb | 2 +- test/vagrant/commands_test.rb | 7 ++++++- test/vagrant/environment_test.rb | 8 ++++++++ 8 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/vagrant/actions/vm/export.rb b/lib/vagrant/actions/vm/export.rb index 603884254..38d6bee4b 100644 --- a/lib/vagrant/actions/vm/export.rb +++ b/lib/vagrant/actions/vm/export.rb @@ -21,14 +21,14 @@ module Vagrant end def setup_temp_dir - @temp_dir = File.join(Env.tmp_path, Time.now.to_i.to_s) + @temp_dir = File.join(@runner.env.tmp_path, Time.now.to_i.to_s) logger.info "Creating temporary directory for export..." FileUtils.mkpath(temp_dir) end def ovf_path - File.join(temp_dir, Vagrant.config.vm.box_ovf) + File.join(temp_dir, @runner.env.config.vm.box_ovf) end def export diff --git a/lib/vagrant/actions/vm/package.rb b/lib/vagrant/actions/vm/package.rb index 49edea5eb..aea5a3b1a 100644 --- a/lib/vagrant/actions/vm/package.rb +++ b/lib/vagrant/actions/vm/package.rb @@ -29,7 +29,7 @@ module Vagrant end def tar_path - File.join(FileUtils.pwd, "#{out_path}#{Vagrant.config.package.extension}") + File.join(FileUtils.pwd, "#{out_path}#{@runner.env.config.package.extension}") end def temp_path diff --git a/lib/vagrant/commands.rb b/lib/vagrant/commands.rb index a75fc0bad..5c909d06b 100644 --- a/lib/vagrant/commands.rb +++ b/lib/vagrant/commands.rb @@ -157,11 +157,11 @@ msg # # This command requires that an instance be powered off def package(out_path=nil, include_files=[]) - Env.load! - Env.require_persisted_vm - error_and_exit(:vm_power_off_to_package) unless Env.persisted_vm.powered_off? + env = Environment.load! + env.require_persisted_vm + error_and_exit(:vm_power_off_to_package) unless env.vm.powered_off? - Env.persisted_vm.package(out_path, include_files) + env.vm.package(out_path, include_files) end # Manages the `vagrant box` command, allowing the user to add diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 5fa9f8cfa..3884e798e 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -70,6 +70,11 @@ module Vagrant config ? config.vagrant.home : nil end + # The path to the Vagrant tmp directory + def tmp_path + File.join(home_path, "tmp") + end + #--------------------------------------------------------------- # Load Methods #--------------------------------------------------------------- diff --git a/test/vagrant/actions/vm/export_test.rb b/test/vagrant/actions/vm/export_test.rb index 4ff1092b7..1228a9fcd 100644 --- a/test/vagrant/actions/vm/export_test.rb +++ b/test/vagrant/actions/vm/export_test.rb @@ -21,9 +21,9 @@ class ExportActionTest < Test::Unit::TestCase Time.stubs(:now).returns(@time_now) @tmp_path = "foo" - Vagrant::Env.stubs(:tmp_path).returns(@tmp_path) + @runner.env.stubs(:tmp_path).returns(@tmp_path) - @temp_dir = File.join(Vagrant::Env.tmp_path, @time_now) + @temp_dir = File.join(@runner.env.tmp_path, @time_now) FileUtils.stubs(:mkpath) end @@ -45,7 +45,7 @@ class ExportActionTest < Test::Unit::TestCase end should "be the temporary directory joined with the OVF filename" do - assert_equal File.join(@temp_dir, Vagrant.config.vm.box_ovf), @action.ovf_path + assert_equal File.join(@temp_dir, @runner.env.config.vm.box_ovf), @action.ovf_path end end diff --git a/test/vagrant/actions/vm/package_test.rb b/test/vagrant/actions/vm/package_test.rb index b633d3a65..1325622ea 100644 --- a/test/vagrant/actions/vm/package_test.rb +++ b/test/vagrant/actions/vm/package_test.rb @@ -41,7 +41,7 @@ class PackageActionTest < Test::Unit::TestCase should "be the temporary directory with the name and extension attached" do pwd = "foo" FileUtils.stubs(:pwd).returns(pwd) - assert_equal File.join(pwd, "#{@action.out_path}#{Vagrant.config.package.extension}"), @action.tar_path + assert_equal File.join(pwd, "#{@action.out_path}#{@runner.env.config.package.extension}"), @action.tar_path end end diff --git a/test/vagrant/commands_test.rb b/test/vagrant/commands_test.rb index beba216b4..1c14a2955 100644 --- a/test/vagrant/commands_test.rb +++ b/test/vagrant/commands_test.rb @@ -211,8 +211,13 @@ class CommandsTest < Test::Unit::TestCase @persisted_vm.stubs(:powered_off?).returns(true) end + should "load the current environment" do + Vagrant::Environment.expects(:load!).once.returns(@env) + Vagrant::Commands.package + end + should "require a persisted vm" do - Vagrant::Env.expects(:require_persisted_vm).once + @env.expects(:require_persisted_vm).once Vagrant::Commands.package end diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 03e813f79..a88c410ae 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -111,6 +111,14 @@ class EnvironmentTest < Test::Unit::TestCase assert_equal @env.config.vagrant.home, @env.home_path end end + + context "temp path" do + should "return the home path joined with 'tmp'" do + home_path = "foo" + @env.stubs(:home_path).returns(home_path) + assert_equal File.join("foo", "tmp"), @env.tmp_path + end + end end context "loading" do