From cd7215ab13d996b0f2e431c99cd177f63540825a Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 30 Jul 2018 13:27:20 -0700 Subject: [PATCH] Add warning when vagrant-winrm is found --- plugins/communicators/winrm/plugin.rb | 22 ++++++++++ .../communicators/winrm/plugin_test.rb | 42 +++++++++++++++++++ .../other/environmental-variables.html.md | 4 ++ 3 files changed, 68 insertions(+) create mode 100644 test/unit/plugins/communicators/winrm/plugin_test.rb diff --git a/plugins/communicators/winrm/plugin.rb b/plugins/communicators/winrm/plugin.rb index a8e8b51a4..ea8e4d8f1 100644 --- a/plugins/communicators/winrm/plugin.rb +++ b/plugins/communicators/winrm/plugin.rb @@ -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 diff --git a/test/unit/plugins/communicators/winrm/plugin_test.rb b/test/unit/plugins/communicators/winrm/plugin_test.rb new file mode 100644 index 000000000..298ef4f74 --- /dev/null +++ b/test/unit/plugins/communicators/winrm/plugin_test.rb @@ -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 diff --git a/website/source/docs/other/environmental-variables.html.md b/website/source/docs/other/environmental-variables.html.md index 6db684e23..21a3345e8 100644 --- a/website/source/docs/other/environmental-variables.html.md +++ b/website/source/docs/other/environmental-variables.html.md @@ -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.