compat_resource 12.10.1 → 12.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c7c3400d3a6270d353403967a7285c17b4c0e01
4
- data.tar.gz: 058a4752161e3c8e1610e80f5ff9497d3802a6b2
3
+ metadata.gz: e5ed711ca2e962b498a3d0f57d83e968f22c3413
4
+ data.tar.gz: 09a6bf93b34094e41df052900426c11fa1863bab
5
5
  SHA512:
6
- metadata.gz: 3e1d3dc00dbe9e97c67a6cc14baa7700ae7462e977130bc2bbe8f6ed75c3f35c45505de9d8082506ac68db68532afbd6443e6b9eb3c356a04d4ac216ffac8ba2
7
- data.tar.gz: f87ce089823b777aa404cf36ab66f1222a50b9554c0bf0c1c948a6687aa85bcc2b9ca33ea4c836d7a54a3d80431cf401d4cd24156d9101e915df7ac26ecc567b
6
+ metadata.gz: e1444ac99b53e4a3af0c7d9121f78bc49942ad4c5c55cf006dde1e5830b5b7758d61fdc16a8ae1f38937a1d742d4dcb6e9a3a718560a00e860db4af0989fcedc
7
+ data.tar.gz: 1d39e68480d28af7e4506e4115475dd0cac935ef25fd9c6ad17ba7ff56c96e9dff4b4214bb352f4ab717de5098f3f7232ef14bbb545ec093d60848585867a9d5
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
- gem 'stove', '3.2.5'
3
+ gem 'stove'
4
4
  if ENV['GEMFILE_MOD']
5
5
  instance_eval(ENV['GEMFILE_MOD'])
6
6
  end
@@ -6,6 +6,7 @@ require 'chef_compat/monkeypatches/chef/property'
6
6
  require 'chef_compat/monkeypatches/chef/provider'
7
7
  require 'chef_compat/monkeypatches/chef/recipe'
8
8
  require 'chef_compat/monkeypatches/chef/resource'
9
+ require 'chef_compat/monkeypatches/chef/resource_builder'
9
10
  require 'chef_compat/monkeypatches/chef/resource/lwrp_base'
10
11
  require 'chef_compat/monkeypatches/chef/resource_collection'
11
12
  require 'chef_compat/monkeypatches/chef/resource_collection/resource_list'
@@ -0,0 +1,159 @@
1
+ #
2
+ # Author:: Lamont Granquist (<lamont@chef.io>)
3
+ # Copyright:: Copyright 2015-2016, Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ # NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb
20
+
21
+ if Gem::Requirement.new("< 12.10.24").satisfied_by?(Gem::Version.new(Chef::VERSION))
22
+ begin
23
+ require 'chef/resource_builder'
24
+ # we use the LoadError this creates on early 12.x to not monkeypatch chef client versions that don't have Chef::ResourceBuilder
25
+ # (it is lazily included and doesn't appear until compile time so we can't resolve the symbol during library loading)
26
+
27
+ class Chef
28
+ class ResourceBuilder
29
+ attr_reader :type
30
+ attr_reader :name
31
+ attr_reader :created_at
32
+ attr_reader :params
33
+ attr_reader :run_context
34
+ attr_reader :cookbook_name
35
+ attr_reader :recipe_name
36
+ attr_reader :enclosing_provider
37
+ attr_reader :resource
38
+
39
+ # FIXME (ruby-2.1 syntax): most of these are mandatory
40
+ def initialize(type:nil, name:nil, created_at: nil, params: nil, run_context: nil, cookbook_name: nil, recipe_name: nil, enclosing_provider: nil)
41
+ @type = type
42
+ @name = name
43
+ @created_at = created_at
44
+ @params = params
45
+ @run_context = run_context
46
+ @cookbook_name = cookbook_name
47
+ @recipe_name = recipe_name
48
+ @enclosing_provider = enclosing_provider
49
+ end
50
+
51
+ def build(&block)
52
+ raise ArgumentError, "You must supply a name when declaring a #{type} resource" if name.nil?
53
+
54
+ @resource = resource_class.new(name, run_context)
55
+ if resource.resource_name.nil?
56
+ raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?"
57
+ end
58
+ resource.source_line = created_at
59
+ resource.declared_type = type
60
+
61
+ # If we have a resource like this one, we want to steal its state
62
+ # This behavior is very counter-intuitive and should be removed.
63
+ # See CHEF-3694, https://tickets.opscode.com/browse/CHEF-3694
64
+ # Moved to this location to resolve CHEF-5052, https://tickets.opscode.com/browse/CHEF-5052
65
+ if prior_resource
66
+ resource.load_from(prior_resource)
67
+ end
68
+
69
+ resource.cookbook_name = cookbook_name
70
+ resource.recipe_name = recipe_name
71
+ # Determine whether this resource is being created in the context of an enclosing Provider
72
+ resource.enclosing_provider = enclosing_provider
73
+
74
+ # XXX: this is required for definition params inside of the scope of a
75
+ # subresource to work correctly.
76
+ resource.params = params
77
+
78
+ # Evaluate resource attribute DSL
79
+ if block_given?
80
+ resource.resource_initializing = true
81
+ begin
82
+ resource.instance_eval(&block)
83
+ ensure
84
+ resource.resource_initializing = false
85
+ end
86
+ end
87
+
88
+ # emit a cloned resource warning if it is warranted
89
+ if prior_resource
90
+ if is_trivial_resource?(prior_resource) && identicalish_resources?(prior_resource, resource)
91
+ emit_harmless_cloning_debug
92
+ else
93
+ emit_cloned_resource_warning
94
+ end
95
+ end
96
+
97
+ # Run optional resource hook
98
+ resource.after_created
99
+
100
+ resource
101
+ end
102
+
103
+ private
104
+
105
+ def resource_class
106
+ # Checks the new platform => short_name => resource mapping initially
107
+ # then fall back to the older approach (Chef::Resource.const_get) for
108
+ # backward compatibility
109
+ @resource_class ||= Chef::Resource.resource_for_node(type, run_context.node)
110
+ end
111
+
112
+ def is_trivial_resource?(resource)
113
+ identicalish_resources?(resource_class.new(name, run_context), resource)
114
+ end
115
+
116
+ # this is an equality test specific to checking for 3694 cloning warnings
117
+ def identicalish_resources?(first, second)
118
+ skipped_ivars = [ :@source_line, :@cookbook_name, :@recipe_name, :@params, :@elapsed_time, :@declared_type ]
119
+ checked_ivars = ( first.instance_variables | second.instance_variables ) - skipped_ivars
120
+ non_matching_ivars = checked_ivars.reject do |iv|
121
+ if iv == :@action && ( [first.instance_variable_get(iv)].flatten == [:nothing] || [second.instance_variable_get(iv)].flatten == [:nothing] )
122
+ # :nothing action on either side of the comparison always matches
123
+ true
124
+ else
125
+ first.instance_variable_get(iv) == second.instance_variable_get(iv)
126
+ end
127
+ end
128
+ Chef::Log.debug("ivars which did not match with the prior resource: #{non_matching_ivars}")
129
+ non_matching_ivars.empty?
130
+ end
131
+
132
+ def emit_cloned_resource_warning
133
+ Chef::Log.warn("Cloning resource attributes for #{resource} from prior resource (CHEF-3694)")
134
+ Chef::Log.warn("Previous #{prior_resource}: #{prior_resource.source_line}") if prior_resource.source_line
135
+ Chef::Log.warn("Current #{resource}: #{resource.source_line}") if resource.source_line
136
+ end
137
+
138
+ def emit_harmless_cloning_debug
139
+ Chef::Log.debug("Harmless resource cloning from #{prior_resource}:#{prior_resource.source_line} to #{resource}:#{resource.source_line}")
140
+ end
141
+
142
+ def prior_resource
143
+ @prior_resource ||=
144
+ begin
145
+ key = "#{type}[#{name}]"
146
+ run_context.resource_collection.lookup_local(key)
147
+ rescue Chef::Exceptions::ResourceNotFound
148
+ nil
149
+ end
150
+ end
151
+
152
+ end
153
+ end
154
+ rescue LoadError
155
+ # cool we're just on early chef 12.x, nothing to do -- we don't have to worry because there's also not parent_run_context pointer, so we don't have to
156
+ # use lookup_local to avoid resource cloning shit out of the parent run_context. the resource collection's lookup() method will always use lookup_local
157
+ # over lookup_recursive.
158
+ end
159
+ end
@@ -21,7 +21,6 @@ module CompatResource
21
21
  s.add_development_dependency 'rake'
22
22
  s.add_development_dependency 'rspec'
23
23
  s.add_development_dependency 'cheffish'
24
- s.add_development_dependency 'stove'
25
24
  s.add_development_dependency 'chef'
26
25
 
27
26
  s.bindir = "files/bin"
@@ -1,3 +1,3 @@
1
1
  module CompatResource
2
- VERSION = '12.10.1'
2
+ VERSION = '12.10.2'
3
3
  end
@@ -19,6 +19,8 @@ describe "compat_resource cookbook" do
19
19
  File.join(cookbooks_path, 'hybrid'))
20
20
  File.symlink(File.expand_path('../data/cookbooks/notifications', __FILE__),
21
21
  File.join(cookbooks_path, 'notifications'))
22
+ File.symlink(File.expand_path('../data/cookbooks/cloning', __FILE__),
23
+ File.join(cookbooks_path, 'cloning'))
22
24
  end
23
25
 
24
26
  require 'chef/mixin/shell_out'
@@ -43,6 +45,11 @@ describe "compat_resource cookbook" do
43
45
  puts result.stderr
44
46
  end
45
47
 
48
+ it "should not clone resources from the outer run context" do
49
+ result = run_chef("-o future::declare_resource,cloning::default")
50
+ expect(result.stdout).not_to match(/3694/)
51
+ end
52
+
46
53
  it "when chef-client runs the test recipe, it succeeds" do
47
54
  result = run_chef("-o test::test,test")
48
55
  puts result.stdout
@@ -0,0 +1,3 @@
1
+ name "cloning"
2
+ description "cookbook that DOES NOT depend on compat_resource"
3
+ version "1.0.0"
@@ -0,0 +1,9 @@
1
+ provides :resource
2
+
3
+ use_inline_resources
4
+
5
+ action :create do
6
+ log "stuff" do
7
+ only_if { true }
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ log "stuff"
2
+
3
+ resource "doit"
@@ -0,0 +1,2 @@
1
+ provides :resource
2
+ resource_name :resource
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compat_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.10.1
4
+ version: 12.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: files/bin
10
10
  cert_chain: []
11
- date: 2016-05-19 00:00:00.000000000 Z
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: stove
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: chef
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +104,7 @@ files:
118
104
  - files/lib/chef_compat/monkeypatches/chef/recipe.rb
119
105
  - files/lib/chef_compat/monkeypatches/chef/resource.rb
120
106
  - files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb
107
+ - files/lib/chef_compat/monkeypatches/chef/resource_builder.rb
121
108
  - files/lib/chef_compat/monkeypatches/chef/resource_collection.rb
122
109
  - files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb
123
110
  - files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb
@@ -131,10 +118,12 @@ files:
131
118
  - files/lib/compat_resource/gemspec.rb
132
119
  - files/lib/compat_resource/version.rb
133
120
  - files/spec/cookbook_spec.rb
134
- - files/spec/data/.bundle/config
135
121
  - files/spec/data/Gemfile
136
- - files/spec/data/Gemfile.lock
137
122
  - files/spec/data/config.rb
123
+ - files/spec/data/cookbooks/cloning/metadata.rb
124
+ - files/spec/data/cookbooks/cloning/providers/resource.rb
125
+ - files/spec/data/cookbooks/cloning/recipes/default.rb
126
+ - files/spec/data/cookbooks/cloning/resources/resource.rb
138
127
  - files/spec/data/cookbooks/future/libraries/future_custom_resource.rb
139
128
  - files/spec/data/cookbooks/future/libraries/super_properties.rb
140
129
  - files/spec/data/cookbooks/future/metadata.rb
@@ -1 +0,0 @@
1
- --- {}
@@ -1,94 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- chef (12.0.3)
5
- chef-zero (~> 3.2)
6
- diff-lcs (~> 1.2, >= 1.2.4)
7
- erubis (~> 2.7)
8
- ffi-yajl (~> 1.2)
9
- highline (~> 1.6, >= 1.6.9)
10
- mixlib-authentication (~> 1.3)
11
- mixlib-cli (~> 1.4)
12
- mixlib-config (~> 2.0)
13
- mixlib-log (~> 1.3)
14
- mixlib-shellout (>= 2.0.0.rc.0, < 3.0)
15
- net-ssh (~> 2.6)
16
- net-ssh-multi (~> 1.1)
17
- ohai (~> 8.0)
18
- plist (~> 3.1.0)
19
- pry (~> 0.9)
20
- chef-zero (3.2.1)
21
- ffi-yajl (~> 1.1)
22
- hashie (~> 2.0)
23
- mixlib-log (~> 1.3)
24
- rack
25
- uuidtools (~> 2.1)
26
- coderay (1.1.1)
27
- diff-lcs (1.2.5)
28
- erubis (2.7.0)
29
- ffi (1.9.10)
30
- ffi-yajl (1.4.0)
31
- ffi (~> 1.5)
32
- libyajl2 (~> 1.2)
33
- hashie (2.1.2)
34
- highline (1.7.8)
35
- ipaddress (0.8.3)
36
- libyajl2 (1.2.0)
37
- method_source (0.8.2)
38
- mime-types (2.99.1)
39
- mixlib-authentication (1.4.0)
40
- mixlib-log
41
- rspec-core (~> 3.2)
42
- rspec-expectations (~> 3.2)
43
- rspec-mocks (~> 3.2)
44
- mixlib-cli (1.6.0)
45
- mixlib-config (2.2.1)
46
- mixlib-log (1.6.0)
47
- mixlib-shellout (2.2.6)
48
- net-ssh (2.9.4)
49
- net-ssh-gateway (1.2.0)
50
- net-ssh (>= 2.6.5)
51
- net-ssh-multi (1.2.1)
52
- net-ssh (>= 2.6.5)
53
- net-ssh-gateway (>= 1.2.0)
54
- ohai (8.4.0)
55
- ffi (~> 1.9)
56
- ffi-yajl (>= 1.1, < 3.0)
57
- ipaddress
58
- mime-types (~> 2.0)
59
- mixlib-cli
60
- mixlib-config (~> 2.0)
61
- mixlib-log
62
- mixlib-shellout (~> 2.0)
63
- rake (~> 10.1)
64
- systemu (~> 2.6.4)
65
- wmi-lite (~> 1.0)
66
- plist (3.1.0)
67
- pry (0.10.3)
68
- coderay (~> 1.1.0)
69
- method_source (~> 0.8.1)
70
- slop (~> 3.4)
71
- rack (1.6.4)
72
- rake (10.5.0)
73
- rspec-core (3.4.4)
74
- rspec-support (~> 3.4.0)
75
- rspec-expectations (3.4.0)
76
- diff-lcs (>= 1.2.0, < 2.0)
77
- rspec-support (~> 3.4.0)
78
- rspec-mocks (3.4.1)
79
- diff-lcs (>= 1.2.0, < 2.0)
80
- rspec-support (~> 3.4.0)
81
- rspec-support (3.4.1)
82
- slop (3.6.0)
83
- systemu (2.6.5)
84
- uuidtools (2.1.5)
85
- wmi-lite (1.0.0)
86
-
87
- PLATFORMS
88
- ruby
89
-
90
- DEPENDENCIES
91
- chef (~> 12.0.0)
92
-
93
- BUNDLED WITH
94
- 1.12.1