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
@@ -1,5 +1,8 @@
1
1
  require 'support/shared/integration/integration_helper'
2
2
 
3
+ # Houses any classes we declare
4
+ module ResourceActionSpec
5
+
3
6
  describe "Resource.action" do
4
7
  include IntegrationSupport
5
8
 
@@ -85,7 +88,7 @@ describe "Resource.action" do
85
88
  converge <<-EOM, __FILE__, __LINE__+1
86
89
  ruby_block 'wow' do
87
90
  block do
88
- ActionJackson.ruby_block_converged = 'ruby_block_converged!'
91
+ ResourceActionSpec::ActionJackson.ruby_block_converged = 'ruby_block_converged!'
89
92
  end
90
93
  end
91
94
 
@@ -107,7 +110,7 @@ describe "Resource.action" do
107
110
 
108
111
  ruby_block 'wow' do
109
112
  block do
110
- ActionJackson.ruby_block_converged = ActionJackson.succeeded
113
+ ResourceActionSpec::ActionJackson.ruby_block_converged = ResourceActionSpec::ActionJackson.succeeded
111
114
  end
112
115
  end
113
116
  EOM
@@ -118,80 +121,79 @@ describe "Resource.action" do
118
121
  end
119
122
 
120
123
  context "With resource 'action_jackson'" do
121
- before(:context) {
122
- class ActionJackson < Chef::Resource
123
- use_automatic_resource_name
124
- def foo(value=nil)
125
- @foo = value if value
126
- @foo
127
- end
128
- def blarghle(value=nil)
129
- @blarghle = value if value
130
- @blarghle
131
- end
124
+ class ActionJackson < Chef::Resource
125
+ use_automatic_resource_name
126
+ def foo(value=nil)
127
+ @foo = value if value
128
+ @foo
129
+ end
130
+ def blarghle(value=nil)
131
+ @blarghle = value if value
132
+ @blarghle
133
+ end
132
134
 
133
- class <<self
134
- attr_accessor :ran_action
135
- attr_accessor :succeeded
136
- attr_accessor :ruby_block_converged
137
- end
135
+ class <<self
136
+ attr_accessor :ran_action
137
+ attr_accessor :succeeded
138
+ attr_accessor :ruby_block_converged
139
+ end
138
140
 
139
- public
140
- def foo_public
141
- 'foo_public!'
142
- end
143
- protected
144
- def foo_protected
145
- 'foo_protected!'
146
- end
147
- private
148
- def foo_private
149
- 'foo_private!'
150
- end
141
+ public
142
+ def foo_public
143
+ 'foo_public!'
144
+ end
145
+ protected
146
+ def foo_protected
147
+ 'foo_protected!'
148
+ end
149
+ private
150
+ def foo_private
151
+ 'foo_private!'
152
+ end
151
153
 
152
- public
153
- action :access_recipe_dsl do
154
- ActionJackson.ran_action = :access_recipe_dsl
155
- ruby_block 'hi there' do
156
- block do
157
- ActionJackson.succeeded = true
158
- end
154
+ public
155
+ action :access_recipe_dsl do
156
+ ActionJackson.ran_action = :access_recipe_dsl
157
+ ruby_block 'hi there' do
158
+ block do
159
+ ActionJackson.succeeded = true
159
160
  end
160
161
  end
161
- action :access_attribute do
162
- ActionJackson.ran_action = :access_attribute
163
- ActionJackson.succeeded = foo
164
- ActionJackson.succeeded += " #{blarghle}" if blarghle
165
- ActionJackson.succeeded += " #{bar}" if respond_to?(:bar)
166
- end
167
- action :access_attribute2 do
168
- ActionJackson.ran_action = :access_attribute2
169
- ActionJackson.succeeded = foo
170
- ActionJackson.succeeded += " #{blarghle}" if blarghle
171
- ActionJackson.succeeded += " #{bar}" if respond_to?(:bar)
172
- end
173
- action :access_method do
174
- ActionJackson.ran_action = :access_method
175
- ActionJackson.succeeded = foo_public
176
- end
177
- action :access_protected_method do
178
- ActionJackson.ran_action = :access_protected_method
179
- ActionJackson.succeeded = foo_protected
180
- end
181
- action :access_private_method do
182
- ActionJackson.ran_action = :access_private_method
183
- ActionJackson.succeeded = foo_private
184
- end
185
- action :access_instance_variable do
186
- ActionJackson.ran_action = :access_instance_variable
187
- ActionJackson.succeeded = @foo
188
- end
189
- action :access_class_method do
190
- ActionJackson.ran_action = :access_class_method
191
- ActionJackson.succeeded = ActionJackson.ruby_block_converged
192
- end
193
162
  end
194
- }
163
+ action :access_attribute do
164
+ ActionJackson.ran_action = :access_attribute
165
+ ActionJackson.succeeded = foo
166
+ ActionJackson.succeeded += " #{blarghle}" if blarghle
167
+ ActionJackson.succeeded += " #{bar}" if respond_to?(:bar)
168
+ end
169
+ action :access_attribute2 do
170
+ ActionJackson.ran_action = :access_attribute2
171
+ ActionJackson.succeeded = foo
172
+ ActionJackson.succeeded += " #{blarghle}" if blarghle
173
+ ActionJackson.succeeded += " #{bar}" if respond_to?(:bar)
174
+ end
175
+ action :access_method do
176
+ ActionJackson.ran_action = :access_method
177
+ ActionJackson.succeeded = foo_public
178
+ end
179
+ action :access_protected_method do
180
+ ActionJackson.ran_action = :access_protected_method
181
+ ActionJackson.succeeded = foo_protected
182
+ end
183
+ action :access_private_method do
184
+ ActionJackson.ran_action = :access_private_method
185
+ ActionJackson.succeeded = foo_private
186
+ end
187
+ action :access_instance_variable do
188
+ ActionJackson.ran_action = :access_instance_variable
189
+ ActionJackson.succeeded = @foo
190
+ end
191
+ action :access_class_method do
192
+ ActionJackson.ran_action = :access_class_method
193
+ ActionJackson.succeeded = ActionJackson.ruby_block_converged
194
+ end
195
+ end
196
+
195
197
  before(:each) {
196
198
  ActionJackson.ran_action = :error
197
199
  ActionJackson.succeeded = :error
@@ -220,33 +222,31 @@ describe "Resource.action" do
220
222
  end
221
223
 
222
224
  context "And 'action_jackalope' inheriting from ActionJackson with an extra attribute, action and custom method" do
223
- before(:context) {
224
- class ActionJackalope < ActionJackson
225
- use_automatic_resource_name
225
+ class ActionJackalope < ActionJackson
226
+ use_automatic_resource_name
226
227
 
227
- def foo(value=nil)
228
- @foo = "#{value}alope" if value
229
- @foo
230
- end
231
- def bar(value=nil)
232
- @bar = "#{value}alope" if value
233
- @bar
234
- end
235
- class <<self
236
- attr_accessor :load_current_resource_ran
237
- attr_accessor :jackalope_ran
238
- end
239
- action :access_jackalope do
240
- ActionJackalope.jackalope_ran = :access_jackalope
241
- ActionJackalope.succeeded = "#{foo} #{blarghle} #{bar}"
242
- end
243
- action :access_attribute do
244
- super()
245
- ActionJackalope.jackalope_ran = :access_attribute
246
- ActionJackalope.succeeded = ActionJackson.succeeded
247
- end
228
+ def foo(value=nil)
229
+ @foo = "#{value}alope" if value
230
+ @foo
248
231
  end
249
- }
232
+ def bar(value=nil)
233
+ @bar = "#{value}alope" if value
234
+ @bar
235
+ end
236
+ class <<self
237
+ attr_accessor :load_current_resource_ran
238
+ attr_accessor :jackalope_ran
239
+ end
240
+ action :access_jackalope do
241
+ ActionJackalope.jackalope_ran = :access_jackalope
242
+ ActionJackalope.succeeded = "#{foo} #{blarghle} #{bar}"
243
+ end
244
+ action :access_attribute do
245
+ super()
246
+ ActionJackalope.jackalope_ran = :access_attribute
247
+ ActionJackalope.succeeded = ActionJackson.succeeded
248
+ end
249
+ end
250
250
  before do
251
251
  ActionJackalope.jackalope_ran = nil
252
252
  ActionJackalope.load_current_resource_ran = nil
@@ -313,20 +313,19 @@ describe "Resource.action" do
313
313
  end
314
314
 
315
315
  context "With a resource with no actions" do
316
- before(:context) {
317
- class NoActionJackson < Chef::Resource
318
- use_automatic_resource_name
316
+ class NoActionJackson < Chef::Resource
317
+ use_automatic_resource_name
319
318
 
320
- def foo(value=nil)
321
- @foo = value if value
322
- @foo
323
- end
319
+ def foo(value=nil)
320
+ @foo = value if value
321
+ @foo
322
+ end
324
323
 
325
- class <<self
326
- attr_accessor :action_was
327
- end
324
+ class <<self
325
+ attr_accessor :action_was
328
326
  end
329
- }
327
+ end
328
+
330
329
  it "the default action is :nothing" do
331
330
  converge {
332
331
  no_action_jackson 'hi' do
@@ -339,19 +338,17 @@ describe "Resource.action" do
339
338
  end
340
339
 
341
340
  context "With a resource with action a-b-c d" do
342
- before(:context) {
343
- class WeirdActionJackson < Chef::Resource
344
- use_automatic_resource_name
341
+ class WeirdActionJackson < Chef::Resource
342
+ use_automatic_resource_name
345
343
 
346
- class <<self
347
- attr_accessor :action_was
348
- end
344
+ class <<self
345
+ attr_accessor :action_was
346
+ end
349
347
 
350
- action "a-b-c d" do
351
- WeirdActionJackson.action_was = action
352
- end
348
+ action "a-b-c d" do
349
+ WeirdActionJackson.action_was = action
353
350
  end
354
- }
351
+ end
355
352
 
356
353
  it "Running the action works" do
357
354
  expect_recipe {
@@ -360,4 +357,102 @@ describe "Resource.action" do
360
357
  expect(WeirdActionJackson.action_was).to eq :"a-b-c d"
361
358
  end
362
359
  end
360
+
361
+ context "With a resource with property x" do
362
+ class ResourceActionSpecWithX < Chef::Resource
363
+ resource_name :resource_action_spec_with_x
364
+ property :x, default: 20
365
+ action :set do
366
+ # Access x during converge to ensure that we emit no warnings there
367
+ x
368
+ end
369
+ end
370
+
371
+ context "And another resource with a property x and an action that sets property x to its value" do
372
+ class ResourceActionSpecAlsoWithX < Chef::Resource
373
+ resource_name :resource_action_spec_also_with_x
374
+ property :x
375
+ action :set_x_to_x do
376
+ resource_action_spec_with_x 'hi' do
377
+ x x
378
+ end
379
+ end
380
+ def self.x_warning_line
381
+ __LINE__-4
382
+ end
383
+ action :set_x_to_x_in_non_initializer do
384
+ r = resource_action_spec_with_x 'hi' do
385
+ x 10
386
+ end
387
+ x_times_2 = r.x*2
388
+ end
389
+ action :set_x_to_10 do
390
+ resource_action_spec_with_x 'hi' do
391
+ x 10
392
+ end
393
+ end
394
+ end
395
+
396
+ attr_reader :x_warning_line
397
+
398
+ it "Using the enclosing resource to set x to x emits a warning that you're using the wrong x" do
399
+ recipe = converge {
400
+ resource_action_spec_also_with_x 'hi' do
401
+ x 1
402
+ action :set_x_to_x
403
+ end
404
+ }
405
+ warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
406
+ expect(warnings.size).to eq 1
407
+ expect(warnings[0]).to match(/property x is declared in both resource_action_spec_with_x\[hi\] and resource_action_spec_also_with_x\[hi\] action :set_x_to_x. Use new_resource.x instead. At #{__FILE__}:#{ResourceActionSpecAlsoWithX.x_warning_line}/)
408
+ end
409
+
410
+ it "Using the enclosing resource to set x to x outside the initializer emits no warning" do
411
+ expect_recipe {
412
+ resource_action_spec_also_with_x 'hi' do
413
+ x 1
414
+ action :set_x_to_x_in_non_initializer
415
+ end
416
+ }.to emit_no_warnings_or_errors
417
+ end
418
+
419
+ it "Using the enclosing resource to set x to 10 emits no warning" do
420
+ expect_recipe {
421
+ resource_action_spec_also_with_x 'hi' do
422
+ x 1
423
+ action :set_x_to_10
424
+ end
425
+ }.to emit_no_warnings_or_errors
426
+ end
427
+
428
+ it "Using the enclosing resource to set x to 10 emits no warning" do
429
+ expect_recipe {
430
+ r = resource_action_spec_also_with_x 'hi'
431
+ r.x 1
432
+ r.action :set_x_to_10
433
+ }.to emit_no_warnings_or_errors
434
+ end
435
+ end
436
+
437
+ end
438
+
439
+ context "When a resource has a property with the same name as another resource" do
440
+ class HasPropertyNamedTemplate < Chef::Resource
441
+ use_automatic_resource_name
442
+ property :template
443
+ action :create do
444
+ template "x" do
445
+ 'blah'
446
+ end
447
+ end
448
+ end
449
+
450
+ it "Raises an error when attempting to use a template in the action" do
451
+ expect_converge {
452
+ has_property_named_template 'hi'
453
+ }.to raise_error(/Property template of has_property_named_template\[hi\] cannot be passed a block! If you meant to create a resource named template instead, you'll need to first rename the property./)
454
+ end
455
+ end
456
+ end
457
+
363
458
  end
@@ -110,6 +110,29 @@ EOM
110
110
  end
111
111
  end
112
112
 
113
+ context "and state1 and state2 are set to new sensitive values" do
114
+ let(:converge_recipe) {
115
+ <<-EOM
116
+ #{resource_name} 'blah' do
117
+ sensitive true
118
+ state1 'new_state1'
119
+ state2 'new_state2'
120
+ end
121
+ EOM
122
+ }
123
+
124
+ it "the resource updates state1 and state2" do
125
+ expect(resource.converged).to eq 1
126
+ expect(resource.updated?).to be_truthy
127
+ expect(converged_recipe.stdout).to eq <<-EOM
128
+ * #{resource_name}[blah] action create
129
+ - update default_identity1
130
+ - set state1 to (suppressed sensitive property)
131
+ - set state2 to (suppressed sensitive property)
132
+ EOM
133
+ end
134
+ end
135
+
113
136
  context "and state1 is set to its current value but state2 is set to a new value" do
114
137
  let(:converge_recipe) {
115
138
  <<-EOM
@@ -246,6 +269,30 @@ EOM
246
269
  - set identity1 to "default_identity1" (default value)
247
270
  - set state1 to "new_state1"
248
271
  - set state2 to "new_state2"
272
+ EOM
273
+ end
274
+ end
275
+
276
+ context "and state1 and state2 are set with sensitive property" do
277
+ let(:converge_recipe) {
278
+ <<-EOM
279
+ #{resource_name} 'blah' do
280
+ sensitive true
281
+ state1 'new_state1'
282
+ state2 'new_state2'
283
+ end
284
+ EOM
285
+ }
286
+
287
+ it "the resource is created" do
288
+ expect(resource.converged).to eq 1
289
+ expect(resource.updated?).to be_truthy
290
+ expect(converged_recipe.stdout).to eq <<-EOM
291
+ * #{resource_name}[blah] action create
292
+ - create default_identity1
293
+ - set identity1 to (suppressed sensitive property) (default value)
294
+ - set state1 to (suppressed sensitive property)
295
+ - set state2 to (suppressed sensitive property)
249
296
  EOM
250
297
  end
251
298
  end
@@ -416,6 +463,31 @@ EOM
416
463
  EOM
417
464
  end
418
465
  end
466
+
467
+ context "and state1 and state2 are set to new sensitive values" do
468
+ let(:converge_recipe) {
469
+ <<-EOM
470
+ #{resource_name} 'blah' do
471
+ sensitive true
472
+ state1 'new_state1'
473
+ state2 'new_state2'
474
+ end
475
+ EOM
476
+ }
477
+
478
+ it "the resource is created" do
479
+ expect(resource.converged).to eq 2
480
+ expect(resource.updated?).to be_truthy
481
+ expect(converged_recipe.stdout).to eq <<-EOM
482
+ * #{resource_name}[blah] action create
483
+ - create default_identity1
484
+ - set state1 to (suppressed sensitive property)
485
+ - create default_identity1
486
+ - set state2 to (suppressed sensitive property)
487
+ EOM
488
+ end
489
+ end
490
+
419
491
  end
420
492
  end
421
493