Merge pull request #10938 from andersk/virtualbox-usable

virtualbox: Fix usability test to reject bad installs without crashing
This commit is contained in:
Brian Cain 2019-10-07 09:04:24 -07:00 committed by GitHub
commit 96e275451c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View File

@ -8,9 +8,10 @@ module VagrantPlugins
def self.installed?
Driver::Meta.new
true
rescue Vagrant::Errors::VirtualBoxInvalidVersion
return false
rescue Vagrant::Errors::VirtualBoxNotDetected
rescue Vagrant::Errors::VirtualBoxInvalidVersion,
Vagrant::Errors::VirtualBoxNotDetected,
Vagrant::Errors::VirtualBoxKernelModuleNotLoaded,
Vagrant::Errors::VirtualBoxInstallIncomplete
return false
end
@ -19,10 +20,10 @@ module VagrantPlugins
# version and all that, which checks for VirtualBox being present
Driver::Meta.new
true
rescue Vagrant::Errors::VirtualBoxInvalidVersion
raise if raise_error
return false
rescue Vagrant::Errors::VirtualBoxNotDetected
rescue Vagrant::Errors::VirtualBoxInvalidVersion,
Vagrant::Errors::VirtualBoxNotDetected,
Vagrant::Errors::VirtualBoxKernelModuleNotLoaded,
Vagrant::Errors::VirtualBoxInstallIncomplete
raise if raise_error
return false
end

View File

@ -47,6 +47,22 @@ describe VagrantPlugins::ProviderVirtualBox::Provider do
expect { subject.usable?(true) }.
to raise_error(Vagrant::Errors::VirtualBoxInvalidVersion)
end
it "raises an exception if virtualbox kernel module is not loaded" do
allow(VagrantPlugins::ProviderVirtualBox::Driver::Meta).to receive(:new).
and_raise(Vagrant::Errors::VirtualBoxKernelModuleNotLoaded)
expect { subject.usable?(true) }.
to raise_error(Vagrant::Errors::VirtualBoxKernelModuleNotLoaded)
end
it "raises an exception if virtualbox installation is incomplete" do
allow(VagrantPlugins::ProviderVirtualBox::Driver::Meta).to receive(:new).
and_raise(Vagrant::Errors::VirtualBoxInstallIncomplete)
expect { subject.usable?(true) }.
to raise_error(Vagrant::Errors::VirtualBoxInstallIncomplete)
end
end
describe "#driver" do