diff options
author | Ryan Hass <rhass@chef.io> | 2016-10-11 09:53:23 -0700 |
---|---|---|
committer | Ryan Hass <rhass@chef.io> | 2016-10-11 09:57:11 -0700 |
commit | 8856a0e4309e23315e2a185f46e2c9f5e19d93ba (patch) | |
tree | f4d2e408cd110e00b6e77eb10e68d5f9533b7681 | |
parent | acb39bdddeabc0cce914ea43c304da80239a849e (diff) | |
parent | 5e7c3b96f125c6a07c6c48c0d27899100b3be9a6 (diff) | |
download | chef-8856a0e4309e23315e2a185f46e2c9f5e19d93ba.tar.gz |
Merge branch 'master' into rhass/release_12.15.18rhass/release_12.15.18
[ci skip]
Signed-off-by: Ryan Hass <rhass@chef.io>
-rw-r--r-- | .github/PULL_REQUEST_TEMPLATE.md | 16 | ||||
-rw-r--r-- | Gemfile.lock | 10 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | chef-config/lib/chef-config/version.rb | 2 | ||||
-rw-r--r-- | lib/chef/dsl/declare_resource.rb | 10 | ||||
-rw-r--r-- | lib/chef/version.rb | 2 | ||||
-rw-r--r-- | spec/integration/recipes/accumulator_spec.rb | 236 |
7 files changed, 268 insertions, 10 deletions
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000..a15e5747cc --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ +### Description + +[Please describe what this change achieves] + +### Issues Resolved + +[List any existing issues this PR resolves, or any Discourse or +StackOverflow discussion that's relevant] + +### Check List + +- [ ] New functionality includes tests +- [ ] All tests pass +- [ ] Documentation, especially RELEASE\_NOTES.md, has been updated if + required +- [ ] All commits have been signed-off for the Developer Certificate of Origin. See <https://github.com/chef/chef/blob/master/CONTRIBUTING.md#developer-certification-of-origin-dco> diff --git a/Gemfile.lock b/Gemfile.lock index defe1e2b6e..81bea1748d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -33,10 +33,10 @@ GIT PATH remote: . specs: - chef (12.15.21) + chef (12.15.24) addressable bundler (>= 1.10) - chef-config (= 12.15.21) + chef-config (= 12.15.24) chef-zero (>= 4.8) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -62,10 +62,10 @@ PATH specinfra (~> 2.10) syslog-logger (~> 1.6) uuidtools (~> 2.1.5) - chef (12.15.21-universal-mingw32) + chef (12.15.24-universal-mingw32) addressable bundler (>= 1.10) - chef-config (= 12.15.21) + chef-config (= 12.15.24) chef-zero (>= 4.8) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -106,7 +106,7 @@ PATH PATH remote: chef-config specs: - chef-config (12.15.21) + chef-config (12.15.24) addressable fuzzyurl mixlib-config (~> 2.0) @@ -1 +1 @@ -12.15.21
\ No newline at end of file +12.15.24
\ No newline at end of file diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index deec2b1966..42ff4feb24 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -21,7 +21,7 @@ module ChefConfig CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__) - VERSION = "12.15.21" + VERSION = "12.15.24" end # diff --git a/lib/chef/dsl/declare_resource.rb b/lib/chef/dsl/declare_resource.rb index 86227a0f9d..ed3083e1ca 100644 --- a/lib/chef/dsl/declare_resource.rb +++ b/lib/chef/dsl/declare_resource.rb @@ -119,7 +119,13 @@ class Chef # def edit_resource!(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block) resource = find_resource!(type, name, run_context: run_context) - resource.instance_eval(&resource_attrs_block) if block_given? + if resource_attrs_block + if defined?(new_resource) + resource.instance_exec(new_resource, &resource_attrs_block) + else + resource.instance_exec(&resource_attrs_block) + end + end resource end @@ -200,7 +206,7 @@ class Chef def find_resource(type, name, created_at: nil, run_context: self.run_context, &resource_attrs_block) find_resource!(type, name, run_context: run_context) rescue Chef::Exceptions::ResourceNotFound - if block_given? + if resource_attrs_block declare_resource(type, name, created_at, run_context: run_context, &resource_attrs_block) end # returns nil otherwise end diff --git a/lib/chef/version.rb b/lib/chef/version.rb index fa2afd7074..8f1ef68efb 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -21,7 +21,7 @@ class Chef CHEF_ROOT = File.expand_path("../..", __FILE__) - VERSION = "12.15.21" + VERSION = "12.15.24" end # diff --git a/spec/integration/recipes/accumulator_spec.rb b/spec/integration/recipes/accumulator_spec.rb new file mode 100644 index 0000000000..b2107b2c02 --- /dev/null +++ b/spec/integration/recipes/accumulator_spec.rb @@ -0,0 +1,236 @@ +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" + +describe "Accumulators" do + include IntegrationSupport + include Chef::Mixin::ShellOut + + let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + + # Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the + # following constraints are satisfied: + # * Windows: windows can only run batch scripts as bare executables. Rubygems + # creates batch wrappers for installed gems, but we don't have batch wrappers + # in the source tree. + # * Other `chef-client` in PATH: A common case is running the tests on a + # machine that has omnibus chef installed. In that case we need to ensure + # we're running `chef-client` from the source tree and not the external one. + # cf. CHEF-4914 + let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" } + + let(:aliases_temppath) do + t = Tempfile.new("chef_accumulator_test") + path = t.path + t.close + t.unlink + path + end + + when_the_repository "edit_resource-based delayed accumulators work" do + before do + directory "cookbooks/x" do + file "resources/email_alias.rb", <<-EOM + provides :email_alias + resource_name :email_alias + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + with_run_context :root do + edit_resource(:template, "#{aliases_temppath}") do |new_resource| + source "aliases.erb" + variables[:aliases] ||= {} + variables[:aliases][new_resource.address] ||= [] + variables[:aliases][new_resource.address] += new_resource.recipients + action :nothing + end + end + log "force delayed notification" do + notifies :create, "template[#{aliases_temppath}]", :delayed + end + end + EOM + + file "resources/nested.rb", <<-EOM + provides :nested + resource_name :nested + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + email_alias address do + recipients new_resource.recipients + end + end + EOM + + file "resources/doubly_nested.rb", <<-EOM + provides :doubly_nested + resource_name :doubly_nested + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + nested address do + recipients new_resource.recipients + end + end + EOM + + file "recipes/default.rb", <<-EOM + email_alias "outer1" do + recipients [ "out1a", "out1b" ] + end + + nested "nested1" do + recipients [ "nested1a", "nested1b" ] + end + + email_alias "outer2" do + recipients [ "out2a", "out2b" ] + end + + doubly_nested "nested2" do + recipients [ "nested2a", "nested2b" ] + end + + email_alias "outer3" do + recipients [ "out3a", "out3b" ] + end + EOM + + file "templates/aliases.erb", <<-EOM.gsub(/^\s+/, "") + <%= pp @aliases %> + EOM + end # directory 'cookbooks/x' + end + + it "should complete with success" do + file "config/client.rb", <<-EOM + local_mode true + cookbook_path "#{path_to('cookbooks')}" + log_level :warn + EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + result.error! + # runs only a single template resource (in the outer run context, as a delayed resource) + expect(result.stdout.scan(/template\S+ action create/).size).to eql(1) + # hash order is insertion order in ruby >= 1.9, so this next line does test that all calls were in the correct order + expect(IO.read(aliases_temppath).chomp).to eql('{"outer1"=>["out1a", "out1b"], "nested1"=>["nested1a", "nested1b"], "outer2"=>["out2a", "out2b"], "nested2"=>["nested2a", "nested2b"], "outer3"=>["out3a", "out3b"]}') + end + end + + when_the_repository "find_resource-based delayed accumulators work" do + before do + directory "cookbooks/x" do + file "resources/email_alias.rb", <<-EOM + provides :email_alias + resource_name :email_alias + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + r = with_run_context :root do + find_resource(:template, "#{aliases_temppath}") do + source "aliases.erb" + variables[:aliases] = {} + action :nothing + end + end + r.variables[:aliases][address] ||= [] + r.variables[:aliases][address] += new_resource.recipients + log "force delayed notification" do + notifies :create, "template[#{aliases_temppath}]", :delayed + end + end + EOM + + file "resources/nested.rb", <<-EOM + provides :nested + resource_name :nested + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + email_alias address do + recipients new_resource.recipients + end + end + EOM + + file "resources/doubly_nested.rb", <<-EOM + provides :doubly_nested + resource_name :doubly_nested + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + nested address do + recipients new_resource.recipients + end + end + EOM + + file "recipes/default.rb", <<-EOM + email_alias "outer1" do + recipients [ "out1a", "out1b" ] + end + + nested "nested1" do + recipients [ "nested1a", "nested1b" ] + end + + email_alias "outer2" do + recipients [ "out2a", "out2b" ] + end + + doubly_nested "nested2" do + recipients [ "nested2a", "nested2b" ] + end + + email_alias "outer3" do + recipients [ "out3a", "out3b" ] + end + EOM + + file "templates/aliases.erb", <<-EOM.gsub(/^\s+/, "") + <%= pp @aliases %> + EOM + end # directory 'cookbooks/x' + end + + it "should complete with success" do + file "config/client.rb", <<-EOM + local_mode true + cookbook_path "#{path_to('cookbooks')}" + log_level :warn + EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + result.error! + # runs only a single template resource (in the outer run context, as a delayed resource) + expect(result.stdout.scan(/template\S+ action create/).size).to eql(1) + # hash order is insertion order in ruby >= 1.9, so this next line does test that all calls were in the correct order + expect(IO.read(aliases_temppath).chomp).to eql('{"outer1"=>["out1a", "out1b"], "nested1"=>["nested1a", "nested1b"], "outer2"=>["out2a", "out2b"], "nested2"=>["nested2a", "nested2b"], "outer3"=>["out3a", "out3b"]}') + end + end +end |