Started on NFS middleware

This commit is contained in:
Mitchell Hashimoto 2010-07-11 09:44:18 -07:00
parent d309f79fbc
commit 1e92f0d58f
4 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,32 @@
module Vagrant
class Action
module VM
# Enables NFS based shared folders. `nfsd` must already be installed
# on the host machine, and NFS client must already be installed on
# the guest machine.
#
# This is a two part process:
#
# 1. Adds an entry to `/etc/exports` on the host machine using
# the host class to export the proper folder to the proper
# machine.
# 2. After boot, runs `mount` on the guest to mount the shared
# folder.
#
class NFS
def initialize(app,env)
@app = app
@env = env
verify_host
end
# Verifies that the host is set and supports NFS.
def verify_host
return @env.error!(:nfs_host_required) if @env["host"].nil?
return @env.error!(:nfs_not_supported) if !@env["host"].nfs?
end
end
end
end
end

View File

@ -50,6 +50,15 @@ module Vagrant
def initialize(env) def initialize(env)
@env = env @env = env
end end
# Returns true of false denoting whether or not this host supports
# NFS shared folder setup. This method ideally should verify that
# NFS is installed.
#
# @return [Boolean]
def nfs?
false
end
end end
end end
end end

View File

@ -137,6 +137,14 @@
already be created, but unfortunately this vagrant still appears to already be created, but unfortunately this vagrant still appears to
have no box! You can setup the environment by setting up your have no box! You can setup the environment by setting up your
<%= Vagrant::Environment::ROOTFILE_NAME %> and running `vagrant up` <%= Vagrant::Environment::ROOTFILE_NAME %> and running `vagrant up`
:nfs_host_required: |-
A host class is required for NFS shared folders. By default, these
are auto-detected, but can be overriden with `config.vagrant.host`.
There is currently not host class loaded.
:nfs_not_supported: |-
The host class is reporting that NFS is not supported by this host,
or `nfsd` may not be installed. Please verify that `nfsd` is installed
on your machine, and retry.
:network_not_found: |- :network_not_found: |-
The specified host network could not be found: <%= name %>. The specified host network could not be found: <%= name %>.
If the name specification is removed, Vagrant will create a new If the name specification is removed, Vagrant will create a new

View File

@ -0,0 +1,46 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class NFSVMActionTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::VM::NFS
@app, @env = mock_action_data
@vm = mock("vm")
@env.env.stubs(:host).returns(Vagrant::Hosts::Base.new(@env))
@env["vm"] = @vm
@internal_vm = mock("internal")
@vm.stubs(:vm).returns(@internal_vm)
end
context "with an instance" do
setup do
# Kind of dirty but not sure of a way around this
@klass.send(:alias_method, :verify_host_real, :verify_host)
@klass.any_instance.stubs(:verify_host)
@instance = @klass.new(@app, @env)
end
context "verifying host" do
should "error environment if host is nil" do
@env.env.stubs(:host).returns(nil)
@instance.verify_host_real
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_host_real
assert @env.error?
assert_equal :nfs_not_supported, @env.error.first
end
should "be fine if everything passes" do
@env.env.host.stubs(:nfs?).returns(true)
@instance.verify_host_real
assert !@env.error?
end
end
end
end