lib/kitchen/driver/vagrant.rb in kitchen-vagrant-1.5.2 vs lib/kitchen/driver/vagrant.rb in kitchen-vagrant-1.6.0
- old
+ new
@@ -38,20 +38,20 @@
kitchen_driver_api_version 2
plugin_version Kitchen::Driver::VAGRANT_VERSION
- default_config(:box) { |driver| driver.default_box }
+ default_config(:box, &:default_box)
required_config :box
default_config :box_check_update, nil
default_config :box_download_insecure, nil
default_config :box_download_ca_cert, nil
- default_config(:box_url) { |driver| driver.default_box_url }
+ default_config(:box_url, &:default_box_url)
default_config :box_version, nil
default_config :boot_timeout, nil
@@ -147,11 +147,12 @@
def package(state)
if state[:hostname].nil?
raise UserError, "Vagrant instance not created!"
end
- if not (config[:ssh] && config[:ssh][:insert_key] == false)
+
+ unless config[:ssh] && config[:ssh][:insert_key] == false
m = "Disable vagrant ssh key replacement to preserve the default key!"
warn(m)
end
instance.transport.connection(state).close
box_name = File.join(Dir.pwd, instance.name + ".box")
@@ -245,18 +246,20 @@
# @return [TrueClass,FalseClass] whether or not the box shoud work with
# shared folders
# @api private
def safe_share?(box)
return false if config[:provider] =~ /(hyperv|libvirt)/
- box =~ /^bento\/(centos|debian|fedora|opensuse|ubuntu|oracle|amazonlinux)-/
+
+ box =~ %r{^bento/(centos|debian|fedora|opensuse|ubuntu|oracle|amazonlinux)-}
end
# Return true if we found the criteria to enable the cache_directory
# functionality
def enable_cache?
return false unless config[:cache_directory]
return true if safe_share?(config[:box])
+
# Otherwise
false
end
# Renders and writes out a Vagrantfile dedicated to this instance.
@@ -289,11 +292,12 @@
#
# @api private
def finalize_ca_cert!
unless config[:box_download_ca_cert].nil?
config[:box_download_ca_cert] = File.expand_path(
- config[:box_download_ca_cert], config[:kitchen_root])
+ config[:box_download_ca_cert], config[:kitchen_root]
+ )
end
end
# Replaces any `{{vagrant_root}}` tokens in the pre create command.
#
@@ -342,12 +346,12 @@
#
# @api private
def finalize_vm_hostname!
string = config[:vm_hostname]
- if windows_os? && string.is_a?(String) && string.size >= 12
- config[:vm_hostname] = "#{string[0...10]}-#{string[-1]}"
+ if windows_os? && string.is_a?(String) && string.size > 15
+ config[:vm_hostname] = "#{string[0...12]}-#{string[-1]}"
end
end
# If Hyper-V and no network configuration
# check KITCHEN_HYPERV_SWITCH and fallback to helper method
@@ -380,14 +384,15 @@
# @return [String] the contents for a Vagrantfile
# @raise [ActionFailed] if the Vagrantfile template was not found
# @api private
def render_template
template = File.expand_path(
- config[:vagrantfile_erb], config[:kitchen_root])
+ config[:vagrantfile_erb], config[:kitchen_root]
+ )
if File.exist?(template)
- ERB.new(IO.read(template)).result(binding).gsub(%r{^\s*$\n}, "")
+ ERB.new(IO.read(template)).result(binding).gsub(/^\s*$\n/, "")
else
raise ActionFailed, "Could not find Vagrantfile template #{template}"
end
end
@@ -430,12 +435,12 @@
# "A Hard Problem"(TM), we simply blow away all known bundler
# related changes.
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
+ env[var] = nil
+ end
# 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)
@@ -527,22 +532,23 @@
# invocation
# @api private
def vagrant_config(type)
lines = run_silently("#{config[:vagrant_binary]} #{type}-config")
.split("\n").map do |line|
- tokens = line.strip.partition(" ")
- [tokens.first, tokens.last.delete('"')]
- end
+ tokens = line.strip.partition(" ")
+ [tokens.first, tokens.last.delete('"')]
+ end
Hash[lines]
end
# @return [String] version of Vagrant
# @raise [UserError] if the `vagrant` command can not be found locally
# @api private
def vagrant_version
self.class.vagrant_version ||= run_silently(
- "#{config[:vagrant_binary]} --version", cwd: Dir.pwd)
+ "#{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}."
end
@@ -581,10 +587,11 @@
# @api private
def winrm_plugin_installed?
return true if self.class.winrm_plugin_passed
self.class.winrm_plugin_passed = run_silently(
- "#{config[:vagrant_binary]} plugin list", cwd: Dir.pwd)
+ "#{config[:vagrant_binary]} plugin list", cwd: Dir.pwd
+ )
.split("\n").find { |line| line =~ /vagrant-winrm\s+/ }
end
end
end
end