Vagrant's environment (which includes the known list of boxes and
versions) is established at the start of the Vagrant run. This means
that box downloads which occur during the run are not contained in the
set until the next run. This causes duplicate box downloads to raise an
error in multi-machine Vagrantfiles.
This commit fixes that issue by pre-processing the machines by provider
and version, creating a unique set of boxes to update.
Fixes GH-6042
Vagrant::Box.load_metadata did not provide a way to specify the HTTPS
download options that could be specified when downloading boxes
(ca cert, ca path, client cert, insecure). As a result, while it was
possible to add a box whose metadata file needed to be downloaded with one of
those options specified, it was impossible to check for updates. The following
changes have been made to address the situation:
1. Create a DownloadMixins module to provide the --insecure, --cacert, --capth,
and --cert command line options to all of `vagrant box add`,
`vagrant box update`, and `vagrant box outdated`.
2. Extend `Vagrant::Box.has_update?` and `Vagrant::Box.load_metadata` to accept
said download options.
3. Extend `box outdated` and `box update` commands to pass download options
down.
4. Extend `Vagrant::Builtin::Action::BoxCheckOutdated` to honour download
options.
5. Options specified on the command line take precedence over options specified
in the machine configuration, if any.
6. Fix bug in `vagrant box add` where client cert was being passed down using
the wrong environment key.
7. Unit test coverage in update_test and box_check_outdated_test.
Resolves#4420
Example:
There are version 0.2.10 and 0.2.11 available. The latest update is version 0.2.12.
```
berendt/ubuntu-14.04-amd64 (virtualbox, 0.2.10)
berendt/ubuntu-14.04-amd64 (virtualbox, 0.2.11)
```
Without this patch it will be checked if a higher version than 0.2.10 is available.
```
Checking for updates to 'berendt/ubuntu-14.04-amd64'
Version constraints: > 0.2.10
Provider: virtualbox
Updating 'berendt/ubuntu-14.04-amd64' with provider 'virtualbox' from version
'0.2.10' to '0.2.12'...
Loading metadata for box 'https://vagrantcloud.com/berendt/ubuntu-14.04-amd64'
Adding box 'berendt/ubuntu-14.04-amd64' (v0.2.12) for provider: virtualbox
Downloading: https://vagrantcloud.com/berendt/ubuntu-14.04-amd64/version/23/provider/virtualbox.box
Successfully added box 'berendt/ubuntu-14.04-amd64' (v0.2.12) for 'virtualbox'!
```
with this patch it will be checked if a higher version than 0.2.11 is available (the expected behaviour).
```
Checking for updates to 'berendt/ubuntu-14.04-amd64'
Version constraints: > 0.2.11
Provider: virtualbox
Updating 'berendt/ubuntu-14.04-amd64' with provider 'virtualbox' from version
'0.2.11' to '0.2.12'...
Loading metadata for box 'https://vagrantcloud.com/berendt/ubuntu-14.04-amd64'
Adding box 'berendt/ubuntu-14.04-amd64' (v0.2.12) for provider: virtualbox
Downloading: https://vagrantcloud.com/berendt/ubuntu-14.04-amd64/version/23/provider/virtualbox.box
Successfully added box 'berendt/ubuntu-14.04-amd64' (v0.2.12) for 'virtualbox'!
```