chef 12.21.1-universal-mingw32 → 12.21.4-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/lib/chef/data_collector/resource_report.rb +32 -4
- data/lib/chef/policy_builder/policyfile.rb +27 -1
- data/lib/chef/version.rb +1 -1
- data/spec/unit/data_collector/resource_report_spec.rb +145 -0
- data/spec/unit/policy_builder/policyfile_spec.rb +50 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 459d357a648c30126a7a4dffbb709c327118879b
|
4
|
+
data.tar.gz: 672f6feac0d731ec7817254138fe803ee3518ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61bd8bb963670a2ef235eb6f612a1964be93774dda090eb4e8e6e9ff9f069cf6a0446c7d886d74a8c4005b631a3a44f1a43f10e9a8c5c9d5233d7b485482a452
|
7
|
+
data.tar.gz: 21119edf195c229828ba14be8213d8f745043eec53ab5685fb419236fa963ff13332e2d75c472d1093b64676b8f48066539170f24f9901d9929c8575af448008
|
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",
|
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
|
+
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" =>
|
71
|
-
"after" =>
|
72
|
-
"before" =>
|
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"]
|
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
@@ -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.
|
4
|
+
version: 12.21.4
|
5
5
|
platform: universal-mingw32
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
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.
|
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.
|
26
|
+
version: 12.21.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mixlib-cli
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -2315,6 +2315,7 @@ files:
|
|
2315
2315
|
- spec/unit/data_bag_spec.rb
|
2316
2316
|
- spec/unit/data_collector/messages/helpers_spec.rb
|
2317
2317
|
- spec/unit/data_collector/messages_spec.rb
|
2318
|
+
- spec/unit/data_collector/resource_report_spec.rb
|
2318
2319
|
- spec/unit/data_collector_spec.rb
|
2319
2320
|
- spec/unit/decorator/lazy_array_spec.rb
|
2320
2321
|
- spec/unit/decorator/lazy_spec.rb
|
@@ -2811,7 +2812,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
2811
2812
|
version: '0'
|
2812
2813
|
requirements: []
|
2813
2814
|
rubyforge_project:
|
2814
|
-
rubygems_version: 2.6.
|
2815
|
+
rubygems_version: 2.6.12
|
2815
2816
|
signing_key:
|
2816
2817
|
specification_version: 4
|
2817
2818
|
summary: A systems integration framework, built to bring the benefits of configuration
|