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/windows: RDP command works without crash. [GH-3962]
- 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: Properly escape facter variables for PowerShell
on Windows guests. [GH-3959]

View File

@ -1,7 +1,10 @@
require "pathname"
require "tempfile"
require "thread"
module Vagrant
@@global_lock = Mutex.new
# This is the default endpoint of the Vagrant Cloud in
# use. API calls will be made to this for various functions
# of Vagrant that may require remote access.
@ -9,6 +12,15 @@ module Vagrant
# @return [String]
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
# environment setup by the Vagrant installers.
#

View File

@ -1,4 +1,6 @@
require 'pathname'
require 'vagrant'
require 'vagrant/util/subprocess'
require File.expand_path("../base", __FILE__)
@ -106,6 +108,7 @@ module VagrantPlugins
# Knife is not part of the current Vagrant bundle, so it needs to run
# in the context of the system.
Vagrant.global_lock do
Bundler.with_clean_env do
command = ["knife", deletable, "delete", "--yes", node_name]
r = Vagrant::Util::Subprocess.execute(*command)
@ -121,4 +124,5 @@ module VagrantPlugins
end
end
end
end
end

View File

@ -8,6 +8,13 @@ describe Vagrant do
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
it "is not if env is not set" do
with_temp_env("VAGRANT_INSTALLER_ENV" => nil) do