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")
|
errors << I18n.t("vagrant.config.chef.validation_key_path")
|
||||||
end
|
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 }
|
{ "chef client provisioner" => errors }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,8 +31,8 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup
|
def cleanup
|
||||||
delete_from_chef_server('client') if @config.delete_client
|
|
||||||
delete_from_chef_server('node') if @config.delete_node
|
delete_from_chef_server('node') if @config.delete_node
|
||||||
|
delete_from_chef_server('client') if @config.delete_client
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_client_key_folder
|
def create_client_key_folder
|
||||||
|
@ -116,6 +116,10 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def guest_client_rb_path
|
||||||
|
File.join(guest_provisioning_path, "client.rb")
|
||||||
|
end
|
||||||
|
|
||||||
def guest_validation_key_path
|
def guest_validation_key_path
|
||||||
File.join(guest_provisioning_path, "validation.pem")
|
File.join(guest_provisioning_path, "validation.pem")
|
||||||
end
|
end
|
||||||
|
@ -130,23 +134,13 @@ module VagrantPlugins
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@machine.ui.info(I18n.t(
|
@machine.ui.info(I18n.t("vagrant.provisioners.chef.deleting_from_server",
|
||||||
"vagrant.provisioners.chef.deleting_from_server",
|
|
||||||
deletable: deletable, name: node_name))
|
deletable: deletable, name: node_name))
|
||||||
|
|
||||||
# Knife is not part of the current Vagrant bundle, so it needs to run
|
command = "knife #{deletable} delete #{node_name}"
|
||||||
# in the context of the system.
|
command << " --config '#{guest_client_rb_path}'"
|
||||||
Vagrant.global_lock do
|
command << " --yes"
|
||||||
command = ["knife", deletable, "delete", "--yes", node_name]
|
@machine.communicate.sudo(command, error_check: true)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
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")])
|
expect(errors).to eq([I18n.t("vagrant.config.chef.validation_key_path")])
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue