From e625dba5abc292de37e2a940429690a47d337ca7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 7 Jul 2011 22:49:58 -0700 Subject: [PATCH] Multiple Chef provisioners no longer overwrite cookbook folders. [closes GH-407] --- CHANGELOG.md | 1 + lib/vagrant/provisioners/chef.rb | 4 +++- lib/vagrant/provisioners/chef_solo.rb | 10 ++++++---- test/vagrant/provisioners/chef_solo_test.rb | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 128c0ac57..5b6343ef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ `merge` technique. [GH-314] - Provisioner configuration is no longer cleared when the box needs to be downloaded during an `up`. [GH-308] + - Multiple Chef provisioners no longer overwrite cookbook folders. [GH-407] ## 0.7.6 (July 2, 2011) diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index bf61d5685..011fb4c31 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -76,6 +76,8 @@ module Vagrant class Chef < Base # This is the configuration which is available through `config.chef` class Config < Vagrant::Config::Base + extend Util::Counter + # Shared config attr_accessor :node_name attr_accessor :provisioning_path @@ -93,7 +95,7 @@ module Vagrant attr_accessor :run_list def initialize - @provisioning_path = "/tmp/vagrant-chef" + @provisioning_path = "/tmp/vagrant-chef-#{self.class.get_and_update_counter}" @log_level = :info @json = {} @http_proxy = nil diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index 7e7d0c4bb..7400636dd 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -4,8 +4,6 @@ module Vagrant class ChefSolo < Chef register :chef_solo - extend Util::Counter - class Config < Chef::Config attr_accessor :cookbooks_path attr_accessor :roles_path @@ -58,6 +56,7 @@ module Vagrant # path element which contains the folder location (:host or :vm) paths = [paths] if paths.is_a?(String) || paths.first.is_a?(Symbol) + index = 0 paths.map do |path| path = [:host, path] if !path.is_a?(Array) type, path = path @@ -66,7 +65,8 @@ module Vagrant # or VM path. local_path = nil local_path = File.expand_path(path, env.root_path) if type == :host - remote_path = type == :host ? "#{config.provisioning_path}/chef-solo-#{self.class.get_and_update_counter}" : path + remote_path = type == :host ? "#{config.provisioning_path}/chef-solo-#{index}" : path + index += 1 # Return the result [type, local_path, remote_path] @@ -76,10 +76,12 @@ module Vagrant # Shares the given folders with the given prefix. The folders should # be of the structure resulting from the `expanded_folders` function. def share_folders(prefix, folders) + index = 0 folders.each do |type, local_path, remote_path| if type == :host - env.config.vm.share_folder("v-#{prefix}-#{self.class.get_and_update_counter}", + env.config.vm.share_folder("v-#{prefix}-#{index}", remote_path, local_path, :nfs => config.nfs) + index += 1 end end end diff --git a/test/vagrant/provisioners/chef_solo_test.rb b/test/vagrant/provisioners/chef_solo_test.rb index 66fa85980..3f1c9088d 100644 --- a/test/vagrant/provisioners/chef_solo_test.rb +++ b/test/vagrant/provisioners/chef_solo_test.rb @@ -52,7 +52,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase should "expand host folders properly" do path = "foo" local_path = File.expand_path(path, @env.root_path) - remote_path = "#{@action.config.provisioning_path}/chef-solo-1" + remote_path = "#{@action.config.provisioning_path}/chef-solo-0" assert_equal [[:host, local_path, remote_path]], @action.expanded_folders([:host, path]) end end