guests/freebsd: Mount NFS folders in a single command

This commit is contained in:
Seth Vargo 2016-06-05 14:00:02 -04:00
parent bf51f6a71d
commit de64bd03de
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
2 changed files with 63 additions and 7 deletions

View File

@ -3,17 +3,20 @@ module VagrantPlugins
module Cap
class MountNFSFolder
def self.mount_nfs_folder(machine, ip, folders)
folders.each do |name, opts|
comm = machine.communicate
commands = []
folders.each do |_, opts|
if opts[:nfs_version]
nfs_version_mount_option="-o nfsv#{opts[:nfs_version]}"
mount_opts = "-o nfsv#{opts[:nfs_version]}"
end
machine.communicate.sudo("mkdir -p #{opts[:guestpath]}", {shell: "sh"})
machine.communicate.sudo(
"mount -t nfs #{nfs_version_mount_option} " +
"'#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'", {shell: "sh"})
commands << "mkdir -p '#{opts[:guestpath]}'"
commands << "mount -t nfs #{mount_opts} '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'"
end
comm.sudo(commands.join("\n"), { shell: "sh" })
end
end
end

View File

@ -0,0 +1,53 @@
require_relative "../../../../base"
describe "VagrantPlugins::GuestFreeBSD::Cap::MountNFSFolder" do
let(:described_class) do
VagrantPlugins::GuestFreeBSD::Plugin
.components
.guest_capabilities[:freebsd]
.get(:mount_nfs_folder)
end
let(:machine) { double("machine") }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
allow(machine).to receive(:communicate).and_return(comm)
end
after do
comm.verify_expectations!
end
describe ".mount_nfs_folder" do
let(:ip) { "1.2.3.4" }
it "mounts the folder" do
folders = {
"/vagrant-nfs" => {
type: :nfs,
guestpath: "/guest",
hostpath: "/host",
}
}
described_class.mount_nfs_folder(machine, ip, folders)
expect(comm.received_commands[0]).to match(/mkdir -p '\/guest'/)
expect(comm.received_commands[0]).to match(/'1.2.3.4:\/host' '\/guest'/)
end
it "mounts with options" do
folders = {
"/vagrant-nfs" => {
type: :nfs,
guestpath: "/guest",
hostpath: "/host",
nfs_version: 2,
}
}
described_class.mount_nfs_folder(machine, ip, folders)
expect(comm.received_commands[0]).to match(/mount -t nfs -o nfsv2/)
end
end
end