providers/virtualbox: don't clear /etc/exports on BSDs for NFS [GH-2645]

This commit is contained in:
Mitchell Hashimoto 2013-12-13 22:03:14 -08:00
parent 86f8ff8816
commit c1141dded3
9 changed files with 109 additions and 41 deletions

View File

@ -22,7 +22,9 @@ BUG FIXES:
[GH-2620] [GH-2620]
- guests/redhat: fix configure networks bringing down interfaces that - guests/redhat: fix configure networks bringing down interfaces that
don't exist. [GH-2614] don't exist. [GH-2614]
- provisioners/chef: fix node/client deletion when node_name is not - providers/virtualbox: don't override NFS exports for all VMs when
coming up. [GH-2645]
- provisioners/chef: fix node/client deletion when node\_name is not
set. [GH-2345] set. [GH-2345]
## 1.4.0 (December 9, 2013) ## 1.4.0 (December 9, 2013)

View File

@ -380,6 +380,10 @@ module Vagrant
error_key(:nfs_no_hostonly_network) error_key(:nfs_no_hostonly_network)
end end
class NFSNoValidIds < VagrantError
error_key(:nfs_no_valid_ids)
end
class NoDefaultSyncedFolderImpl < VagrantError class NoDefaultSyncedFolderImpl < VagrantError
error_key(:no_default_synced_folder_impl) error_key(:no_default_synced_folder_impl)
end end

View File

@ -33,6 +33,7 @@ module VagrantPlugins
autoload :Package, File.expand_path("../action/package", __FILE__) autoload :Package, File.expand_path("../action/package", __FILE__)
autoload :PackageVagrantfile, File.expand_path("../action/package_vagrantfile", __FILE__) autoload :PackageVagrantfile, File.expand_path("../action/package_vagrantfile", __FILE__)
autoload :PrepareNFSSettings, File.expand_path("../action/prepare_nfs_settings", __FILE__) autoload :PrepareNFSSettings, File.expand_path("../action/prepare_nfs_settings", __FILE__)
autoload :PrepareNFSValidIds, File.expand_path("../action/prepare_nfs_valid_ids", __FILE__)
autoload :PrepareForwardedPortCollisionParams, File.expand_path("../action/prepare_forwarded_port_collision_params", __FILE__) autoload :PrepareForwardedPortCollisionParams, File.expand_path("../action/prepare_forwarded_port_collision_params", __FILE__)
autoload :Resume, File.expand_path("../action/resume", __FILE__) autoload :Resume, File.expand_path("../action/resume", __FILE__)
autoload :SaneDefaults, File.expand_path("../action/sane_defaults", __FILE__) autoload :SaneDefaults, File.expand_path("../action/sane_defaults", __FILE__)
@ -56,6 +57,7 @@ module VagrantPlugins
b.use EnvSet, :port_collision_repair => true b.use EnvSet, :port_collision_repair => true
b.use PrepareForwardedPortCollisionParams b.use PrepareForwardedPortCollisionParams
b.use HandleForwardedPortCollisions b.use HandleForwardedPortCollisions
b.use PrepareNFSValidIds
b.use SyncedFolderCleanup b.use SyncedFolderCleanup
b.use SyncedFolders b.use SyncedFolders
b.use PrepareNFSSettings b.use PrepareNFSSettings
@ -93,6 +95,7 @@ module VagrantPlugins
b3.use CleanMachineFolder b3.use CleanMachineFolder
b3.use DestroyUnusedNetworkInterfaces b3.use DestroyUnusedNetworkInterfaces
b3.use ProvisionerCleanup b3.use ProvisionerCleanup
b3.use PrepareNFSValidIds
b3.use SyncedFolderCleanup b3.use SyncedFolderCleanup
else else
b3.use MessageWillNotDestroy b3.use MessageWillNotDestroy
@ -143,6 +146,7 @@ module VagrantPlugins
b2.use CheckAccessible b2.use CheckAccessible
b2.use action_halt b2.use action_halt
b2.use ClearForwardedPorts b2.use ClearForwardedPorts
b2.use PrepareNFSValidIds
b2.use SyncedFolderCleanup b2.use SyncedFolderCleanup
b2.use Export b2.use Export
b2.use PackageVagrantfile b2.use PackageVagrantfile

View File

@ -4,18 +4,19 @@ module VagrantPlugins
class PrepareNFSSettings class PrepareNFSSettings
include Vagrant::Util::Retryable include Vagrant::Util::Retryable
def initialize(app,env) def initialize(app, env)
@app = app @app = app
@logger = Log4r::Logger.new("vagrant::action::vm::nfs") @logger = Log4r::Logger.new("vagrant::action::vm::nfs")
end end
def call(env) def call(env)
@machine = env[:machine] @machine = env[:machine]
@app.call(env) @app.call(env)
if using_nfs? if using_nfs?
@logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP") @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
add_nfs_settings_to_env!(env) add_ips_to_env!(env)
end end
end end
@ -31,7 +32,7 @@ module VagrantPlugins
# mounting. # mounting.
# #
# The ! indicates that this method modifies its argument. # The ! indicates that this method modifies its argument.
def add_nfs_settings_to_env!(env) def add_ips_to_env!(env)
adapter, host_ip = find_host_only_adapter adapter, host_ip = find_host_only_adapter
machine_ip = nil machine_ip = nil
machine_ip = read_machine_ip(adapter) if adapter machine_ip = read_machine_ip(adapter) if adapter

View File

@ -0,0 +1,17 @@
module VagrantPlugins
module ProviderVirtualBox
module Action
class PrepareNFSValidIds
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::action::vm::nfs")
end
def call(env)
env[:nfs_valid_ids] = env[:machine].provider.driver.read_vms.values
@app.call(env)
end
end
end
end
end

View File

@ -1,6 +1,8 @@
require 'fileutils' require 'fileutils'
require 'zlib' require 'zlib'
require "log4r"
require "vagrant/util/platform" require "vagrant/util/platform"
module VagrantPlugins module VagrantPlugins
@ -13,6 +15,12 @@ module VagrantPlugins
# will be mounted. # will be mounted.
# #
class SyncedFolder < Vagrant.plugin("2", :synced_folder) class SyncedFolder < Vagrant.plugin("2", :synced_folder)
def initialize(*args)
super
@logger = Log4r::Logger.new("vagrant::synced_folders::nfs")
end
def usable?(machine) def usable?(machine)
# NFS is always available # NFS is always available
true true
@ -53,14 +61,10 @@ module VagrantPlugins
def cleanup(machine, opts) def cleanup(machine, opts)
ids = opts[:nfs_valid_ids] ids = opts[:nfs_valid_ids]
if !ids raise Vagrant::Errors::NFSNoValidIds if !ids
# Get the ID of all active machines.
ids = machine.env.active_machines.map do |name, provider|
machine.env.machine(name, provider).id
end
end
# Prune any of the unused machines # Prune any of the unused machines
@logger.info("NFS pruning. Valid IDs: #{ids.inspect}")
machine.env.host.nfs_prune(ids) machine.env.host.nfs_prune(ids)
end end

View File

@ -443,6 +443,10 @@ en:
NFS requires a host-only network to be created. NFS requires a host-only network to be created.
Please add a host-only network to the machine (with either DHCP or a Please add a host-only network to the machine (with either DHCP or a
static IP) for NFS to work. static IP) for NFS to work.
nfs_no_valid_ids: |-
No valid IDs were given to the NFS synced folder implementation to
prune. This is an internal bug with Vagrant and an issue should be
filed.
no_default_synced_folder_impl: |- no_default_synced_folder_impl: |-
No synced folder implementation is available for your synced folders! No synced folder implementation is available for your synced folders!
Please consult the documentation to learn why this may be the case. Please consult the documentation to learn why this may be the case.

View File

@ -38,24 +38,22 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
called.should == true called.should == true
end end
describe "with an nfs synced folder" do context "with an nfs synced folder" do
before do before do
env[:machine].config.vm.synced_folder("/host/path", "/guest/path", nfs: true) env[:machine].config.vm.synced_folder("/host/path", "/guest/path", nfs: true)
env[:machine].config.finalize! env[:machine].config.finalize!
# Stub out the stuff so it just works by default
driver.stub(read_network_interfaces: {
2 => {type: :hostonly, hostonly: "vmnet2"},
})
driver.stub(read_host_only_interfaces: [
{name: "vmnet2", ip: "1.2.3.4"},
])
driver.stub(:read_guest_ip).with(1).and_return("2.3.4.5")
end end
it "sets nfs_host_ip and nfs_machine_ip properly" do it "sets nfs_host_ip and nfs_machine_ip properly" do
adapter_number = 2
adapter_name = "vmnet2"
driver.stub(:read_network_interfaces).and_return(
adapter_number => {type: :hostonly, hostonly: adapter_name}
)
driver.stub(:read_host_only_interfaces).and_return([
{name: adapter_name, ip: "1.2.3.4"}
])
driver.should_receive(:read_guest_ip).with(adapter_number-1).
and_return("2.3.4.5")
subject.call(env) subject.call(env)
env[:nfs_host_ip].should == "1.2.3.4" env[:nfs_host_ip].should == "1.2.3.4"
@ -70,17 +68,6 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
end end
it "retries through guest property not found errors" do it "retries through guest property not found errors" do
adapter_number = 2
adapter_name = "vmnet2"
driver.stub(:read_network_interfaces).and_return({
adapter_number => {type: :hostonly, hostonly: adapter_name}
})
driver.stub(:read_host_only_interfaces).and_return([
{name: adapter_name, ip: "1.2.3.4"}
])
driver.should_receive(:read_guest_ip).with(adapter_number-1).
and_return("2.3.4.5")
raise_then_return = [ raise_then_return = [
lambda { raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, :guest_property => 'stub' }, lambda { raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, :guest_property => 'stub' },
lambda { "2.3.4.5" } lambda { "2.3.4.5" }
@ -98,14 +85,6 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
end end
it "raises an error informing the user of a bug when the guest IP cannot be found" do it "raises an error informing the user of a bug when the guest IP cannot be found" do
adapter_number = 2
adapter_name = "vmnet2"
driver.stub(:read_network_interfaces).and_return({
adapter_number => {type: :hostonly, hostonly: adapter_name}
})
driver.stub(:read_host_only_interfaces).and_return([
{name: adapter_name, ip: "1.2.3.4"}
])
driver.stub(:read_guest_ip) { driver.stub(:read_guest_ip) {
raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, :guest_property => 'stub' raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, :guest_property => 'stub'
} }

View File

@ -0,0 +1,53 @@
require_relative "../base"
describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds do
include_context "virtualbox"
let(:machine) {
environment = Vagrant::Environment.new
provider = :virtualbox
provider_cls, provider_options = Vagrant.plugin("2").manager.providers[provider]
provider_config = Vagrant.plugin("2").manager.provider_configs[provider]
Vagrant::Machine.new(
'test_machine',
provider,
provider_cls,
provider_config,
provider_options,
environment.config_global,
Pathname('data_dir'),
double('box'),
environment
)
}
let(:env) {{ machine: machine }}
let(:app) { lambda { |*args| }}
let(:driver) { env[:machine].provider.driver }
subject { described_class.new(app, env) }
before do
driver.stub(read_vms: {})
end
it "calls the next action in the chain" do
called = false
app = lambda { |*args| called = true }
action = described_class.new(app, env)
action.call(env)
called.should == true
end
it "sets nfs_valid_ids" do
hash = {"foo" => "1", "bar" => "4"}
driver.stub(read_vms: hash)
subject.call(env)
expect(env[:nfs_valid_ids]).to eql(hash.values)
end
end