Merge pull request #10199 from chrisroberts/f-multi-vagrantfile-load

Force command to be re-run after installing local plugins
This commit is contained in:
Chris Roberts 2018-09-11 10:46:32 -07:00 committed by GitHub
commit a3c056ef6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 30 deletions

View File

@ -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

View File

@ -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

View File

@ -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