From 798fb81926ac15b026ed239dab310833969d098e Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 10 Sep 2018 09:27:40 -0700 Subject: [PATCH] Force command to be re-run after installing local plugins Reloading the Vagrantfile causes issue with multiple evaluations where users expect single evaluation. Instead of allowing local plugin installation to happen prior to command execution, force halt after installation and the command to be re-run. This will prevent multiple loads of the Vagrantfile within a single run. --- lib/vagrant/environment.rb | 34 +++++++++------------------ templates/locales/en.yml | 3 +++ test/unit/vagrant/environment_test.rb | 17 ++++++++------ 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index db0bd036f..8236f67b8 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -167,21 +167,18 @@ module Vagrant # Initialize localized plugins plugins = Vagrant::Plugin::Manager.instance.localize!(self) + # Load any environment local plugins + Vagrant::Plugin::Manager.instance.load_plugins(plugins) + + # Initialize globalize plugins + plugins = Vagrant::Plugin::Manager.instance.globalize! + # Load any global plugins + Vagrant::Plugin::Manager.instance.load_plugins(plugins) if !vagrantfile.config.vagrant.plugins.empty? plugins = process_configured_plugins end - # Load any environment local plugins - Vagrant::Plugin::Manager.instance.load_plugins(plugins) - - plugins = Vagrant::Plugin::Manager.instance.globalize! - Vagrant::Plugin::Manager.instance.load_plugins(plugins) - - # Reset so Vagrantfile will be reloaded with expected support for - # any new plugins provided - post_plugins_reset! - # Call the hooks that does not require configurations to be loaded # by using a "clean" action runner hook(:environment_plugins_loaded, runner: Action::Runner.new(env: self)) @@ -917,18 +914,6 @@ module Vagrant protected - # Unsets the internal vagrantfile and config_loader - # to force them to be regenerated. This is used after - # plugins have been loaded so that newly discovered - # plugin configurations are properly available - # - # @return [nil] - def post_plugins_reset! - @vagrantfile = nil - @config_loader = nil - nil - end - # Check for any local plugins defined within the Vagrantfile. If # found, validate they are available. If they are not available, # request to install them, or raise an exception @@ -982,7 +967,10 @@ module Vagrant name: spec.name, version: spec.version.to_s)) end ui.info("\n") - Vagrant::Plugin::Manager.instance.localize!(self) + # Force halt after installation and require command to be run again. This + # will proper load any new locally installed plugins which are now available. + ui.warn(I18n.t("vagrant.plugins.local.install_rerun_command")) + exit(-1) end Vagrant::Plugin::Manager.instance.local_file.installed_plugins end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 167f7f7a1..b4f9ea139 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -419,6 +419,9 @@ en: %{plugins} request_plugin_install: |- Install local plugins (Y/N) + install_rerun_command: |- + Vagrant has completed installing local plugins for the current Vagrant + project directory. Please run the requested command again. install_all: |- Vagrant will now install the following plugins to the local project diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 435db6ab3..215d61ae8 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -25,13 +25,6 @@ describe Vagrant::Environment do let(:instance) { env.create_vagrant_env } subject { instance } - describe "#initialize" do - it "should do an internal reset after plugin loading" do - expect_any_instance_of(described_class).to receive(:post_plugins_reset!) - instance - end - end - describe "#can_install_provider?" do let(:plugin_hosts) { {} } let(:plugin_host_caps) { {} } @@ -1495,6 +1488,8 @@ VF context "without plugin installed" do + before { allow(instance).to receive(:exit) } + it "should prompt user before installation" do expect(instance.ui).to receive(:ask).and_return("n") expect(plugin_manager).to receive(:installed_plugins).and_return({}) @@ -1507,6 +1502,14 @@ VF expect(plugin_manager).to receive(:install_plugin).and_return(double("spec", "name" => "vagrant", "version" => "1")) instance.send(:process_configured_plugins) end + + it "should exit after install" do + expect(instance.ui).to receive(:ask).and_return("y") + expect(plugin_manager).to receive(:installed_plugins).and_return({}) + expect(plugin_manager).to receive(:install_plugin).and_return(double("spec", "name" => "vagrant", "version" => "1")) + expect(instance).to receive(:exit) + instance.send(:process_configured_plugins) + end end end end