Environment has defaults for values. Import properly sets VM

This commit is contained in:
Mitchell Hashimoto 2010-07-05 03:17:09 +02:00
parent d4de0d7357
commit c365a7ffac
5 changed files with 50 additions and 4 deletions

View File

@ -14,6 +14,17 @@ module Vagrant
attr_reader :error
def initialize(env)
super() do |h,k|
# By default, try to find the key as a method on the
# environment. Gross eval use here.
begin
value = eval("h.env.#{k}")
h[k] = value
rescue Exception
nil
end
end
@env = env
@error = nil
end

View File

@ -11,12 +11,12 @@ module Vagrant
begin
# Import the virtual machine
env['vm'] = VirtualBox::VM.import(env.env.box.ovf_file) do |progress|
env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file) do |progress|
env.logger.report_progress(progress.percent, 100, false)
end
# Flag as erroneous and return if import failed
return env.error!(:virtualbox_import_failure) if !env['vm']
return env.error!(:virtualbox_import_failure) if !env['vm'].vm
ensure
env.logger.clear_progress
end

View File

@ -6,6 +6,11 @@ class ActionEnvironmentTest < Test::Unit::TestCase
@instance = @klass.new(mock_environment)
end
should "default values to those on the env" do
@instance.env.stubs(:key).returns("value")
assert_equal "value", @instance["key"]
end
should "setup the logger" do
assert_equal @instance.env.logger, @instance.logger
end

View File

@ -11,6 +11,8 @@ class ImportVMActionTest < Test::Unit::TestCase
@box.stubs(:ovf_file).returns(ovf_file)
@env.env.stubs(:box).returns(@box)
@env.env.vm = Vagrant::VM.new
VirtualBox::VM.stubs(:import)
end
@ -25,7 +27,7 @@ class ImportVMActionTest < Test::Unit::TestCase
@app.expects(:call).with(@env).once
@instance.call(@env)
assert_equal vm, @env["vm"]
assert_equal vm, @env["vm"].vm
end
should "mark environment erroneous and not continue chain on failure" do

View File

@ -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-07-02}
s.date = %q{2010-07-05}
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"]
@ -33,6 +33,16 @@ Gem::Specification.new do |s|
"keys/vagrant.ppk",
"keys/vagrant.pub",
"lib/vagrant.rb",
"lib/vagrant/action.rb",
"lib/vagrant/action/builder.rb",
"lib/vagrant/action/builtin.rb",
"lib/vagrant/action/environment.rb",
"lib/vagrant/action/error_halt.rb",
"lib/vagrant/action/vm/boot.rb",
"lib/vagrant/action/vm/customize.rb",
"lib/vagrant/action/vm/forward_ports.rb",
"lib/vagrant/action/vm/import.rb",
"lib/vagrant/action/vm/share_folders.rb",
"lib/vagrant/actions/base.rb",
"lib/vagrant/actions/box/add.rb",
"lib/vagrant/actions/box/destroy.rb",
@ -113,6 +123,15 @@ Gem::Specification.new do |s|
"templates/unison/crontab_entry.erb",
"templates/unison/script.erb",
"test/test_helper.rb",
"test/vagrant/action/builder_test.rb",
"test/vagrant/action/environment_test.rb",
"test/vagrant/action/error_halt_test.rb",
"test/vagrant/action/vm/boot_test.rb",
"test/vagrant/action/vm/customize_test.rb",
"test/vagrant/action/vm/forward_ports_test.rb",
"test/vagrant/action/vm/import_test.rb",
"test/vagrant/action/vm/share_folders_test.rb",
"test/vagrant/action_test.rb",
"test/vagrant/actions/base_test.rb",
"test/vagrant/actions/box/add_test.rb",
"test/vagrant/actions/box/destroy_test.rb",
@ -190,6 +209,15 @@ Gem::Specification.new do |s|
s.summary = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.test_files = [
"test/test_helper.rb",
"test/vagrant/action/builder_test.rb",
"test/vagrant/action/environment_test.rb",
"test/vagrant/action/error_halt_test.rb",
"test/vagrant/action/vm/boot_test.rb",
"test/vagrant/action/vm/customize_test.rb",
"test/vagrant/action/vm/forward_ports_test.rb",
"test/vagrant/action/vm/import_test.rb",
"test/vagrant/action/vm/share_folders_test.rb",
"test/vagrant/action_test.rb",
"test/vagrant/actions/base_test.rb",
"test/vagrant/actions/box/add_test.rb",
"test/vagrant/actions/box/destroy_test.rb",