From 2fa44f5b8f9a06e7465070973797b112a46e4eb0 Mon Sep 17 00:00:00 2001 From: Jeff Bonhag Date: Tue, 17 Dec 2019 12:34:53 -0500 Subject: [PATCH] Fixes #11218: Update apk cache when installing rsync (#11220) This ensures that rsync can be installed on an Alpine Linux machine where the apk cache may not be current. Display a warning if the vagrant-alpine plugin is installed, since Alpine guest support has been merged into Vagrant core. --- plugins/guests/alpine/cap/rsync.rb | 2 +- plugins/guests/alpine/plugin.rb | 16 ++++++++++ .../plugins/guests/alpine/cap/rsync_test.rb | 4 +-- .../unit/plugins/guests/alpine/plugin_test.rb | 32 +++++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 test/unit/plugins/guests/alpine/plugin_test.rb diff --git a/plugins/guests/alpine/cap/rsync.rb b/plugins/guests/alpine/cap/rsync.rb index 436bfbc20..ba61a4fcc 100644 --- a/plugins/guests/alpine/cap/rsync.rb +++ b/plugins/guests/alpine/cap/rsync.rb @@ -8,7 +8,7 @@ module VagrantPlugins def self.rsync_install(machine) machine.communicate.tap do |comm| - comm.sudo('apk add rsync') + comm.sudo('apk add --update-cache rsync') end end end diff --git a/plugins/guests/alpine/plugin.rb b/plugins/guests/alpine/plugin.rb index 62e8ec6fd..2597004ff 100644 --- a/plugins/guests/alpine/plugin.rb +++ b/plugins/guests/alpine/plugin.rb @@ -45,6 +45,22 @@ module VagrantPlugins require_relative 'cap/smb' Cap::SMB end + + def self.check_community_plugin + plugins = Vagrant::Plugin::Manager.instance.installed_plugins + if plugins.keys.include?("vagrant-alpine") + $stderr.puts <<-EOF +WARNING: Vagrant has detected the `vagrant-alpine` plugin. This plugin's +functionality has been merged into the main Vagrant project and should be +considered deprecated. To uninstall the plugin, run the command shown below: + + vagrant plugin uninstall vagrant-alpine + +EOF + end + end + + self.check_community_plugin end end end diff --git a/test/unit/plugins/guests/alpine/cap/rsync_test.rb b/test/unit/plugins/guests/alpine/cap/rsync_test.rb index 6b305a5f9..70253495f 100644 --- a/test/unit/plugins/guests/alpine/cap/rsync_test.rb +++ b/test/unit/plugins/guests/alpine/cap/rsync_test.rb @@ -16,9 +16,9 @@ describe 'VagrantPlugins::GuestAlpine::Cap::RSync' do VagrantPlugins::GuestAlpine::Plugin.components.guest_capabilities[:alpine].get(:rsync_install) end - it 'should install rsync' do + it 'should install rsync with --update-cache flag' do # communicator.should_receive(:sudo).with('apk add rsync') - expect(communicator).to receive(:sudo).with('apk add rsync') + expect(communicator).to receive(:sudo).with('apk add --update-cache rsync') allow_message_expectations_on_nil described_class.rsync_install(machine) end diff --git a/test/unit/plugins/guests/alpine/plugin_test.rb b/test/unit/plugins/guests/alpine/plugin_test.rb new file mode 100644 index 000000000..8e4341c27 --- /dev/null +++ b/test/unit/plugins/guests/alpine/plugin_test.rb @@ -0,0 +1,32 @@ +require File.expand_path("../../../../base", __FILE__) + + +describe VagrantPlugins::GuestAlpine::Plugin do + let(:manager) { double("manager") } + + before do + allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(manager) + end + + context "when vagrant-alpine plugin is not installed" do + before do + allow(manager).to receive(:installed_plugins).and_return({}) + end + + it "should not display a warning" do + expect($stderr).to_not receive(:puts) + VagrantPlugins::GuestAlpine::Plugin.check_community_plugin + end + end + + context "when vagrant-alpine plugin is installed" do + before do + allow(manager).to receive(:installed_plugins).and_return({ "vagrant-alpine" => {} }) + end + + it "should display a warning" do + expect($stderr).to receive(:puts).with(/vagrant plugin uninstall vagrant-alpine/) + VagrantPlugins::GuestAlpine::Plugin.check_community_plugin + end + end +end