core: Environment#default_provider can look into machines
This commit is contained in:
parent
4d85e0e145
commit
768d453739
|
@ -308,10 +308,19 @@ module Vagrant
|
|||
# that (the default behavior)
|
||||
return default if default && opts[:force_default]
|
||||
|
||||
# Determine the config to use to look for provider definitions. By
|
||||
# default it is the global but if we're targeting a specific machine,
|
||||
# then look there.
|
||||
root_config = vagrantfile.config
|
||||
if opts[:machine]
|
||||
machine_info = vagrantfile.machine_config(opts[:machine], nil, nil)
|
||||
root_config = machine_info[:config]
|
||||
end
|
||||
|
||||
# Get the list of providers within our configuration and assign
|
||||
# a priority to each in the order they exist so that we try these first.
|
||||
config = {}
|
||||
vagrantfile.config.vm.__providers.each_with_index do |key, idx|
|
||||
root_config.vm.__providers.each_with_index do |key, idx|
|
||||
config[key] = idx
|
||||
end
|
||||
|
||||
|
|
|
@ -114,24 +114,30 @@ module Vagrant
|
|||
name: name, provider: provider
|
||||
end
|
||||
|
||||
provider_plugin = Vagrant.plugin("2").manager.providers[provider]
|
||||
if !provider_plugin
|
||||
raise Errors::ProviderNotFound,
|
||||
machine: name, provider: provider
|
||||
end
|
||||
provider_plugin = nil
|
||||
provider_cls = nil
|
||||
provider_options = {}
|
||||
box_formats = nil
|
||||
if provider != nil
|
||||
provider_plugin = Vagrant.plugin("2").manager.providers[provider]
|
||||
if !provider_plugin
|
||||
raise Errors::ProviderNotFound,
|
||||
machine: name, provider: provider
|
||||
end
|
||||
|
||||
provider_cls = provider_plugin[0]
|
||||
provider_options = provider_plugin[1]
|
||||
box_formats = provider_options[:box_format] || provider
|
||||
provider_cls = provider_plugin[0]
|
||||
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
|
||||
# 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
|
||||
end
|
||||
|
||||
# Add the sub-machine configuration to the loader and keys
|
||||
|
@ -153,7 +159,7 @@ module Vagrant
|
|||
local_keys = keys.dup
|
||||
|
||||
# Load the box Vagrantfile, if there is one
|
||||
if config.vm.box
|
||||
if config.vm.box && boxes
|
||||
box = boxes.find(config.vm.box, box_formats, config.vm.box_version)
|
||||
if box
|
||||
box_vagrantfile = find_vagrantfile(box.directory)
|
||||
|
|
|
@ -822,7 +822,7 @@ VF
|
|||
end
|
||||
end
|
||||
|
||||
it "is the provider in the Vagrantfile that is usable" do
|
||||
it "is the highest usable provider outside the Vagrantfile" do
|
||||
subject.vagrantfile.config.vm.provider "foo"
|
||||
subject.vagrantfile.config.vm.finalize!
|
||||
|
||||
|
@ -835,6 +835,23 @@ VF
|
|||
expect(subject.default_provider).to eq(:bar)
|
||||
end
|
||||
end
|
||||
|
||||
it "is the provider in the Vagrantfile that is usable for a machine" do
|
||||
subject.vagrantfile.config.vm.provider "foo"
|
||||
subject.vagrantfile.config.vm.define "sub" do |v|
|
||||
v.vm.provider "bar"
|
||||
end
|
||||
subject.vagrantfile.config.vm.finalize!
|
||||
|
||||
plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }]
|
||||
plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }]
|
||||
plugin_providers[:baz] = [provider_usable_class(true), { priority: 2 }]
|
||||
plugin_providers[:boom] = [provider_usable_class(true), { priority: 3 }]
|
||||
|
||||
with_temp_env("VAGRANT_DEFAULT_PROVIDER" => nil) do
|
||||
expect(subject.default_provider(machine: :sub)).to eq(:bar)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "local data path" do
|
||||
|
|
|
@ -149,6 +149,21 @@ describe Vagrant::Vagrantfile do
|
|||
expect(results[:provider_cls]).to equal(provider_cls)
|
||||
end
|
||||
|
||||
it "configures without a provider or boxes" do
|
||||
register_provider("foo")
|
||||
|
||||
configure do |config|
|
||||
config.vm.box = "foo"
|
||||
end
|
||||
|
||||
results = subject.machine_config(:default, nil, nil)
|
||||
box = results[:box]
|
||||
config = results[:config]
|
||||
expect(config.vm.box).to eq("foo")
|
||||
expect(box).to be_nil
|
||||
expect(results[:provider_cls]).to be_nil
|
||||
end
|
||||
|
||||
it "configures with sub-machine config" do
|
||||
register_provider("foo")
|
||||
|
||||
|
|
Loading…
Reference in New Issue