From b549cc45ee85924eaaec09c75abc520cccba7df5 Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 25 Mar 2016 20:20:45 +0100 Subject: [PATCH] Make vagrant binary configurable --- lib/kitchen/driver/vagrant.rb | 14 +++++++++----- spec/kitchen/driver/vagrant_spec.rb | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index bac22c00..07428e7a 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -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 @@ -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) @@ -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) @@ -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 @@ -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}." @@ -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 diff --git a/spec/kitchen/driver/vagrant_spec.rb b/spec/kitchen/driver/vagrant_spec.rb index 5b9ddcdd..e32da30e 100644 --- a/spec/kitchen/driver/vagrant_spec.rb +++ b/spec/kitchen/driver/vagrant_spec.rb @@ -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$}