From 4c9e6e46b2a6cf7b7949ab85e960957fdf5faf83 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 7 Mar 2014 09:18:34 -0800 Subject: [PATCH] provisioners/salt: don't use exteranl deep_merge [GH-2348] --- CHANGELOG.md | 2 ++ lib/vagrant/util/deep_merge.rb | 20 ++++++++++++++++ plugins/provisioners/salt/config.rb | 4 ++-- test/unit/vagrant/util/deep_merge_test.rb | 29 +++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 lib/vagrant/util/deep_merge.rb create mode 100644 test/unit/vagrant/util/deep_merge_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f5990446..12563b9fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -131,6 +131,8 @@ BUG FIXES: the newest versions of Docker. [GH-2874] - provisioners/puppet: Append default module path to the module paths always. [GH-2677] + - provisioners/salt: Setting pillar data doesn't require `deep_merge` + plugin anymore. [GH-2348] - provisioners/salt: Options can now set install type and install args. [GH-2766] - provisioners/salt: Fix case when salt would say "options only allowed diff --git a/lib/vagrant/util/deep_merge.rb b/lib/vagrant/util/deep_merge.rb new file mode 100644 index 000000000..3fb625d5f --- /dev/null +++ b/lib/vagrant/util/deep_merge.rb @@ -0,0 +1,20 @@ +module Vagrant + module Util + module DeepMerge + # This was lifted straight from Rails 4.0.2 as a basic Hash + # deep merge. + def self.deep_merge(myself, other_hash, &block) + myself = myself.dup + other_hash.each_pair do |k,v| + tv = myself[k] + if tv.is_a?(Hash) && v.is_a?(Hash) + myself[k] = deep_merge(tv, v, &block) + else + myself[k] = block && tv ? block.call(k, tv, v) : v + end + end + myself + end + end + end +end diff --git a/plugins/provisioners/salt/config.rb b/plugins/provisioners/salt/config.rb index 6ca014218..f91617224 100644 --- a/plugins/provisioners/salt/config.rb +++ b/plugins/provisioners/salt/config.rb @@ -1,5 +1,5 @@ -require "i18n" require "vagrant" +require "vagrant/util/deep_merge" module VagrantPlugins module Salt @@ -78,7 +78,7 @@ module VagrantPlugins def pillar(data) @pillar_data = {} if @pillar_data == UNSET_VALUE - @pillar_data.deep_merge!(data) + @pillar_data = Vagrant::Util::DeepMerge.deep_merge(@pillar_data, data) end def validate(machine) diff --git a/test/unit/vagrant/util/deep_merge_test.rb b/test/unit/vagrant/util/deep_merge_test.rb new file mode 100644 index 000000000..74f6fb70b --- /dev/null +++ b/test/unit/vagrant/util/deep_merge_test.rb @@ -0,0 +1,29 @@ +require File.expand_path("../../../base", __FILE__) + +require 'vagrant/util/deep_merge' + +describe Vagrant::Util::DeepMerge do + it "should deep merge hashes" do + original = { + "foo" => { + "bar" => "baz", + }, + "bar" => "blah", + } + + other = { + "foo" => { + "bar" => "new", + }, + } + + result = described_class.deep_merge(original, other) + expect(result).to_not equal(original) + expect(result).to eq({ + "foo" => { + "bar" => "new", + }, + "bar" => "blah", + }) + end +end