From 33bfe75cbde872a529a3b0b42f1e770cef3158db Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 15 May 2010 01:34:31 -0700 Subject: [PATCH] Environment loads blank VMs for non-created VMs. --- Gemfile | 1 + VERSION | 2 +- lib/vagrant/command.rb | 4 +- lib/vagrant/commands/up.rb | 20 +++--- lib/vagrant/environment.rb | 30 ++++++--- test/vagrant/environment_test.rb | 50 +++++++++++++-- vagrant.gemspec | 102 +++++++++++++++---------------- 7 files changed, 136 insertions(+), 73 deletions(-) diff --git a/Gemfile b/Gemfile index 9018dc64f..2cfcecca7 100644 --- a/Gemfile +++ b/Gemfile @@ -14,4 +14,5 @@ group :test do gem "contest", ">= 0.1.2" gem "mocha" gem "ruby-debug", ">= 0.10.3" if RUBY_VERSION < '1.9' + gem "jeweler", "~> 1.4.0" end diff --git a/VERSION b/VERSION index 162013faa..02bee0ac4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.3.dev \ No newline at end of file +0.3.4.dev \ No newline at end of file diff --git a/lib/vagrant/command.rb b/lib/vagrant/command.rb index 1f63e20fb..686c2d6e2 100644 --- a/lib/vagrant/command.rb +++ b/lib/vagrant/command.rb @@ -5,7 +5,7 @@ module Vagrant class Command attr_reader :env - class < f.read } + data = { DEFAULT_VM => f.read } begin - data = JSON.parse(data[:__vagrant]) + data = JSON.parse(data[DEFAULT_VM]) rescue JSON::ParserError # Most likely an older (<= 0.3.x) dotfile. Try to load it # as the :__vagrant VM. @@ -231,6 +231,20 @@ module Vagrant # Just rescue it. end + # Loads blank VMs into the `vms` attribute. + def load_blank_vms! + # Clear existing vms + vms.clear + + # Load up the blank VMs + defined_vms = config.vm.defined_vms.keys + defined_vms = [DEFAULT_VM] if defined_vms.empty? + + defined_vms.each do |name| + vms[name] = Vagrant::VM.new(:vm_name => name, :env => self) + end + end + # Loads the activelist for this environment def load_active_list! @active_list = ActiveList.new(self) diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 4260ce7b7..32a085431 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -372,12 +372,20 @@ class EnvironmentTest < Test::Unit::TestCase File.stubs(:file?).returns(true) end + should "blank the VMs" do + load_seq = sequence("load_seq") + @env.stubs(:root_path).returns("foo") + @env.expects(:load_blank_vms!).in_sequence(load_seq) + File.expects(:open).in_sequence(load_seq) + @env.load_vm! + end + should "load the UUID if the JSON parsing fails" do vm = mock("vm") filemock = mock("filemock") filemock.expects(:read).returns("foo") - Vagrant::VM.expects(:find).with("foo", @env, :__vagrant).returns(vm) + Vagrant::VM.expects(:find).with("foo", @env, Vagrant::Environment::DEFAULT_VM).returns(vm) File.expects(:open).with(@env.dotfile_path).once.yields(filemock) File.expects(:file?).with(@env.dotfile_path).once.returns(true) @env.load_vm! @@ -413,10 +421,13 @@ class EnvironmentTest < Test::Unit::TestCase @env.load_vm! end - should "do nothing if the root path is nil" do + should "do nothing if the dotfile is nil" do + @env.stubs(:dotfile_path).returns(nil) File.expects(:open).never - @env.stubs(:root_path).returns(nil) - @env.load_vm! + + assert_nothing_raised { + @env.load_vm! + } end should "do nothing if dotfile is not a file" do @@ -432,6 +443,37 @@ class EnvironmentTest < Test::Unit::TestCase end end + context "loading blank VMs" do + setup do + @env = mock_environment + end + + should "blank the VMs" do + @env = mock_environment do |config| + config.vm.define :foo do |config| + end + + config.vm.define :bar do |config| + end + end + + @env.load_blank_vms! + + assert_equal 2, @env.vms.length + assert_equal [:foo, :bar], @env.vms.keys + assert(@env.vms.all? { |name, vm| !vm.created? }) + end + + should "load the default VM blank if no multi-VMs are specified" do + assert @env.config.vm.defined_vms.empty? # sanity + + @env.load_blank_vms! + + assert_equal 1, @env.vms.length + assert !@env.vms.values.first.created? + end + end + context "loading the active list" do setup do @env = mock_environment diff --git a/vagrant.gemspec b/vagrant.gemspec index fd2fd4d2f..d005ca06d 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{vagrant} - s.version = "0.3.3.dev" + s.version = "0.3.4.dev" 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-05-01} + s.date = %q{2010-05-15} 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"] @@ -175,67 +175,67 @@ 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/actions/base_test.rb", - "test/vagrant/actions/box/add_test.rb", - "test/vagrant/actions/box/destroy_test.rb", - "test/vagrant/actions/box/download_test.rb", - "test/vagrant/actions/box/unpackage_test.rb", - "test/vagrant/actions/box/verify_test.rb", - "test/vagrant/actions/collection_test.rb", - "test/vagrant/actions/runner_test.rb", - "test/vagrant/actions/vm/boot_test.rb", - "test/vagrant/actions/vm/customize_test.rb", - "test/vagrant/actions/vm/destroy_test.rb", - "test/vagrant/actions/vm/down_test.rb", - "test/vagrant/actions/vm/export_test.rb", - "test/vagrant/actions/vm/forward_ports_test.rb", - "test/vagrant/actions/vm/halt_test.rb", - "test/vagrant/actions/vm/import_test.rb", - "test/vagrant/actions/vm/move_hard_drive_test.rb", - "test/vagrant/actions/vm/package_test.rb", - "test/vagrant/actions/vm/provision_test.rb", - "test/vagrant/actions/vm/reload_test.rb", - "test/vagrant/actions/vm/resume_test.rb", - "test/vagrant/actions/vm/shared_folders_test.rb", - "test/vagrant/actions/vm/start_test.rb", - "test/vagrant/actions/vm/suspend_test.rb", - "test/vagrant/actions/vm/up_test.rb", - "test/vagrant/active_list_test.rb", + "test/vagrant/vm_test.rb", + "test/vagrant/command_test.rb", + "test/vagrant/environment_test.rb", + "test/vagrant/util_test.rb", "test/vagrant/box_test.rb", "test/vagrant/busy_test.rb", - "test/vagrant/command_test.rb", + "test/vagrant/provisioners/base_test.rb", + "test/vagrant/provisioners/chef_test.rb", + "test/vagrant/provisioners/chef_server_test.rb", + "test/vagrant/provisioners/chef_solo_test.rb", + "test/vagrant/systems/linux_test.rb", + "test/vagrant/config_test.rb", + "test/vagrant/actions/base_test.rb", + "test/vagrant/actions/runner_test.rb", + "test/vagrant/actions/box/verify_test.rb", + "test/vagrant/actions/box/destroy_test.rb", + "test/vagrant/actions/box/add_test.rb", + "test/vagrant/actions/box/unpackage_test.rb", + "test/vagrant/actions/box/download_test.rb", + "test/vagrant/actions/collection_test.rb", + "test/vagrant/actions/vm/reload_test.rb", + "test/vagrant/actions/vm/suspend_test.rb", + "test/vagrant/actions/vm/boot_test.rb", + "test/vagrant/actions/vm/package_test.rb", + "test/vagrant/actions/vm/down_test.rb", + "test/vagrant/actions/vm/shared_folders_test.rb", + "test/vagrant/actions/vm/destroy_test.rb", + "test/vagrant/actions/vm/halt_test.rb", + "test/vagrant/actions/vm/import_test.rb", + "test/vagrant/actions/vm/customize_test.rb", + "test/vagrant/actions/vm/start_test.rb", + "test/vagrant/actions/vm/move_hard_drive_test.rb", + "test/vagrant/actions/vm/up_test.rb", + "test/vagrant/actions/vm/export_test.rb", + "test/vagrant/actions/vm/provision_test.rb", + "test/vagrant/actions/vm/resume_test.rb", + "test/vagrant/actions/vm/forward_ports_test.rb", + "test/vagrant/active_list_test.rb", "test/vagrant/commands/base_test.rb", - "test/vagrant/commands/box/add_test.rb", - "test/vagrant/commands/box/list_test.rb", - "test/vagrant/commands/box/remove_test.rb", + "test/vagrant/commands/reload_test.rb", + "test/vagrant/commands/ssh_config_test.rb", + "test/vagrant/commands/suspend_test.rb", + "test/vagrant/commands/package_test.rb", + "test/vagrant/commands/status_test.rb", + "test/vagrant/commands/init_test.rb", "test/vagrant/commands/destroy_test.rb", "test/vagrant/commands/halt_test.rb", - "test/vagrant/commands/init_test.rb", - "test/vagrant/commands/package_test.rb", - "test/vagrant/commands/reload_test.rb", - "test/vagrant/commands/resume_test.rb", - "test/vagrant/commands/ssh_config_test.rb", - "test/vagrant/commands/ssh_test.rb", - "test/vagrant/commands/status_test.rb", - "test/vagrant/commands/suspend_test.rb", + "test/vagrant/commands/box/remove_test.rb", + "test/vagrant/commands/box/add_test.rb", + "test/vagrant/commands/box/list_test.rb", "test/vagrant/commands/up_test.rb", - "test/vagrant/config_test.rb", + "test/vagrant/commands/resume_test.rb", + "test/vagrant/commands/ssh_test.rb", "test/vagrant/downloaders/base_test.rb", "test/vagrant/downloaders/file_test.rb", "test/vagrant/downloaders/http_test.rb", - "test/vagrant/environment_test.rb", - "test/vagrant/provisioners/base_test.rb", - "test/vagrant/provisioners/chef_server_test.rb", - "test/vagrant/provisioners/chef_solo_test.rb", - "test/vagrant/provisioners/chef_test.rb", - "test/vagrant/ssh_test.rb", - "test/vagrant/systems/linux_test.rb", - "test/vagrant/util/progress_meter_test.rb", "test/vagrant/util/stacked_proc_runner_test.rb", + "test/vagrant/util/progress_meter_test.rb", "test/vagrant/util/template_renderer_test.rb", "test/vagrant/util/translator_test.rb", - "test/vagrant/util_test.rb", - "test/vagrant/vm_test.rb" + "test/vagrant/ssh_test.rb" ] if s.respond_to? :specification_version then