compat_resource 12.9.1 → 12.10.1

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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +8 -3
  3. data/files/lib/chef_compat/copied_from_chef/chef/dsl/core.rb +56 -0
  4. data/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb +182 -7
  5. data/files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb +5 -2
  6. data/files/lib/chef_compat/copied_from_chef/chef/mixin/lazy_module_include.rb +90 -0
  7. data/files/lib/chef_compat/copied_from_chef/chef/mixin/notifying_block.rb +66 -0
  8. data/files/lib/chef_compat/copied_from_chef/chef/mixin/powershell_out.rb +109 -0
  9. data/files/lib/chef_compat/copied_from_chef/chef/property.rb +9 -2
  10. data/files/lib/chef_compat/copied_from_chef/chef/provider.rb +2 -2
  11. data/files/lib/chef_compat/copied_from_chef/chef/resource.rb +1 -0
  12. data/files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb +3 -0
  13. data/files/lib/chef_compat/copied_from_chef/chef/resource_builder.rb +1 -1
  14. data/files/lib/chef_compat/monkeypatches.rb +7 -3
  15. data/files/lib/chef_compat/monkeypatches/chef.rb +3 -2
  16. data/files/lib/chef_compat/monkeypatches/chef/log.rb +13 -0
  17. data/files/lib/chef_compat/monkeypatches/chef/resource_collection.rb +103 -0
  18. data/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb +49 -0
  19. data/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb +49 -0
  20. data/files/lib/chef_compat/monkeypatches/chef/run_context.rb +74 -9
  21. data/files/lib/chef_compat/monkeypatches/chef/runner.rb +60 -0
  22. data/files/lib/compat_resource/version.rb +1 -1
  23. data/files/spec/cookbook_spec.rb +10 -1
  24. data/files/spec/data/.bundle/config +1 -0
  25. data/files/spec/data/Gemfile.lock +18 -50
  26. data/files/spec/data/config.rb +1 -1
  27. data/files/spec/data/cookbooks/notifications/metadata.rb +4 -0
  28. data/files/spec/data/cookbooks/notifications/recipes/default.rb +5 -0
  29. data/files/spec/data/cookbooks/notifications/resources/resource.rb +8 -0
  30. metadata +15 -3
@@ -0,0 +1,49 @@
1
+ #
2
+ # Author:: Tyler Ball (<tball@chef.io>)
3
+ # Copyright:: Copyright 2014-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
+ require "chef/resource_collection/resource_list"
20
+ require "chef/exceptions"
21
+
22
+ module ChefCompat
23
+ module Monkeypatches
24
+ module Chef
25
+ module ResourceCollection
26
+ module ResourceSet
27
+ module DeleteResource
28
+ def delete(key)
29
+ raise ArgumentError, "Must pass a Chef::Resource or String to delete" unless key.is_a?(String) || key.is_a?(Chef::Resource)
30
+ key = key.to_s
31
+ res = @resources_by_key.delete(key)
32
+
33
+ if res == @resources_by_key.default
34
+ raise Chef::Exceptions::ResourceNotFound, "Cannot find a resource matching #{key} (did you define it first?)"
35
+ end
36
+ res
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ class Chef::ResourceCollection::ResourceSet
46
+ unless method_defined?(:delete)
47
+ prepend ChefCompat::Monkeypatches::Chef::ResourceCollection::ResourceSet::DeleteResource
48
+ end
49
+ end
@@ -1,12 +1,77 @@
1
- require 'chef/resource'
2
-
3
- class Chef
4
- class RunContext
5
- if !method_defined?(:create_child)
6
- def create_child
7
- result = dup
8
- result.resource_collection = Chef::ResourceCollection.new
9
- result
1
+ require 'chef/run_context'
2
+ require 'chef_compat/monkeypatches/chef/resource_collection'
3
+
4
+ if Gem::Requirement.new("< 12.10.24").satisfied_by?(Gem::Version.new(Chef::VERSION))
5
+ module ChefCompat
6
+ module Monkeypatches
7
+ module Chef
8
+ module RunContext
9
+ # for versions after we added intialize_child_state but before 12.10.24
10
+ def initialize_child_state(*args)
11
+ super
12
+ @resource_collection.run_context = self
13
+ @delayed_actions = []
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ class Chef
21
+ class RunContext
22
+ #
23
+ # NOTE: The root run_context is created long before we start monkeying around
24
+ # with patching the class. No child run context has been created yet. This
25
+ # still patches the root run_context and implements the new behaviors on it.
26
+ #
27
+ # This does affect our ability to patch methods like #initialize, since the
28
+ # root has already been created and initialized, obviously.
29
+ #
30
+
31
+ unless method_defined?(:parent_run_context)
32
+ attr_accessor :parent_run_context
33
+ end
34
+
35
+ unless method_defined?(:delayed_actions)
36
+ def delayed_actions
37
+ @delayed_actions ||= []
38
+ end
39
+ end
40
+
41
+ unless method_defined?(:initialize_child_state)
42
+ #
43
+ # Copied verbatim from 12.10.24 Chef::RunContext
44
+ #
45
+ def initialize_child_state
46
+ @audits = {}
47
+ @resource_collection = Chef::ResourceCollection.new(self)
48
+ @before_notification_collection = Hash.new { |h, k| h[k] = [] }
49
+ @immediate_notification_collection = Hash.new { |h, k| h[k] = [] }
50
+ @delayed_notification_collection = Hash.new { |h, k| h[k] = [] }
51
+ @delayed_actions = []
52
+ end
53
+ else
54
+ prepend ChefCompat::Monkeypatches::Chef::RunContext
55
+ end
56
+
57
+ unless method_defined?(:add_delayed_action)
58
+ def add_delayed_action(notification)
59
+ if delayed_actions.any? { |existing_notification| existing_notification.duplicates?(notification) }
60
+ Chef::Log.info( "#{notification.notifying_resource} not queuing delayed action #{notification.action} on #{notification.resource}"\
61
+ " (delayed), as it's already been queued")
62
+ else
63
+ delayed_actions << notification
64
+ end
65
+ end
66
+ end
67
+
68
+ unless method_defined?(:create_child)
69
+ def create_child
70
+ result = dup
71
+ result.parent_run_context = self
72
+ result.initialize_child_state
73
+ result
74
+ end
10
75
  end
11
76
  end
12
77
  end
@@ -0,0 +1,60 @@
1
+ #--
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Author:: Christopher Walters (<cw@chef.io>)
4
+ # Author:: Tim Hinderliter (<tim@chef.io>)
5
+ # Copyright:: Copyright 2008-2016, Chef Software Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ # minimal monkeypatch necessary to implement the notifcation features
22
+ # of 12.10.x
23
+ #
24
+ # if before notifications are also pulled into this monkeypatch then it
25
+ # may simply be easier to copy the entire Chef::Runner class from 12.10.24
26
+ # into this file.
27
+ #
28
+ class Chef
29
+ # == Chef::Runner
30
+ # This class is responsible for executing the steps in a Chef run.
31
+ class Runner
32
+
33
+ def delayed_actions
34
+ @run_context.delayed_actions
35
+ end
36
+
37
+ # Determine the appropriate provider for the given resource, then
38
+ # execute it.
39
+ def run_action(resource, action, notification_type = nil, notifying_resource = nil)
40
+ # Actually run the action for realsies
41
+ resource.run_action(action, notification_type, notifying_resource)
42
+
43
+ # Execute any immediate and queue up any delayed notifications
44
+ # associated with the resource, but only if it was updated *this time*
45
+ # we ran an action on it.
46
+ if resource.updated_by_last_action?
47
+ run_context.immediate_notifications(resource).each do |notification|
48
+ Chef::Log.info("#{resource} sending #{notification.action} action to #{notification.resource} (immediate)")
49
+ run_action(notification.resource, notification.action, :immediate, resource)
50
+ end
51
+
52
+ run_context.delayed_notifications(resource).each do |notification|
53
+ # send the notification to the run_context of the receiving resource
54
+ notification.resource.run_context.add_delayed_action(notification)
55
+ end
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module CompatResource
2
- VERSION = '12.9.1'
2
+ VERSION = '12.10.1'
3
3
  end
@@ -17,11 +17,14 @@ describe "compat_resource cookbook" do
17
17
  File.join(cookbooks_path, 'normal'))
18
18
  File.symlink(File.expand_path('../data/cookbooks/hybrid', __FILE__),
19
19
  File.join(cookbooks_path, 'hybrid'))
20
+ File.symlink(File.expand_path('../data/cookbooks/notifications', __FILE__),
21
+ File.join(cookbooks_path, 'notifications'))
20
22
  end
21
23
 
22
24
  require 'chef/mixin/shell_out'
23
25
  include Chef::Mixin::ShellOut
24
26
  before :all do
27
+ FileUtils.rm_f(File.expand_path('../data/Gemfile.lock', __FILE__))
25
28
  Bundler.with_clean_env do
26
29
  shell_out!("bundle install --gemfile #{File.expand_path('../data/Gemfile', __FILE__)}")
27
30
  end
@@ -34,6 +37,12 @@ describe "compat_resource cookbook" do
34
37
  end
35
38
  end
36
39
 
40
+ it "should handle new-style recursive notifications" do
41
+ result = run_chef("-o notifications")
42
+ puts result.stdout
43
+ puts result.stderr
44
+ end
45
+
37
46
  it "when chef-client runs the test recipe, it succeeds" do
38
47
  result = run_chef("-o test::test,test")
39
48
  puts result.stdout
@@ -61,7 +70,7 @@ describe "compat_resource cookbook" do
61
70
  # - set y to 4 \(default value\)
62
71
  # /)
63
72
  end
64
- if Chef::VERSION.to_f <= 12.5
73
+ if Gem::Requirement.new("< 12.6").satisfied_by?(Gem::Version.new(Chef::VERSION))
65
74
  it "when chef-client tries to declare_resource with extra parameters, it fails" do
66
75
  expect {
67
76
  run_chef("-o normal::declare_resource")
@@ -0,0 +1 @@
1
+ --- {}
@@ -1,12 +1,11 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- builder (3.2.2)
5
- chef (12.3.0)
6
- chef-zero (~> 4.1)
4
+ chef (12.0.3)
5
+ chef-zero (~> 3.2)
7
6
  diff-lcs (~> 1.2, >= 1.2.4)
8
7
  erubis (~> 2.7)
9
- ffi-yajl (>= 1.2, < 3.0)
8
+ ffi-yajl (~> 1.2)
10
9
  highline (~> 1.6, >= 1.6.9)
11
10
  mixlib-authentication (~> 1.3)
12
11
  mixlib-cli (~> 1.4)
@@ -18,18 +17,9 @@ GEM
18
17
  ohai (~> 8.0)
19
18
  plist (~> 3.1.0)
20
19
  pry (~> 0.9)
21
- rspec-core (~> 3.2)
22
- rspec-expectations (~> 3.2)
23
- rspec-mocks (~> 3.2)
24
- rspec_junit_formatter (~> 0.2.0)
25
- serverspec (~> 2.7)
26
- specinfra (~> 2.10)
27
- chef-config (12.8.1)
28
- mixlib-config (~> 2.0)
29
- mixlib-shellout (~> 2.0)
30
- chef-zero (4.5.0)
31
- ffi-yajl (~> 2.2)
32
- hashie (>= 2.0, < 4.0)
20
+ chef-zero (3.2.1)
21
+ ffi-yajl (~> 1.1)
22
+ hashie (~> 2.0)
33
23
  mixlib-log (~> 1.3)
34
24
  rack
35
25
  uuidtools (~> 2.1)
@@ -37,42 +27,40 @@ GEM
37
27
  diff-lcs (1.2.5)
38
28
  erubis (2.7.0)
39
29
  ffi (1.9.10)
40
- ffi-yajl (2.2.3)
30
+ ffi-yajl (1.4.0)
31
+ ffi (~> 1.5)
41
32
  libyajl2 (~> 1.2)
42
- hashie (3.4.3)
33
+ hashie (2.1.2)
43
34
  highline (1.7.8)
44
35
  ipaddress (0.8.3)
45
36
  libyajl2 (1.2.0)
46
37
  method_source (0.8.2)
38
+ mime-types (2.99.1)
47
39
  mixlib-authentication (1.4.0)
48
40
  mixlib-log
49
41
  rspec-core (~> 3.2)
50
42
  rspec-expectations (~> 3.2)
51
43
  rspec-mocks (~> 3.2)
52
- mixlib-cli (1.5.0)
44
+ mixlib-cli (1.6.0)
53
45
  mixlib-config (2.2.1)
54
46
  mixlib-log (1.6.0)
55
47
  mixlib-shellout (2.2.6)
56
- multi_json (1.11.2)
57
- net-scp (1.2.1)
58
- net-ssh (>= 2.6.5)
59
48
  net-ssh (2.9.4)
60
49
  net-ssh-gateway (1.2.0)
61
50
  net-ssh (>= 2.6.5)
62
51
  net-ssh-multi (1.2.1)
63
52
  net-ssh (>= 2.6.5)
64
53
  net-ssh-gateway (>= 1.2.0)
65
- net-telnet (0.1.1)
66
- ohai (8.12.1)
67
- chef-config (>= 12.5.0.alpha.1, < 13)
54
+ ohai (8.4.0)
68
55
  ffi (~> 1.9)
69
- ffi-yajl (~> 2.2)
56
+ ffi-yajl (>= 1.1, < 3.0)
70
57
  ipaddress
58
+ mime-types (~> 2.0)
71
59
  mixlib-cli
72
60
  mixlib-config (~> 2.0)
73
61
  mixlib-log
74
62
  mixlib-shellout (~> 2.0)
75
- plist
63
+ rake (~> 10.1)
76
64
  systemu (~> 2.6.4)
77
65
  wmi-lite (~> 1.0)
78
66
  plist (3.1.0)
@@ -81,37 +69,17 @@ GEM
81
69
  method_source (~> 0.8.1)
82
70
  slop (~> 3.4)
83
71
  rack (1.6.4)
84
- rspec (3.4.0)
85
- rspec-core (~> 3.4.0)
86
- rspec-expectations (~> 3.4.0)
87
- rspec-mocks (~> 3.4.0)
72
+ rake (10.5.0)
88
73
  rspec-core (3.4.4)
89
74
  rspec-support (~> 3.4.0)
90
75
  rspec-expectations (3.4.0)
91
76
  diff-lcs (>= 1.2.0, < 2.0)
92
77
  rspec-support (~> 3.4.0)
93
- rspec-its (1.2.0)
94
- rspec-core (>= 3.0.0)
95
- rspec-expectations (>= 3.0.0)
96
78
  rspec-mocks (3.4.1)
97
79
  diff-lcs (>= 1.2.0, < 2.0)
98
80
  rspec-support (~> 3.4.0)
99
81
  rspec-support (3.4.1)
100
- rspec_junit_formatter (0.2.3)
101
- builder (< 4)
102
- rspec-core (>= 2, < 4, != 2.12.0)
103
- serverspec (2.31.0)
104
- multi_json
105
- rspec (~> 3.0)
106
- rspec-its
107
- specinfra (~> 2.53)
108
- sfl (2.2)
109
82
  slop (3.6.0)
110
- specinfra (2.54.1)
111
- net-scp
112
- net-ssh (>= 2.7, < 3.1)
113
- net-telnet
114
- sfl
115
83
  systemu (2.6.5)
116
84
  uuidtools (2.1.5)
117
85
  wmi-lite (1.0.0)
@@ -120,7 +88,7 @@ PLATFORMS
120
88
  ruby
121
89
 
122
90
  DEPENDENCIES
123
- chef (~> 12.3, < 12.4)
91
+ chef (~> 12.0.0)
124
92
 
125
93
  BUNDLED WITH
126
- 1.11.2
94
+ 1.12.1
@@ -1,3 +1,3 @@
1
1
  local_mode true
2
2
  chef_repo_path File.dirname(__FILE__)
3
- log_level :debug
3
+ #log_level :debug
@@ -0,0 +1,4 @@
1
+ name "notifications"
2
+ description "cookbook that depends on compat_resource"
3
+ version "1.0.0"
4
+ depends "compat_resource"
@@ -0,0 +1,5 @@
1
+ log "recipe" do
2
+ action :nothing
3
+ end
4
+
5
+ resource "doit"
@@ -0,0 +1,8 @@
1
+ provides :resource
2
+ resource_name :resource
3
+
4
+ action :create do
5
+ log "resource" do
6
+ notifies :write, "log[recipe]"
7
+ end
8
+ end
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.9.1
4
+ version: 12.10.1
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-03-23 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -94,9 +94,13 @@ files:
94
94
  - files/lib/chef_compat/copied_from_chef.rb
95
95
  - files/lib/chef_compat/copied_from_chef/chef/constants.rb
96
96
  - files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb
97
+ - files/lib/chef_compat/copied_from_chef/chef/dsl/core.rb
97
98
  - files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb
98
99
  - files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb
100
+ - files/lib/chef_compat/copied_from_chef/chef/mixin/lazy_module_include.rb
101
+ - files/lib/chef_compat/copied_from_chef/chef/mixin/notifying_block.rb
99
102
  - files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb
103
+ - files/lib/chef_compat/copied_from_chef/chef/mixin/powershell_out.rb
100
104
  - files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb
101
105
  - files/lib/chef_compat/copied_from_chef/chef/property.rb
102
106
  - files/lib/chef_compat/copied_from_chef/chef/provider.rb
@@ -114,7 +118,11 @@ files:
114
118
  - files/lib/chef_compat/monkeypatches/chef/recipe.rb
115
119
  - files/lib/chef_compat/monkeypatches/chef/resource.rb
116
120
  - files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb
121
+ - files/lib/chef_compat/monkeypatches/chef/resource_collection.rb
122
+ - files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb
123
+ - files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb
117
124
  - files/lib/chef_compat/monkeypatches/chef/run_context.rb
125
+ - files/lib/chef_compat/monkeypatches/chef/runner.rb
118
126
  - files/lib/chef_compat/property.rb
119
127
  - files/lib/chef_compat/recipe.rb
120
128
  - files/lib/chef_compat/resource.rb
@@ -123,6 +131,7 @@ files:
123
131
  - files/lib/compat_resource/gemspec.rb
124
132
  - files/lib/compat_resource/version.rb
125
133
  - files/spec/cookbook_spec.rb
134
+ - files/spec/data/.bundle/config
126
135
  - files/spec/data/Gemfile
127
136
  - files/spec/data/Gemfile.lock
128
137
  - files/spec/data/config.rb
@@ -141,6 +150,9 @@ files:
141
150
  - files/spec/data/cookbooks/normal/providers/resource.rb
142
151
  - files/spec/data/cookbooks/normal/recipes/declare_resource.rb
143
152
  - files/spec/data/cookbooks/normal/resources/resource.rb
153
+ - files/spec/data/cookbooks/notifications/metadata.rb
154
+ - files/spec/data/cookbooks/notifications/recipes/default.rb
155
+ - files/spec/data/cookbooks/notifications/resources/resource.rb
144
156
  - files/spec/data/cookbooks/test/metadata.rb
145
157
  - files/spec/data/cookbooks/test/recipes/default.rb
146
158
  - files/spec/data/cookbooks/test/recipes/test.rb
@@ -166,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
178
  version: '0'
167
179
  requirements: []
168
180
  rubyforge_project:
169
- rubygems_version: 2.6.1
181
+ rubygems_version: 2.4.8
170
182
  signing_key:
171
183
  specification_version: 4
172
184
  summary: Bring some new features of Chef 12.5 to previous 12.X releases