lib/kitchen/driver/vagrant.rb in kitchen-vagrant-1.6.1 vs lib/kitchen/driver/vagrant.rb in kitchen-vagrant-1.7.0

- old
+ new

@@ -43,10 +43,14 @@ default_config(:box, &:default_box) required_config :box default_config :box_check_update, nil + default_config :box_auto_update, nil + + default_config :box_auto_prune, nil + default_config :box_download_insecure, nil default_config :box_download_ca_cert, nil default_config(:box_url, &:default_box_url) @@ -107,10 +111,12 @@ # @param state [Hash] mutable instance state # @raise [ActionFailed] if the action could not be completed def create(state) create_vagrantfile run_pre_create_command + run_box_auto_update + run_box_auto_prune run_vagrant_up update_state(state) instance.transport.connection(state).wait_until_ready info("Vagrant instance #{instance.to_str} created.") end @@ -170,10 +176,12 @@ # @return [self] itself, for use in chaining # @raise [ClientError] if instance parameter is nil def finalize_config!(instance) super finalize_vm_hostname! + finalize_box_auto_update! + finalize_box_auto_prune! finalize_pre_create_command! finalize_synced_folders! finalize_ca_cert! finalize_network! self @@ -297,10 +305,24 @@ config[:box_download_ca_cert], config[:kitchen_root] ) end end + # Create vagrant command to update box to the latest version + def finalize_box_auto_update! + return if config[:box_auto_update].nil? + + config[:box_auto_update] = "vagrant box update #{'--insecure ' if config[:box_download_insecure]}--box #{config[:box]}" + end + + # Create vagrant command to remove older versions of the box + def finalize_box_auto_prune! + return if config[:box_auto_prune].nil? + + config[:box_auto_prune] = "vagrant box prune --name #{config[:box]}" + end + # Replaces any `{{vagrant_root}}` tokens in the pre create command. # # @api private def finalize_pre_create_command! return if config[:pre_create_command].nil? @@ -458,9 +480,23 @@ end super(cmd, merged) end # rubocop:enable Metrics/CyclomaticComplexity + + # Tell vagrant to update vagrant box to latest version + def run_box_auto_update + if config[:box_auto_update] + run(config[:box_auto_update]) + end + end + + # Tell vagrant to remove older vagrant boxes + def run_box_auto_prune + if config[:box_auto_prune] + run(config[:box_auto_prune]) + end + end # Runs a local command before `vagrant up` has been called. # # @api private def run_pre_create_command