chef 12.5.1 → 12.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/README.md +6 -4
  4. data/Rakefile +1 -4
  5. data/chef-windows.gemspec +21 -0
  6. data/chef.gemspec +58 -0
  7. data/lib/chef/api_client/registration.rb +9 -4
  8. data/lib/chef/application.rb +3 -84
  9. data/lib/chef/application/apply.rb +9 -2
  10. data/lib/chef/application/client.rb +8 -3
  11. data/lib/chef/application/solo.rb +7 -1
  12. data/lib/chef/application/windows_service.rb +21 -6
  13. data/lib/chef/application/windows_service_manager.rb +2 -3
  14. data/lib/chef/audit/runner.rb +1 -0
  15. data/lib/chef/chef_class.rb +1 -11
  16. data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
  17. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
  18. data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
  19. data/lib/chef/client.rb +28 -1
  20. data/lib/chef/cookbook/cookbook_collection.rb +14 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +115 -9
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +6 -2
  25. data/lib/chef/data_bag.rb +1 -1
  26. data/lib/chef/data_bag_item.rb +1 -1
  27. data/lib/chef/digester.rb +5 -1
  28. data/lib/chef/dsl/chef_provisioning.rb +57 -0
  29. data/lib/chef/dsl/cheffish.rb +64 -0
  30. data/lib/chef/dsl/declare_resource.rb +108 -0
  31. data/lib/chef/dsl/platform_introspection.rb +3 -3
  32. data/lib/chef/dsl/recipe.rb +3 -73
  33. data/lib/chef/dsl/resources.rb +27 -1
  34. data/lib/chef/event_dispatch/base.rb +3 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +5 -0
  36. data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
  37. data/lib/chef/exceptions.rb +21 -1
  38. data/lib/chef/file_access_control/unix.rb +12 -12
  39. data/lib/chef/file_content_management/deploy/cp.rb +2 -2
  40. data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
  41. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  42. data/lib/chef/formatters/base.rb +7 -0
  43. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  44. data/lib/chef/formatters/indentable_output_stream.rb +5 -0
  45. data/lib/chef/http.rb +19 -3
  46. data/lib/chef/http/decompressor.rb +2 -2
  47. data/lib/chef/json_compat.rb +1 -0
  48. data/lib/chef/knife.rb +16 -2
  49. data/lib/chef/knife/bootstrap.rb +55 -10
  50. data/lib/chef/knife/cookbook_site_install.rb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +2 -1
  52. data/lib/chef/knife/core/node_presenter.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +30 -16
  54. data/lib/chef/knife/ssl_check.rb +4 -2
  55. data/lib/chef/knife/ssl_fetch.rb +3 -2
  56. data/lib/chef/knife/status.rb +14 -1
  57. data/lib/chef/log.rb +14 -0
  58. data/lib/chef/mixin/get_source_from_package.rb +7 -2
  59. data/lib/chef/mixin/properties.rb +302 -0
  60. data/lib/chef/mixin/proxified_socket.rb +38 -0
  61. data/lib/chef/mixin/subclass_directive.rb +37 -0
  62. data/lib/chef/node.rb +13 -5
  63. data/lib/chef/platform/query_helpers.rb +14 -3
  64. data/lib/chef/platform/service_helpers.rb +20 -38
  65. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  66. data/lib/chef/policy_builder/policyfile.rb +1 -0
  67. data/lib/chef/property.rb +51 -12
  68. data/lib/chef/provider.rb +40 -35
  69. data/lib/chef/provider/deploy.rb +1 -1
  70. data/lib/chef/provider/dsc_resource.rb +54 -20
  71. data/lib/chef/provider/execute.rb +25 -4
  72. data/lib/chef/provider/group.rb +1 -1
  73. data/lib/chef/provider/lwrp_base.rb +1 -0
  74. data/lib/chef/provider/package.rb +76 -30
  75. data/lib/chef/provider/package/dpkg.rb +152 -69
  76. data/lib/chef/provider/package/openbsd.rb +6 -8
  77. data/lib/chef/provider/package/solaris.rb +2 -0
  78. data/lib/chef/provider/package/windows.rb +95 -14
  79. data/lib/chef/provider/package/windows/exe.rb +129 -0
  80. data/lib/chef/provider/package/windows/msi.rb +37 -13
  81. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
  82. data/lib/chef/provider/package/yum.rb +13 -3
  83. data/lib/chef/provider/powershell_script.rb +3 -0
  84. data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
  85. data/lib/chef/provider/remote_file/http.rb +1 -1
  86. data/lib/chef/provider/script.rb +1 -0
  87. data/lib/chef/provider/service.rb +13 -10
  88. data/lib/chef/provider/service/solaris.rb +43 -17
  89. data/lib/chef/provider/service/upstart.rb +3 -3
  90. data/lib/chef/provider/user.rb +1 -1
  91. data/lib/chef/provider/user/dscl.rb +111 -100
  92. data/lib/chef/provider/user/windows.rb +5 -3
  93. data/lib/chef/recipe.rb +3 -5
  94. data/lib/chef/resource.rb +77 -320
  95. data/lib/chef/resource/action_class.rb +4 -0
  96. data/lib/chef/resource/dpkg_package.rb +4 -3
  97. data/lib/chef/resource/dsc_resource.rb +40 -2
  98. data/lib/chef/resource/execute.rb +9 -1
  99. data/lib/chef/resource/ksh.rb +32 -0
  100. data/lib/chef/resource/lwrp_base.rb +6 -10
  101. data/lib/chef/resource/package.rb +8 -9
  102. data/lib/chef/resource/registry_key.rb +1 -1
  103. data/lib/chef/resource/resource_notification.rb +14 -1
  104. data/lib/chef/resource/script.rb +1 -1
  105. data/lib/chef/resource/windows_package.rb +1 -1
  106. data/lib/chef/resource_builder.rb +14 -7
  107. data/lib/chef/resource_reporter.rb +6 -0
  108. data/lib/chef/resources.rb +1 -7
  109. data/lib/chef/rest.rb +1 -1
  110. data/lib/chef/run_context.rb +45 -2
  111. data/lib/chef/run_list/run_list_expansion.rb +47 -0
  112. data/lib/chef/runner.rb +25 -0
  113. data/lib/chef/search/query.rb +16 -2
  114. data/lib/chef/util/diff.rb +2 -2
  115. data/lib/chef/util/powershell/ps_credential.rb +2 -3
  116. data/lib/chef/version.rb +1 -1
  117. data/lib/chef/win32/api/file.rb +51 -1
  118. data/lib/chef/win32/file.rb +5 -0
  119. data/lib/chef/win32/file/version_info.rb +93 -0
  120. data/lib/chef/win32/mutex.rb +1 -1
  121. data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
  122. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
  123. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
  124. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
  125. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
  126. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
  127. data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
  128. data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
  129. data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
  130. data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
  131. data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
  132. data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
  133. data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
  134. data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
  135. data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
  136. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
  137. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
  138. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
  139. data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
  140. data/spec/functional/application_spec.rb +1 -1
  141. data/spec/functional/audit/runner_spec.rb +4 -0
  142. data/spec/functional/knife/ssh_spec.rb +5 -5
  143. data/spec/functional/notifications_spec.rb +74 -4
  144. data/spec/functional/resource/aix_service_spec.rb +2 -2
  145. data/spec/functional/resource/dpkg_package_spec.rb +339 -0
  146. data/spec/functional/resource/ifconfig_spec.rb +3 -1
  147. data/spec/functional/resource/mount_spec.rb +5 -2
  148. data/spec/functional/resource/package_spec.rb +1 -1
  149. data/spec/functional/resource/user/windows_spec.rb +8 -0
  150. data/spec/functional/resource/windows_package_spec.rb +177 -0
  151. data/spec/functional/win32/version_info_spec.rb +50 -0
  152. data/spec/integration/client/client_spec.rb +80 -0
  153. data/spec/integration/knife/download_spec.rb +9 -0
  154. data/spec/integration/knife/upload_spec.rb +28 -1
  155. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
  156. data/spec/integration/recipes/resource_action_spec.rb +211 -116
  157. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
  158. data/spec/integration/solo/solo_spec.rb +34 -0
  159. data/spec/spec_helper.rb +11 -1
  160. data/spec/support/platform_helpers.rb +8 -0
  161. data/spec/support/shared/integration/integration_helper.rb +6 -0
  162. data/spec/support/shared/unit/execute_resource.rb +5 -0
  163. data/spec/support/shared/unit/platform_introspector.rb +7 -0
  164. data/spec/tiny_server.rb +6 -2
  165. data/spec/unit/api_client/registration_spec.rb +5 -4
  166. data/spec/unit/application_spec.rb +1 -181
  167. data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
  168. data/spec/unit/cookbook/metadata_spec.rb +122 -2
  169. data/spec/unit/http_spec.rb +102 -0
  170. data/spec/unit/knife/bootstrap_spec.rb +55 -13
  171. data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
  172. data/spec/unit/knife/ssl_check_spec.rb +7 -3
  173. data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
  174. data/spec/unit/knife/status_spec.rb +13 -13
  175. data/spec/unit/knife_spec.rb +26 -2
  176. data/spec/unit/lwrp_spec.rb +1 -1
  177. data/spec/unit/mixin/properties_spec.rb +97 -0
  178. data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
  179. data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
  180. data/spec/unit/node_spec.rb +9 -1
  181. data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
  182. data/spec/unit/property/validation_spec.rb +14 -12
  183. data/spec/unit/property_spec.rb +56 -0
  184. data/spec/unit/provider/deploy_spec.rb +1 -1
  185. data/spec/unit/provider/dsc_resource_spec.rb +63 -24
  186. data/spec/unit/provider/execute_spec.rb +95 -28
  187. data/spec/unit/provider/package/dpkg_spec.rb +185 -96
  188. data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
  189. data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
  190. data/spec/unit/provider/package/windows_spec.rb +227 -26
  191. data/spec/unit/provider/package/yum_spec.rb +6 -0
  192. data/spec/unit/provider/package_spec.rb +495 -366
  193. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
  194. data/spec/unit/provider/script_spec.rb +2 -2
  195. data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
  196. data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
  197. data/spec/unit/provider/user/dscl_spec.rb +14 -0
  198. data/spec/unit/provider/user/windows_spec.rb +2 -2
  199. data/spec/unit/provider/user_spec.rb +9 -0
  200. data/spec/unit/provider_resolver_spec.rb +6 -30
  201. data/spec/unit/recipe_spec.rb +46 -20
  202. data/spec/unit/resource/chef_gem_spec.rb +1 -1
  203. data/spec/unit/resource/dsc_resource_spec.rb +14 -3
  204. data/spec/unit/resource/ksh_spec.rb +40 -0
  205. data/spec/unit/resource/registry_key_spec.rb +2 -2
  206. data/spec/unit/resource/resource_notification_spec.rb +44 -45
  207. data/spec/unit/resource_reporter_spec.rb +7 -0
  208. data/spec/unit/resource_spec.rb +268 -253
  209. data/spec/unit/rest_spec.rb +2 -2
  210. data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
  211. data/spec/unit/search/query_spec.rb +19 -1
  212. data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
  213. data/spec/unit/windows_service_spec.rb +83 -38
  214. data/tasks/external_tests.rb +19 -9
  215. data/tasks/rspec.rb +1 -1
  216. metadata +64 -15
  217. data/spec/support/pedant/Gemfile +0 -3
  218. data/spec/support/pedant/pedant_config.rb +0 -129
  219. data/spec/support/pedant/run_pedant.rb +0 -63
  220. data/spec/support/pedant/stickywicket.pem +0 -27
  221. data/spec/unit/provider/package_spec.rbe +0 -0
@@ -21,6 +21,10 @@ require 'chef/exceptions'
21
21
  class Chef
22
22
  class Resource
23
23
  module ActionClass
24
+ def to_s
25
+ "#{new_resource || "<no resource>"} action #{action ? action.inspect : "<no action>"}"
26
+ end
27
+
24
28
  #
25
29
  # If load_current_value! is defined on the resource, use that.
26
30
  #
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
3
+ # Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,14 +17,15 @@
17
17
  #
18
18
 
19
19
  require 'chef/resource/package'
20
- require 'chef/provider/package/dpkg'
21
20
 
22
21
  class Chef
23
22
  class Resource
24
23
  class DpkgPackage < Chef::Resource::Package
25
-
26
24
  provides :dpkg_package, os: "linux"
27
25
 
26
+ resource_name :dpkg_package
27
+
28
+ property :source, [String, Array, nil]
28
29
  end
29
30
  end
30
31
  end
@@ -20,17 +20,36 @@ require 'chef/dsl/powershell'
20
20
  class Chef
21
21
  class Resource
22
22
  class DscResource < Chef::Resource
23
-
24
23
  provides :dsc_resource, os: "windows"
25
24
 
25
+ # This class will check if the object responds to
26
+ # to_text. If it does, it will call that as opposed
27
+ # to inspect. This is useful for properties that hold
28
+ # objects such as PsCredential, where we do not want
29
+ # to dump the actual ivars
30
+ class ToTextHash < Hash
31
+ def to_text
32
+ descriptions = self.map do |(property, obj)|
33
+ obj_text = if obj.respond_to?(:to_text)
34
+ obj.to_text
35
+ else
36
+ obj.inspect
37
+ end
38
+ "#{property}=>#{obj_text}"
39
+ end
40
+ "{#{descriptions.join(', ')}}"
41
+ end
42
+ end
43
+
26
44
  include Chef::DSL::Powershell
27
45
 
28
46
  default_action :run
29
47
 
30
48
  def initialize(name, run_context)
31
49
  super
32
- @properties = {}
50
+ @properties = ToTextHash.new
33
51
  @resource = nil
52
+ @reboot_action = :nothing
34
53
  end
35
54
 
36
55
  def resource(value=nil)
@@ -68,6 +87,25 @@ class Chef
68
87
  end
69
88
  end
70
89
 
90
+ # This property takes the action message for the reboot resource
91
+ # If the set method of the DSC resource indicate that a reboot
92
+ # is necessary, reboot_action provides the mechanism for a reboot to
93
+ # be requested.
94
+ def reboot_action(value=nil)
95
+ if value
96
+ @reboot_action = value
97
+ else
98
+ @reboot_action
99
+ end
100
+ end
101
+
102
+ def timeout(arg=nil)
103
+ set_or_return(
104
+ :timeout,
105
+ arg,
106
+ :kind_of => [ Integer ]
107
+ )
108
+ end
71
109
  private
72
110
 
73
111
  def value_of(value)
@@ -49,6 +49,7 @@ class Chef
49
49
  @umask = nil
50
50
  @default_guard_interpreter = :execute
51
51
  @is_guard_interpreter = false
52
+ @live_stream = false
52
53
  end
53
54
 
54
55
  def umask(arg=nil)
@@ -101,8 +102,15 @@ class Chef
101
102
  )
102
103
  end
103
104
 
105
+ def live_stream(arg=nil)
106
+ set_or_return(
107
+ :live_stream,
108
+ arg,
109
+ :kind_of => [ TrueClass, FalseClass ])
110
+ end
111
+
104
112
  def path(arg=nil)
105
- Chef::Log.warn "'path' attribute of 'execute' is not used by any provider in Chef 11 and Chef 12. Use 'environment' attribute to configure 'PATH'. This attribute will be removed in Chef 13."
113
+ Chef::Log.warn "The 'path' attribute of 'execute' is not used by any provider in Chef 11 or Chef 12. Use 'environment' attribute to configure 'PATH'. This attribute will be removed in Chef 13."
106
114
 
107
115
  set_or_return(
108
116
  :path,
@@ -0,0 +1,32 @@
1
+ #
2
+ # Author:: Nolan Davidson (<nolan.davidson@gmail.com>)
3
+ # Copyright:: Copyright (c) 2015 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/script'
20
+
21
+ class Chef
22
+ class Resource
23
+ class Ksh < Chef::Resource::Script
24
+
25
+ def initialize(name, run_context=nil)
26
+ super
27
+ @interpreter = "ksh"
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -1,8 +1,8 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Author:: Christopher Walters (<cw@opscode.com>)
4
- # Author:: Daniel DeLeo (<dan@opscode.com>)
5
- # Copyright:: Copyright (c) 2008-2012 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Author:: Christopher Walters (<cw@chef.io>)
4
+ # Author:: Daniel DeLeo (<dan@chef.io>)
5
+ # Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -45,7 +45,7 @@ class Chef
45
45
 
46
46
  def build_from_file(cookbook_name, filename, run_context)
47
47
  if LWRPBase.loaded_lwrps[filename]
48
- Chef::Log.info("LWRP resource #{filename} from cookbook #{cookbook_name} has already been loaded! Skipping the reload.")
48
+ Chef::Log.info("Custom resource #{filename} from cookbook #{cookbook_name} has already been loaded! Skipping the reload.")
49
49
  return loaded_lwrps[filename]
50
50
  end
51
51
 
@@ -60,7 +60,7 @@ class Chef
60
60
  # Make a useful string for the class (rather than <Class:312894723894>)
61
61
  resource_class.instance_eval do
62
62
  define_singleton_method(:to_s) do
63
- "LWRP resource #{resource_name} from cookbook #{cookbook_name}"
63
+ "Custom resource #{resource_name} from cookbook #{cookbook_name}"
64
64
  end
65
65
  define_singleton_method(:inspect) { to_s }
66
66
  end
@@ -102,10 +102,6 @@ class Chef
102
102
  run_context ? run_context.node : nil
103
103
  end
104
104
 
105
- def lazy(&block)
106
- DelayedEvaluator.new(&block)
107
- end
108
-
109
105
  protected
110
106
 
111
107
  def loaded_lwrps
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
3
  # Author:: Tyler Cloke (<tyler@opscode.com>)
4
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,14 +31,13 @@ class Chef
31
31
 
32
32
  def initialize(name, run_context=nil)
33
33
  super
34
- @candidate_version = nil
35
- @options = nil
36
- @package_name = name
37
- @response_file = nil
38
- @response_file_variables = Hash.new
39
- @source = nil
40
- @version = nil
41
- @timeout = nil
34
+ options nil
35
+ package_name name
36
+ response_file nil
37
+ response_file_variables Hash.new
38
+ source nil
39
+ version nil
40
+ timeout nil
42
41
  end
43
42
 
44
43
  def package_name(arg=nil)
@@ -125,7 +125,7 @@ class Chef
125
125
  scrubbed_value = value.dup
126
126
  if needs_checksum?(scrubbed_value)
127
127
  data_io = StringIO.new(scrubbed_value[:data].to_s)
128
- scrubbed_value[:data] = Chef::Digester.instance.generate_md5_checksum(data_io)
128
+ scrubbed_value[:data] = Chef::Digester.instance.generate_checksum(data_io)
129
129
  end
130
130
  scrubbed << scrubbed_value
131
131
  end
@@ -20,7 +20,15 @@ require 'chef/resource'
20
20
 
21
21
  class Chef
22
22
  class Resource
23
- class Notification < Struct.new(:resource, :action, :notifying_resource)
23
+ class Notification
24
+
25
+ attr_accessor :resource, :action, :notifying_resource
26
+
27
+ def initialize(resource, action, notifying_resource)
28
+ @resource = resource
29
+ @action = action
30
+ @notifying_resource = notifying_resource
31
+ end
24
32
 
25
33
  def duplicates?(other_notification)
26
34
  unless other_notification.respond_to?(:resource) && other_notification.respond_to?(:action)
@@ -104,6 +112,11 @@ is defined near #{resource.source_line}
104
112
  raise err
105
113
  end
106
114
 
115
+ def ==(other)
116
+ return false unless other.is_a?(self.class)
117
+ other.resource == resource && other.action == action && other.notifying_resource == notifying_resource
118
+ end
119
+
107
120
  end
108
121
  end
109
122
  end
@@ -40,7 +40,7 @@ class Chef
40
40
  unless arg.nil?
41
41
  # Chef-13: change this to raise if the user is trying to set a value here
42
42
  Chef::Log.warn "Specifying command attribute on a script resource is a coding error, use the 'code' attribute, or the execute resource"
43
- Chef::Log.warn "This attribute is deprecated and must be fixed or this code will fail on Chef-13"
43
+ Chef::Log.warn "This attribute is deprecated and must be fixed or this code will fail on Chef 13"
44
44
  end
45
45
  super
46
46
  end
@@ -67,7 +67,7 @@ class Chef
67
67
  end
68
68
 
69
69
  def source(arg=nil)
70
- if arg == nil && self.instance_variable_defined?(:@source) == true
70
+ if arg == nil
71
71
  @source
72
72
  else
73
73
  raise ArgumentError, "Bad type for WindowsPackage resource, use a String" unless arg.is_a?(String)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Lamont Granquist (<lamont@chef.io>)
3
- # Copyright:: Copyright (c) 2015 Opscode, Inc.
3
+ # Copyright:: Copyright (c) 2015-2015 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,10 +18,6 @@
18
18
 
19
19
  # NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb
20
20
 
21
- require 'chef/exceptions'
22
- require 'chef/resource'
23
- require 'chef/log'
24
-
25
21
  class Chef
26
22
  class ResourceBuilder
27
23
  attr_reader :type
@@ -74,7 +70,14 @@ class Chef
74
70
  resource.params = params
75
71
 
76
72
  # Evaluate resource attribute DSL
77
- resource.instance_eval(&block) if block_given?
73
+ if block_given?
74
+ resource.resource_initializing = true
75
+ begin
76
+ resource.instance_eval(&block)
77
+ ensure
78
+ resource.resource_initializing = false
79
+ end
80
+ end
78
81
 
79
82
  # emit a cloned resource warning if it is warranted
80
83
  if prior_resource
@@ -134,7 +137,7 @@ class Chef
134
137
  @prior_resource ||=
135
138
  begin
136
139
  key = "#{type}[#{name}]"
137
- prior_resource = run_context.resource_collection.lookup(key)
140
+ run_context.resource_collection.lookup(key)
138
141
  rescue Chef::Exceptions::ResourceNotFound
139
142
  nil
140
143
  end
@@ -142,3 +145,7 @@ class Chef
142
145
 
143
146
  end
144
147
  end
148
+
149
+ require 'chef/exceptions'
150
+ require 'chef/resource'
151
+ require 'chef/log'
@@ -112,6 +112,7 @@ class Chef
112
112
  @exception = nil
113
113
  @rest_client = rest_client
114
114
  @error_descriptions = {}
115
+ @expanded_run_list = {}
115
116
  end
116
117
 
117
118
  def run_started(run_status)
@@ -217,6 +218,10 @@ class Chef
217
218
  end
218
219
  end
219
220
 
221
+ def run_list_expanded(run_list_expansion)
222
+ @expanded_run_list = run_list_expansion
223
+ end
224
+
220
225
  def post_reporting_data
221
226
  if reporting_enabled?
222
227
  run_data = prepare_run_data
@@ -271,6 +276,7 @@ class Chef
271
276
  run_data["data"] = {}
272
277
  run_data["start_time"] = start_time.to_s
273
278
  run_data["end_time"] = end_time.to_s
279
+ run_data["expanded_run_list"] = Chef::JSONCompat.to_json(@expanded_run_list)
274
280
 
275
281
  if exception
276
282
  exception_data = {}
@@ -43,6 +43,7 @@ require 'chef/resource/group'
43
43
  require 'chef/resource/http_request'
44
44
  require 'chef/resource/homebrew_package'
45
45
  require 'chef/resource/ifconfig'
46
+ require 'chef/resource/ksh'
46
47
  require 'chef/resource/link'
47
48
  require 'chef/resource/log'
48
49
  require 'chef/resource/macports_package'
@@ -81,10 +82,3 @@ require 'chef/resource/yum_package'
81
82
  require 'chef/resource/lwrp_base'
82
83
  require 'chef/resource/bff_package'
83
84
  require 'chef/resource/zypper_package'
84
-
85
- begin
86
- # Optional resources chef_node, chef_client, machine, machine_image, etc.
87
- require 'cheffish'
88
- require 'chef/provisioning'
89
- rescue LoadError
90
- end
@@ -166,7 +166,7 @@ class Chef
166
166
  def retriable_http_request(method, url, req_body, headers)
167
167
  rest_request = Chef::HTTP::HTTPRequest.new(method, url, req_body, headers)
168
168
 
169
- Chef::Log.debug("Sending HTTP Request via #{method} to #{url.host}:#{url.port}#{rest_request.path}")
169
+ Chef::Log.debug("Sending HTTP request via #{method} to #{url.host}:#{url.port}#{rest_request.path}")
170
170
 
171
171
  retrying_http_errors(url) do
172
172
  yield rest_request
@@ -103,6 +103,15 @@ class Chef
103
103
  # Notification handling
104
104
  #
105
105
 
106
+ #
107
+ # A Hash containing the before notifications triggered by resources
108
+ # during the converge phase of the chef run.
109
+ #
110
+ # @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from
111
+ # <notifying resource name> => <list of notifications it sent>
112
+ #
113
+ attr_reader :before_notification_collection
114
+
106
115
  #
107
116
  # A Hash containing the immediate notifications triggered by resources
108
117
  # during the converge phase of the chef run.
@@ -164,10 +173,25 @@ class Chef
164
173
  def initialize_child_state
165
174
  @audits = {}
166
175
  @resource_collection = Chef::ResourceCollection.new
176
+ @before_notification_collection = Hash.new {|h,k| h[k] = []}
167
177
  @immediate_notification_collection = Hash.new {|h,k| h[k] = []}
168
178
  @delayed_notification_collection = Hash.new {|h,k| h[k] = []}
169
179
  end
170
180
 
181
+ #
182
+ # Adds an before notification to the +before_notification_collection+.
183
+ #
184
+ # @param [Chef::Resource::Notification] The notification to add.
185
+ #
186
+ def notifies_before(notification)
187
+ nr = notification.notifying_resource
188
+ if nr.instance_of?(Chef::Resource)
189
+ before_notification_collection[nr.name] << notification
190
+ else
191
+ before_notification_collection[nr.declared_key] << notification
192
+ end
193
+ end
194
+
171
195
  #
172
196
  # Adds an immediate notification to the +immediate_notification_collection+.
173
197
  #
@@ -196,6 +220,22 @@ class Chef
196
220
  end
197
221
  end
198
222
 
223
+ #
224
+ # Get the list of before notifications sent by the given resource.
225
+ #
226
+ # TODO seriously, this is actually wrong. resource.name is not unique,
227
+ # you need the type as well.
228
+ #
229
+ # @return [Array[Notification]]
230
+ #
231
+ def before_notifications(resource)
232
+ if resource.instance_of?(Chef::Resource)
233
+ return before_notification_collection[resource.name]
234
+ else
235
+ return before_notification_collection[resource.declared_key]
236
+ end
237
+ end
238
+
199
239
  #
200
240
  # Get the list of immediate notifications sent by the given resource.
201
241
  #
@@ -268,7 +308,7 @@ class Chef
268
308
  # @see DSL::IncludeRecipe#load_recipe
269
309
  #
270
310
  def load_recipe(recipe_name, current_cookbook: nil)
271
- Chef::Log.debug("Loading Recipe #{recipe_name} via include_recipe")
311
+ Chef::Log.debug("Loading recipe #{recipe_name} via include_recipe")
272
312
 
273
313
  cookbook_name, recipe_short_name = Chef::Recipe.parse_recipe_name(recipe_name, current_cookbook: current_cookbook)
274
314
 
@@ -308,7 +348,7 @@ ERROR_MESSAGE
308
348
  raise Chef::Exceptions::RecipeNotFound, "could not find recipe file #{recipe_file}"
309
349
  end
310
350
 
311
- Chef::Log.debug("Loading Recipe File #{recipe_file}")
351
+ Chef::Log.debug("Loading recipe file #{recipe_file}")
312
352
  recipe = Chef::Recipe.new('@recipe_files', recipe_file, self)
313
353
  recipe.from_file(recipe_file)
314
354
  recipe
@@ -608,10 +648,13 @@ ERROR_MESSAGE
608
648
  immediate_notification_collection
609
649
  immediate_notification_collection=
610
650
  immediate_notifications
651
+ before_notification_collection
652
+ before_notifications
611
653
  include_recipe
612
654
  initialize_child_state
613
655
  load_recipe
614
656
  load_recipe_file
657
+ notifies_before
615
658
  notifies_immediately
616
659
  notifies_delayed
617
660
  parent_run_context