From c6ee1049aa5922ad783bc33dd71019da031aeabe Mon Sep 17 00:00:00 2001 From: Jeff Bonhag Date: Mon, 25 Nov 2019 15:41:05 -0500 Subject: [PATCH] Darwin: put each NFS export on its own line (#11216) This commit introduces a Darwin-specific template for NFS exports. This is almost identical to the standard BSD template except it puts each NFS export on its own line. This resolves NFS issues discovered in macOS Catalina. --- plugins/hosts/darwin/cap/nfs.rb | 11 +++ plugins/hosts/darwin/plugin.rb | 5 ++ templates/nfs/exports_darwin.erb | 7 ++ .../unit/plugins/hosts/darwin/cap/nfs_test.rb | 17 +++++ .../unit/templates/nfs/exports_darwin_test.rb | 68 +++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 plugins/hosts/darwin/cap/nfs.rb create mode 100644 templates/nfs/exports_darwin.erb create mode 100644 test/unit/plugins/hosts/darwin/cap/nfs_test.rb create mode 100644 test/unit/templates/nfs/exports_darwin_test.rb diff --git a/plugins/hosts/darwin/cap/nfs.rb b/plugins/hosts/darwin/cap/nfs.rb new file mode 100644 index 000000000..8b998e2bc --- /dev/null +++ b/plugins/hosts/darwin/cap/nfs.rb @@ -0,0 +1,11 @@ +module VagrantPlugins + module HostDarwin + module Cap + class NFS + def self.nfs_exports_template(environment) + "nfs/exports_darwin" + end + end + end + end +end diff --git a/plugins/hosts/darwin/plugin.rb b/plugins/hosts/darwin/plugin.rb index b6c535c9b..d27e2eda4 100644 --- a/plugins/hosts/darwin/plugin.rb +++ b/plugins/hosts/darwin/plugin.rb @@ -55,6 +55,11 @@ module VagrantPlugins require_relative "cap/configured_ip_addresses" Cap::ConfiguredIPAddresses end + + host_capability("darwin", "nfs_exports_template") do + require_relative "cap/nfs" + Cap::NFS + end end end end diff --git a/templates/nfs/exports_darwin.erb b/templates/nfs/exports_darwin.erb new file mode 100644 index 000000000..74cca7537 --- /dev/null +++ b/templates/nfs/exports_darwin.erb @@ -0,0 +1,7 @@ +# VAGRANT-BEGIN: <%= user %> <%= uuid %> +<% folders.each do |dirs, opts| %> +<% dirs.each do |d| %> +<%= d %> <%=opts[:bsd__compiled_nfs_options] %> <%= ips.join(" ") %> +<% end %> +<% end %> +# VAGRANT-END: <%= user %> <%= uuid %> diff --git a/test/unit/plugins/hosts/darwin/cap/nfs_test.rb b/test/unit/plugins/hosts/darwin/cap/nfs_test.rb new file mode 100644 index 000000000..c2acc1cc2 --- /dev/null +++ b/test/unit/plugins/hosts/darwin/cap/nfs_test.rb @@ -0,0 +1,17 @@ +require_relative "../../../../base" + +require_relative "../../../../../../plugins/hosts/darwin/cap/nfs" + +describe VagrantPlugins::HostDarwin::Cap::NFS do + include_context "unit" + + let(:subject){ VagrantPlugins::HostDarwin::Cap::NFS } + + it "exists" do + expect(subject).to_not be(nil) + end + + it "should use nfs/exports_darwin as its template" do + expect(subject.nfs_exports_template(nil)).to eq("nfs/exports_darwin") + end +end diff --git a/test/unit/templates/nfs/exports_darwin_test.rb b/test/unit/templates/nfs/exports_darwin_test.rb new file mode 100644 index 000000000..e0f7476a2 --- /dev/null +++ b/test/unit/templates/nfs/exports_darwin_test.rb @@ -0,0 +1,68 @@ +require_relative "../../base" + +require "vagrant/util/template_renderer" + +describe "templates/nfs/exports_darwin" do + let(:template) { "nfs/exports_darwin" } + let(:user) { "501" } + let(:uuid) { "UUID" } + let(:opts) { {:bsd__compiled_nfs_options => "-alldirs -mapall=501:80"} } + let(:ips) { ["172.16.0.2"] } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, { + user: user, + uuid: uuid, + folders: [] + }) + expect(result).to eq <<-EOH.gsub(/^ {6}/, "") + # VAGRANT-BEGIN: 501 UUID + # VAGRANT-END: 501 UUID + EOH + end + + context "one nfs mount" do + let(:folders) { + { + ["/vagrant"] => opts + } + } + + it "renders the template" do + result = Vagrant::Util::TemplateRenderer.render(template, { + user: user, + uuid: uuid, + folders: folders, + ips: ips + }) + expect(result).to eq <<-EOH.gsub(/^ {8}/, "") + # VAGRANT-BEGIN: 501 UUID + /vagrant -alldirs -mapall=501:80 172.16.0.2 + # VAGRANT-END: 501 UUID + EOH + end + end + + context "subdirectory that should also be exported" do + let(:folders) { + { + ["/vagrant", "/vagrant/other"] => opts + } + } + + it "puts each directory on its own line" do + result = Vagrant::Util::TemplateRenderer.render(template, { + user: user, + uuid: uuid, + folders: folders, + ips: ips + }) + expect(result).to eq <<-EOH.gsub(/^ {8}/, "") + # VAGRANT-BEGIN: 501 UUID + /vagrant -alldirs -mapall=501:80 172.16.0.2 + /vagrant/other -alldirs -mapall=501:80 172.16.0.2 + # VAGRANT-END: 501 UUID + EOH + end + end +end