Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only set custom :box & :box_url values for known Bento boxes. #151

Merged
merged 1 commit into from
Mar 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ module Driver
# @author Fletcher Nichol <[email protected]>
class Vagrant < Kitchen::Driver::SSHBase

default_config :box do |driver|
"opscode-#{driver.instance.platform.name}"
end
default_config(:box) { |driver| driver.default_box }
required_config :box

default_config :box_check_update, nil
Expand Down Expand Up @@ -82,16 +80,26 @@ def create(state)
info("Vagrant instance #{instance.to_str} created.")
end

# @return [String,nil] the Vagrant box for this Instance
def default_box
if bento_boxes.include?(instance.platform.name)
"opscode-#{instance.platform.name}"
else
instance.platform.name
end
end

# @return [String,nil] the Vagrant box URL for this Instance
def default_box_url
# No default neede for 1.5 onwards - Vagrant Cloud only needs a box name
return if Gem::Version.new(vagrant_version) >= Gem::Version.new(1.5)
return unless bento_boxes.include?(instance.platform.name)

bucket = config[:provider]
bucket = "vmware" if config[:provider] =~ /^vmware_(.+)$/
provider = config[:provider]
provider = "vmware" if config[:provider] =~ /^vmware_(.+)$/

"https://opscode-vm-bento.s3.amazonaws.com/vagrant/#{bucket}/" \
"opscode_#{instance.platform.name}_chef-provisionerless.box"
if %w[virtualbox vmware].include?(provider)
"https://opscode-vm-bento.s3.amazonaws.com/vagrant/#{provider}/" \
"opscode_#{instance.platform.name}_chef-provisionerless.box"
end
end

# Destroys an instance.
Expand Down Expand Up @@ -149,6 +157,19 @@ def verify_dependencies
WEBSITE = "http://www.vagrantup.com/downloads.html".freeze
MIN_VER = "1.1.0".freeze

# Retuns a list of Vagrant base boxes produced by the Bento project
# (https://github.com/chef/bento).
#
# @return [Arrau<String>] list of Bento box names
# @api private
def bento_boxes
%W[
centos-5.11 centos-6.6 centos-7.0 debian-6.0.10 debian-7.8 fedora-20
fedora-21 freebsd-9.3 freebsd-10.1 opensuse-13.1 ubuntu-10.04
ubuntu-12.04 ubuntu-14.04 ubuntu-14.10
].map { |name| [name, "#{name}-i386"] }.flatten
end

# Renders and writes out a Vagrantfile dedicated to this instance.
#
# @api private
Expand Down
104 changes: 54 additions & 50 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,62 @@

describe "configuration" do

it "sets :box based on the platform name by default" do
expect(driver[:box]).to eq("opscode-fooos-99")
context "for known bento platform names" do

before { allow(platform).to receive(:name) { "ubuntu-14.04" } }

it "sets :box based on the platform name by default" do
expect(driver[:box]).to eq("opscode-ubuntu-14.04")
end

it "sets :box to a custom value" do
config[:box] = "booya"

expect(driver[:box]).to eq("booya")
end

it "sets :box_url to a bento box URL for a virtualbox provider" do
config[:provider] = "virtualbox"

expect(driver[:box_url]).to eq(
"https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/" \
"opscode_ubuntu-14.04_chef-provisionerless.box"
)
end

it "sets :box_url to a bento box URL for a vmware-based provider" do
config[:provider] = "vmware_awesometown"

expect(driver[:box_url]).to eq(
"https://opscode-vm-bento.s3.amazonaws.com/vagrant/vmware/" \
"opscode_ubuntu-14.04_chef-provisionerless.box"
)
end

it "sets :box_url to nil for any other provider" do
config[:provider] = "the-next-coolness"

expect(driver[:box_url]).to eq(nil)
end
end

it "sets :box to a custom value" do
config[:box] = "booya"
context "for unknown bento platform names" do

before { allow(platform).to receive(:name) { "slackware-14.1" } }

expect(driver[:box]).to eq("booya")
it "sets :box based on the platform name by default" do
expect(driver[:box]).to eq("slackware-14.1")
end

it "sets :box to a custom value" do
config[:box] = "booya"

expect(driver[:box]).to eq("booya")
end

it "sets :box_url to nil" do
expect(driver[:box_url]).to eq(nil)
end
end

it "sets :box_check_update to nil by default" do
Expand Down Expand Up @@ -256,45 +304,6 @@

expect(driver[:vm_hostname]).to eq("okay")
end

context "with old versions of Vagrant" do

before { with_old_vagrant }

it "sets :box_url to a default based platform" do
expect(driver[:box_url]).to eq(
"https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/" \
"opscode_fooos-99_chef-provisionerless.box"
)
end

it "sets :box_url to a default based on provider" do
config[:provider] = "vcool"

expect(driver[:box_url]).to eq(
"https://opscode-vm-bento.s3.amazonaws.com/vagrant/vcool/" \
"opscode_fooos-99_chef-provisionerless.box"
)
end

it "sets :box_url to a default for vmware-based providers" do
config[:provider] = "vmware_awesometown"

expect(driver[:box_url]).to eq(
"https://opscode-vm-bento.s3.amazonaws.com/vagrant/vmware/" \
"opscode_fooos-99_chef-provisionerless.box"
)
end
end

context "with modern versions of Vagrant" do

before { with_modern_vagrant }

it "sets :box_url to nil" do
expect(driver[:box_url]).to eq(nil)
end
end
end

describe "#verify_dependencies" do
Expand Down Expand Up @@ -597,7 +606,7 @@
it "sets the vm.box" do
cmd

expect(vagrantfile).to match(regexify(%{c.vm.box = "opscode-fooos-99"}))
expect(vagrantfile).to match(regexify(%{c.vm.box = "fooos-99"}))
end

it "sets the vm.hostname" do
Expand Down Expand Up @@ -1016,11 +1025,6 @@ def with_modern_vagrant
with("vagrant --version", any_args).and_return("Vagrant 1.7.2")
end

def with_old_vagrant
allow(driver).to receive(:run_command).
with("vagrant --version", any_args).and_return("Vagrant 1.4.5")
end

def with_unsupported_vagrant
allow(driver).to receive(:run_command).
with("vagrant --version", any_args).and_return("Vagrant 1.0.5")
Expand Down