Add warning when vagrant-winrm is found

This commit is contained in:
Chris Roberts 2018-07-30 13:27:20 -07:00
parent 80edb39122
commit cd7215ab13
3 changed files with 68 additions and 0 deletions

View File

@ -33,12 +33,34 @@ module VagrantPlugins
"templates/locales/comm_winrm.yml", Vagrant.source_root)
I18n.reload!
# Check if vagrant-winrm plugin is installed and
# output warning to user if found
if !ENV["VAGRANT_IGNORE_WINRM_PLUGIN"] &&
Vagrant::Plugin::Manager.instance.installed_plugins.keys.include?("vagrant-winrm")
$stderr.puts <<-EOF
WARNING: Vagrant has detected the `vagrant-winrm` plugin. Vagrant ships with
WinRM support builtin and no longer requires the `vagrant-winrm` plugin. To
prevent unexpected errors please uninstall the `vagrant-winrm` plugin using
the command shown below:
vagrant plugin uninstall vagrant-winrm
To disable this warning, set the environment variable `VAGRANT_IGNORE_WINRM_PLUGIN`
EOF
end
# Load the WinRM gem
require "vagrant/util/silence_warnings"
Vagrant::Util::SilenceWarnings.silence! do
require "winrm"
end
end
# @private
# Reset the cached values. This is not considered a public
# API and should only be used for testing.
def self.reset!
instance_variables.each(&method(:remove_instance_variable))
end
end
end
end

View File

@ -0,0 +1,42 @@
require File.expand_path("../../../../base", __FILE__)
require Vagrant.source_root.join("plugins/communicators/winrm/plugin")
describe VagrantPlugins::CommunicatorWinRM::Plugin do
describe "#init!" do
let(:manager_instance) { double("manager_instance", installed_plugins: installed_plugins) }
let(:installed_plugins) { {} }
before do
allow(I18n).to receive(:load_path).and_return("")
allow(I18n).to receive(:reload!)
allow(described_class).to receive(:require)
allow(Vagrant::Plugin::Manager).to receive(:instance).and_return(manager_instance)
end
after do
described_class.init!
described_class.reset!
end
it "should not output any warning" do
expect($stderr).not_to receive(:puts).with(/WARNING/)
end
context "when vagrant-winrm plugin is installed" do
let(:installed_plugins) { {"vagrant-winrm" => "PLUGIN_INFO"} }
it "should output a warning" do
expect($stderr).to receive(:puts).with(/WARNING/)
end
context "with VAGRANT_IGNORE_WINRM_PLUGIN set" do
before { allow(ENV).to receive(:[]).with("VAGRANT_IGNORE_WINRM_PLUGIN").and_return("1") }
it "should not output any warning" do
expect($stderr).not_to receive(:puts).with(/WARNING/)
end
end
end
end
end

View File

@ -265,6 +265,10 @@ it will use 30 seconds as a timeout.
Vagrant will not display the warning about disabling the core trigger feature if
the community plugin is installed.
## `VAGRANT_IGNORE_WINRM_PLUGIN`
Vagrant will not display warning when `vagrant-winrm` plugin is installed.
## `VAGRANT_USER_AGENT_PROVISIONAL_STRING`
Vagrant will append the contents of this variable to the default user agent header.