Skip to content

Commit

Permalink
[Fix #37] Ensure we got the key before destroying VM
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassiano Leal committed Aug 13, 2015
1 parent a7f5836 commit 5590428
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/vagrant-butcher/action/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def initialize(app, env)

def call(env)
if butcher_config(machine(env)).enabled
grab_key_from_guest(env) unless client_key_cached?(env)
cleanup(env)
else
env[:ui].warn "Vagrant::Butcher disabled, not cleaning up Chef server!"
Expand Down
5 changes: 4 additions & 1 deletion lib/vagrant-butcher/helpers/key_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def client_key_path(env)
@client_key_path ||= butcher_config(env).client_key || "#{cache_dir(env)}/#{key_filename(env)}"
end

def client_key_cached?(env)
File::exist?(client_key_path(env))
end

def copy_guest_key(env)
begin
grab_key_from_guest(env)
Expand Down Expand Up @@ -57,7 +61,6 @@ def cleanup_cache_dir(env)
def key_filename(env)
@key_filename ||= "#{env[:machine].name}-client.pem"
end

end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-butcher/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def provision(hook)
action_hook(:vagrant_butcher_copy_guest_key, :machine_action_provision, &method(:provision))

action_hook(:vagrant_butcher_cleanup, :machine_action_destroy) do |hook|
hook.before(::Vagrant::Action::Builtin::ProvisionerCleanup, Vagrant::Butcher::Action.cleanup)
hook.after(::Vagrant::Action::Builtin::DestroyConfirm, Vagrant::Butcher::Action.cleanup)
end

config("butcher") do
Expand Down

0 comments on commit 5590428

Please sign in to comment.