diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index c9c113056..5108b232d 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -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 diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index 2b83b254d..bd6c1b71b 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -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) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a28684dd2..5c8c26bc1 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -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. diff --git a/test/unit/vagrant/vagrantfile_test.rb b/test/unit/vagrant/vagrantfile_test.rb index 0cdcf29c9..17971e738 100644 --- a/test/unit/vagrant/vagrantfile_test.rb +++ b/test/unit/vagrant/vagrantfile_test.rb @@ -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