chef 12.4.0.rc.0-universal-mingw32 → 12.4.0.rc.2-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +12 -1
  3. data/lib/chef/api_client.rb +130 -26
  4. data/lib/chef/application.rb +0 -1
  5. data/lib/chef/application/client.rb +8 -19
  6. data/lib/chef/audit/audit_reporter.rb +12 -7
  7. data/lib/chef/audit/logger.rb +36 -0
  8. data/lib/chef/audit/runner.rb +4 -2
  9. data/lib/chef/chef_class.rb +62 -11
  10. data/lib/chef/client.rb +587 -207
  11. data/lib/chef/config.rb +0 -1
  12. data/lib/chef/dsl/recipe.rb +45 -56
  13. data/lib/chef/dsl/resources.rb +3 -2
  14. data/lib/chef/event_dispatch/base.rb +7 -2
  15. data/lib/chef/exceptions.rb +4 -1
  16. data/lib/chef/file_content_management/deploy/mv_windows.rb +16 -6
  17. data/lib/chef/formatters/doc.rb +15 -7
  18. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +10 -7
  19. data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -0
  20. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +4 -1
  21. data/lib/chef/http/authenticator.rb +7 -2
  22. data/lib/chef/knife.rb +16 -4
  23. data/lib/chef/knife/client_create.rb +55 -31
  24. data/lib/chef/knife/core/generic_presenter.rb +1 -1
  25. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  26. data/lib/chef/knife/osc_user_create.rb +97 -0
  27. data/lib/chef/knife/osc_user_delete.rb +51 -0
  28. data/lib/chef/knife/osc_user_edit.rb +58 -0
  29. data/lib/chef/knife/osc_user_list.rb +47 -0
  30. data/lib/chef/knife/osc_user_reregister.rb +64 -0
  31. data/lib/chef/knife/osc_user_show.rb +54 -0
  32. data/lib/chef/knife/user_create.rb +95 -36
  33. data/lib/chef/knife/user_delete.rb +52 -2
  34. data/lib/chef/knife/user_edit.rb +37 -7
  35. data/lib/chef/knife/user_list.rb +3 -0
  36. data/lib/chef/knife/user_reregister.rb +39 -8
  37. data/lib/chef/knife/user_show.rb +30 -1
  38. data/lib/chef/mixin/api_version_request_handling.rb +66 -0
  39. data/lib/chef/mixin/convert_to_class_name.rb +10 -4
  40. data/lib/chef/mixin/deprecation.rb +24 -0
  41. data/lib/chef/mixin/powershell_out.rb +98 -0
  42. data/lib/chef/mixin/provides.rb +5 -18
  43. data/lib/chef/mixin/uris.rb +11 -0
  44. data/lib/chef/mixin/windows_architecture_helper.rb +5 -2
  45. data/lib/chef/mixin/windows_env_helper.rb +11 -2
  46. data/lib/chef/node_map.rb +130 -75
  47. data/lib/chef/osc_user.rb +194 -0
  48. data/lib/chef/platform/provider_mapping.rb +2 -269
  49. data/lib/chef/platform/provider_priority_map.rb +6 -69
  50. data/lib/chef/platform/query_helpers.rb +5 -0
  51. data/lib/chef/platform/resource_priority_map.rb +12 -15
  52. data/lib/chef/policy_builder/policyfile.rb +1 -0
  53. data/lib/chef/provider.rb +19 -0
  54. data/lib/chef/provider/directory.rb +3 -0
  55. data/lib/chef/provider/dsc_resource.rb +8 -1
  56. data/lib/chef/provider/file.rb +1 -0
  57. data/lib/chef/provider/group/aix.rb +1 -0
  58. data/lib/chef/provider/group/dscl.rb +1 -1
  59. data/lib/chef/provider/group/gpasswd.rb +1 -0
  60. data/lib/chef/provider/group/groupmod.rb +1 -1
  61. data/lib/chef/provider/group/pw.rb +1 -0
  62. data/lib/chef/provider/group/suse.rb +2 -0
  63. data/lib/chef/provider/group/usermod.rb +2 -1
  64. data/lib/chef/provider/group/windows.rb +1 -1
  65. data/lib/chef/provider/ifconfig.rb +2 -0
  66. data/lib/chef/provider/ifconfig/aix.rb +1 -0
  67. data/lib/chef/provider/ifconfig/debian.rb +2 -0
  68. data/lib/chef/provider/ifconfig/redhat.rb +1 -0
  69. data/lib/chef/provider/lwrp_base.rb +4 -0
  70. data/lib/chef/provider/mount.rb +0 -1
  71. data/lib/chef/provider/mount/aix.rb +1 -0
  72. data/lib/chef/provider/mount/mount.rb +2 -0
  73. data/lib/chef/provider/mount/solaris.rb +2 -0
  74. data/lib/chef/provider/package.rb +55 -0
  75. data/lib/chef/provider/package/aix.rb +7 -7
  76. data/lib/chef/provider/package/apt.rb +3 -3
  77. data/lib/chef/provider/package/dpkg.rb +4 -4
  78. data/lib/chef/provider/package/easy_install.rb +5 -5
  79. data/lib/chef/provider/package/freebsd/base.rb +2 -2
  80. data/lib/chef/provider/package/freebsd/pkg.rb +6 -6
  81. data/lib/chef/provider/package/freebsd/pkgng.rb +5 -5
  82. data/lib/chef/provider/package/freebsd/port.rb +4 -4
  83. data/lib/chef/provider/package/homebrew.rb +2 -2
  84. data/lib/chef/provider/package/ips.rb +4 -4
  85. data/lib/chef/provider/package/macports.rb +5 -6
  86. data/lib/chef/provider/package/openbsd.rb +4 -5
  87. data/lib/chef/provider/package/pacman.rb +4 -4
  88. data/lib/chef/provider/package/portage.rb +2 -0
  89. data/lib/chef/provider/package/rpm.rb +7 -8
  90. data/lib/chef/provider/package/rubygems.rb +5 -12
  91. data/lib/chef/provider/package/smartos.rb +4 -4
  92. data/lib/chef/provider/package/solaris.rb +7 -7
  93. data/lib/chef/provider/package/windows/msi.rb +1 -1
  94. data/lib/chef/provider/package/yum.rb +4 -6
  95. data/lib/chef/provider/package/zypper.rb +16 -14
  96. data/lib/chef/provider/powershell_script.rb +129 -47
  97. data/lib/chef/provider/remote_file/content.rb +4 -1
  98. data/lib/chef/provider/remote_file/local_file.rb +10 -4
  99. data/lib/chef/provider/service.rb +44 -0
  100. data/lib/chef/provider/service/freebsd.rb +1 -1
  101. data/lib/chef/provider/service/init.rb +1 -0
  102. data/lib/chef/provider/service/macosx.rb +1 -1
  103. data/lib/chef/provider/service/windows.rb +0 -1
  104. data/lib/chef/provider/user.rb +1 -1
  105. data/lib/chef/provider/user/aix.rb +3 -2
  106. data/lib/chef/provider/user/pw.rb +1 -0
  107. data/lib/chef/provider/user/solaris.rb +2 -0
  108. data/lib/chef/provider/user/useradd.rb +1 -0
  109. data/lib/chef/provider_resolver.rb +87 -134
  110. data/lib/chef/resource.rb +274 -68
  111. data/lib/chef/resource/apt_package.rb +0 -2
  112. data/lib/chef/resource/bash.rb +0 -2
  113. data/lib/chef/resource/batch.rb +1 -1
  114. data/lib/chef/resource/bff_package.rb +0 -7
  115. data/lib/chef/resource/breakpoint.rb +3 -6
  116. data/lib/chef/resource/chef_gem.rb +0 -3
  117. data/lib/chef/resource/cookbook_file.rb +1 -3
  118. data/lib/chef/resource/cron.rb +2 -4
  119. data/lib/chef/resource/csh.rb +0 -2
  120. data/lib/chef/resource/deploy.rb +9 -6
  121. data/lib/chef/resource/deploy_revision.rb +0 -14
  122. data/lib/chef/resource/directory.rb +2 -4
  123. data/lib/chef/resource/dpkg_package.rb +0 -5
  124. data/lib/chef/resource/dsc_resource.rb +2 -3
  125. data/lib/chef/resource/dsc_script.rb +2 -3
  126. data/lib/chef/resource/easy_install_package.rb +0 -7
  127. data/lib/chef/resource/env.rb +3 -3
  128. data/lib/chef/resource/erl_call.rb +2 -5
  129. data/lib/chef/resource/execute.rb +2 -4
  130. data/lib/chef/resource/file.rb +2 -4
  131. data/lib/chef/resource/freebsd_package.rb +0 -5
  132. data/lib/chef/resource/gem_package.rb +0 -3
  133. data/lib/chef/resource/git.rb +0 -3
  134. data/lib/chef/resource/group.rb +2 -4
  135. data/lib/chef/resource/homebrew_package.rb +0 -2
  136. data/lib/chef/resource/http_request.rb +3 -4
  137. data/lib/chef/resource/ifconfig.rb +3 -4
  138. data/lib/chef/resource/ips_package.rb +2 -2
  139. data/lib/chef/resource/link.rb +3 -5
  140. data/lib/chef/resource/log.rb +2 -4
  141. data/lib/chef/resource/lwrp_base.rb +10 -61
  142. data/lib/chef/resource/macosx_service.rb +1 -2
  143. data/lib/chef/resource/macports_package.rb +0 -7
  144. data/lib/chef/resource/mdadm.rb +2 -5
  145. data/lib/chef/resource/mount.rb +2 -4
  146. data/lib/chef/resource/ohai.rb +2 -4
  147. data/lib/chef/resource/openbsd_package.rb +0 -6
  148. data/lib/chef/resource/package.rb +9 -6
  149. data/lib/chef/resource/pacman_package.rb +0 -7
  150. data/lib/chef/resource/paludis_package.rb +2 -3
  151. data/lib/chef/resource/perl.rb +0 -3
  152. data/lib/chef/resource/portage_package.rb +0 -3
  153. data/lib/chef/resource/powershell_script.rb +1 -2
  154. data/lib/chef/resource/python.rb +0 -3
  155. data/lib/chef/resource/reboot.rb +1 -3
  156. data/lib/chef/resource/registry_key.rb +3 -5
  157. data/lib/chef/resource/remote_directory.rb +3 -5
  158. data/lib/chef/resource/remote_file.rb +4 -5
  159. data/lib/chef/resource/route.rb +3 -5
  160. data/lib/chef/resource/rpm_package.rb +0 -2
  161. data/lib/chef/resource/ruby.rb +0 -4
  162. data/lib/chef/resource/ruby_block.rb +2 -4
  163. data/lib/chef/resource/scm.rb +3 -5
  164. data/lib/chef/resource/script.rb +0 -3
  165. data/lib/chef/resource/service.rb +3 -5
  166. data/lib/chef/resource/smartos_package.rb +0 -9
  167. data/lib/chef/resource/solaris_package.rb +0 -10
  168. data/lib/chef/resource/subversion.rb +1 -3
  169. data/lib/chef/resource/template.rb +0 -4
  170. data/lib/chef/resource/timestamped_deploy.rb +0 -4
  171. data/lib/chef/resource/user.rb +2 -5
  172. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -7
  173. data/lib/chef/resource/windows_package.rb +3 -3
  174. data/lib/chef/resource/windows_script.rb +2 -2
  175. data/lib/chef/resource/windows_service.rb +3 -3
  176. data/lib/chef/resource/yum_package.rb +0 -3
  177. data/lib/chef/resource/zypper_package.rb +27 -0
  178. data/lib/chef/resource_builder.rb +7 -0
  179. data/lib/chef/resource_reporter.rb +1 -1
  180. data/lib/chef/resource_resolver.rb +108 -62
  181. data/lib/chef/resources.rb +1 -0
  182. data/lib/chef/rest.rb +1 -0
  183. data/lib/chef/server_api.rb +2 -0
  184. data/lib/chef/user.rb +193 -42
  185. data/lib/chef/util/backup.rb +9 -1
  186. data/lib/chef/util/path_helper.rb +0 -1
  187. data/lib/chef/version.rb +1 -1
  188. data/spec/functional/audit/runner_spec.rb +22 -42
  189. data/spec/functional/mixin/powershell_out_spec.rb +43 -0
  190. data/spec/functional/resource/execute_spec.rb +9 -2
  191. data/spec/functional/resource/file_spec.rb +25 -0
  192. data/spec/functional/resource/group_spec.rb +5 -0
  193. data/spec/functional/resource/link_spec.rb +5 -11
  194. data/spec/functional/resource/powershell_spec.rb +40 -5
  195. data/spec/functional/resource/user/useradd_spec.rb +10 -18
  196. data/spec/integration/recipes/lwrp_spec.rb +57 -0
  197. data/spec/integration/recipes/provider_choice.rb +2 -7
  198. data/spec/integration/recipes/recipe_dsl_spec.rb +517 -19
  199. data/spec/spec_helper.rb +1 -1
  200. data/spec/support/lib/chef/provider/openldap_includer.rb +29 -0
  201. data/spec/support/lib/chef/resource/cat.rb +0 -2
  202. data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -6
  203. data/spec/support/lib/chef/resource/openldap_includer.rb +27 -0
  204. data/spec/support/lib/chef/resource/with_state.rb +0 -9
  205. data/spec/support/lib/chef/resource/zen_follower.rb +0 -6
  206. data/spec/support/lib/chef/resource/zen_master.rb +1 -6
  207. data/spec/support/shared/context/client.rb +277 -0
  208. data/spec/support/shared/examples/client.rb +53 -0
  209. data/spec/support/shared/functional/file_resource.rb +0 -4
  210. data/spec/support/shared/functional/securable_resource.rb +0 -24
  211. data/spec/support/shared/functional/securable_resource_with_reporting.rb +4 -4
  212. data/spec/support/shared/functional/windows_script.rb +1 -1
  213. data/spec/support/shared/unit/api_versioning.rb +77 -0
  214. data/spec/support/shared/unit/knife_shared.rb +40 -0
  215. data/spec/support/shared/unit/user_and_client_shared.rb +115 -0
  216. data/spec/unit/api_client_spec.rb +189 -14
  217. data/spec/unit/application/client_spec.rb +0 -5
  218. data/spec/unit/audit/audit_reporter_spec.rb +58 -14
  219. data/spec/unit/audit/logger_spec.rb +42 -0
  220. data/spec/unit/audit/runner_spec.rb +2 -2
  221. data/spec/unit/chef_fs/file_pattern_spec.rb +3 -15
  222. data/spec/unit/client_spec.rb +58 -374
  223. data/spec/unit/cookbook_spec.rb +0 -9
  224. data/spec/unit/cookbook_version_spec.rb +0 -20
  225. data/spec/unit/deprecation_spec.rb +55 -0
  226. data/spec/unit/dsl/resources_spec.rb +85 -0
  227. data/spec/unit/exceptions_spec.rb +2 -2
  228. data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +60 -0
  229. data/spec/unit/formatters/doc_spec.rb +46 -0
  230. data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +12 -10
  231. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +8 -0
  232. data/spec/unit/http/authenticator_spec.rb +11 -2
  233. data/spec/unit/knife/client_create_spec.rb +122 -51
  234. data/spec/unit/knife/core/subcommand_loader_spec.rb +19 -3
  235. data/spec/unit/knife/core/ui_spec.rb +14 -0
  236. data/spec/unit/knife/osc_user_create_spec.rb +93 -0
  237. data/spec/unit/knife/osc_user_delete_spec.rb +44 -0
  238. data/spec/unit/knife/osc_user_edit_spec.rb +52 -0
  239. data/spec/unit/knife/osc_user_list_spec.rb +37 -0
  240. data/spec/unit/knife/osc_user_reregister_spec.rb +58 -0
  241. data/spec/unit/knife/osc_user_show_spec.rb +46 -0
  242. data/spec/unit/knife/user_create_spec.rb +177 -51
  243. data/spec/unit/knife/user_delete_spec.rb +34 -8
  244. data/spec/unit/knife/user_edit_spec.rb +31 -12
  245. data/spec/unit/knife/user_list_spec.rb +7 -3
  246. data/spec/unit/knife/user_reregister_spec.rb +38 -17
  247. data/spec/unit/knife/user_show_spec.rb +35 -11
  248. data/spec/unit/knife_spec.rb +10 -4
  249. data/spec/unit/lwrp_spec.rb +228 -54
  250. data/spec/unit/mixin/api_version_request_handling_spec.rb +127 -0
  251. data/spec/unit/mixin/command_spec.rb +1 -2
  252. data/spec/unit/mixin/powershell_out_spec.rb +70 -0
  253. data/spec/unit/mixin/uris_spec.rb +23 -11
  254. data/spec/unit/node_map_spec.rb +4 -1
  255. data/spec/unit/osc_user_spec.rb +276 -0
  256. data/spec/unit/platform_spec.rb +0 -60
  257. data/spec/unit/provider/deploy_spec.rb +1 -1
  258. data/spec/unit/provider/directory_spec.rb +199 -135
  259. data/spec/unit/provider/ifconfig/debian_spec.rb +0 -10
  260. data/spec/unit/provider/package/aix_spec.rb +16 -16
  261. data/spec/unit/provider/package/dpkg_spec.rb +2 -2
  262. data/spec/unit/provider/package/freebsd/pkg_spec.rb +13 -13
  263. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
  264. data/spec/unit/provider/package/freebsd/port_spec.rb +7 -7
  265. data/spec/unit/provider/package/ips_spec.rb +22 -22
  266. data/spec/unit/provider/package/macports_spec.rb +10 -10
  267. data/spec/unit/provider/package/openbsd_spec.rb +4 -26
  268. data/spec/unit/provider/package/pacman_spec.rb +5 -5
  269. data/spec/unit/provider/package/rpm_spec.rb +14 -14
  270. data/spec/unit/provider/package/rubygems_spec.rb +10 -44
  271. data/spec/unit/provider/package/smartos_spec.rb +4 -4
  272. data/spec/unit/provider/package/solaris_spec.rb +11 -11
  273. data/spec/unit/provider/package/zypper_spec.rb +125 -90
  274. data/spec/unit/provider/package_spec.rb +34 -0
  275. data/spec/unit/provider/powershell_spec.rb +53 -11
  276. data/spec/unit/provider/remote_directory_spec.rb +2 -2
  277. data/spec/unit/provider/remote_file/local_file_spec.rb +25 -6
  278. data/spec/unit/provider/service/freebsd_service_spec.rb +0 -12
  279. data/spec/unit/provider/user_spec.rb +3 -3
  280. data/spec/unit/provider_resolver_spec.rb +463 -327
  281. data/spec/unit/recipe_spec.rb +42 -15
  282. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  283. data/spec/unit/resource/erl_call_spec.rb +1 -1
  284. data/spec/unit/resource/file_spec.rb +1 -1
  285. data/spec/unit/resource/ifconfig_spec.rb +10 -6
  286. data/spec/unit/resource/remote_file_spec.rb +5 -0
  287. data/spec/unit/resource/route_spec.rb +1 -1
  288. data/spec/unit/resource/ruby_block_spec.rb +2 -2
  289. data/spec/unit/resource/template_spec.rb +1 -1
  290. data/spec/unit/resource/timestamped_deploy_spec.rb +1 -2
  291. data/spec/unit/resource/windows_service_spec.rb +1 -1
  292. data/spec/unit/resource_spec.rb +99 -13
  293. data/spec/unit/rest_spec.rb +5 -5
  294. data/spec/unit/run_context_spec.rb +41 -0
  295. data/spec/unit/runner_spec.rb +2 -2
  296. data/spec/unit/user_spec.rb +406 -93
  297. data/tasks/maintainers.rb +69 -0
  298. metadata +37 -4
@@ -151,7 +151,7 @@ RSpec.configure do |config|
151
151
  config.filter_run_excluding :aes_256_gcm_only => true unless aes_256_gcm?
152
152
  config.filter_run_excluding :broken => true
153
153
 
154
- running_platform_arch = `uname -m`.strip
154
+ running_platform_arch = `uname -m`.strip unless windows?
155
155
 
156
156
  config.filter_run_excluding :arch => lambda {|target_arch|
157
157
  running_platform_arch != target_arch
@@ -0,0 +1,29 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, 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
+ class Chef
20
+ class Provider
21
+ class OpenldapIncluder < Chef::Provider::LWRPBase
22
+ provides :openldap_includer
23
+
24
+ def action_run
25
+ include_recipe "openldap::default"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -19,12 +19,10 @@
19
19
  class Chef
20
20
  class Resource
21
21
  class Cat < Chef::Resource
22
- provides :cat
23
22
 
24
23
  attr_accessor :action
25
24
 
26
25
  def initialize(name, run_context=nil)
27
- @resource_name = :cat
28
26
  super
29
27
  @action = "sell"
30
28
  end
@@ -19,15 +19,9 @@
19
19
  class Chef
20
20
  class Resource
21
21
  class OneTwoThreeFour < Chef::Resource
22
- provides :one_two_three_four
23
22
 
24
23
  attr_reader :i_can_count
25
24
 
26
- def initialize(name, run_context)
27
- @resource_name = :one_two_three_four
28
- super
29
- end
30
-
31
25
  def i_can_count(tf)
32
26
  @i_can_count = tf
33
27
  end
@@ -0,0 +1,27 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008, 2010 Opscode, 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
+
20
+ class Chef
21
+ class Resource
22
+ class OpenldapIncluder < Chef::Resource::LWRPBase
23
+ allowed_actions :run
24
+ default_action :run
25
+ end
26
+ end
27
+ end
@@ -23,15 +23,6 @@ class Chef
23
23
  class Resource
24
24
  class WithState < Chef::Resource
25
25
  attr_accessor :state
26
-
27
- def initialize(name, run_context=nil)
28
- @resource_name = :with_state
29
- super
30
- end
31
-
32
- def state
33
- @state
34
- end
35
26
  end
36
27
  end
37
28
  end
@@ -21,15 +21,9 @@ require 'chef/json_compat'
21
21
  class Chef
22
22
  class Resource
23
23
  class ZenFollower < Chef::Resource
24
- provides :zen_follower
25
24
 
26
25
  provides :follower, platform: "zen"
27
26
 
28
- def initialize(name, run_context=nil)
29
- @resource_name = :zen_follower
30
- super
31
- end
32
-
33
27
  def master(arg=nil)
34
28
  if !arg.nil?
35
29
  @master = arg
@@ -22,15 +22,10 @@ require 'chef/json_compat'
22
22
  class Chef
23
23
  class Resource
24
24
  class ZenMaster < Chef::Resource
25
- provides :zen_master
25
+ allowed_actions :win, :score
26
26
 
27
27
  attr_reader :peace
28
28
 
29
- def initialize(name, run_context=nil)
30
- @resource_name = :zen_master
31
- super
32
- allowed_actions << :win << :score
33
- end
34
29
 
35
30
  def peace(tf)
36
31
  @peace = tf
@@ -0,0 +1,277 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ # Stubs a basic client object
5
+ shared_context "client" do
6
+ let(:fqdn) { "hostname.example.org" }
7
+ let(:hostname) { "hostname" }
8
+ let(:machinename) { "machinename.example.org" }
9
+ let(:platform) { "example-platform" }
10
+ let(:platform_version) { "example-platform-1.0" }
11
+
12
+ let(:ohai_data) do
13
+ {
14
+ :fqdn => fqdn,
15
+ :hostname => hostname,
16
+ :machinename => machinename,
17
+ :platform => platform,
18
+ :platform_version => platform_version
19
+ }
20
+ end
21
+
22
+ let(:ohai_system) do
23
+ ohai = instance_double("Ohai::System", :all_plugins => true, :data => ohai_data)
24
+ allow(ohai).to receive(:[]) do |k|
25
+ ohai_data[k]
26
+ end
27
+ ohai
28
+ end
29
+
30
+ let(:node) do
31
+ Chef::Node.new.tap do |n|
32
+ n.name(fqdn)
33
+ n.chef_environment("_default")
34
+ end
35
+ end
36
+
37
+ let(:json_attribs) { nil }
38
+ let(:client_opts) { {} }
39
+
40
+ let(:client) do
41
+ Chef::Config[:event_loggers] = []
42
+ Chef::Client.new(json_attribs, client_opts).tap do |c|
43
+ c.node = node
44
+ end
45
+ end
46
+
47
+ before do
48
+ Chef::Log.logger = Logger.new(StringIO.new)
49
+
50
+ # Node/Ohai data
51
+ #Chef::Config[:node_name] = fqdn
52
+ allow(Ohai::System).to receive(:new).and_return(ohai_system)
53
+ end
54
+ end
55
+
56
+ # Stubs a client for a client run.
57
+ # Requires a client object be defined in the scope of this included context.
58
+ # e.g.:
59
+ # describe "some functionality" do
60
+ # include_context "client"
61
+ # include_context "a client run"
62
+ # ...
63
+ # end
64
+ shared_context "a client run" do
65
+ let(:stdout) { StringIO.new }
66
+ let(:stderr) { StringIO.new }
67
+
68
+ let(:api_client_exists?) { false }
69
+ let(:enable_fork) { false }
70
+
71
+ let(:http_cookbook_sync) { double("Chef::REST (cookbook sync)") }
72
+ let(:http_node_load) { double("Chef::REST (node)") }
73
+ let(:http_node_save) { double("Chef::REST (node save)") }
74
+
75
+ let(:runner) { instance_double("Chef::Runner") }
76
+ let(:audit_runner) { instance_double("Chef::Audit::Runner", :failed? => false) }
77
+
78
+ def stub_for_register
79
+ # --Client.register
80
+ # Make sure Client#register thinks the client key doesn't
81
+ # exist, so it tries to register and create one.
82
+ allow(File).to receive(:exists?).and_call_original
83
+ expect(File).to receive(:exists?).
84
+ with(Chef::Config[:client_key]).
85
+ exactly(:once).
86
+ and_return(api_client_exists?)
87
+
88
+ unless api_client_exists?
89
+ # Client.register will register with the validation client name.
90
+ expect_any_instance_of(Chef::ApiClient::Registration).to receive(:run)
91
+ end
92
+ end
93
+
94
+ def stub_for_node_load
95
+ # Client.register will then turn around create another
96
+ # Chef::REST object, this time with the client key it got from the
97
+ # previous step.
98
+ expect(Chef::REST).to receive(:new).
99
+ with(Chef::Config[:chef_server_url], fqdn, Chef::Config[:client_key]).
100
+ exactly(:once).
101
+ and_return(http_node_load)
102
+
103
+ # --Client#build_node
104
+ # looks up the node, which we will return, then later saves it.
105
+ expect(Chef::Node).to receive(:find_or_create).with(fqdn).and_return(node)
106
+
107
+ # --ResourceReporter#node_load_completed
108
+ # gets a run id from the server for storing resource history
109
+ # (has its own tests, so stubbing it here.)
110
+ expect_any_instance_of(Chef::ResourceReporter).to receive(:node_load_completed)
111
+ end
112
+
113
+ def stub_for_sync_cookbooks
114
+ # --Client#setup_run_context
115
+ # ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
116
+ #
117
+ expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
118
+ expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
119
+ expect(http_cookbook_sync).to receive(:post).
120
+ with("environments/_default/cookbook_versions", {:run_list => []}).
121
+ and_return({})
122
+ end
123
+
124
+ def stub_for_converge
125
+ # define me
126
+ end
127
+
128
+ def stub_for_audit
129
+ # define me
130
+ end
131
+
132
+ def stub_for_node_save
133
+ # define me
134
+ end
135
+
136
+ def stub_for_run
137
+ # define me
138
+ end
139
+
140
+ before do
141
+ Chef::Config[:client_fork] = enable_fork
142
+ Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
143
+ Chef::Config[:why_run] = false
144
+ Chef::Config[:audit_mode] = :enabled
145
+
146
+ stub_const("Chef::Client::STDOUT_FD", stdout)
147
+ stub_const("Chef::Client::STDERR_FD", stderr)
148
+
149
+ stub_for_register
150
+ stub_for_node_load
151
+ stub_for_sync_cookbooks
152
+ stub_for_converge
153
+ stub_for_audit
154
+ stub_for_node_save
155
+
156
+ expect_any_instance_of(Chef::RunLock).to receive(:acquire)
157
+ expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
158
+ expect_any_instance_of(Chef::RunLock).to receive(:release)
159
+
160
+ # Post conditions: check that node has been filled in correctly
161
+ expect(client).to receive(:run_started)
162
+
163
+ stub_for_run
164
+ end
165
+ end
166
+
167
+ shared_context "converge completed" do
168
+ def stub_for_converge
169
+ # --Client#converge
170
+ expect(Chef::Runner).to receive(:new).and_return(runner)
171
+ expect(runner).to receive(:converge).and_return(true)
172
+ end
173
+
174
+ def stub_for_node_save
175
+ allow(node).to receive(:data_for_save).and_return(node.for_json)
176
+
177
+ # --Client#save_updated_node
178
+ expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url], fqdn, Chef::Config[:client_key], validate_utf8: false).and_return(http_node_save)
179
+ expect(http_node_save).to receive(:put_rest).with("nodes/#{fqdn}", node.for_json).and_return(true)
180
+ end
181
+ end
182
+
183
+ shared_context "converge failed" do
184
+ let(:converge_error) do
185
+ err = Chef::Exceptions::UnsupportedAction.new("Action unsupported")
186
+ err.set_backtrace([ "/path/recipe.rb:15", "/path/recipe.rb:12" ])
187
+ err
188
+ end
189
+
190
+ def stub_for_converge
191
+ expect(Chef::Runner).to receive(:new).and_return(runner)
192
+ expect(runner).to receive(:converge).and_raise(converge_error)
193
+ end
194
+
195
+ def stub_for_node_save
196
+ expect(client).to_not receive(:save_updated_node)
197
+ end
198
+ end
199
+
200
+ shared_context "audit phase completed" do
201
+ def stub_for_audit
202
+ # -- Client#run_audits
203
+ expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
204
+ expect(audit_runner).to receive(:run).and_return(true)
205
+ expect(client.events).to receive(:audit_phase_complete)
206
+ end
207
+ end
208
+
209
+ shared_context "audit phase failed with error" do
210
+ let(:audit_error) do
211
+ err = RuntimeError.new("Unexpected audit error")
212
+ err.set_backtrace([ "/path/recipe.rb:57", "/path/recipe.rb:55" ])
213
+ err
214
+ end
215
+
216
+ def stub_for_audit
217
+ expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
218
+ expect(Chef::Audit::Logger).to receive(:read_buffer).and_return("Audit mode output!")
219
+ expect(audit_runner).to receive(:run).and_raise(audit_error)
220
+ expect(client.events).to receive(:audit_phase_failed).with(audit_error, "Audit mode output!")
221
+ end
222
+ end
223
+
224
+ shared_context "audit phase completed with failed controls" do
225
+ let(:audit_runner) { instance_double("Chef::Audit::Runner", :failed? => true,
226
+ :num_failed => 1, :num_total => 3) }
227
+
228
+ let(:audit_error) do
229
+ err = Chef::Exceptions::AuditsFailed.new(audit_runner.num_failed, audit_runner.num_total)
230
+ err.set_backtrace([ "/path/recipe.rb:108", "/path/recipe.rb:103" ])
231
+ err
232
+ end
233
+
234
+ def stub_for_audit
235
+ expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
236
+ expect(Chef::Audit::Logger).to receive(:read_buffer).and_return("Audit mode output!")
237
+ expect(audit_runner).to receive(:run)
238
+ expect(Chef::Exceptions::AuditsFailed).to receive(:new).with(
239
+ audit_runner.num_failed, audit_runner.num_total
240
+ ).and_return(audit_error)
241
+ expect(client.events).to receive(:audit_phase_failed).with(audit_error, "Audit mode output!")
242
+ end
243
+ end
244
+
245
+ shared_context "run completed" do
246
+ def stub_for_run
247
+ expect(client).to receive(:run_completed_successfully)
248
+
249
+ # --ResourceReporter#run_completed
250
+ # updates the server with the resource history
251
+ # (has its own tests, so stubbing it here.)
252
+ expect_any_instance_of(Chef::ResourceReporter).to receive(:run_completed)
253
+ # --AuditReporter#run_completed
254
+ # posts the audit data to server.
255
+ # (has its own tests, so stubbing it here.)
256
+ expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_completed)
257
+ end
258
+ end
259
+
260
+ shared_context "run failed" do
261
+ def stub_for_run
262
+ expect(client).to receive(:run_failed)
263
+
264
+ # --ResourceReporter#run_completed
265
+ # updates the server with the resource history
266
+ # (has its own tests, so stubbing it here.)
267
+ expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed)
268
+ # --AuditReporter#run_completed
269
+ # posts the audit data to server.
270
+ # (has its own tests, so stubbing it here.)
271
+ expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_failed)
272
+ end
273
+
274
+ before do
275
+ expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError)
276
+ end
277
+ end
@@ -0,0 +1,53 @@
1
+
2
+ require 'spec_helper'
3
+ require 'spec/support/shared/context/client'
4
+
5
+ # requires platform and platform_version be defined
6
+ shared_examples "a completed run" do
7
+ include_context "run completed"
8
+
9
+ it "runs ohai, sets up authentication, loads node state, synchronizes policy, converges, and runs audits" do
10
+ # This is what we're testing.
11
+ expect(client.run).to be true
12
+
13
+ # fork is stubbed, so we can see the outcome of the run
14
+ expect(node.automatic_attrs[:platform]).to eq(platform)
15
+ expect(node.automatic_attrs[:platform_version]).to eq(platform_version)
16
+ end
17
+ end
18
+
19
+ shared_examples "a completed run with audit failure" do
20
+ include_context "run completed"
21
+
22
+ before do
23
+ expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError)
24
+ end
25
+
26
+ it "converges, runs audits, saves the node and raises the error in a wrapping error" do
27
+ expect{ client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
28
+ expect(error.wrapped_errors.size).to eq(run_errors.size)
29
+ run_errors.each do |run_error|
30
+ expect(error.wrapped_errors).to include(run_error)
31
+ expect(error.backtrace).to include(*run_error.backtrace)
32
+ end
33
+ end
34
+
35
+ # fork is stubbed, so we can see the outcome of the run
36
+ expect(node.automatic_attrs[:platform]).to eq(platform)
37
+ expect(node.automatic_attrs[:platform_version]).to eq(platform_version)
38
+ end
39
+ end
40
+
41
+ shared_examples "a failed run" do
42
+ include_context "run failed"
43
+
44
+ it "skips node save and raises the error in a wrapping error" do
45
+ expect{ client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
46
+ expect(error.wrapped_errors.size).to eq(run_errors.size)
47
+ run_errors.each do |run_error|
48
+ expect(error.wrapped_errors).to include(run_error)
49
+ expect(error.backtrace).to include(*run_error.backtrace)
50
+ end
51
+ end
52
+ end
53
+ end