diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a3d31849..1515dfa72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ BUG FIXES: of Vagrant. [GH-3386] - core: Don't error if network problems cause box update check to fail [GH-3391] + - commands/rsync-auto: Don't crash if the machine can't be communicated + to. [GH-3419] - guests/fedora: Fix hostname setting. [GH-3382] - guests/fedora: Support predictable network interface names for public/private networks. [GH-3207] diff --git a/plugins/synced_folders/rsync/command/rsync_auto.rb b/plugins/synced_folders/rsync/command/rsync_auto.rb index 8e1951214..48ac287e5 100644 --- a/plugins/synced_folders/rsync/command/rsync_auto.rb +++ b/plugins/synced_folders/rsync/command/rsync_auto.rb @@ -112,7 +112,14 @@ module VagrantPlugins tosync.each do |folders| folders.each do |opts| ssh_info = opts[:machine].ssh_info - RsyncHelper.rsync_single(opts[:machine], ssh_info, opts[:opts]) + begin + RsyncHelper.rsync_single(opts[:machine], ssh_info, opts[:opts]) + rescue Vagrant::Errors::MachineGuestNotReady + # Error communicating to the machine, probably a reload or + # halt is happening. Just notify the user but don't fail out. + opts[:machine].ui.error(I18n.t( + "vagrant.rsync_communicator_not_ready_callback")) + end end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 9b85a2b9a..487c9a87d 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -159,6 +159,10 @@ en: rsync_communicator_not_ready: |- The machine is reporting that it is not ready for rsync to communiate with it. Verify that this machine is properly running. + rsync_communicator_not_ready_callback: |- + Failed to connect to remote machine. This is usually caused by the + machine rebooting or being halted. Please make sure the machine is + running, and modify a file to try again. rsync_folder: |- Rsyncing folder: %{hostpath} => %{guestpath} rsync_folder_excludes: " - Exclude: %{excludes}" diff --git a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb index bb8982b9f..7324b7962 100644 --- a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb +++ b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb @@ -30,6 +30,9 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do def machine_stub(name) double(name).tap do |m| m.stub(ssh_info: ssh_info) + m.stub(ui: double("ui")) + + m.ui.stub(error: nil) end end @@ -95,5 +98,27 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do r = ["/foo/bar"] subject.callback(paths, m, a, r) end + + it "doesn't fail if guest error occurs" do + paths["/foo"] = [ + { machine: machine_stub("m1"), opts: double("opts_m1") }, + { machine: machine_stub("m2"), opts: double("opts_m2") }, + ] + paths["/bar"] = [ + { machine: machine_stub("m3"), opts: double("opts_m3") }, + ] + + paths["/foo"].each do |data| + expect(helper_class).to receive(:rsync_single). + with(data[:machine], data[:machine].ssh_info, data[:opts]). + and_raise(Vagrant::Errors::MachineGuestNotReady) + end + + m = [] + a = [] + r = ["/foo/bar"] + expect { subject.callback(paths, m, a, r) }. + to_not raise_error + end end end