synced_folders/nfs: always prune [GH-2738]

This commit is contained in:
Mitchell Hashimoto 2014-01-10 15:41:57 -08:00
parent c4c265e97e
commit 9a58caaf9c
4 changed files with 93 additions and 2 deletions

View File

@ -56,6 +56,8 @@ BUG FIXES:
[GH-2792]
- providers/virtualbox: Enabling internal networks by just setting "true"
works properly. [GH-2751]
- synced\_folders/nfs: NFS entries are pruned on every `vagrant up`,
if there are any to prune. [GH-2738]
## 1.4.3 (January 2, 2014)

View File

@ -0,0 +1,24 @@
require "log4r"
module VagrantPlugins
module SyncedFolderNFS
class ActionCleanup
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::synced_folders::nfs")
end
def call(env)
if !env[:nfs_valid_ids]
@logger.warn("nfs_valid_ids not set, cleanup cannot occur")
return @app.call(env)
end
@logger.info("NFS pruning. Valid IDs: #{env[:nfs_valid_ids].inspect}")
env[:machine].env.host.capability(
:nfs_prune, env[:machine].ui, env[:nfs_valid_ids])
@app.call(env)
end
end
end
end

View File

@ -2,6 +2,22 @@ require "vagrant"
module VagrantPlugins
module SyncedFolderNFS
# This plugin implements NFS synced folders. In order to take advantage
# of NFS synced folders, some provider-specific assistance is required.
# Within the middleware sequences, some data must be put into the
# environment state bag:
#
# * `nfs_host_ip` (string) - The IP of the host machine that the NFS
# client in the machine should talk to.
# * `nfs_machine_ip` (string) - The IP of the guest machine that the NFS
# server should serve the folders to.
# * `nfs_valid_ids` (array of strings) - A list of IDs that are "valid"
# and should not be pruned. The synced folder implementation will
# regularly prune NFS exports of invalid IDs.
#
# If any of these variables are not set, an internal exception will be
# raised.
#
class Plugin < Vagrant.plugin("2")
name "NFS synced folders"
description <<-EOF
@ -10,14 +26,21 @@ module VagrantPlugins
EOF
config("nfs") do
require File.expand_path("../config", __FILE__)
require_relative "config"
Config
end
synced_folder("nfs", 5) do
require File.expand_path("../synced_folder", __FILE__)
require_relative "synced_folder"
SyncedFolder
end
action_hook("nfs_cleanup") do |hook|
require_relative "action_cleanup"
hook.before(
Vagrant::Action::Builtin::SyncedFolderCleanup,
ActionCleanup)
end
end
end
end

View File

@ -0,0 +1,42 @@
require_relative "../../../base"
require Vagrant.source_root.join("plugins/synced_folders/nfs/action_cleanup")
describe VagrantPlugins::SyncedFolderNFS::ActionCleanup do
include_context "unit"
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
end
let(:host) { double("host") }
let(:machine) { iso_env.machine(iso_env.machine_names[0], :virtualbox) }
let(:app) { lambda {} }
let(:env) { {
machine: machine,
} }
subject { described_class.new(app, env) }
before do
machine.env.stub(host: host)
end
it "does nothing if there are no valid IDs" do
app.should_receive(:call).with(env)
subject.call(env)
end
it "prunes the NFS entries if valid IDs are given" do
env[:nfs_valid_ids] = [1,2,3]
host.should_receive(:capability).with(:nfs_prune, machine.ui, [1,2,3]).ordered
app.should_receive(:call).with(env).ordered
subject.call(env)
end
end