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

Make vagrant binary a parameter #219

Merged
merged 1 commit into from
Mar 30, 2016
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
14 changes: 9 additions & 5 deletions lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Vagrant < Kitchen::Driver::Base

default_config :synced_folders, []

default_config :vagrant_binary, "vagrant"

default_config :vagrantfile_erb,
File.join(File.dirname(__FILE__), "../../../templates/Vagrantfile.erb")
expand_path_for :vagrantfile_erb
Expand Down Expand Up @@ -121,7 +123,7 @@ def destroy(state)
create_vagrantfile
@vagrantfile_created = false
instance.transport.connection(state).close
run("vagrant destroy -f")
run("#{config[:vagrant_binary]} destroy -f")
FileUtils.rm_rf(vagrant_root)
info("Vagrant instance #{instance.to_str} destroyed.")
state.delete(:hostname)
Expand Down Expand Up @@ -365,7 +367,7 @@ def run_silently(cmd, options = {})
#
# @api private
def run_vagrant_up
cmd = "vagrant up"
cmd = "#{config[:vagrant_binary]} up"
cmd += " --no-provision" unless config[:provision]
cmd += " --provider #{config[:provider]}" if config[:provider]
run(cmd)
Expand Down Expand Up @@ -403,7 +405,8 @@ def vagrant_root
# invocation
# @api private
def vagrant_config(type)
lines = run_silently("vagrant #{type}-config").split("\n").map do |line|
lines = run_silently("#{config[:vagrant_binary]} #{type}-config").
split("\n").map do |line|
tokens = line.strip.partition(" ")
[tokens.first, tokens.last.gsub(/"/, "")]
end
Expand All @@ -415,7 +418,8 @@ def vagrant_config(type)
# @api private
def vagrant_version
self.class.vagrant_version ||= run_silently(
"vagrant --version", :cwd => Dir.pwd).chomp.split(" ").last
"#{config[:vagrant_binary]} --version", :cwd => Dir.pwd).
chomp.split(" ").last
rescue Errno::ENOENT
raise UserError, "Vagrant #{MIN_VER} or higher is not installed." \
" Please download a package from #{WEBSITE}."
Expand Down Expand Up @@ -448,7 +452,7 @@ def winrm_plugin_installed?
return true if self.class.winrm_plugin_passed

self.class.winrm_plugin_passed = run_silently(
"vagrant plugin list", :cwd => Dir.pwd).
"#{config[:vagrant_binary]} plugin list", :cwd => Dir.pwd).
split("\n").find { |line| line =~ /^vagrant-winrm\s+/ }
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ def run_command(_cmd, options = {})
])
end

it "sets :vagrant_binary to 'vagrant' by default" do
expect(driver[:vagrant_binary]).to eq("vagrant")
end

it "sets :vagrant_binary to a custom value" do
config[:vagrant_binary] = "vagrant.cmd"
expect(driver[:vagrant_binary]).to eq("vagrant.cmd")
end

it "sets :vagrantfile_erb to a default" do
expect(driver[:vagrantfile_erb]).to match(
%r{/kitchen-vagrant/templates/Vagrantfile\.erb$}
Expand Down