chef 12.5.0.alpha.1 → 12.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +21 -25
  3. data/Gemfile +46 -0
  4. data/README.md +4 -4
  5. data/Rakefile +5 -110
  6. data/distro/common/html/knife_cookbook_site.html +18 -18
  7. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  8. data/lib/chef/application.rb +1 -1
  9. data/lib/chef/application/apply.rb +19 -1
  10. data/lib/chef/application/client.rb +11 -5
  11. data/lib/chef/application/knife.rb +2 -2
  12. data/lib/chef/application/windows_service_manager.rb +9 -7
  13. data/lib/chef/chef_class.rb +39 -0
  14. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  15. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  16. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  17. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  18. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  19. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  20. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  21. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  22. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  23. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  24. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  25. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
  26. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  27. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  28. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  29. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  30. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  31. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  32. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  33. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  35. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  36. data/lib/chef/client.rb +2 -3
  37. data/lib/chef/config.rb +34 -2
  38. data/lib/chef/cookbook/metadata.rb +25 -3
  39. data/lib/chef/cookbook/synchronizer.rb +1 -1
  40. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  41. data/lib/chef/cookbook_version.rb +3 -3
  42. data/lib/chef/deprecation/mixin/template.rb +1 -2
  43. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  44. data/lib/chef/deprecation/provider/file.rb +1 -1
  45. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  46. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  47. data/lib/chef/deprecation/provider/template.rb +1 -1
  48. data/lib/chef/deprecation/warnings.rb +3 -4
  49. data/lib/chef/dsl/reboot_pending.rb +3 -2
  50. data/lib/chef/dsl/recipe.rb +6 -5
  51. data/lib/chef/dsl/resources.rb +2 -2
  52. data/lib/chef/event_dispatch/base.rb +12 -7
  53. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  54. data/lib/chef/exceptions.rb +22 -0
  55. data/lib/chef/file_content_management/tempfile.rb +1 -1
  56. data/lib/chef/formatters/base.rb +3 -0
  57. data/lib/chef/formatters/doc.rb +53 -5
  58. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  59. data/lib/chef/formatters/minimal.rb +2 -2
  60. data/lib/chef/knife.rb +35 -55
  61. data/lib/chef/knife/bootstrap.rb +41 -0
  62. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  63. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  64. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  65. data/lib/chef/knife/cookbook_create.rb +1 -1
  66. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  67. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  68. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  69. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  70. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  71. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  72. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  73. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  74. data/lib/chef/knife/core/node_presenter.rb +24 -1
  75. data/lib/chef/knife/core/object_loader.rb +1 -0
  76. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  77. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  78. data/lib/chef/knife/null.rb +10 -0
  79. data/lib/chef/knife/rehash.rb +62 -0
  80. data/lib/chef/knife/search.rb +3 -3
  81. data/lib/chef/knife/ssh.rb +52 -30
  82. data/lib/chef/local_mode.rb +5 -0
  83. data/lib/chef/log.rb +5 -1
  84. data/lib/chef/mixin/deprecation.rb +8 -8
  85. data/lib/chef/mixin/params_validate.rb +2 -2
  86. data/lib/chef/mixin/template.rb +48 -0
  87. data/lib/chef/mixin/which.rb +1 -1
  88. data/lib/chef/mixin/wide_string.rb +72 -0
  89. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  90. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  91. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  92. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  93. data/lib/chef/node.rb +97 -3
  94. data/lib/chef/node_map.rb +2 -2
  95. data/lib/chef/platform/provider_mapping.rb +5 -6
  96. data/lib/chef/platform/query_helpers.rb +46 -4
  97. data/lib/chef/platform/service_helpers.rb +30 -32
  98. data/lib/chef/policy_builder.rb +1 -8
  99. data/lib/chef/policy_builder/dynamic.rb +186 -0
  100. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  101. data/lib/chef/policy_builder/policyfile.rb +155 -18
  102. data/lib/chef/property.rb +38 -9
  103. data/lib/chef/provider.rb +104 -12
  104. data/lib/chef/provider/batch.rb +8 -0
  105. data/lib/chef/provider/deploy.rb +2 -2
  106. data/lib/chef/provider/directory.rb +14 -2
  107. data/lib/chef/provider/dsc_resource.rb +5 -9
  108. data/lib/chef/provider/group/pw.rb +1 -1
  109. data/lib/chef/provider/ifconfig.rb +2 -2
  110. data/lib/chef/provider/mount.rb +7 -3
  111. data/lib/chef/provider/package/dpkg.rb +5 -11
  112. data/lib/chef/provider/package/rpm.rb +2 -2
  113. data/lib/chef/provider/package/rubygems.rb +1 -1
  114. data/lib/chef/provider/package/windows/msi.rb +2 -2
  115. data/lib/chef/provider/package/yum.rb +17 -5
  116. data/lib/chef/provider/powershell_script.rb +27 -4
  117. data/lib/chef/provider/remote_directory.rb +190 -102
  118. data/lib/chef/provider/service.rb +12 -2
  119. data/lib/chef/provider/service/aix.rb +1 -1
  120. data/lib/chef/provider/service/debian.rb +3 -5
  121. data/lib/chef/provider/service/freebsd.rb +1 -1
  122. data/lib/chef/provider/service/gentoo.rb +3 -3
  123. data/lib/chef/provider/service/init.rb +3 -3
  124. data/lib/chef/provider/service/insserv.rb +2 -4
  125. data/lib/chef/provider/service/invokercd.rb +2 -4
  126. data/lib/chef/provider/service/openbsd.rb +2 -1
  127. data/lib/chef/provider/service/redhat.rb +52 -16
  128. data/lib/chef/provider/service/simple.rb +2 -2
  129. data/lib/chef/provider/service/systemd.rb +3 -5
  130. data/lib/chef/provider/service/upstart.rb +4 -6
  131. data/lib/chef/provider/subversion.rb +13 -7
  132. data/lib/chef/provider/template/content.rb +16 -6
  133. data/lib/chef/provider/user/solaris.rb +32 -4
  134. data/lib/chef/provider/windows_script.rb +3 -5
  135. data/lib/chef/provider_resolver.rb +2 -2
  136. data/lib/chef/resource.rb +85 -27
  137. data/lib/chef/resource/action_class.rb +83 -0
  138. data/lib/chef/resource/chef_gem.rb +3 -3
  139. data/lib/chef/resource/deploy.rb +8 -2
  140. data/lib/chef/resource/dsc_script.rb +2 -0
  141. data/lib/chef/resource/file/verification.rb +1 -1
  142. data/lib/chef/resource/registry_key.rb +1 -1
  143. data/lib/chef/resource/service.rb +10 -2
  144. data/lib/chef/resource/subversion.rb +5 -0
  145. data/lib/chef/resource/windows_script.rb +6 -2
  146. data/lib/chef/resource/yum_package.rb +10 -1
  147. data/lib/chef/resource_resolver.rb +3 -3
  148. data/lib/chef/run_context.rb +6 -8
  149. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  150. data/lib/chef/run_lock.rb +30 -21
  151. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  152. data/lib/chef/util/windows.rb +0 -32
  153. data/lib/chef/util/windows/net_group.rb +85 -106
  154. data/lib/chef/util/windows/net_use.rb +35 -71
  155. data/lib/chef/util/windows/net_user.rb +0 -1
  156. data/lib/chef/util/windows/volume.rb +19 -19
  157. data/lib/chef/version.rb +3 -3
  158. data/lib/chef/win32/api.rb +1 -0
  159. data/lib/chef/win32/api/file.rb +20 -0
  160. data/lib/chef/win32/api/net.rb +163 -43
  161. data/lib/chef/win32/api/registry.rb +51 -0
  162. data/lib/chef/win32/api/system.rb +23 -0
  163. data/lib/chef/win32/api/unicode.rb +0 -43
  164. data/lib/chef/win32/crypto.rb +2 -1
  165. data/lib/chef/win32/file.rb +28 -3
  166. data/lib/chef/win32/mutex.rb +1 -2
  167. data/lib/chef/win32/net.rb +162 -8
  168. data/lib/chef/win32/process.rb +13 -0
  169. data/lib/chef/win32/registry.rb +25 -28
  170. data/lib/chef/win32/security.rb +1 -1
  171. data/lib/chef/win32/security/token.rb +1 -1
  172. data/lib/chef/win32/system.rb +62 -0
  173. data/lib/chef/win32/unicode.rb +7 -2
  174. data/lib/chef/win32/version.rb +0 -4
  175. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  176. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  177. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  178. data/spec/data/dsc_lcm.pfx +0 -0
  179. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  180. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  181. data/spec/functional/knife/ssh_spec.rb +16 -0
  182. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  183. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  184. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  185. data/spec/functional/resource/group_spec.rb +67 -44
  186. data/spec/functional/resource/powershell_script_spec.rb +104 -15
  187. data/spec/functional/resource/windows_service_spec.rb +1 -1
  188. data/spec/functional/run_lock_spec.rb +368 -189
  189. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
  190. data/spec/integration/client/client_spec.rb +51 -0
  191. data/spec/integration/knife/download_spec.rb +4 -0
  192. data/spec/integration/knife/list_spec.rb +8 -0
  193. data/spec/integration/knife/upload_spec.rb +1 -1
  194. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  195. data/spec/integration/recipes/remote_directory.rb +74 -0
  196. data/spec/integration/recipes/resource_action_spec.rb +42 -22
  197. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  198. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  199. data/spec/spec_helper.rb +8 -0
  200. data/spec/support/platform_helpers.rb +13 -0
  201. data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
  202. data/spec/support/shared/functional/windows_script.rb +63 -26
  203. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  204. data/spec/support/shared/unit/provider/file.rb +10 -4
  205. data/spec/unit/application/client_spec.rb +16 -3
  206. data/spec/unit/application/knife_spec.rb +2 -2
  207. data/spec/unit/chef_class_spec.rb +0 -4
  208. data/spec/unit/client_spec.rb +6 -1
  209. data/spec/unit/config_spec.rb +31 -0
  210. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  211. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  212. data/spec/unit/deprecation_spec.rb +3 -6
  213. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  214. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  215. data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
  216. data/spec/unit/formatters/doc_spec.rb +32 -0
  217. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  218. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  219. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  220. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  221. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  222. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  223. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  224. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  225. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  226. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  227. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  228. data/spec/unit/mixin/template_spec.rb +5 -1
  229. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  230. data/spec/unit/node_spec.rb +213 -0
  231. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  232. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  233. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  234. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  235. data/spec/unit/property/validation_spec.rb +5 -0
  236. data/spec/unit/property_spec.rb +152 -26
  237. data/spec/unit/provider/deploy_spec.rb +5 -5
  238. data/spec/unit/provider/directory_spec.rb +35 -0
  239. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  240. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  241. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  242. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  243. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  244. data/spec/unit/provider/mount_spec.rb +12 -1
  245. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  246. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  247. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  248. data/spec/unit/provider/package/yum_spec.rb +97 -24
  249. data/spec/unit/provider/powershell_script_spec.rb +52 -26
  250. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  251. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  252. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  253. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  254. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  255. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  256. data/spec/unit/provider/service/windows_spec.rb +211 -200
  257. data/spec/unit/provider/subversion_spec.rb +50 -31
  258. data/spec/unit/provider/template/content_spec.rb +93 -2
  259. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  260. data/spec/unit/provider_resolver_spec.rb +707 -650
  261. data/spec/unit/resource/deploy_spec.rb +7 -1
  262. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  263. data/spec/unit/resource/file/verification_spec.rb +1 -1
  264. data/spec/unit/resource/powershell_script_spec.rb +17 -13
  265. data/spec/unit/resource/service_spec.rb +4 -4
  266. data/spec/unit/resource/subversion_spec.rb +4 -0
  267. data/spec/unit/resource/yum_package_spec.rb +10 -1
  268. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  269. data/spec/unit/win32/registry_spec.rb +394 -0
  270. data/tasks/external_tests.rb +47 -23
  271. data/tasks/maintainers.rb +155 -14
  272. metadata +51 -26
  273. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  274. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  275. data/spec/unit/registry_helper_spec.rb +0 -390
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: AJ Christensen (<aj@hjksolutions.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");
@@ -25,6 +25,10 @@ class Chef
25
25
 
26
26
  include Chef::Mixin::Command
27
27
 
28
+ def supports
29
+ @supports ||= new_resource.supports.dup
30
+ end
31
+
28
32
  def initialize(new_resource, run_context)
29
33
  super
30
34
  @enabled = nil
@@ -34,6 +38,12 @@ class Chef
34
38
  true
35
39
  end
36
40
 
41
+ def load_current_resource
42
+ supports[:status] = false if supports[:status].nil?
43
+ supports[:reload] = false if supports[:reload].nil?
44
+ supports[:restart] = false if supports[:restart].nil?
45
+ end
46
+
37
47
  def load_new_resource_state
38
48
  # If the user didn't specify a change in enabled state,
39
49
  # it will be the same as the old resource
@@ -50,7 +60,7 @@ class Chef
50
60
 
51
61
  def define_resource_requirements
52
62
  requirements.assert(:reload) do |a|
53
- a.assertion { @new_resource.supports[:reload] || @new_resource.reload_command }
63
+ a.assertion { supports[:reload] || @new_resource.reload_command }
54
64
  a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
55
65
  # if a service is not declared to support reload, that won't
56
66
  # typically change during the course of a run - so no whyrun
@@ -116,7 +116,7 @@ class Chef
116
116
  end
117
117
 
118
118
  def is_resource_group?
119
- so = shell_out!("lssrc -g #{@new_resource.service_name}")
119
+ so = shell_out("lssrc -g #{@new_resource.service_name}")
120
120
  if so.exitstatus == 0
121
121
  Chef::Log.debug("#{@new_resource.service_name} is a group")
122
122
  @is_resource_group = true
@@ -22,15 +22,13 @@ class Chef
22
22
  class Provider
23
23
  class Service
24
24
  class Debian < Chef::Provider::Service::Init
25
- provides :service, platform_family: 'debian'
25
+ provides :service, platform_family: 'debian' do |node|
26
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:debian)
27
+ end
26
28
 
27
29
  UPDATE_RC_D_ENABLED_MATCHES = /\/rc[\dS].d\/S|not installed/i
28
30
  UPDATE_RC_D_PRIORITIES = /\/rc([\dS]).d\/([SK])(\d\d)/i
29
31
 
30
- def self.provides?(node, resource)
31
- super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:debian)
32
- end
33
-
34
32
  def self.supports?(resource, action)
35
33
  Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd)
36
34
  end
@@ -99,7 +99,7 @@ class Chef
99
99
  def restart_service
100
100
  if new_resource.restart_command
101
101
  super
102
- elsif new_resource.supports[:restart]
102
+ elsif supports[:restart]
103
103
  shell_out_with_systems_locale!("#{init_command} fastrestart")
104
104
  else
105
105
  stop_service
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Lee Jensen (<ljensen@engineyard.com>)
3
3
  # Author:: AJ Christensen (<aj@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");
@@ -26,9 +26,9 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
26
26
  provides :service, platform_family: "gentoo"
27
27
 
28
28
  def load_current_resource
29
+ supports[:status] = true if supports[:status].nil?
30
+ supports[:restart] = true if supports[:restart].nil?
29
31
 
30
- @new_resource.supports[:status] = true
31
- @new_resource.supports[:restart] = true
32
32
  @found_script = false
33
33
  super
34
34
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: AJ Christensen (<aj@hjksolutions.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");
@@ -72,7 +72,7 @@ class Chef
72
72
  def restart_service
73
73
  if @new_resource.restart_command
74
74
  super
75
- elsif @new_resource.supports[:restart]
75
+ elsif supports[:restart]
76
76
  shell_out_with_systems_locale!("#{default_init_command} restart")
77
77
  else
78
78
  stop_service
@@ -84,7 +84,7 @@ class Chef
84
84
  def reload_service
85
85
  if @new_resource.reload_command
86
86
  super
87
- elsif @new_resource.supports[:reload]
87
+ elsif supports[:reload]
88
88
  shell_out_with_systems_locale!("#{default_init_command} reload")
89
89
  end
90
90
  end
@@ -24,10 +24,8 @@ class Chef
24
24
  class Service
25
25
  class Insserv < Chef::Provider::Service::Init
26
26
 
27
- provides :service, platform_family: %w(debian rhel fedora suse)
28
-
29
- def self.provides?(node, resource)
30
- super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:insserv)
27
+ provides :service, platform_family: %w(debian rhel fedora suse) do |node|
28
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:insserv)
31
29
  end
32
30
 
33
31
  def self.supports?(resource, action)
@@ -23,10 +23,8 @@ class Chef
23
23
  class Service
24
24
  class Invokercd < Chef::Provider::Service::Init
25
25
 
26
- provides :service, platform_family: 'debian', override: true
27
-
28
- def self.provides?(node, resource)
29
- super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:invokercd)
26
+ provides :service, platform_family: 'debian', override: true do |node|
27
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:invokercd)
30
28
  end
31
29
 
32
30
  def self.supports?(resource, action)
@@ -40,11 +40,12 @@ class Chef
40
40
  @rc_conf = ::File.read(RC_CONF_PATH) rescue ''
41
41
  @rc_conf_local = ::File.read(RC_CONF_LOCAL_PATH) rescue ''
42
42
  @init_command = ::File.exist?(rcd_script_path) ? rcd_script_path : nil
43
- new_resource.supports[:status] = true
44
43
  new_resource.status_command("#{default_init_command} check")
45
44
  end
46
45
 
47
46
  def load_current_resource
47
+ supports[:status] = true if supports[:status].nil?
48
+
48
49
  @current_resource = Chef::Resource::Service.new(new_resource.name)
49
50
  current_resource.service_name(new_resource.service_name)
50
51
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: AJ Christensen (<aj@hjksolutions.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");
@@ -23,24 +23,32 @@ class Chef
23
23
  class Service
24
24
  class Redhat < Chef::Provider::Service::Init
25
25
 
26
- provides :service, platform_family: %w(rhel fedora suse)
26
+ # @api private
27
+ attr_accessor :service_missing
28
+ # @api private
29
+ attr_accessor :current_run_levels
30
+
31
+ provides :service, platform_family: %w(rhel fedora suse) do |node|
32
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat)
33
+ end
27
34
 
28
35
  CHKCONFIG_ON = /\d:on/
29
36
  CHKCONFIG_MISSING = /No such/
30
37
 
31
- def self.provides?(node, resource)
32
- super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat)
33
- end
34
-
35
38
  def self.supports?(resource, action)
36
39
  Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd)
37
40
  end
38
41
 
39
42
  def initialize(new_resource, run_context)
40
43
  super
41
- @init_command = "/sbin/service #{@new_resource.service_name}"
42
- @new_resource.supports[:status] = true
44
+ @init_command = "/sbin/service #{new_resource.service_name}"
43
45
  @service_missing = false
46
+ @current_run_levels = []
47
+ end
48
+
49
+ # @api private
50
+ def run_levels
51
+ new_resource.run_levels
44
52
  end
45
53
 
46
54
  def define_resource_requirements
@@ -49,34 +57,62 @@ class Chef
49
57
  requirements.assert(:all_actions) do |a|
50
58
  chkconfig_file = "/sbin/chkconfig"
51
59
  a.assertion { ::File.exists? chkconfig_file }
52
- a.failure_message Chef::Exceptions::Service, "#{chkconfig_file} does not exist!"
60
+ a.failure_message Chef::Exceptions::Service, "#{chkconfig_file} dbleoes not exist!"
53
61
  end
54
62
 
55
63
  requirements.assert(:start, :enable, :reload, :restart) do |a|
56
- a.assertion { !@service_missing }
57
- a.failure_message Chef::Exceptions::Service, "#{@new_resource}: unable to locate the init.d script!"
64
+ a.assertion do
65
+ custom_command_for_action?(action) || !@service_missing
66
+ end
67
+ a.failure_message Chef::Exceptions::Service, "#{new_resource}: No custom command for #{action} specified and unable to locate the init.d script!"
58
68
  a.whyrun "Assuming service would be disabled. The init script is not presently installed."
59
69
  end
60
70
  end
61
71
 
62
72
  def load_current_resource
73
+ supports[:status] = true if supports[:status].nil?
74
+
63
75
  super
64
76
 
65
77
  if ::File.exists?("/sbin/chkconfig")
66
- chkconfig = shell_out!("/sbin/chkconfig --list #{@current_resource.service_name}", :returns => [0,1])
67
- @current_resource.enabled(!!(chkconfig.stdout =~ CHKCONFIG_ON))
78
+ chkconfig = shell_out!("/sbin/chkconfig --list #{current_resource.service_name}", :returns => [0,1])
79
+ unless run_levels.nil? or run_levels.empty?
80
+ all_levels_match = true
81
+ chkconfig.stdout.split(/\s+/)[1..-1].each do |level|
82
+ index = level.split(':').first
83
+ status = level.split(':').last
84
+ if level =~ CHKCONFIG_ON
85
+ @current_run_levels << index.to_i
86
+ all_levels_match = false unless run_levels.include?(index.to_i)
87
+ else
88
+ all_levels_match = false if run_levels.include?(index.to_i)
89
+ end
90
+ end
91
+ current_resource.enabled(all_levels_match)
92
+ else
93
+ current_resource.enabled(!!(chkconfig.stdout =~ CHKCONFIG_ON))
94
+ end
68
95
  @service_missing = !!(chkconfig.stderr =~ CHKCONFIG_MISSING)
69
96
  end
70
97
 
71
- @current_resource
98
+ current_resource
99
+ end
100
+
101
+ # @api private
102
+ def levels
103
+ (run_levels.nil? or run_levels.empty?) ? "" : "--level #{run_levels.join('')} "
72
104
  end
73
105
 
74
106
  def enable_service()
75
- shell_out! "/sbin/chkconfig #{@new_resource.service_name} on"
107
+ unless run_levels.nil? or run_levels.empty?
108
+ disable_levels = current_run_levels - run_levels
109
+ shell_out! "/sbin/chkconfig --level #{disable_levels.join('')} #{new_resource.service_name} off" unless disable_levels.empty?
110
+ end
111
+ shell_out! "/sbin/chkconfig #{levels}#{new_resource.service_name} on"
76
112
  end
77
113
 
78
114
  def disable_service()
79
- shell_out! "/sbin/chkconfig #{@new_resource.service_name} off"
115
+ shell_out! "/sbin/chkconfig #{levels}#{new_resource.service_name} off"
80
116
  end
81
117
  end
82
118
  end
@@ -76,7 +76,7 @@ class Chef
76
76
  end
77
77
 
78
78
  requirements.assert(:all_actions) do |a|
79
- a.assertion { @new_resource.status_command or @new_resource.supports[:status] or
79
+ a.assertion { @new_resource.status_command or supports[:status] or
80
80
  (!ps_cmd.nil? and !ps_cmd.empty?) }
81
81
  a.failure_message Chef::Exceptions::Service, "#{@new_resource} could not determine how to inspect the process table, please set this node's 'command.ps' attribute"
82
82
  end
@@ -127,7 +127,7 @@ class Chef
127
127
  nil
128
128
  end
129
129
 
130
- elsif @new_resource.supports[:status]
130
+ elsif supports[:status]
131
131
  Chef::Log.debug("#{@new_resource} supports status, running")
132
132
  begin
133
133
  if shell_out("#{default_init_command} status").exitstatus == 0
@@ -24,14 +24,12 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
24
24
 
25
25
  include Chef::Mixin::Which
26
26
 
27
- provides :service, os: "linux"
27
+ provides :service, os: "linux" do |node|
28
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd)
29
+ end
28
30
 
29
31
  attr_accessor :status_check_success
30
32
 
31
- def self.provides?(node, resource)
32
- super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd)
33
- end
34
-
35
33
  def self.supports?(resource, action)
36
34
  Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:systemd)
37
35
  end
@@ -26,14 +26,12 @@ class Chef
26
26
  class Service
27
27
  class Upstart < Chef::Provider::Service::Simple
28
28
 
29
- provides :service, platform_family: 'debian', override: true
29
+ provides :service, platform_family: 'debian', override: true do |node|
30
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart)
31
+ end
30
32
 
31
33
  UPSTART_STATE_FORMAT = /\w+ \(?(\w+)\)?[\/ ](\w+)/
32
34
 
33
- def self.provides?(node, resource)
34
- super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart)
35
- end
36
-
37
35
  def self.supports?(resource, action)
38
36
  Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:upstart)
39
37
  end
@@ -108,7 +106,7 @@ class Chef
108
106
  Chef::Log.debug("#{@new_resource} you have specified a status command, running..")
109
107
 
110
108
  begin
111
- if shell_out!(@new_resource.status_command) == 0
109
+ if shell_out!(@new_resource.status_command).exitstatus == 0
112
110
  @current_resource.running true
113
111
  end
114
112
  rescue
@@ -130,8 +130,8 @@ class Chef
130
130
  @new_resource.revision
131
131
  else
132
132
  command = scm(:info, @new_resource.repository, @new_resource.svn_info_args, authentication, "-r#{@new_resource.revision}")
133
- status, svn_info, error_message = output_of_command(command, run_options)
134
- handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
133
+ svn_info = shell_out!(command, run_options(:cwd => cwd, :returns => [0,1])).stdout
134
+
135
135
  extract_revision_info(svn_info)
136
136
  end
137
137
  end
@@ -142,11 +142,8 @@ class Chef
142
142
  def find_current_revision
143
143
  return nil unless ::File.exist?(::File.join(@new_resource.destination, ".svn"))
144
144
  command = scm(:info)
145
- status, svn_info, error_message = output_of_command(command, run_options(:cwd => cwd))
145
+ svn_info = shell_out!(command, run_options(:cwd => cwd, :returns => [0,1])).stdout
146
146
 
147
- unless [0,1].include?(status.exitstatus)
148
- handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
149
- end
150
147
  extract_revision_info(svn_info)
151
148
  end
152
149
 
@@ -180,6 +177,7 @@ class Chef
180
177
  attrs
181
178
  end
182
179
  rev = (repo_attrs['Last Changed Rev'] || repo_attrs['Revision'])
180
+ rev.strip! if rev
183
181
  raise "Could not parse `svn info` data: #{svn_info}" if repo_attrs.empty?
184
182
  Chef::Log.debug "#{@new_resource} resolved revision #{@new_resource.revision} to #{rev}"
185
183
  rev
@@ -197,12 +195,20 @@ class Chef
197
195
  end
198
196
 
199
197
  def scm(*args)
200
- ['svn', *args].compact.join(" ")
198
+ binary = svn_binary
199
+ binary = "\"#{binary}\"" if binary =~ /\s/
200
+ [binary, *args].compact.join(" ")
201
201
  end
202
202
 
203
203
  def target_dir_non_existent_or_empty?
204
204
  !::File.exist?(@new_resource.destination) || Dir.entries(@new_resource.destination).sort == ['.','..']
205
205
  end
206
+
207
+ def svn_binary
208
+ @new_resource.svn_binary ||
209
+ (Chef::Platform.windows? ? 'svn.exe' : 'svn')
210
+ end
211
+
206
212
  def assert_target_directory_valid!
207
213
  target_parent_directory = ::File.dirname(@new_resource.destination)
208
214
  unless ::File.directory?(target_parent_directory)
@@ -29,20 +29,30 @@ class Chef
29
29
 
30
30
  def template_location
31
31
  @template_file_cache_location ||= begin
32
- template_finder.find(@new_resource.source, :local => @new_resource.local, :cookbook => @new_resource.cookbook)
32
+ template_finder.find(new_resource.source, :local => new_resource.local, :cookbook => new_resource.cookbook)
33
33
  end
34
34
  end
35
35
 
36
36
  private
37
37
 
38
38
  def file_for_provider
39
- context = TemplateContext.new(@new_resource.variables)
40
- context[:node] = @run_context.node
39
+ context = TemplateContext.new(new_resource.variables)
40
+ context[:node] = run_context.node
41
41
  context[:template_finder] = template_finder
42
- context._extend_modules(@new_resource.helper_modules)
42
+
43
+ # helper variables
44
+ context[:cookbook_name] = new_resource.cookbook_name unless context.keys.include?(:coookbook_name)
45
+ context[:recipe_name] = new_resource.recipe_name unless context.keys.include?(:recipe_name)
46
+ context[:recipe_line_string] = new_resource.source_line unless context.keys.include?(:recipe_line_string)
47
+ context[:recipe_path] = new_resource.source_line_file unless context.keys.include?(:recipe_path)
48
+ context[:recipe_line] = new_resource.source_line_number unless context.keys.include?(:recipe_line)
49
+ context[:template_name] = new_resource.source unless context.keys.include?(:template_name)
50
+ context[:template_path] = template_location unless context.keys.include?(:template_path)
51
+
52
+ context._extend_modules(new_resource.helper_modules)
43
53
  output = context.render_template(template_location)
44
54
 
45
- tempfile = Tempfile.open("chef-rendered-template")
55
+ tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile
46
56
  tempfile.binmode
47
57
  tempfile.write(output)
48
58
  tempfile.close
@@ -51,7 +61,7 @@ class Chef
51
61
 
52
62
  def template_finder
53
63
  @template_finder ||= begin
54
- TemplateFinder.new(run_context, @new_resource.cookbook_name, @run_context.node)
64
+ TemplateFinder.new(run_context, new_resource.cookbook_name, run_context.node)
55
65
  end
56
66
  end
57
67
  end