From f2954a64c6d29f38b9ad53106d80498fdd28bc20 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 23 Feb 2018 11:24:30 -0800 Subject: [PATCH] Fix Hyper-v and VirtualBox check Prior to this commit, the hyper-v and virtualbox system crash check existed within the initialize function of the virtualbox provider. That caused an issue when running with other providers, because the virtualbox provider still gets initialized even if not used. This commit changes that by placing the check inside of one of the virtualbox provider actions that checks if virtualbox is installed and ready to use. This action is action is used by the main vbox provider actions, and should not be called when other providers are being used with Vagrant. --- plugins/providers/virtualbox/action/check_virtualbox.rb | 9 +++++++++ plugins/providers/virtualbox/driver/base.rb | 6 ------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/providers/virtualbox/action/check_virtualbox.rb b/plugins/providers/virtualbox/action/check_virtualbox.rb index 1d590fe4f..800852c2a 100644 --- a/plugins/providers/virtualbox/action/check_virtualbox.rb +++ b/plugins/providers/virtualbox/action/check_virtualbox.rb @@ -1,3 +1,5 @@ +require 'vagrant/util/platform' + module VagrantPlugins module ProviderVirtualBox module Action @@ -5,6 +7,7 @@ module VagrantPlugins class CheckVirtualbox def initialize(app, env) @app = app + @logger = Log4r::Logger.new("vagrant::provider::virtualbox") end def call(env) @@ -13,6 +16,12 @@ module VagrantPlugins # which will break us out of execution of the middleware sequence. Driver::Meta.new.verify! + if Vagrant::Util::Platform.windows? && Vagrant::Util::Platform.windows_hyperv_enabled? + @logger.error("Virtualbox and Hyper-V cannot be used together at the same time on Windows and will result in a system crash.") + + raise Vagrant::Errors::HypervVirtualBoxError + end + # Carry on. @app.call(env) end diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb index 97311b76b..76f08487e 100644 --- a/plugins/providers/virtualbox/driver/base.rb +++ b/plugins/providers/virtualbox/driver/base.rb @@ -78,12 +78,6 @@ module VagrantPlugins end end - if Vagrant::Util::Platform.windows? && Vagrant::Util::Platform.windows_hyperv_enabled? - @logger.error("Virtualbox and Hyper-V cannot be used together at the same time on Windows and will result in a system crash.") - - raise Vagrant::Errors::HypervVirtualBoxError - end - # Fall back to hoping for the PATH to work out @vboxmanage_path ||= "VBoxManage" @logger.info("VBoxManage path: #{@vboxmanage_path}")