Fixes #10016: Add `automount` flag if specified with synced_folder

This commit adds a new option to virtualbox synced_folders called
`automount`, where if set to true, will supply the `--automount` flag to
virtualbox.
This commit is contained in:
Brian Cain 2018-10-22 15:45:32 -07:00
parent 5ac79d2821
commit 6d0dfb2690
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
5 changed files with 43 additions and 2 deletions

View File

@ -674,6 +674,8 @@ module VagrantPlugins
hostpath] hostpath]
args << "--transient" if folder.key?(:transient) && folder[:transient] args << "--transient" if folder.key?(:transient) && folder[:transient]
args << "--automount" if folder.key?(:automount) && folder[:automount]
if folder[:SharedFoldersEnableSymlinksCreate] if folder[:SharedFoldersEnableSymlinksCreate]
# Enable symlinks on the shared folder # Enable symlinks on the shared folder
execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1", retryable: true) execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1", retryable: true)

View File

@ -124,8 +124,10 @@ module VagrantPlugins
name: os_friendly_id(id), name: os_friendly_id(id),
hostpath: hostpath.to_s, hostpath: hostpath.to_s,
transient: transient, transient: transient,
SharedFoldersEnableSymlinksCreate: enable_symlink_create SharedFoldersEnableSymlinksCreate: enable_symlink_create,
} automount: data[:automount]
}.delete_if { |_,v| v.nil?}
end end
end end

View File

@ -15,6 +15,12 @@ describe VagrantPlugins::ProviderVirtualBox::Driver::Version_5_0 do
:transient=>false, :transient=>false,
:SharedFoldersEnableSymlinksCreate=>true}]} :SharedFoldersEnableSymlinksCreate=>true}]}
let(:folders_automount) { [{:name=>"folder",
:hostpath=>"/Users/brian/vagrant-folder",
:transient=>false,
:automount=>true,
:SharedFoldersEnableSymlinksCreate=>true}]}
let(:folders_disabled) { [{:name=>"folder", let(:folders_disabled) { [{:name=>"folder",
:hostpath=>"/Users/brian/vagrant-folder", :hostpath=>"/Users/brian/vagrant-folder",
:transient=>false, :transient=>false,
@ -32,6 +38,19 @@ describe VagrantPlugins::ProviderVirtualBox::Driver::Version_5_0 do
end end
it "enables automount if option is true" do
expect(subprocess).to receive(:execute).
with("VBoxManage", "setextradata", anything, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/folder", "1", {:notify=>[:stdout, :stderr]}).
and_return(subprocess_result(exit_code: 0))
expect(subprocess).to receive(:execute).
with("VBoxManage", "sharedfolder", "add", anything, "--name", "folder", "--hostpath", "/Users/brian/vagrant-folder", "--automount", {:notify=>[:stdout, :stderr]}).
and_return(subprocess_result(exit_code: 0))
subject.share_folders(folders_automount)
end
it "disables SharedFoldersEnableSymlinksCreate if false" do it "disables SharedFoldersEnableSymlinksCreate if false" do
expect(subprocess).to receive(:execute). expect(subprocess).to receive(:execute).
with("VBoxManage", "sharedfolder", "add", anything, "--name", "folder", "--hostpath", "/Users/brian/vagrant-folder", {:notify=>[:stdout, :stderr]}). with("VBoxManage", "sharedfolder", "add", anything, "--name", "folder", "--hostpath", "/Users/brian/vagrant-folder", {:notify=>[:stdout, :stderr]}).

View File

@ -53,6 +53,15 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
:disabled=>false, :disabled=>false,
:__vagrantfile=>true}} } :__vagrantfile=>true}} }
let(:folders_automount) { {"/folder"=>
{:SharedFoldersEnableSymlinksCreate=>true,
:guestpath=>"/folder",
:hostpath=>"/Users/brian/vagrant-folder",
:disabled=>false,
:automount=>true,
:__vagrantfile=>true}} }
let(:folders_nosymvar) { {"/folder"=> let(:folders_nosymvar) { {"/folder"=>
{:guestpath=>"/folder", {:guestpath=>"/folder",
:hostpath=>"/Users/brian/vagrant-folder", :hostpath=>"/Users/brian/vagrant-folder",
@ -88,6 +97,11 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>true}]) expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>true}])
subject.prepare(machine, folders, nil) subject.prepare(machine, folders, nil)
end end
it "should prepare and share the folders with automount enabled" do
expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>true, :automount=>true}])
subject.prepare(machine, folders_automount, nil)
end
end end
describe "#os_friendly_id" do describe "#os_friendly_id" do

View File

@ -18,6 +18,10 @@ the guest to the host and vice versa.
## Options ## Options
* `automount` (boolean) - If true, the `--automount` flag will be used when
using the VirtualBox tools to share the folder with the guest vm. Defaults to false
if not present.
* `SharedFoldersEnableSymlinksCreate` (boolean) - If false, will disable the * `SharedFoldersEnableSymlinksCreate` (boolean) - If false, will disable the
ability to create symlinks with the given virtualbox shared folder. Defaults to ability to create symlinks with the given virtualbox shared folder. Defaults to
true if the option is not present. true if the option is not present.