provisioners/chef: put global lock around knife exec

This commit is contained in:
Mitchell Hashimoto 2014-08-06 10:24:05 -07:00
parent 22395e5cb4
commit 2cdcc29902
4 changed files with 33 additions and 9 deletions

View File

@ -23,6 +23,7 @@ BUG FIXES:
- hosts/arch: NFS works with latest versions. [GH-4224] - hosts/arch: NFS works with latest versions. [GH-4224]
- hosts/windows: RDP command works without crash. [GH-3962] - hosts/windows: RDP command works without crash. [GH-3962]
- providers/virtualbox: Increase network device limit to 36. [GH-4206] - providers/virtualbox: Increase network device limit to 36. [GH-4206]
- provisioners/chef: Chef client cleanup should work. [GH-4099]
- provisioners/puppet: Manifest file can be a directory. [GH-4169] - provisioners/puppet: Manifest file can be a directory. [GH-4169]
- provisioners/puppet: Properly escape facter variables for PowerShell - provisioners/puppet: Properly escape facter variables for PowerShell
on Windows guests. [GH-3959] on Windows guests. [GH-3959]

View File

@ -1,7 +1,10 @@
require "pathname" require "pathname"
require "tempfile" require "tempfile"
require "thread"
module Vagrant module Vagrant
@@global_lock = Mutex.new
# This is the default endpoint of the Vagrant Cloud in # This is the default endpoint of the Vagrant Cloud in
# use. API calls will be made to this for various functions # use. API calls will be made to this for various functions
# of Vagrant that may require remote access. # of Vagrant that may require remote access.
@ -9,6 +12,15 @@ module Vagrant
# @return [String] # @return [String]
DEFAULT_SERVER_URL = "https://vagrantcloud.com" DEFAULT_SERVER_URL = "https://vagrantcloud.com"
# This holds a global lock for the duration of the block. This should
# be invoked around anything that is modifying process state (such as
# environmental variables).
def self.global_lock
@@global_lock.synchronize do
return yield
end
end
# This returns a true/false showing whether we're running from the # This returns a true/false showing whether we're running from the
# environment setup by the Vagrant installers. # environment setup by the Vagrant installers.
# #

View File

@ -1,4 +1,6 @@
require 'pathname' require 'pathname'
require 'vagrant'
require 'vagrant/util/subprocess' require 'vagrant/util/subprocess'
require File.expand_path("../base", __FILE__) require File.expand_path("../base", __FILE__)
@ -106,15 +108,17 @@ module VagrantPlugins
# Knife is not part of the current Vagrant bundle, so it needs to run # Knife is not part of the current Vagrant bundle, so it needs to run
# in the context of the system. # in the context of the system.
Bundler.with_clean_env do Vagrant.global_lock do
command = ["knife", deletable, "delete", "--yes", node_name] Bundler.with_clean_env do
r = Vagrant::Util::Subprocess.execute(*command) command = ["knife", deletable, "delete", "--yes", node_name]
if r.exit_code != 0 r = Vagrant::Util::Subprocess.execute(*command)
@machine.ui.error(I18n.t( if r.exit_code != 0
"vagrant.chef_client_cleanup_failed", @machine.ui.error(I18n.t(
deletable: deletable, "vagrant.chef_client_cleanup_failed",
stdout: r.stdout, deletable: deletable,
stderr: r.stderr)) stdout: r.stdout,
stderr: r.stderr))
end
end end
end end
end end

View File

@ -8,6 +8,13 @@ describe Vagrant do
subject { described_class } subject { described_class }
describe "#global_lock" do
it "yields to the block" do
result = subject.global_lock { 42 }
expect(result).to eq(42)
end
end
describe "#in_installer?" do describe "#in_installer?" do
it "is not if env is not set" do it "is not if env is not set" do
with_temp_env("VAGRANT_INSTALLER_ENV" => nil) do with_temp_env("VAGRANT_INSTALLER_ENV" => nil) do