Handle box overrides in provider-specific overrides properly [GH-1617]
This commit is contained in:
parent
780a312fc9
commit
661b982502
|
@ -13,6 +13,8 @@ IMPROVEMENTS:
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
|
||||||
- `vagrant package --base` works again. [GH-1615]
|
- `vagrant package --base` works again. [GH-1615]
|
||||||
|
- Box overrides specified in provider config overrides no longer
|
||||||
|
fail to detect the box. [GH-1617]
|
||||||
|
|
||||||
## 1.2.1 (April 17, 2013)
|
## 1.2.1 (April 17, 2013)
|
||||||
|
|
||||||
|
|
|
@ -328,58 +328,58 @@ module Vagrant
|
||||||
config, config_warnings, config_errors = \
|
config, config_warnings, config_errors = \
|
||||||
@config_loader.load([:default, :home, :root, vm_config_key])
|
@config_loader.load([:default, :home, :root, vm_config_key])
|
||||||
|
|
||||||
|
# Determine the possible box formats for any boxes and find the box
|
||||||
|
box_formats = provider_options[:box_format] || provider
|
||||||
box = nil
|
box = nil
|
||||||
if config.vm.box
|
box = find_box(config.vm.box, box_formats) if config.vm.box
|
||||||
# Determine the box formats we support
|
|
||||||
formats = provider_options[:box_format]
|
|
||||||
formats ||= provider
|
|
||||||
formats = [formats] if !formats.is_a?(Array)
|
|
||||||
|
|
||||||
@logger.info("Provider-supported box formats: #{formats.inspect}")
|
# Set this variable in order to keep track of if the box changes
|
||||||
formats.each do |format|
|
# too many times.
|
||||||
begin
|
original_box = config.vm.box
|
||||||
box = boxes.find(config.vm.box, format.to_s)
|
|
||||||
rescue Errors::BoxUpgradeRequired
|
|
||||||
# Upgrade the box if we must
|
|
||||||
@logger.info("Upgrading box during config load: #{config.vm.box}")
|
|
||||||
boxes.upgrade(config.vm.box)
|
|
||||||
retry
|
|
||||||
end
|
|
||||||
|
|
||||||
# If a box was found, we exit
|
load_box_and_overrides = lambda do
|
||||||
if box
|
# If a box was found, then we attempt to load the Vagrantfile for
|
||||||
@logger.info("Box found with format: #{format}")
|
# that box. We don't require a box since we allow providers to download
|
||||||
break
|
# boxes and so on.
|
||||||
|
if box
|
||||||
|
box_vagrantfile = find_vagrantfile(box.directory)
|
||||||
|
if box_vagrantfile
|
||||||
|
# The box has a custom Vagrantfile, so we load that into the config
|
||||||
|
# as well.
|
||||||
|
@logger.info("Box exists with Vagrantfile. Reloading machine config.")
|
||||||
|
box_config_key = "box_#{box.name}_#{box.provider}".to_sym
|
||||||
|
@config_loader.set(box_config_key, box_vagrantfile)
|
||||||
|
config, config_warnings, config_errors = \
|
||||||
|
@config_loader.load([:default, box_config_key, :home, :root, vm_config_key])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# If a box was found, then we attempt to load the Vagrantfile for
|
# If there are provider overrides for the machine, then we run
|
||||||
# that box. We don't require a box since we allow providers to download
|
# those as well.
|
||||||
# boxes and so on.
|
provider_overrides = config.vm.get_provider_overrides(provider)
|
||||||
if box
|
if provider_overrides.length > 0
|
||||||
box_vagrantfile = find_vagrantfile(box.directory)
|
@logger.info("Applying #{provider_overrides.length} provider overrides. Reloading config.")
|
||||||
if box_vagrantfile
|
provider_override_key = "vm_#{name}_#{config.vm.box}_#{provider}".to_sym
|
||||||
# The box has a custom Vagrantfile, so we load that into the config
|
@config_loader.set(provider_override_key, provider_overrides)
|
||||||
# as well.
|
|
||||||
@logger.info("Box exists with Vagrantfile. Reloading machine config.")
|
|
||||||
box_config_key = "box_#{box.name}_#{box.provider}".to_sym
|
|
||||||
@config_loader.set(box_config_key, box_vagrantfile)
|
|
||||||
config, config_warnings, config_errors = \
|
config, config_warnings, config_errors = \
|
||||||
@config_loader.load([:default, box_config_key, :home, :root, vm_config_key])
|
@config_loader.load([:default, box_config_key, :home, :root, vm_config_key, provider_override_key])
|
||||||
|
end
|
||||||
|
|
||||||
|
if config.vm.box && original_box != config.vm.box
|
||||||
|
# The box changed, probably due to the provider override. Let's
|
||||||
|
# run the configuration one more time with the new box.
|
||||||
|
# TODO: previous original box
|
||||||
|
@logger.info("Box changed to: #{config.vm.box}. Reloading configurations.")
|
||||||
|
original_box = config.vm.box
|
||||||
|
box = find_box(config.vm.box, box_formats)
|
||||||
|
|
||||||
|
# Recurse so that we reload all the configurations
|
||||||
|
load_box_and_overrides.call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# If there are provider overrides for the machine, then we run
|
# Load the box and overrides configuration
|
||||||
# those as well.
|
load_box_and_overrides.call
|
||||||
provider_overrides = config.vm.get_provider_overrides(provider)
|
|
||||||
if provider_overrides.length > 0
|
|
||||||
@logger.info("Applying #{provider_overrides.length} provider overrides. Reloading config.")
|
|
||||||
provider_override_key = "vm_#{name}_#{config.vm.box}_#{provider}".to_sym
|
|
||||||
@config_loader.set(provider_override_key, provider_overrides)
|
|
||||||
config, config_warnings, config_errors = \
|
|
||||||
@config_loader.load([:default, box_config_key, :home, :root, vm_config_key, provider_override_key])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get the provider configuration from the final loaded configuration
|
# Get the provider configuration from the final loaded configuration
|
||||||
provider_config = config.vm.get_provider_config(provider)
|
provider_config = config.vm.get_provider_config(provider)
|
||||||
|
@ -398,11 +398,11 @@ module Vagrant
|
||||||
"config/messages",
|
"config/messages",
|
||||||
:warnings => config_warnings,
|
:warnings => config_warnings,
|
||||||
:errors => config_errors).chomp
|
:errors => config_errors).chomp
|
||||||
@ui.send(level, I18n.t("vagrant.general.config_upgrade_messages",
|
@ui.send(level, I18n.t("vagrant.general.config_upgrade_messages",
|
||||||
:output => output))
|
:output => output))
|
||||||
|
|
||||||
# If we had errors, then we bail
|
# If we had errors, then we bail
|
||||||
raise Errors::ConfigUpgradeErrors if !config_errors.empty?
|
raise Errors::ConfigUpgradeErrors if !config_errors.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create the machine and cache it for future calls. This will also
|
# Create the machine and cache it for future calls. This will also
|
||||||
|
@ -686,6 +686,39 @@ module Vagrant
|
||||||
Pathname.new(path)
|
Pathname.new(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This finds a box for the given name and formats, or returns nil
|
||||||
|
# if the box isn't found.
|
||||||
|
#
|
||||||
|
# @param [String] name Name of the box
|
||||||
|
# @param [Array<Symbol>] formats The formats to search for the box.
|
||||||
|
# @return [Box]
|
||||||
|
def find_box(name, formats)
|
||||||
|
# Determine the box formats we support
|
||||||
|
formats = [formats] if !formats.is_a?(Array)
|
||||||
|
|
||||||
|
@logger.info("Provider-supported box formats: #{formats.inspect}")
|
||||||
|
formats.each do |format|
|
||||||
|
box = nil
|
||||||
|
|
||||||
|
begin
|
||||||
|
box = boxes.find(name, format.to_s)
|
||||||
|
rescue Errors::BoxUpgradeRequired
|
||||||
|
# Upgrade the box if we must
|
||||||
|
@logger.info("Upgrading box during config load: #{name}")
|
||||||
|
boxes.upgrade(name)
|
||||||
|
retry
|
||||||
|
end
|
||||||
|
|
||||||
|
# If a box was found, we exit
|
||||||
|
if box
|
||||||
|
@logger.info("Box found with format: #{format}")
|
||||||
|
return box
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
# Finds the Vagrantfile in the given directory.
|
# Finds the Vagrantfile in the given directory.
|
||||||
#
|
#
|
||||||
# @param [Pathname] path Path to search in.
|
# @param [Pathname] path Path to search in.
|
||||||
|
@ -797,7 +830,7 @@ module Vagrant
|
||||||
|
|
||||||
# Upgrade complete! Let the user know
|
# Upgrade complete! Let the user know
|
||||||
@ui.info(I18n.t("vagrant.general.upgraded_v1_dotfile",
|
@ui.info(I18n.t("vagrant.general.upgraded_v1_dotfile",
|
||||||
:backup_path => backup_file.to_s))
|
:backup_path => backup_file.to_s))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue