chef 12.21.1 → 12.21.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc22d5fbbee25b481abe4fb3ba2ee92644e265a4
4
- data.tar.gz: e528ca22e29da3d99967cca0e00f6350ad4cf7f3
3
+ metadata.gz: 940ffb28debafbd614e98afd2da63753e6d354d2
4
+ data.tar.gz: 21e4e44090b891127901a1b55b0252c7e7197423
5
5
  SHA512:
6
- metadata.gz: 2e2c18119e148482bc477a38c9c62a1ce7d8cf348e8cbc80570b551ed4538f9771a8cfe0c7d3dc10e410cbef48eb31f2cdf8efe5de2cfba25f472573c30fb670
7
- data.tar.gz: fca9e5a4f9d4d54197e0bd1594ebb3fbc87636f9bba63135a98fcdbbd7d0b89be61d67eaff09ffbffb4b136b460016b0a4d32496a19cb088360a8ec9b89455a9
6
+ metadata.gz: c3cf414db8718169c4d6a4b8d5bf25c56c6d56c302814105ca9b7c9ac3d31f0f97afb71eb849ebaa153346f9e3d68bfd523199aba72a2d9f5a07cad21baf4ab0
7
+ data.tar.gz: f341b5778da53e3dd05f5d81d3df6df38424d094e9625400ba3d22f1b25b70028600dd76b7c680aea336c8139f04d0677210ee41aaf10ffb01fe5bf1a6a7708f
data/Gemfile CHANGED
@@ -74,7 +74,7 @@ group(:development, :test) do
74
74
 
75
75
  # for testing new chefstyle rules
76
76
  # gem 'chefstyle', github: 'chef/chefstyle'
77
- gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
77
+ gem "chefstyle", "= 0.5.0"
78
78
  end
79
79
 
80
80
  group(:changelog) do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 12.21.1
1
+ 12.21.4
@@ -18,6 +18,8 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
+ require "chef/exceptions"
22
+
21
23
  class Chef
22
24
  class DataCollector
23
25
  class ResourceReport
@@ -67,9 +69,9 @@ class Chef
67
69
  hash = {
68
70
  "type" => new_resource.resource_name.to_sym,
69
71
  "name" => new_resource.name.to_s,
70
- "id" => new_resource.identity.to_s,
71
- "after" => new_resource.state_for_resource_reporter,
72
- "before" => current_resource ? current_resource.state_for_resource_reporter : {},
72
+ "id" => resource_identity,
73
+ "after" => new_resource_state_reporter,
74
+ "before" => current_resource_state_reporter,
73
75
  "duration" => elapsed_time_in_milliseconds.to_s,
74
76
  "delta" => new_resource.respond_to?(:diff) && potentially_changed? ? new_resource.diff : "",
75
77
  "ignore_failure" => new_resource.ignore_failure,
@@ -83,13 +85,39 @@ class Chef
83
85
  hash["recipe_name"] = new_resource.recipe_name
84
86
  end
85
87
 
86
- hash["conditional"] = conditional.to_text if status == "skipped"
88
+ hash["conditional"] = conditional.to_text if status == "skipped"
87
89
  hash["error_message"] = exception.message unless exception.nil?
88
90
 
89
91
  hash
90
92
  end
91
93
  alias :to_h :to_hash
92
94
  alias :for_json :to_hash
95
+
96
+ # We should be able to call the identity of a resource safely, but there
97
+ # is an edge case where resources that have a lazy property that is both
98
+ # the name_property and the identity property, it will thow a validation
99
+ # exception causing the chef-client run to fail. We are not fixing this
100
+ # case since Chef is actually doing the right thing but we are making the
101
+ # ResourceReporter smarter so that it detects the failure and sends a
102
+ # message to the data collector containing a static resource identity
103
+ # since we were unable to generate a proper one.
104
+ def resource_identity
105
+ new_resource.identity.to_s
106
+ rescue => e
107
+ "unknown identity (due to #{e.class})"
108
+ end
109
+
110
+ def new_resource_state_reporter
111
+ new_resource.state_for_resource_reporter
112
+ rescue
113
+ {}
114
+ end
115
+
116
+ def current_resource_state_reporter
117
+ current_resource ? current_resource.state_for_resource_reporter : {}
118
+ rescue
119
+ {}
120
+ end
93
121
  end
94
122
  end
95
123
  end
@@ -51,7 +51,32 @@ class Chef
51
51
 
52
52
  class PolicyfileError < StandardError; end
53
53
 
54
- RunListExpansionIsh = Struct.new(:recipes, :roles)
54
+ RunListExpansionIsh = Struct.new(:recipes, :roles) do
55
+ # Implementing the parts of the RunListExpansion
56
+ # interface we need to properly send this through to
57
+ # events.run_list_expanded as it is expecting a RunListExpansion
58
+ # object.
59
+ def to_hash
60
+ # It looks like version only gets populated in the expanded_run_list when
61
+ # using a little used feature of roles to version lock cookbooks, so
62
+ # version is not reliable in here anyway (places like Automate UI are
63
+ # not getting version out of here.
64
+ #
65
+ # Skipped will always be false as it can only be true when two expanded
66
+ # roles contain the same recipe.
67
+ expanded_run_list = recipes.map do |r|
68
+ { type: "recipe", name: r, skipped: false, version: nil }
69
+ end
70
+ data_collector_hash = {}
71
+ data_collector_hash[:id] = "_policy_node"
72
+ data_collector_hash[:run_list] = expanded_run_list
73
+ data_collector_hash
74
+ end
75
+
76
+ def to_json(*opts)
77
+ to_hash.to_json(*opts)
78
+ end
79
+ end
55
80
 
56
81
  attr_reader :events
57
82
  attr_reader :node
@@ -137,6 +162,7 @@ class Chef
137
162
  Chef::Log.info("Run List expands to [#{run_list_with_versions_for_display.join(', ')}]")
138
163
 
139
164
  events.node_load_completed(node, run_list_with_versions_for_display, Chef::Config)
165
+ events.run_list_expanded(run_list_expansion_ish)
140
166
 
141
167
  node
142
168
  rescue Exception => e
data/lib/chef/version.rb CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  class Chef
23
23
  CHEF_ROOT = File.expand_path("../..", __FILE__)
24
- VERSION = "12.21.1"
24
+ VERSION = "12.21.4"
25
25
  end
26
26
 
27
27
  #
@@ -0,0 +1,145 @@
1
+ #
2
+ # Author:: Salim Afiune (<afiune@chef.io)
3
+ #
4
+ # Copyright:: Copyright 2012-2017, Chef Software Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require "spec_helper"
21
+
22
+ describe Chef::DataCollector::ResourceReport do
23
+ let(:cookbook_repo_path) { File.join(CHEF_SPEC_DATA, "cookbooks") }
24
+ let(:cookbook_collection) { Chef::CookbookCollection.new(Chef::CookbookLoader.new(cookbook_repo_path)) }
25
+ let(:node) { Chef::Node.new }
26
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
27
+ let(:run_context) { Chef::RunContext.new(node, cookbook_collection, events) }
28
+ let(:resource) { Chef::Resource.new("zelda", run_context) }
29
+ let(:report) { described_class.new(resource, :create) }
30
+
31
+ describe "#skipped" do
32
+ let(:conditional) { double("Chef::Resource::Conditional") }
33
+
34
+ it "should set status and conditional" do
35
+ report.skipped(conditional)
36
+ expect(report.conditional).to eq conditional
37
+ expect(report.status).to eq "skipped"
38
+ end
39
+ end
40
+
41
+ describe "#up_to_date" do
42
+ it "should set status" do
43
+ report.up_to_date
44
+ expect(report.status).to eq "up-to-date"
45
+ end
46
+ end
47
+
48
+ describe "#updated" do
49
+ it "should set status" do
50
+ report.updated
51
+ expect(report.status).to eq "updated"
52
+ end
53
+ end
54
+
55
+ describe "#elapsed_time_in_milliseconds" do
56
+
57
+ context "when elapsed_time is not set" do
58
+ it "should return nil" do
59
+ allow(report).to receive(:elapsed_time).and_return(nil)
60
+ expect(report.elapsed_time_in_milliseconds).to eq nil
61
+ end
62
+ end
63
+
64
+ context "when elapsed_time is set" do
65
+ it "should return it in milliseconds" do
66
+ allow(report).to receive(:elapsed_time).and_return(1)
67
+ expect(report.elapsed_time_in_milliseconds).to eq 1000
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "#failed" do
73
+ let(:exception) { double("Chef::Exception::Test") }
74
+
75
+ it "should set exception and status" do
76
+ report.failed(exception)
77
+ expect(report.exception).to eq exception
78
+ expect(report.status).to eq "failed"
79
+ end
80
+ end
81
+
82
+ describe "#to_hash" do
83
+ context "for a simple_resource" do
84
+ let(:resource) do
85
+ klass = Class.new(Chef::Resource) do
86
+ resource_name "zelda"
87
+ end
88
+ klass.new("hyrule", run_context)
89
+ end
90
+ let(:hash) do
91
+ {
92
+ "after" => {},
93
+ "before" => {},
94
+ "delta" => "",
95
+ "duration" => "",
96
+ "id" => "hyrule",
97
+ "ignore_failure" => false,
98
+ "name" => "hyrule",
99
+ "result" => "create",
100
+ "status" => "unprocessed",
101
+ "type" => :zelda,
102
+ }
103
+ end
104
+
105
+ it "returns a hash containing the expected values" do
106
+ expect(report.to_hash).to eq hash
107
+ end
108
+ end
109
+
110
+ context "for a lazy_resource that got skipped" do
111
+ let(:resource) do
112
+ klass = Class.new(Chef::Resource) do
113
+ resource_name "link"
114
+ property :sword, String, name_property: true, identity: true
115
+ end
116
+ resource = klass.new("hyrule")
117
+ resource.sword = Chef::DelayedEvaluator.new { nil }
118
+ resource
119
+ end
120
+ let(:hash) do
121
+ {
122
+ "after" => {},
123
+ "before" => {},
124
+ "delta" => "",
125
+ "duration" => "",
126
+ "conditional" => "because",
127
+ "id" => "unknown identity (due to Chef::Exceptions::ValidationFailed)",
128
+ "ignore_failure" => false,
129
+ "name" => "hyrule",
130
+ "result" => "create",
131
+ "status" => "skipped",
132
+ "type" => :link,
133
+ }
134
+ end
135
+ let(:conditional) do
136
+ double("Chef::Resource::Conditional", :to_text => "because")
137
+ end
138
+
139
+ it "should handle any Exception and throw a helpful message by mocking the identity" do
140
+ report.skipped(conditional)
141
+ expect(report.to_hash).to eq hash
142
+ end
143
+ end
144
+ end
145
+ end
@@ -330,6 +330,56 @@ describe Chef::PolicyBuilder::Policyfile do
330
330
 
331
331
  end
332
332
 
333
+ describe "#build_node" do
334
+
335
+ let(:node) do
336
+ node = Chef::Node.new
337
+ node.name(node_name)
338
+ node
339
+ end
340
+
341
+ before do
342
+ allow(policy_builder).to receive(:node).and_return(node)
343
+ end
344
+
345
+ context "when the run is successful" do
346
+ let(:run_list) do
347
+ ["recipe[test::default]",
348
+ "recipe[test::other]"]
349
+ end
350
+
351
+ let(:version_hash) do
352
+ {
353
+ "version" => "0.1.0",
354
+ "identifier" => "012345678",
355
+ }
356
+ end
357
+
358
+ let(:run_list_for_data_collector) do
359
+ {
360
+ :id => "_policy_node",
361
+ :run_list => [
362
+ { :type => "recipe", :name => "test::default", :skipped => false, :version => nil },
363
+ { :type => "recipe", :name => "test::other", :skipped => false, :version => nil },
364
+ ],
365
+ }
366
+ end
367
+
368
+ before do
369
+ allow(policy_builder).to receive(:run_list)
370
+ .and_return(run_list)
371
+ allow(policy_builder).to receive(:cookbook_lock_for)
372
+ .and_return(version_hash)
373
+ end
374
+
375
+ it "sends the run_list_expanded event" do
376
+ policy_builder.build_node
377
+ expect(policy_builder.run_list_expansion_ish.to_hash)
378
+ .to eq(run_list_for_data_collector)
379
+ end
380
+ end
381
+ end
382
+
333
383
  describe "building the node object" do
334
384
 
335
385
  let(:extra_chef_config) { {} }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.21.1
4
+ version: 12.21.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-20 00:00:00.000000000 Z
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 12.21.1
19
+ version: 12.21.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 12.21.1
26
+ version: 12.21.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mixlib-cli
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -2154,6 +2154,7 @@ files:
2154
2154
  - spec/unit/data_bag_spec.rb
2155
2155
  - spec/unit/data_collector/messages/helpers_spec.rb
2156
2156
  - spec/unit/data_collector/messages_spec.rb
2157
+ - spec/unit/data_collector/resource_report_spec.rb
2157
2158
  - spec/unit/data_collector_spec.rb
2158
2159
  - spec/unit/decorator/lazy_array_spec.rb
2159
2160
  - spec/unit/decorator/lazy_spec.rb
@@ -2650,7 +2651,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2650
2651
  version: '0'
2651
2652
  requirements: []
2652
2653
  rubyforge_project:
2653
- rubygems_version: 2.6.10
2654
+ rubygems_version: 2.6.12
2654
2655
  signing_key:
2655
2656
  specification_version: 4
2656
2657
  summary: A systems integration framework, built to bring the benefits of configuration