guests/freebsd: Mount NFS folders in a single command
This commit is contained in:
parent
bf51f6a71d
commit
de64bd03de
|
@ -3,17 +3,20 @@ module VagrantPlugins
|
||||||
module Cap
|
module Cap
|
||||||
class MountNFSFolder
|
class MountNFSFolder
|
||||||
def self.mount_nfs_folder(machine, ip, folders)
|
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]
|
if opts[:nfs_version]
|
||||||
nfs_version_mount_option="-o nfsv#{opts[:nfs_version]}"
|
mount_opts = "-o nfsv#{opts[:nfs_version]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
machine.communicate.sudo("mkdir -p #{opts[:guestpath]}", {shell: "sh"})
|
commands << "mkdir -p '#{opts[:guestpath]}'"
|
||||||
|
commands << "mount -t nfs #{mount_opts} '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'"
|
||||||
machine.communicate.sudo(
|
|
||||||
"mount -t nfs #{nfs_version_mount_option} " +
|
|
||||||
"'#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'", {shell: "sh"})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
comm.sudo(commands.join("\n"), { shell: "sh" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue