From 1bfb99d606a8b8e6b4cadb6693896612c63b0a40 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Jul 2010 20:25:20 -0700 Subject: [PATCH] Only verify NFS settings if NFS shared folders exist --- lib/vagrant/action/vm/nfs.rb | 11 +++++++++- test/vagrant/action/vm/nfs_test.rb | 35 ++++++++++++++++++++++++------ vagrant.gemspec | 2 +- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/lib/vagrant/action/vm/nfs.rb b/lib/vagrant/action/vm/nfs.rb index ed31dcc42..bd222faf2 100644 --- a/lib/vagrant/action/vm/nfs.rb +++ b/lib/vagrant/action/vm/nfs.rb @@ -20,7 +20,7 @@ module Vagrant @app = app @env = env - verify_settings + verify_settings if nfs_enabled? end def call(env) @@ -105,6 +105,15 @@ module Vagrant @env["config"].vm.network_options[1][:ip] end + # Checks if there are any NFS enabled shared folders. + def nfs_enabled? + @env["config"].vm.shared_folders.each do |key, opts| + return true if opts[:nfs] + end + + false + end + # Verifies that the host is set and supports NFS. def verify_settings return @env.error!(:nfs_host_required) if @env["host"].nil? diff --git a/test/vagrant/action/vm/nfs_test.rb b/test/vagrant/action/vm/nfs_test.rb index 742f17cbc..633755ec1 100644 --- a/test/vagrant/action/vm/nfs_test.rb +++ b/test/vagrant/action/vm/nfs_test.rb @@ -15,11 +15,21 @@ class NFSVMActionTest < Test::Unit::TestCase @vm.stubs(:vm).returns(@internal_vm) end + context "initializing" do + should "not call verify settings if NFS is not enabled" do + @klass.any_instance.expects(:verify_settings).never + @klass.new(@app, @env) + end + + should "call verify settings if NFS is enabled" do + @env.env.config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true) + @klass.any_instance.expects(:verify_settings).once + @klass.new(@app, @env) + end + end + context "with an instance" do setup do - # Kind of dirty but not sure of a way around this - @klass.send(:alias_method, :verify_settings_real, :verify_settings) - @klass.any_instance.stubs(:verify_settings) @instance = @klass.new(@app, @env) end @@ -161,6 +171,17 @@ class NFSVMActionTest < Test::Unit::TestCase end end + context "nfs enabled" do + should "return false if no folders are marked for NFS" do + assert !@instance.nfs_enabled? + end + + should "return true if a shared folder is marked for NFS" do + @env.env.config.vm.share_folder("v-foo", "/foo", "/bar", :nfs => true) + assert @instance.nfs_enabled? + end + end + context "verifying settings" do setup do @env.env.host.stubs(:nfs?).returns(true) @@ -168,28 +189,28 @@ class NFSVMActionTest < Test::Unit::TestCase should "error environment if host is nil" do @env.env.stubs(:host).returns(nil) - @instance.verify_settings_real + @instance.verify_settings assert @env.error? assert_equal :nfs_host_required, @env.error.first end should "error environment if host does not support NFS" do @env.env.host.stubs(:nfs?).returns(false) - @instance.verify_settings_real + @instance.verify_settings assert @env.error? assert_equal :nfs_not_supported, @env.error.first end should "error environment if host only networking is not enabled" do @env.env.config.vm.network_options.clear - @instance.verify_settings_real + @instance.verify_settings assert @env.error? assert_equal :nfs_no_host_network, @env.error.first end should "be fine if everything passes" do @env.env.host.stubs(:nfs?).returns(true) - @instance.verify_settings_real + @instance.verify_settings assert !@env.error? end end diff --git a/vagrant.gemspec b/vagrant.gemspec index c57d41d80..3b87bb549 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -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-12} + s.date = %q{2010-07-13} 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"]