core: check if provider is usable when requesting a machine
This commit is contained in:
parent
740652aef9
commit
9dd9fff637
|
@ -496,6 +496,10 @@ module Vagrant
|
|||
error_key(:provider_not_found)
|
||||
end
|
||||
|
||||
class ProviderNotUsable < VagrantError
|
||||
error_key(:provider_not_usable)
|
||||
end
|
||||
|
||||
class ProvisionerFlagInvalid < VagrantError
|
||||
error_key(:provisioner_flag_invalid)
|
||||
end
|
||||
|
|
|
@ -124,6 +124,16 @@ module Vagrant
|
|||
provider_options = provider_plugin[1]
|
||||
box_formats = provider_options[:box_format] || provider
|
||||
|
||||
# Test if the provider is usable or not
|
||||
begin
|
||||
provider_cls.usable?(true)
|
||||
rescue Errors::VagrantError => e
|
||||
raise Errors::ProviderNotUsable,
|
||||
machine: name.to_s,
|
||||
provider: provider.to_s,
|
||||
message: e.to_s
|
||||
end
|
||||
|
||||
# Add the sub-machine configuration to the loader and keys
|
||||
vm_config_key = "#{object_id}_machine_#{name}"
|
||||
@loader.set(vm_config_key, sub_machine.config_procs)
|
||||
|
|
|
@ -855,6 +855,12 @@ en:
|
|||
provider_not_found: |-
|
||||
The provider '%{provider}' could not be found, but was requested to
|
||||
back the machine '%{machine}'. Please use a provider that exists.
|
||||
provider_not_usable: |-
|
||||
The provider '%{provider}' that was requested to back the machine
|
||||
'%{machine}' is reporting that it isn't usable on this system. The
|
||||
reason is shown below:
|
||||
|
||||
%{message}
|
||||
provisioner_flag_invalid: |-
|
||||
'%{name}' is not a known provisioner. Please specify a valid
|
||||
provisioner.
|
||||
|
|
|
@ -26,7 +26,14 @@ describe Vagrant::Vagrantfile do
|
|||
|
||||
# A helper to register a provider for use in tests.
|
||||
def register_provider(name, config_class=nil, options=nil)
|
||||
provider_cls = Class.new(Vagrant.plugin("2", :provider))
|
||||
provider_cls = Class.new(Vagrant.plugin("2", :provider)) do
|
||||
if options && options[:unusable]
|
||||
def self.usable?(raise_error=false)
|
||||
raise Vagrant::Errors::VagrantError if raise_error
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
register_plugin("2") do |p|
|
||||
p.provider(name, options) { provider_cls }
|
||||
|
@ -298,6 +305,13 @@ describe Vagrant::Vagrantfile do
|
|||
expect { subject.machine_config(:default, :foo, boxes) }.
|
||||
to raise_error(Vagrant::Errors::ProviderNotFound)
|
||||
end
|
||||
|
||||
it "raises an error if the provider is not usable" do
|
||||
register_provider("foo", nil, unusable: true)
|
||||
|
||||
expect { subject.machine_config(:default, :foo, boxes) }.
|
||||
to raise_error(Vagrant::Errors::ProviderNotUsable)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#machine_names" do
|
||||
|
|
Loading…
Reference in New Issue