diff --git a/plugins/guests/linux/cap/mount_smb_shared_folder.rb b/plugins/guests/linux/cap/mount_smb_shared_folder.rb index a16ce92cd..a011e551f 100644 --- a/plugins/guests/linux/cap/mount_smb_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_smb_shared_folder.rb @@ -18,10 +18,9 @@ module VagrantPlugins def self.mount_smb_shared_folder(machine, name, guestpath, options) expanded_guest_path = machine.guest.capability( :shell_expand_guest_path, guestpath) - - mount_device = "//#{options[:smb_host]}/#{name}" - options[:smb_id] ||= name + + mount_device = options[:plugin].capability(:mount_name, options) mount_options, _, _ = options[:plugin].capability( :mount_options, name, expanded_guest_path, options) mount_type = options[:plugin].capability(:mount_type) @@ -30,7 +29,6 @@ module VagrantPlugins smb_password = options[:smb_password] # Ensure password is scrubbed Vagrant::Util::CredentialScrubber.sensitive(smb_password) - if mount_options.include?("mfsymlinks") display_mfsymlinks_warning(machine.env) diff --git a/plugins/guests/linux/cap/persist_mount_shared_folder.rb b/plugins/guests/linux/cap/persist_mount_shared_folder.rb index 3f4202906..ac37b1fbf 100644 --- a/plugins/guests/linux/cap/persist_mount_shared_folder.rb +++ b/plugins/guests/linux/cap/persist_mount_shared_folder.rb @@ -31,15 +31,11 @@ module VagrantPlugins data[:owner] ||= ssh_info[:username] data[:group] ||= ssh_info[:username] mount_type = data[:plugin].capability(:mount_type) - - if type == :smb - data[:smb_host] ||= machine.guest.capability( - :choose_addressable_ip_addr, candidate_ips) - name = "//#{data[:smb_host]}/#{data[:smb_id]}" - end - mount_options, _, _ = data[:plugin].capability( :mount_options, name, guest_path, data) + if data[:plugin].capability?(:mount_name) + name = data[:plugin].capability(:mount_name, data) + end else next end diff --git a/plugins/synced_folders/smb/cap/mount_options.rb b/plugins/synced_folders/smb/cap/mount_options.rb index 2150dbca0..7f4ecdf41 100644 --- a/plugins/synced_folders/smb/cap/mount_options.rb +++ b/plugins/synced_folders/smb/cap/mount_options.rb @@ -44,6 +44,12 @@ module VagrantPlugins def self.mount_type(machine) return MOUNT_TYPE end + + def self.mount_name(machine, data) + data[:smb_host] ||= machine.guest.capability( + :choose_addressable_ip_addr, candidate_ips) + "//#{data[:smb_host]}/#{data[:smb_id]}" + end end end end diff --git a/plugins/synced_folders/smb/plugin.rb b/plugins/synced_folders/smb/plugin.rb index 71c0cca00..85a1b1997 100644 --- a/plugins/synced_folders/smb/plugin.rb +++ b/plugins/synced_folders/smb/plugin.rb @@ -33,6 +33,11 @@ module VagrantPlugins Cap::MountOptions end + synced_folder_capability("smb", "mount_name") do + require_relative "cap/mount_options" + Cap::MountOptions + end + synced_folder_capability("smb", "mount_type") do require_relative "cap/mount_options" Cap::MountOptions diff --git a/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder_test.rb b/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder_test.rb index c5e19e6ab..3414a1b69 100644 --- a/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder_test.rb +++ b/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder_test.rb @@ -43,6 +43,7 @@ describe "VagrantPlugins::GuestLinux::Cap::MountSMBSharedFolder" do allow(folder_plugin).to receive(:capability).with(:mount_options, mount_name, mount_guest_path, folder_options). and_return(["uid=#{mount_uid},gid=#{mount_gid},sec=ntlmssp,credentials=/etc/smb_creds_id", mount_uid, mount_gid]) allow(folder_plugin).to receive(:capability).with(:mount_type).and_return("cifs") + allow(folder_plugin).to receive(:capability).with(:mount_name, any_args).and_return("//localhost/#{mount_name}") end after do diff --git a/test/unit/plugins/guests/linux/cap/persist_mount_shared_folder_test.rb b/test/unit/plugins/guests/linux/cap/persist_mount_shared_folder_test.rb index 40943e5f4..36240612c 100644 --- a/test/unit/plugins/guests/linux/cap/persist_mount_shared_folder_test.rb +++ b/test/unit/plugins/guests/linux/cap/persist_mount_shared_folder_test.rb @@ -34,6 +34,7 @@ describe "VagrantPlugins::GuestLinux::Cap::PersistMountSharedFolder" do before do allow(machine).to receive(:communicate).and_return(comm) allow(machine).to receive(:ssh_info).and_return(ssh_info) + allow(folder_plugin).to receive(:capability?).with(:mount_name).and_return(false) allow(folder_plugin).to receive(:capability?).with(:mount_type).and_return(true) allow(folder_plugin).to receive(:capability).with(:mount_options, any_args). and_return(["uid=#{options_uid},gid=#{options_gid}", options_uid, options_gid]) @@ -116,17 +117,21 @@ describe "VagrantPlugins::GuestLinux::Cap::PersistMountSharedFolder" do :smb => fstab_folders } } - before do - allow(folder_plugin).to receive(:capability).with(:mount_type).and_return("cifs") - end - - it "inserts folders into /etc/fstab" do - expected_entry_vagrant = "//192.168.42.42/vtg-id2 /vagrant cifs #{expected_mount_options} 0 0" - expected_entry_test = "//192.168.42.42/vtg-id1 /test1 cifs #{expected_mount_options} 0 0" - expect(cap).to receive(:remove_vagrant_managed_fstab) - expect(comm).to receive(:sudo).with(/#{expected_entry_test}\n#{expected_entry_vagrant}/) - - cap.persist_mount_shared_folder(machine, folders) + context "folder with mount_name cap" do + before do + allow(folder_plugin).to receive(:capability).with(:mount_type).and_return("cifs") + allow(folder_plugin).to receive(:capability?).with(:mount_name).and_return(true) + allow(folder_plugin).to receive(:capability).with(:mount_name, any_args).and_return("//192.168.42.42/dummyname") + end + + it "inserts folders into /etc/fstab" do + expected_entry_vagrant = "//192.168.42.42/dummyname /vagrant cifs #{expected_mount_options} 0 0" + expected_entry_test = "//192.168.42.42/dummyname /test1 cifs #{expected_mount_options} 0 0" + expect(cap).to receive(:remove_vagrant_managed_fstab) + expect(comm).to receive(:sudo).with(/#{expected_entry_test}\n#{expected_entry_vagrant}/) + + cap.persist_mount_shared_folder(machine, folders) + end end end end