Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions plugins/hosts/bsd/cap/nfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class NFS
def self.nfs_export(environment, ui, id, ips, folders)
nfs_exports_template = environment.host.capability(:nfs_exports_template)
nfs_restart_command = environment.host.capability(:nfs_restart_command)
nfs_status_command = environment.host.capability(:nfs_status_command)
nfs_update_command = environment.host.capability(:nfs_update_command)
logger = Log4r::Logger.new("vagrant::hosts::bsd")

nfs_checkexports! if File.file?("/etc/exports")
Expand Down Expand Up @@ -117,9 +119,12 @@ def self.nfs_export(environment, ui, id, ips, folders)
"#{sudo_command}/usr/bin/tee -a /etc/exports >/dev/null")
end

# We run restart here instead of "update" just in case nfsd
# is not starting
system(*nfs_restart_command)
# Check if nfsd is running, and update or restart depending on the result
if nfs_running?(nfs_status_command)
system(*nfs_update_command)
else
system(*nfs_restart_command)
end
end

def self.nfs_exports_template(environment)
Expand Down Expand Up @@ -159,10 +164,22 @@ def self.nfs_prune(environment, ui, valid_ids)
raise Vagrant::Errors::NFSCantReadExports
end

def self.nfs_running?(check_command)
Vagrant::Util::Subprocess.execute(*check_command).exit_code == 0
end

def self.nfs_restart_command(environment)
["sudo", "nfsd", "restart"]
end

def self.nfs_update_command(environment)
["sudo", "nfsd", "update"]
end

def self.nfs_status_command(environment)
["sudo", "nfsd", "status"]
end

protected

def self.nfs_cleanup(id)
Expand Down
10 changes: 10 additions & 0 deletions plugins/hosts/bsd/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class Plugin < Vagrant.plugin("2")
Cap::NFS
end

host_capability("bsd", "nfs_update_command") do
require_relative "cap/nfs"
Cap::NFS
end

host_capability("bsd", "nfs_status_command") do
require_relative "cap/nfs"
Cap::NFS
end

host_capability("bsd", "resolve_host_path") do
require_relative "cap/path"
Cap::Path
Expand Down
10 changes: 5 additions & 5 deletions plugins/synced_folders/nfs/synced_folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ def enable(machine, folders, nfsopts)
mount_folders = {}
folders.each do |id, opts|
mount_folders[id] = opts.dup if opts[:guestpath]
end

machine.ui.detail(I18n.t("vagrant.actions.vm.nfs.mounting_entry",
guestpath: opts[:guestpath],
hostpath: opts[:hostpath]
))
machine.ui.detail(I18n.t("vagrant.actions.vm.nfs.mounting_entry",
guestpath: opts[:guestpath],
hostpath: opts[:hostpath]
))
end

# Mount them!
if machine.guest.capability?(:nfs_pre)
Expand Down
23 changes: 23 additions & 0 deletions test/unit/plugins/hosts/bsd/cap/nfs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
allow(described_class).to receive(:sleep)
allow(described_class).to receive(:nfs_cleanup)
allow(described_class).to receive(:system)
allow(described_class).to receive(:nfs_running?).and_return(true)
allow(File).to receive(:writable?).with("/etc/exports")

allow(Vagrant::Util::Subprocess).to receive(:execute).with("nfsd", "checkexports").
Expand Down Expand Up @@ -49,5 +50,27 @@
described_class.nfs_export(environment, ui, id, ips, folders)
end
end

context "when nfsd is not running" do
before {
allow(described_class).to receive(:nfs_running?).and_return(false)
}
it "should restart nfsd" do
expect(host).to receive(:capability).with(:nfs_restart_command).and_return(["restart"])
expect(described_class).to receive(:system).with("restart")
described_class.nfs_export(environment, ui, id, ips, folders)
end
end

context "when nfsd is running" do
before {
allow(described_class).to receive(:nfs_running?).and_return(true)
}
it "should update nfsd" do
expect(host).to receive(:capability).with(:nfs_update_command).and_return(["update"])
expect(described_class).to receive(:system).with("update")
described_class.nfs_export(environment, ui, id, ips, folders)
end
end
end
end