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:
|
||||
|
||||
- `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)
|
||||
|
||||
|
|
|
@ -328,32 +328,16 @@ module Vagrant
|
|||
config, config_warnings, config_errors = \
|
||||
@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
|
||||
if config.vm.box
|
||||
# Determine the box formats we support
|
||||
formats = provider_options[:box_format]
|
||||
formats ||= provider
|
||||
formats = [formats] if !formats.is_a?(Array)
|
||||
box = find_box(config.vm.box, box_formats) if config.vm.box
|
||||
|
||||
@logger.info("Provider-supported box formats: #{formats.inspect}")
|
||||
formats.each do |format|
|
||||
begin
|
||||
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
|
||||
if box
|
||||
@logger.info("Box found with format: #{format}")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
# Set this variable in order to keep track of if the box changes
|
||||
# too many times.
|
||||
original_box = config.vm.box
|
||||
|
||||
load_box_and_overrides = lambda do
|
||||
# If a box was found, then we attempt to load the Vagrantfile for
|
||||
# that box. We don't require a box since we allow providers to download
|
||||
# boxes and so on.
|
||||
|
@ -381,6 +365,22 @@ module Vagrant
|
|||
@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
|
||||
|
||||
# Load the box and overrides configuration
|
||||
load_box_and_overrides.call
|
||||
|
||||
# Get the provider configuration from the final loaded configuration
|
||||
provider_config = config.vm.get_provider_config(provider)
|
||||
|
||||
|
@ -686,6 +686,39 @@ module Vagrant
|
|||
Pathname.new(path)
|
||||
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.
|
||||
#
|
||||
# @param [Pathname] path Path to search in.
|
||||
|
|
Loading…
Reference in New Issue