Prevent exception from raising on hyper-v check
This commit is contained in:
parent
ed310a954b
commit
ca81f9d6cb
|
@ -13,6 +13,14 @@ module Vagrant
|
|||
# This class just contains some platform checking code.
|
||||
class Platform
|
||||
class << self
|
||||
|
||||
def logger
|
||||
if !defined?(@_logger)
|
||||
@_logger = Log4r::Logger.new("vagrant::util::platform")
|
||||
end
|
||||
@_logger
|
||||
end
|
||||
|
||||
def cygwin?
|
||||
if !defined?(@_cygwin)
|
||||
@_cygwin = ENV["VAGRANT_DETECTED_OS"].to_s.downcase.include?("cygwin") ||
|
||||
|
@ -134,8 +142,13 @@ module Vagrant
|
|||
@_windows_hyperv_enabled = -> {
|
||||
["Get-WindowsOptionalFeature", "Get-WindowsFeature"].each do |cmd_name|
|
||||
ps_cmd = "$(#{cmd_name} -FeatureName Microsoft-Hyper-V-Hypervisor).State"
|
||||
output = Vagrant::Util::PowerShell.execute_cmd(ps_cmd)
|
||||
return true if output == "Enabled"
|
||||
begin
|
||||
output = Vagrant::Util::PowerShell.execute_cmd(ps_cmd)
|
||||
return true if output == "Enabled"
|
||||
rescue Errors::PowerShellInvalidVersion
|
||||
logger.warn("Invalid PowerShell version detected during Hyper-V enable check")
|
||||
return false
|
||||
end
|
||||
end
|
||||
return false
|
||||
}.call
|
||||
|
|
|
@ -262,6 +262,13 @@ describe Vagrant::Util::Platform do
|
|||
|
||||
expect(Vagrant::Util::Platform.windows_hyperv_enabled?).to be_falsey
|
||||
end
|
||||
|
||||
it "should return false if PowerShell cannot be validated" do
|
||||
allow_any_instance_of(Vagrant::Errors::PowerShellInvalidVersion).to receive(:translate_error)
|
||||
allow(Vagrant::Util::PowerShell).to receive(:execute_cmd).and_raise(Vagrant::Errors::PowerShellInvalidVersion)
|
||||
|
||||
expect(Vagrant::Util::Platform.windows_hyperv_enabled?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context "within the WSL" do
|
||||
|
|
Loading…
Reference in New Issue