lib/kitchen/driver/vagrant.rb in kitchen-vagrant-1.0.2 vs lib/kitchen/driver/vagrant.rb in kitchen-vagrant-1.1.0

- old
+ new

@@ -84,14 +84,15 @@ default_config(:vm_hostname) do |driver| driver.windows_os? ? nil : "#{driver.instance.name}.vagrantup.com" end - default_config(:cache_directory) do |driver| - driver.windows_os? ? "/omnibus/cache" : "/tmp/omnibus/cache" - end + default_config :cache_directory, false + default_config :kitchen_cache_directory, + File.expand_path("~/.kitchen/cache") + default_config :cachier, nil no_parallel_for :create, :destroy # Creates a Vagrant VM instance. @@ -135,10 +136,24 @@ FileUtils.rm_rf(vagrant_root) info("Vagrant instance #{instance.to_str} destroyed.") state.delete(:hostname) end + def package(state) + if state[:hostname].nil? + raise UserError, "Vagrant instance not created!" + end + if not (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") + run("#{config[:vagrant_binary]} package --output #{box_name}") + destroy(state) + end + # A lifecycle method that should be invoked when the object is about # ready to be used. A reference to an Instance is required as # configuration dependant data may be access through an Instance. This # also acts as a hook point where the object may wish to perform other # last minute checks, validations, or configuration expansions. @@ -180,12 +195,15 @@ # 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 - return if disable_cache? - config[:cache_directory] + if enable_cache? && !config[:cache_directory] + windows_os? ? "/omnibus/cache" : "/tmp/omnibus/cache" + else + config[:cache_directory] + end end protected WEBSITE = "http://www.vagrantup.com/downloads.html".freeze @@ -212,21 +230,25 @@ # @api private def bento_box?(name) name =~ /^(centos|debian|fedora|freebsd|opensuse|ubuntu|oracle)-/ end - # Return true if we found the criteria to disable the cache_directory + # Returns whether or not the we expect the box to work with shared folders + # by matching against a whitelist of bento boxes + # @return [TrueClass,FalseClass] whether or not the box shoud work with + # shared folders + # @api private + def safe_share?(box) + box =~ /^bento\/(centos|debian|fedora|opensuse|ubuntu|oracle)-/ + end + + # Return true if we found the criteria to enable the cache_directory # functionality - def disable_cache? - # Disable for Windows not using Virtualbox - if windows_host? && config[:provider] != "virtualbox" || - instance.platform.name =~ /(freebsd|macos|osx)/ || - # Disable if cache_directory is set to "false" on .kitchen.yml - !config[:cache_directory] + def enable_cache? + if safe_share?(config[:box]) return true end - # Otherwise false end # Renders and writes out a Vagrantfile dedicated to this instance. @@ -460,10 +482,10 @@ end # @return [String] full absolute path to the kitchen cache directory # @api private def local_kitchen_cache - @local_kitchen_cache ||= File.expand_path("~/.kitchen/cache") + @local_kitchen_cache ||= config[:kitchen_cache_directory] end # @return [String] full local path to the directory containing the # instance's Vagrantfile # @api private