lib/kitchen/driver/vagrant.rb in kitchen-vagrant-0.21.0 vs lib/kitchen/driver/vagrant.rb in kitchen-vagrant-0.21.1

- old
+ new

@@ -82,10 +82,14 @@ default_config(:vm_hostname) do |driver| driver.windows_os? ? nil : driver.instance.name end + default_config(:cache_directory) do |driver| + driver.windows_os? ? "/omnibus/cache" : "/tmp/omnibus/cache" + end + no_parallel_for :create, :destroy # Creates a Vagrant VM instance. # # @param state [Hash] mutable instance state @@ -171,11 +175,12 @@ # Setting up the `cache_directory` to store omnibus packages in cache # and share a local folder to that directory so that we don't pull them # down every single time def cache_directory - windows_os? ? "$env:TEMP\\omnibus\\cache" : "/tmp/omnibus/cache" + return if disable_cache? + config[:cache_directory] end protected WEBSITE = "http://www.vagrantup.com/downloads.html".freeze @@ -199,13 +204,29 @@ # # @return [TrueClass,FalseClass] whether or not the name could be a Bento # box # @api private def bento_box?(name) - name =~ /^(centos|debian|fedora|freebsd|opensuse|ubuntu)-/ + name =~ /^(centos|debian|fedora|freebsd|opensuse|ubuntu|oracle)-/ end + # Return true if we found the criteria to disable the cache_directory + # functionality + def disable_cache? + # Disable for Windows not using Virtualbox + if windows_host? && config[:provider] != "virtualbox" || + # Disable for FreeBSD + instance.platform.name == "freebsd" || + # Disable if cache_directory is set to "false" on .kitchen.yml + !config[:cache_directory] + return true + end + + # Otherwise + false + end + # Renders and writes out a Vagrantfile dedicated to this instance. # # @api private def create_vagrantfile return if @vagrantfile_created @@ -335,10 +356,11 @@ # Since vagrant does not support being run through bundler, we escape # any bundler environment should we detect one. Otherwise, subcommands # will inherit our bundled environment. # @see https://github.com/test-kitchen/kitchen-vagrant/issues/190 # @see Kitchen::ShellOut#run_command + # rubocop:disable Metrics/CyclomaticComplexity def run_command(cmd, options = {}) merged = { :use_sudo => config[:use_sudo], :log_subject => name, :environment => {} @@ -353,19 +375,31 @@ env = merged[:environment] %w[BUNDLE_BIN_PATH BUNDLE_GEMFILE GEM_HOME GEM_PATH GEM_ROOT RUBYLIB RUBYOPT _ORIGINAL_GEM_PATH].each do |var| env[var] = nil end - gem_home = ENV["GEM_HOME"] - if gem_home && (env["PATH"] || ENV["PATH"]) - env["PATH"] ||= ENV["PATH"].dup if ENV["PATH"] - gem_bin = File.join(gem_home, "bin") + File::PATH_SEPARATOR - env["PATH"][gem_bin] = "" if env["PATH"].include?(gem_bin) + + # Altering the path seems to break vagrant. When the :environment + # is passed to a windows process with a PATH, Vagrant's batch installer + # (https://github.com/mitchellh/vagrant-installers/blob/master/substrate + # /modules/vagrant_installer/templates/windows_vagrant.bat.erb) + # does not efectively prepend the vagrant ruby path in a persistent + # manner which causes vagrant to use the same ruby as test-kitchen and + # then the environment is essentially corrupted leading to many errors + # and dispair + unless windows_host? + gem_home = ENV["GEM_HOME"] + if gem_home && (env["PATH"] || ENV["PATH"]) + env["PATH"] ||= ENV["PATH"].dup if ENV["PATH"] + gem_bin = File.join(gem_home, "bin") + File::PATH_SEPARATOR + env["PATH"][gem_bin] = "" if env["PATH"].include?(gem_bin) + end end super(cmd, merged) end + # rubocop:enable Metrics/CyclomaticComplexity # Runs a local command before `vagrant up` has been called. # # @api private def run_pre_create_command @@ -469,9 +503,16 @@ raise UserError, "WinRM Transport requires the vagrant-winrm " \ "Vagrant plugin to properly communicate with this Vagrant VM. " \ "Please install this plugin with: " \ "`vagrant plugin install vagrant-winrm' and try again." end + end + + # @return [true,false] whether or not the host is windows + # + # @api private + def windows_host? + RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ end # @return [true,false] whether or not the vagrant-winrm plugin is # installed # @api private