From 98b0ad14646b61e389f750fb1a4956c5af55a805 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 24 Mar 2017 13:32:49 -0700 Subject: [PATCH] Fix linux guest mount smb capability --- .../linux/cap/mount_smb_shared_folder.rb | 2 +- .../linux/cap/mount_smb_shared_folder.rb | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb diff --git a/plugins/guests/linux/cap/mount_smb_shared_folder.rb b/plugins/guests/linux/cap/mount_smb_shared_folder.rb index bce106c6b..c0d1bf3f3 100644 --- a/plugins/guests/linux/cap/mount_smb_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_smb_shared_folder.rb @@ -15,7 +15,7 @@ module VagrantPlugins mount_device = "//#{options[:smb_host]}/#{name}" mount_options = options.fetch(:mount_options, []) - detected_ids = detect_owner_group_ids(machine, guest_path, mount_options, options) + detected_ids = detect_owner_group_ids(machine, guestpath, mount_options, options) mount_uid = detected_ids[:uid] mount_gid = detected_ids[:gid] diff --git a/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb b/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb new file mode 100644 index 000000000..cde67e6a6 --- /dev/null +++ b/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb @@ -0,0 +1,71 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestLinux::Cap::MountSMBSharedFolder" do + let(:caps) do + VagrantPlugins::GuestLinux::Plugin + .components + .guest_capabilities[:linux] + end + + let(:machine) { double("machine") } + let(:guest) { double("guest") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + let(:mount_owner){ "vagrant" } + let(:mount_group){ "vagrant" } + let(:mount_uid){ "1000" } + let(:mount_gid){ "1000" } + let(:mount_name){ "vagrant" } + let(:mount_guest_path){ "/vagrant" } + let(:folder_options) do + { + owner: mount_owner, + group: mount_group, + smb_host: "localhost", + smb_username: "user", + smb_password: "pass" + } + end + let(:cap){ caps.get(:mount_smb_shared_folder) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + after do + comm.verify_expectations! + end + + describe ".mount_smb_shared_folder" do + before do + allow(comm).to receive(:sudo).with(any_args).and_return(0) + allow(comm).to receive(:execute).with(any_args) + allow(machine).to receive(:guest).and_return(guest) + allow(guest).to receive(:capability).with(:shell_expand_guest_path, mount_guest_path).and_return(mount_guest_path) + end + + it "generates the expected default mount command" do + expect(comm).to receive(:sudo).with(/mount -t cifs/, anything).and_return(0) + cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options) + end + + it "creates directory on guest machine" do + expect(comm).to receive(:sudo).with("mkdir -p #{mount_guest_path}") + cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options) + end + + it "writes username into guest credentials file" do + expect(comm).to receive(:sudo).with(/smb_creds.*username=#{folder_options[:smb_username]}/m) + cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options) + end + + it "writes password into guest credentials file" do + expect(comm).to receive(:sudo).with(/smb_creds.*password=#{folder_options[:smb_password]}/m) + cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options) + end + + it "sends upstart notification after mount" do + expect(comm).to receive(:sudo).with(/emit/) + cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options) + end + end +end