From 0736f8582d1022f3d4fc5fe3e934f564b02c79f7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 25 Apr 2010 02:08:59 -0700 Subject: [PATCH] Shared folder action uses new system abstraction --- lib/vagrant/actions/vm/shared_folders.rb | 30 +------- lib/vagrant/active_list.rb | 2 +- lib/vagrant/vm.rb | 2 +- .../vagrant/actions/vm/shared_folders_test.rb | 72 +------------------ test/vagrant/active_list_test.rb | 2 +- vagrant.gemspec | 10 +-- 6 files changed, 12 insertions(+), 106 deletions(-) diff --git a/lib/vagrant/actions/vm/shared_folders.rb b/lib/vagrant/actions/vm/shared_folders.rb index 4d8167cbf..12b7923b1 100644 --- a/lib/vagrant/actions/vm/shared_folders.rb +++ b/lib/vagrant/actions/vm/shared_folders.rb @@ -20,9 +20,7 @@ module Vagrant @runner.env.ssh.execute do |ssh| shared_folders.each do |name, hostpath, guestpath| logger.info "-- #{name}: #{guestpath}" - ssh.exec!("sudo mkdir -p #{guestpath}") - mount_folder(ssh, name, guestpath) - ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{guestpath}") + @runner.system.mount_shared_folder(ssh, name, guestpath) end end end @@ -49,32 +47,6 @@ module Vagrant @runner.vm.save end - - def mount_folder(ssh, name, guestpath, sleeptime=5) - # Note: This method seems pretty OS-specific and could also use - # some configuration options. For now its duct tape and "works" - # but should be looked at in the future. - - # Determine the permission string to attach to the mount command - perms = [] - perms << "uid=#{@runner.env.config.vm.shared_folder_uid}" - perms << "gid=#{@runner.env.config.vm.shared_folder_gid}" - perms = " -o #{perms.join(",")}" if !perms.empty? - - attempts = 0 - while true - result = ssh.exec!("sudo mount -t vboxsf#{perms} #{name} #{guestpath}") do |ch, type, data| - # net/ssh returns the value in ch[:result] (based on looking at source) - ch[:result] = !!(type == :stderr && data =~ /No such device/i) - end - - break unless result - - attempts += 1 - raise ActionException.new(:vm_mount_fail) if attempts >= 10 - sleep sleeptime - end - end end end end diff --git a/lib/vagrant/active_list.rb b/lib/vagrant/active_list.rb index 50d16a8c0..da292f49a 100644 --- a/lib/vagrant/active_list.rb +++ b/lib/vagrant/active_list.rb @@ -35,7 +35,7 @@ module Vagrant # Returns an array of {Vagrant::VM} objects which are currently # active. def vms - list.collect { |uuid| Vagrant::VM.find(uuid) }.compact + list.collect { |uuid| Vagrant::VM.find(uuid, env) }.compact end # Returns an array of UUIDs filtered so each is verified to exist. diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 71b7a84cf..175bd19c5 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -20,7 +20,7 @@ module Vagrant @env = env @vm = vm - load_system! + load_system! unless @env.nil? end def load_system! diff --git a/test/vagrant/actions/vm/shared_folders_test.rb b/test/vagrant/actions/vm/shared_folders_test.rb index 503559c02..56804cc70 100644 --- a/test/vagrant/actions/vm/shared_folders_test.rb +++ b/test/vagrant/actions/vm/shared_folders_test.rb @@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper') class SharedFoldersActionTest < Test::Unit::TestCase setup do @runner, @vm, @action = mock_action(Vagrant::Actions::VM::SharedFolders) + @runner.stubs(:system).returns(Vagrant::Systems::Linux.new(@vm)) end def stub_shared_folders @@ -96,80 +97,11 @@ class SharedFoldersActionTest < Test::Unit::TestCase mount_seq = sequence("mount_seq") ssh = mock("ssh") @folders.each do |name, hostpath, guestpath| - ssh.expects(:exec!).with("sudo mkdir -p #{guestpath}").in_sequence(mount_seq) - @action.expects(:mount_folder).with(ssh, name, guestpath).in_sequence(mount_seq) - ssh.expects(:exec!).with("sudo chown #{@runner.env.config.ssh.username} #{guestpath}").in_sequence(mount_seq) + @runner.system.expects(:mount_shared_folder).with(ssh, name, guestpath).in_sequence(mount_seq) end @runner.env.ssh.expects(:execute).yields(ssh) @action.after_boot end end - - context "mounting the main folder" do - setup do - @ssh = mock("ssh") - @name = "foo" - @guestpath = "bar" - @sleeptime = 0 - @limit = 10 - - @success_return = false - end - - def mount_folder - @action.mount_folder(@ssh, @name, @guestpath, @sleeptime) - end - - should "execute the proper mount command" do - @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{@runner.env.config.ssh.username},gid=#{@runner.env.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return) - mount_folder - end - - should "test type of text and text string to detect error" do - data = mock("data") - data.expects(:[]=).with(:result, !@success_return) - - @ssh.expects(:exec!).yields(data, :stderr, "No such device").returns(@success_return) - mount_folder - end - - should "test type of text and test string to detect success" do - data = mock("data") - data.expects(:[]=).with(:result, @success_return) - - @ssh.expects(:exec!).yields(data, :stdout, "Nothing such device").returns(@success_return) - mount_folder - end - - should "raise an ActionException if the command fails constantly" do - @ssh.expects(:exec!).times(@limit).returns(!@success_return) - - assert_raises(Vagrant::Actions::ActionException) { - mount_folder - } - end - - should "not raise any exception if the command succeeded" do - @ssh.expects(:exec!).once.returns(@success_return) - - assert_nothing_raised { - mount_folder - } - end - - should "add uid AND gid to mount" do - uid = "foo" - gid = "bar" - env = mock_environment do |config| - config.vm.shared_folder_uid = uid - config.vm.shared_folder_gid = gid - end - - @runner.expects(:env).twice.returns(env) - - @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return) - mount_folder - end - end end diff --git a/test/vagrant/active_list_test.rb b/test/vagrant/active_list_test.rb index 1c4bed92d..843aeba1b 100644 --- a/test/vagrant/active_list_test.rb +++ b/test/vagrant/active_list_test.rb @@ -70,7 +70,7 @@ class ActiveListTest < Test::Unit::TestCase results = [] @the_list.each do |item| result = mock("result-#{item}") - Vagrant::VM.expects(:find).with(item).returns(result).in_sequence(new_seq) + Vagrant::VM.expects(:find).with(item, @env).returns(result).in_sequence(new_seq) results << result end diff --git a/vagrant.gemspec b/vagrant.gemspec index 3e996ffae..2e0da1009 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-04-24} + s.date = %q{2010-04-25} 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"] @@ -68,7 +68,6 @@ Gem::Specification.new do |s| "lib/vagrant/commands/box/list.rb", "lib/vagrant/commands/box/remove.rb", "lib/vagrant/commands/destroy.rb", - "lib/vagrant/commands/down.rb", "lib/vagrant/commands/halt.rb", "lib/vagrant/commands/init.rb", "lib/vagrant/commands/package.rb", @@ -89,8 +88,11 @@ Gem::Specification.new do |s| "lib/vagrant/provisioners/chef_server.rb", "lib/vagrant/provisioners/chef_solo.rb", "lib/vagrant/ssh.rb", + "lib/vagrant/systems/base.rb", + "lib/vagrant/systems/linux.rb", "lib/vagrant/util.rb", "lib/vagrant/util/errors.rb", + "lib/vagrant/util/glob_loader.rb", "lib/vagrant/util/platform.rb", "lib/vagrant/util/progress_meter.rb", "lib/vagrant/util/stacked_proc_runner.rb", @@ -137,7 +139,6 @@ Gem::Specification.new do |s| "test/vagrant/commands/box/list_test.rb", "test/vagrant/commands/box/remove_test.rb", "test/vagrant/commands/destroy_test.rb", - "test/vagrant/commands/down_test.rb", "test/vagrant/commands/halt_test.rb", "test/vagrant/commands/init_test.rb", "test/vagrant/commands/package_test.rb", @@ -158,6 +159,7 @@ Gem::Specification.new do |s| "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/errors_test.rb", "test/vagrant/util/progress_meter_test.rb", "test/vagrant/util/stacked_proc_runner_test.rb", @@ -207,7 +209,6 @@ Gem::Specification.new do |s| "test/vagrant/commands/box/list_test.rb", "test/vagrant/commands/box/remove_test.rb", "test/vagrant/commands/destroy_test.rb", - "test/vagrant/commands/down_test.rb", "test/vagrant/commands/halt_test.rb", "test/vagrant/commands/init_test.rb", "test/vagrant/commands/package_test.rb", @@ -228,6 +229,7 @@ Gem::Specification.new do |s| "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/errors_test.rb", "test/vagrant/util/progress_meter_test.rb", "test/vagrant/util/stacked_proc_runner_test.rb",