Merge pull request #6543 from mitchellh/sethvargo/chef_delete
Perform Chef delete operations on the guest instead of the host
This commit is contained in:
commit
f7fc3c07e4
|
@ -63,12 +63,6 @@ module VagrantPlugins
|
|||
errors << I18n.t("vagrant.config.chef.validation_key_path")
|
||||
end
|
||||
|
||||
if delete_client || delete_node
|
||||
if !Vagrant::Util::Which.which("knife")
|
||||
errors << I18n.t("vagrant.chef_config_knife_not_found")
|
||||
end
|
||||
end
|
||||
|
||||
{ "chef client provisioner" => errors }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,8 +31,8 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def cleanup
|
||||
delete_from_chef_server('client') if @config.delete_client
|
||||
delete_from_chef_server('node') if @config.delete_node
|
||||
delete_from_chef_server('client') if @config.delete_client
|
||||
end
|
||||
|
||||
def create_client_key_folder
|
||||
|
@ -116,6 +116,10 @@ module VagrantPlugins
|
|||
end
|
||||
end
|
||||
|
||||
def guest_client_rb_path
|
||||
File.join(guest_provisioning_path, "client.rb")
|
||||
end
|
||||
|
||||
def guest_validation_key_path
|
||||
File.join(guest_provisioning_path, "validation.pem")
|
||||
end
|
||||
|
@ -130,23 +134,13 @@ module VagrantPlugins
|
|||
return
|
||||
end
|
||||
|
||||
@machine.ui.info(I18n.t(
|
||||
"vagrant.provisioners.chef.deleting_from_server",
|
||||
@machine.ui.info(I18n.t("vagrant.provisioners.chef.deleting_from_server",
|
||||
deletable: deletable, name: node_name))
|
||||
|
||||
# Knife is not part of the current Vagrant bundle, so it needs to run
|
||||
# in the context of the system.
|
||||
Vagrant.global_lock do
|
||||
command = ["knife", deletable, "delete", "--yes", node_name]
|
||||
r = Vagrant::Util::Subprocess.execute(*command)
|
||||
if r.exit_code != 0
|
||||
@machine.ui.error(I18n.t(
|
||||
"vagrant.chef_client_cleanup_failed",
|
||||
deletable: deletable,
|
||||
stdout: r.stdout,
|
||||
stderr: r.stderr))
|
||||
end
|
||||
end
|
||||
command = "knife #{deletable} delete #{node_name}"
|
||||
command << " --config '#{guest_client_rb_path}'"
|
||||
command << " --yes"
|
||||
@machine.communicate.sudo(command, error_check: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -96,41 +96,5 @@ describe VagrantPlugins::Chef::Config::ChefClient do
|
|||
expect(errors).to eq([I18n.t("vagrant.config.chef.validation_key_path")])
|
||||
end
|
||||
end
|
||||
|
||||
context "when #delete_client is given" do
|
||||
before { subject.delete_client = true }
|
||||
|
||||
context "when knife does not exist" do
|
||||
before do
|
||||
allow(Vagrant::Util::Which)
|
||||
.to receive(:which)
|
||||
.with("knife")
|
||||
.and_return(nil)
|
||||
end
|
||||
|
||||
it "returns an error" do
|
||||
subject.finalize!
|
||||
expect(errors).to eq([I18n.t("vagrant.chef_config_knife_not_found")])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when #delete_node is given" do
|
||||
before { subject.delete_node = true }
|
||||
|
||||
context "when knife does not exist" do
|
||||
before do
|
||||
allow(Vagrant::Util::Which)
|
||||
.to receive(:which)
|
||||
.with("knife")
|
||||
.and_return(nil)
|
||||
end
|
||||
|
||||
it "returns an error" do
|
||||
subject.finalize!
|
||||
expect(errors).to eq([I18n.t("vagrant.chef_config_knife_not_found")])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue