From e09077ee332d993b6407261df4dadf6538e38b13 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 9 Mar 2017 10:29:47 -0800 Subject: [PATCH 1/2] Add box from local path and use generic name --- test/acceptance/provider-virtualbox/linked_clone_spec.rb | 2 +- test/acceptance/provider-virtualbox/network_intnet_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/acceptance/provider-virtualbox/linked_clone_spec.rb b/test/acceptance/provider-virtualbox/linked_clone_spec.rb index f2b45ee2e..44d55fa7f 100644 --- a/test/acceptance/provider-virtualbox/linked_clone_spec.rb +++ b/test/acceptance/provider-virtualbox/linked_clone_spec.rb @@ -9,7 +9,7 @@ shared_examples 'provider/linked_clone' do |provider, options| before do environment.skeleton('linked_clone') - assert_execute('vagrant', 'box', 'add', options[:box]) + assert_execute('vagrant', 'box', 'add', 'box', options[:box]) end after do diff --git a/test/acceptance/provider-virtualbox/network_intnet_spec.rb b/test/acceptance/provider-virtualbox/network_intnet_spec.rb index 8219637c1..1976ceea9 100644 --- a/test/acceptance/provider-virtualbox/network_intnet_spec.rb +++ b/test/acceptance/provider-virtualbox/network_intnet_spec.rb @@ -8,7 +8,7 @@ shared_examples "provider/network/intnet" do |provider, options| before do environment.skeleton("network_intnet") - assert_execute("vagrant", "box", "add", options[:box]) + assert_execute("vagrant", "box", "add", "box", options[:box]) assert_execute("vagrant", "up", "--provider=#{provider}") end From dcdcf3f013ca7519c316d5dc3148faa0abe0da25 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 9 Mar 2017 10:35:06 -0800 Subject: [PATCH 2/2] Add entry point for running vagrant-spec --- .gitignore | 3 + test/vagrant-spec/Vagrantfile.spec | 72 +++++++++++++++++++ test/vagrant-spec/boxes/.keep | 0 .../configs/vagrant-spec.config.virtualbox.rb | 10 +++ .../scripts/ubuntu-run.virtualbox.sh | 8 +++ .../scripts/ubuntu-setup.virtualbox.sh | 12 ++++ 6 files changed, 105 insertions(+) create mode 100644 test/vagrant-spec/Vagrantfile.spec create mode 100644 test/vagrant-spec/boxes/.keep create mode 100644 test/vagrant-spec/configs/vagrant-spec.config.virtualbox.rb create mode 100644 test/vagrant-spec/scripts/ubuntu-run.virtualbox.sh create mode 100644 test/vagrant-spec/scripts/ubuntu-setup.virtualbox.sh diff --git a/.gitignore b/.gitignore index 681341552..21e59b03d 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ doc/ .ruby-gemset .ruby-version .rvmrc + +# Box storage for spec +test/vagrant-spec/boxes/*.box \ No newline at end of file diff --git a/test/vagrant-spec/Vagrantfile.spec b/test/vagrant-spec/Vagrantfile.spec new file mode 100644 index 000000000..a8043a636 --- /dev/null +++ b/test/vagrant-spec/Vagrantfile.spec @@ -0,0 +1,72 @@ +# Guest boxes to use for vagrant-spec +GUEST_BOXES = { + 'spox/ubuntu-16.04' => '0.0.1', + 'spox/centos-7' => '0.0.1', + 'spox/windows-10' => '0.0.1', + 'spox/osx-10.12' => '0.0.1' +} + +# Host boxes to run vagrant-spec +HOST_BOXES = { + 'spox/ubuntu-16.04' => '0.0.1', + 'spox/centos-7' => '0.0.1', + 'spox/windows-10' => '0.0.1', + 'spox/osx-10.12' => '0.0.1' +} + +# Determine what providers to test +enabled_providers = ENV.fetch("VAGRANT_SPEC_PROVIDERS", "virtualbox").split(",") +# Set what boxes should be used +enabled_guests = ENV["VAGRANT_GUEST_BOXES"] ? ENV["VAGRANT_GUEST_BOXES"].split(",") : GUEST_BOXES.keys +enabled_hosts = ENV["VAGRANT_HOST_BOXES"] ? ENV["VAGRANT_HOST_BOXES"].split(",") : HOST_BOXES.keys + +guest_boxes = Hash[GUEST_BOXES.find_all{|name, version| enabled_guests.include?(name)}.compact] +host_boxes = Hash[HOST_BOXES.find_all{|name, version| enabled_hosts.include?(name)}.compact] + +# Download copies of the guest boxes for testing if missing +enabled_providers.each do |provider_name| + guest_boxes.each do |guest_box, box_version| + box_owner, box_name = guest_box.split('/') + box_path = File.join(File.dirname(__FILE__), "./boxes/#{guest_box.sub('/', '_')}.#{provider_name}.#{box_version}.box") + if !File.exist?(box_path) + $stderr.puts "Downloading guest box #{guest_box}" + result = system("curl -Lf -o #{box_path} \"https://atlas.hashicorp.com/#{box_owner}/boxes/#{box_name}/versions/#{box_version}/providers/#{provider_name}.box\"") + if !result + $stderr.puts + $stderr.puts "ERROR: Failed to download guest box #{guest_box} for #{provider_name}!" + exit 1 + end + end + end +end + +Vagrant.configure(2) do |global_config| + host_boxes.each do |box_name, box_version| + platform = box_name.split('/').last.sub(/[^a-z]+$/, '') + + enabled_providers.each do |provider_name| + global_config.vm.define("#{box_name.split('/').last}-#{provider_name}") do |config| + config.vm.box = box_name + config.vm.box_version = box_version + config.vm.synced_folder '.', '/vagrant', disable: true + config.vm.synced_folder '../../', '/vagrant' + config.vm.provider :vmware_workstation do |vmware| + vmware.vmx["memsize"] = "2048" + vmware.vmx['vhv.enable'] = 'TRUE' + vmware.vmx['vhv.allow'] = 'TRUE' + end + config.vm.provision :shell, path: "./scripts/#{platform}-setup.#{provider_name}.sh" + GUEST_BOXES.each do |guest_box, box_version| + config.vm.provision( + :shell, + path: "./scripts/#{platform}-run.#{provider_name}.sh", + keep_color: true, + env: { + "VAGRANT_SPEC_BOX" => "/vagrant/test/vagrant-spec/boxes/#{guest_box.sub('/', '_')}.#{provider_name}.#{box_version}.box" + } + ) + end + end + end + end +end diff --git a/test/vagrant-spec/boxes/.keep b/test/vagrant-spec/boxes/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/vagrant-spec/configs/vagrant-spec.config.virtualbox.rb b/test/vagrant-spec/configs/vagrant-spec.config.virtualbox.rb new file mode 100644 index 000000000..850d1bfc1 --- /dev/null +++ b/test/vagrant-spec/configs/vagrant-spec.config.virtualbox.rb @@ -0,0 +1,10 @@ +require_relative "../../acceptance/base" + +Vagrant::Spec::Acceptance.configure do |c| + c.component_paths << File.expand_path("../test/acceptance", __FILE__) + c.skeleton_paths << File.expand_path("../test/acceptance/skeletons", __FILE__) + + c.provider "virtualbox", + box: ENV["VAGRANT_SPEC_BOX"], + contexts: ["provider-context/virtualbox"] +end diff --git a/test/vagrant-spec/scripts/ubuntu-run.virtualbox.sh b/test/vagrant-spec/scripts/ubuntu-run.virtualbox.sh new file mode 100644 index 000000000..17153557f --- /dev/null +++ b/test/vagrant-spec/scripts/ubuntu-run.virtualbox.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -x + +export VAGRANT_SPEC_BOX="${VAGRANT_SPEC_BOX}" +vagrant vagrant-spec /vagrant/test/vagrant-spec/configs/vagrant-spec.config.virtualbox.rb +result=$? + +exit $result diff --git a/test/vagrant-spec/scripts/ubuntu-setup.virtualbox.sh b/test/vagrant-spec/scripts/ubuntu-setup.virtualbox.sh new file mode 100644 index 000000000..af3ddac08 --- /dev/null +++ b/test/vagrant-spec/scripts/ubuntu-setup.virtualbox.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -xe + +apt-get update -q +apt-get install -qy virtualbox + +pushd /vagrant + +dpkg -i ./pkg/dist/vagrant_*_x86_64.deb +vagrant plugin install ./vagrant-spec.gem + +popd