From 1e39161a7b4f1c4191c32ea6d9a7dc73b53ef13b Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 2 Sep 2022 10:42:17 -0500 Subject: [PATCH] Ensure candidate ips are available when determining mount name --- .../synced_folders/smb/cap/mount_options.rb | 1 + .../smb/caps/mount_options_test.rb | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugins/synced_folders/smb/cap/mount_options.rb b/plugins/synced_folders/smb/cap/mount_options.rb index 4c0adcc49..95e66fe35 100644 --- a/plugins/synced_folders/smb/cap/mount_options.rb +++ b/plugins/synced_folders/smb/cap/mount_options.rb @@ -46,6 +46,7 @@ module VagrantPlugins end def self.mount_name(machine, name, data) + candidate_ips = machine.env.host.capability(:configured_ip_addresses) data[:smb_host] ||= machine.guest.capability( :choose_addressable_ip_addr, candidate_ips) "//#{data[:smb_host]}/#{data[:smb_id]}" diff --git a/test/unit/plugins/synced_folders/smb/caps/mount_options_test.rb b/test/unit/plugins/synced_folders/smb/caps/mount_options_test.rb index 095c41534..9ab640349 100644 --- a/test/unit/plugins/synced_folders/smb/caps/mount_options_test.rb +++ b/test/unit/plugins/synced_folders/smb/caps/mount_options_test.rb @@ -11,8 +11,12 @@ describe VagrantPlugins::SyncedFolderSMB::Cap::MountOptions do end let(:cap){ caps.get(:mount_options) } + let(:dummy_smb_host) { "my.smb.host" } let(:machine) { double("machine") } let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + let(:env) { double("env") } + let(:guest) { double("guest") } + let(:host) { double("host") } let(:mount_owner){ "vagrant" } let(:mount_group){ "vagrant" } let(:mount_uid){ "1000" } @@ -28,12 +32,32 @@ describe VagrantPlugins::SyncedFolderSMB::Cap::MountOptions do end before do + allow(guest).to receive(:capability).with(:choose_addressable_ip_addr, any_args).and_return(dummy_smb_host) + allow(host).to receive(:capability).with(:configured_ip_addresses) + allow(env).to receive(:host).and_return(host) + allow(machine).to receive(:env).and_return(env) allow(machine).to receive(:communicate).and_return(comm) + allow(machine).to receive(:guest).and_return(guest) allow(machine).to receive_message_chain(:env, :host, :capability?).with(:smb_mount_options).and_return(false) allow(ENV).to receive(:[]).with("VAGRANT_DISABLE_SMBMFSYMLINKS").and_return(true) allow(ENV).to receive(:[]).with("GEM_SKIP").and_return(false) end + describe ".mount_name" do + it "generates the mount name when smb_host and smb_id are set" do + folder_options[:smb_host] = "smb_host" + folder_options[:smb_id] = "smbid" + mn = cap.mount_name(machine, "", folder_options) + expect(mn).to eq("//smb_host/smbid") + end + + it "generates the mount name when smb_host is not set" do + folder_options[:smb_id] = "smbid" + mn = cap.mount_name(machine, "", folder_options) + expect(mn).to eq("//#{dummy_smb_host}/smbid") + end + end + describe ".mount_options" do context "with valid existent owner group" do