From 6d0dfb2690ab70edb420ca18c9535b01220a300a Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Mon, 22 Oct 2018 15:45:32 -0700 Subject: [PATCH 1/2] 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. --- .../virtualbox/driver/version_5_0.rb | 2 ++ plugins/providers/virtualbox/synced_folder.rb | 6 ++++-- .../virtualbox/driver/version_5_0_test.rb | 19 +++++++++++++++++++ .../virtualbox/synced_folder_test.rb | 14 ++++++++++++++ .../docs/synced-folders/virtualbox.html.md | 4 ++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_5_0.rb b/plugins/providers/virtualbox/driver/version_5_0.rb index 1d6e5ec4f..e8522e7ac 100644 --- a/plugins/providers/virtualbox/driver/version_5_0.rb +++ b/plugins/providers/virtualbox/driver/version_5_0.rb @@ -674,6 +674,8 @@ module VagrantPlugins hostpath] args << "--transient" if folder.key?(:transient) && folder[:transient] + args << "--automount" if folder.key?(:automount) && folder[:automount] + if folder[:SharedFoldersEnableSymlinksCreate] # Enable symlinks on the shared folder execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1", retryable: true) diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index 5b8a9799b..b40e9277b 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -124,8 +124,10 @@ module VagrantPlugins name: os_friendly_id(id), hostpath: hostpath.to_s, transient: transient, - SharedFoldersEnableSymlinksCreate: enable_symlink_create - } + SharedFoldersEnableSymlinksCreate: enable_symlink_create, + automount: data[:automount] + }.delete_if { |_,v| v.nil?} + end end diff --git a/test/unit/plugins/providers/virtualbox/driver/version_5_0_test.rb b/test/unit/plugins/providers/virtualbox/driver/version_5_0_test.rb index 194306799..1e833afcc 100644 --- a/test/unit/plugins/providers/virtualbox/driver/version_5_0_test.rb +++ b/test/unit/plugins/providers/virtualbox/driver/version_5_0_test.rb @@ -15,6 +15,12 @@ describe VagrantPlugins::ProviderVirtualBox::Driver::Version_5_0 do :transient=>false, :SharedFoldersEnableSymlinksCreate=>true}]} + let(:folders_automount) { [{:name=>"folder", + :hostpath=>"/Users/brian/vagrant-folder", + :transient=>false, + :automount=>true, + :SharedFoldersEnableSymlinksCreate=>true}]} + let(:folders_disabled) { [{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, @@ -32,6 +38,19 @@ describe VagrantPlugins::ProviderVirtualBox::Driver::Version_5_0 do 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 expect(subprocess).to receive(:execute). with("VBoxManage", "sharedfolder", "add", anything, "--name", "folder", "--hostpath", "/Users/brian/vagrant-folder", {:notify=>[:stdout, :stderr]}). diff --git a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb index 1eb3d77c3..2aaba1ac2 100644 --- a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb +++ b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb @@ -53,6 +53,15 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do :disabled=>false, :__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"=> {:guestpath=>"/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}]) subject.prepare(machine, folders, nil) 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 describe "#os_friendly_id" do diff --git a/website/source/docs/synced-folders/virtualbox.html.md b/website/source/docs/synced-folders/virtualbox.html.md index 86f9b8beb..8cef10488 100644 --- a/website/source/docs/synced-folders/virtualbox.html.md +++ b/website/source/docs/synced-folders/virtualbox.html.md @@ -18,6 +18,10 @@ the guest to the host and vice versa. ## 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 ability to create symlinks with the given virtualbox shared folder. Defaults to true if the option is not present. From 7c06950e43d1c06cdcd498de161c7c59c417a81d Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 23 Oct 2018 09:00:55 -0700 Subject: [PATCH 2/2] Ensure true or false for automount option --- plugins/providers/virtualbox/synced_folder.rb | 5 ++--- .../providers/virtualbox/synced_folder_test.rb | 11 +++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index b40e9277b..89b006cf2 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -125,9 +125,8 @@ module VagrantPlugins hostpath: hostpath.to_s, transient: transient, SharedFoldersEnableSymlinksCreate: enable_symlink_create, - automount: data[:automount] - }.delete_if { |_,v| v.nil?} - + automount: !!data[:automount] + } end end diff --git a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb index 2aaba1ac2..a5b121581 100644 --- a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb +++ b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb @@ -43,6 +43,7 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do {:SharedFoldersEnableSymlinksCreate=>true, :guestpath=>"/folder", :hostpath=>"/Users/brian/vagrant-folder", + :automount=>false, :disabled=>false, :__vagrantfile=>true}} } @@ -50,6 +51,7 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do {:SharedFoldersEnableSymlinksCreate=>false, :guestpath=>"/folder", :hostpath=>"/Users/brian/vagrant-folder", + :automount=>false, :disabled=>false, :__vagrantfile=>true}} } @@ -65,6 +67,7 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do let(:folders_nosymvar) { {"/folder"=> {:guestpath=>"/folder", :hostpath=>"/Users/brian/vagrant-folder", + :automount=>false, :disabled=>false, :__vagrantfile=>true}} } @@ -75,26 +78,26 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do end it "should prepare and share the folders" 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, :automount=>false, :SharedFoldersEnableSymlinksCreate=>true}]) subject.prepare(machine, folders, nil) end it "should prepare and share the folders without symlinks enabled" do - expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>false}]) + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :automount=>false, :SharedFoldersEnableSymlinksCreate=>false}]) subject.prepare(machine, folders_disabled, nil) end it "should prepare and share the folders without symlinks enabled with env var set" do stub_env('VAGRANT_DISABLE_VBOXSYMLINKCREATE'=>'1') - expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>false}]) + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :automount=>false, :SharedFoldersEnableSymlinksCreate=>false}]) subject.prepare(machine, folders_nosymvar, nil) end it "should prepare and share the folders and override symlink setting" do stub_env('VAGRANT_DISABLE_VBOXSYMLINKCREATE'=>'1') - 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, :automount=>false, :SharedFoldersEnableSymlinksCreate=>true}]) subject.prepare(machine, folders, nil) end