chef 15.4.45-universal-mingw32 → 15.5.9-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -3
  3. data/Rakefile +5 -3
  4. data/chef.gemspec +2 -1
  5. data/ext/win32-eventlog/Rakefile +9 -1
  6. data/ext/win32-eventlog/{chef-log.man → chef-log.man.erb} +4 -4
  7. data/lib/chef/application.rb +2 -2
  8. data/lib/chef/application/client.rb +1 -1
  9. data/lib/chef/application/knife.rb +1 -0
  10. data/lib/chef/application/solo.rb +1 -1
  11. data/lib/chef/chef_class.rb +1 -6
  12. data/lib/chef/chef_fs.rb +1 -1
  13. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  14. data/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb +2 -2
  15. data/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb +2 -2
  16. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_artifact_dir.rb +1 -1
  17. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +7 -1
  18. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +4 -3
  19. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +3 -3
  20. data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb +1 -1
  21. data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +3 -3
  22. data/lib/chef/chef_fs/knife.rb +1 -1
  23. data/lib/chef/chef_fs/path_utils.rb +2 -2
  24. data/lib/chef/client.rb +4 -5
  25. data/lib/chef/config.rb +3 -2
  26. data/lib/chef/cookbook/chefignore.rb +16 -11
  27. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  28. data/lib/chef/cookbook/syntax_check.rb +5 -3
  29. data/lib/chef/cookbook_loader.rb +3 -3
  30. data/lib/chef/cookbook_uploader.rb +1 -1
  31. data/lib/chef/data_collector.rb +2 -2
  32. data/lib/chef/data_collector/run_end_message.rb +1 -0
  33. data/lib/chef/deprecated.rb +4 -0
  34. data/lib/chef/dsl/core.rb +1 -1
  35. data/lib/chef/dsl/platform_introspection.rb +9 -18
  36. data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
  37. data/lib/chef/file_content_management/deploy.rb +3 -3
  38. data/lib/chef/file_content_management/deploy/mv_windows.rb +2 -2
  39. data/lib/chef/file_content_management/tempfile.rb +1 -1
  40. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +2 -2
  41. data/lib/chef/http.rb +1 -1
  42. data/lib/chef/http/socketless_chef_zero_client.rb +1 -1
  43. data/lib/chef/knife.rb +4 -3
  44. data/lib/chef/knife/config_get.rb +2 -1
  45. data/lib/chef/knife/configure.rb +1 -1
  46. data/lib/chef/knife/cookbook_metadata_from_file.rb +6 -0
  47. data/lib/chef/knife/core/generic_presenter.rb +1 -1
  48. data/lib/chef/knife/core/status_presenter.rb +1 -1
  49. data/lib/chef/knife/ssh.rb +6 -0
  50. data/lib/chef/local_mode.rb +1 -1
  51. data/lib/chef/mash.rb +21 -232
  52. data/lib/chef/mixin/file_class.rb +2 -2
  53. data/lib/chef/mixin/lazy_module_include.rb +1 -1
  54. data/lib/chef/mixin/path_sanity.rb +3 -39
  55. data/lib/chef/mixin/securable.rb +1 -1
  56. data/lib/chef/mixin/shell_out.rb +4 -5
  57. data/lib/chef/mixin/template.rb +1 -1
  58. data/lib/chef/mixin/user_context.rb +3 -3
  59. data/lib/chef/mixin/which.rb +10 -38
  60. data/lib/chef/mixin/windows_architecture_helper.rb +6 -6
  61. data/lib/chef/mixin/windows_env_helper.rb +5 -5
  62. data/lib/chef/node/attribute.rb +2 -2
  63. data/lib/chef/node_map.rb +17 -4
  64. data/lib/chef/platform/query_helpers.rb +4 -2
  65. data/lib/chef/platform/rebooter.rb +1 -1
  66. data/lib/chef/platform/service_helpers.rb +14 -85
  67. data/lib/chef/provider.rb +2 -0
  68. data/lib/chef/provider/file.rb +2 -2
  69. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  70. data/lib/chef/provider/link.rb +3 -3
  71. data/lib/chef/provider/mount/solaris.rb +1 -1
  72. data/lib/chef/provider/package/yum.rb +1 -1
  73. data/lib/chef/provider/registry_key.rb +1 -1
  74. data/lib/chef/provider/remote_directory.rb +3 -3
  75. data/lib/chef/provider/remote_file/fetcher.rb +2 -2
  76. data/lib/chef/provider/remote_file/local_file.rb +1 -1
  77. data/lib/chef/provider/script.rb +3 -3
  78. data/lib/chef/provider/service.rb +5 -2
  79. data/lib/chef/provider/service/arch.rb +1 -1
  80. data/lib/chef/provider/service/debian.rb +4 -4
  81. data/lib/chef/provider/service/init.rb +1 -1
  82. data/lib/chef/provider/service/insserv.rb +4 -4
  83. data/lib/chef/provider/service/invokercd.rb +4 -4
  84. data/lib/chef/provider/service/redhat.rb +4 -4
  85. data/lib/chef/provider/service/systemd.rb +19 -3
  86. data/lib/chef/provider/service/upstart.rb +3 -3
  87. data/lib/chef/provider/subversion.rb +1 -1
  88. data/lib/chef/provider/systemd_unit.rb +26 -2
  89. data/lib/chef/provider/windows_path.rb +3 -3
  90. data/lib/chef/provider/windows_task.rb +4 -4
  91. data/lib/chef/resource.rb +1 -0
  92. data/lib/chef/resource/bash.rb +2 -0
  93. data/lib/chef/resource/batch.rb +2 -0
  94. data/lib/chef/resource/breakpoint.rb +3 -1
  95. data/lib/chef/resource/build_essential.rb +3 -3
  96. data/lib/chef/resource/chef_sleep.rb +70 -0
  97. data/lib/chef/resource/cookbook_file.rb +2 -1
  98. data/lib/chef/resource/csh.rb +2 -0
  99. data/lib/chef/resource/directory.rb +2 -0
  100. data/lib/chef/resource/dmg_package.rb +1 -1
  101. data/lib/chef/resource/dnf_package.rb +1 -1
  102. data/lib/chef/resource/execute.rb +2 -0
  103. data/lib/chef/resource/file.rb +2 -1
  104. data/lib/chef/resource/git.rb +2 -0
  105. data/lib/chef/resource/group.rb +1 -1
  106. data/lib/chef/resource/homebrew_package.rb +1 -1
  107. data/lib/chef/resource/http_request.rb +2 -0
  108. data/lib/chef/resource/ifconfig.rb +3 -1
  109. data/lib/chef/resource/ksh.rb +2 -0
  110. data/lib/chef/resource/link.rb +4 -2
  111. data/lib/chef/resource/locale.rb +1 -1
  112. data/lib/chef/resource/log.rb +2 -0
  113. data/lib/chef/resource/ohai.rb +2 -0
  114. data/lib/chef/resource/perl.rb +2 -0
  115. data/lib/chef/resource/python.rb +2 -0
  116. data/lib/chef/resource/reboot.rb +2 -0
  117. data/lib/chef/resource/registry_key.rb +2 -0
  118. data/lib/chef/resource/remote_directory.rb +3 -2
  119. data/lib/chef/resource/remote_file.rb +1 -0
  120. data/lib/chef/resource/ruby.rb +2 -0
  121. data/lib/chef/resource/ruby_block.rb +2 -0
  122. data/lib/chef/resource/scm.rb +2 -0
  123. data/lib/chef/resource/script.rb +2 -0
  124. data/lib/chef/resource/service.rb +9 -1
  125. data/lib/chef/resource/solaris_package.rb +1 -1
  126. data/lib/chef/resource/subversion.rb +2 -0
  127. data/lib/chef/resource/sudo.rb +1 -1
  128. data/lib/chef/resource/systemd_unit.rb +1 -0
  129. data/lib/chef/resource/template.rb +2 -0
  130. data/lib/chef/resource/user.rb +2 -0
  131. data/lib/chef/resource/user/aix_user.rb +2 -0
  132. data/lib/chef/resource/user/linux_user.rb +2 -0
  133. data/lib/chef/resource/user/pw_user.rb +2 -0
  134. data/lib/chef/resource/user/solaris_user.rb +2 -0
  135. data/lib/chef/resource/user/windows_user.rb +2 -0
  136. data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
  137. data/lib/chef/resource/windows_ad_join.rb +1 -1
  138. data/lib/chef/resource/windows_env.rb +1 -1
  139. data/lib/chef/resource/windows_feature.rb +2 -2
  140. data/lib/chef/resource/windows_feature_powershell.rb +1 -1
  141. data/lib/chef/resource/windows_firewall_rule.rb +11 -6
  142. data/lib/chef/resource/windows_script.rb +3 -1
  143. data/lib/chef/resource/yum_package.rb +1 -1
  144. data/lib/chef/resource_reporter.rb +1 -1
  145. data/lib/chef/resources.rb +1 -0
  146. data/lib/chef/run_context.rb +1 -1
  147. data/lib/chef/run_lock.rb +5 -5
  148. data/lib/chef/search/query.rb +0 -3
  149. data/lib/chef/train_transport.rb +3 -1
  150. data/lib/chef/util/powershell/ps_credential.rb +2 -2
  151. data/lib/chef/util/selinux.rb +1 -1
  152. data/lib/chef/util/windows/logon_session.rb +2 -2
  153. data/lib/chef/version.rb +1 -1
  154. data/lib/chef/win32/eventlog.rb +2 -2
  155. data/spec/data/cookbooks/starter/chefignore +8 -0
  156. data/spec/data/cookbooks/starter/files/sample.txt +1 -0
  157. data/spec/data/cookbooks/starter/metadata.rb +2 -0
  158. data/spec/data/cookbooks/starter/recipes/default.rb +4 -0
  159. data/spec/functional/event_loggers/windows_eventlog_spec.rb +1 -1
  160. data/spec/functional/mixin/user_context_spec.rb +2 -2
  161. data/spec/functional/rebooter_spec.rb +1 -1
  162. data/spec/functional/resource/cookbook_file_spec.rb +2 -2
  163. data/spec/functional/resource/template_spec.rb +1 -1
  164. data/spec/functional/version_spec.rb +1 -1
  165. data/spec/functional/win32/crypto_spec.rb +1 -1
  166. data/spec/functional/win32/security_spec.rb +1 -1
  167. data/spec/functional/win32/service_manager_spec.rb +1 -1
  168. data/spec/functional/win32/sid_spec.rb +2 -2
  169. data/spec/functional/win32/version_info_spec.rb +1 -1
  170. data/spec/functional/win32/versions_spec.rb +1 -1
  171. data/spec/integration/knife/config_get_profile_spec.rb +2 -2
  172. data/spec/integration/knife/config_get_spec.rb +9 -2
  173. data/spec/integration/knife/config_list_profiles_spec.rb +2 -2
  174. data/spec/integration/knife/config_use_profile_spec.rb +2 -2
  175. data/spec/integration/knife/list_spec.rb +2 -2
  176. data/spec/integration/solo/solo_spec.rb +1 -1
  177. data/spec/support/matchers/leak.rb +1 -1
  178. data/spec/support/mock/platform.rb +1 -1
  179. data/spec/support/platform_helpers.rb +2 -0
  180. data/spec/support/shared/integration/integration_helper.rb +1 -1
  181. data/spec/support/shared/integration/knife_support.rb +1 -1
  182. data/spec/support/shared/unit/provider/file.rb +4 -4
  183. data/spec/unit/application/client_spec.rb +2 -2
  184. data/spec/unit/application/knife_spec.rb +17 -0
  185. data/spec/unit/application_spec.rb +1 -1
  186. data/spec/unit/chef_fs/file_pattern_spec.rb +2 -2
  187. data/spec/unit/chef_fs/path_util_spec.rb +3 -3
  188. data/spec/unit/client_spec.rb +2 -2
  189. data/spec/unit/cookbook/chefignore_spec.rb +31 -11
  190. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
  191. data/spec/unit/cookbook/syntax_check_spec.rb +2 -2
  192. data/spec/unit/cookbook_loader_spec.rb +2 -2
  193. data/spec/unit/cookbook_uploader_spec.rb +6 -1
  194. data/spec/unit/data_bag_spec.rb +2 -2
  195. data/spec/unit/data_collector_spec.rb +7 -0
  196. data/spec/unit/dsl/platform_introspection_spec.rb +31 -1
  197. data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +1 -1
  198. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +1 -1
  199. data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +7 -0
  200. data/spec/unit/knife/cookbook_show_spec.rb +1 -1
  201. data/spec/unit/knife/core/gem_glob_loader_spec.rb +1 -1
  202. data/spec/unit/knife/core/hashed_command_loader_spec.rb +1 -1
  203. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
  204. data/spec/unit/knife/core/ui_spec.rb +2 -2
  205. data/spec/unit/knife/data_bag_from_file_spec.rb +2 -2
  206. data/spec/unit/knife/environment_from_file_spec.rb +2 -2
  207. data/spec/unit/knife/ssh_spec.rb +27 -17
  208. data/spec/unit/knife/status_spec.rb +1 -1
  209. data/spec/unit/knife/supermarket_install_spec.rb +1 -1
  210. data/spec/unit/mixin/path_sanity_spec.rb +3 -3
  211. data/spec/unit/mixin/shell_out_spec.rb +2 -3
  212. data/spec/unit/mixin/template_spec.rb +4 -4
  213. data/spec/unit/mixin/user_context_spec.rb +3 -3
  214. data/spec/unit/node_map_spec.rb +12 -12
  215. data/spec/unit/platform/query_helpers_spec.rb +9 -9
  216. data/spec/unit/provider/execute_spec.rb +1 -1
  217. data/spec/unit/provider/link_spec.rb +5 -5
  218. data/spec/unit/provider/package/openbsd_spec.rb +1 -1
  219. data/spec/unit/provider/package/smartos_spec.rb +1 -1
  220. data/spec/unit/provider/package/windows/exe_spec.rb +1 -1
  221. data/spec/unit/provider/package/windows_spec.rb +2 -2
  222. data/spec/unit/provider/remote_file/fetcher_spec.rb +2 -2
  223. data/spec/unit/provider/remote_file/local_file_spec.rb +1 -1
  224. data/spec/unit/provider/remote_file/network_file_spec.rb +1 -1
  225. data/spec/unit/provider/script_spec.rb +2 -2
  226. data/spec/unit/provider/service/systemd_service_spec.rb +26 -2
  227. data/spec/unit/provider/subversion_spec.rb +3 -3
  228. data/spec/unit/provider/systemd_unit_spec.rb +53 -4
  229. data/spec/unit/provider/user/dscl_spec.rb +1 -1
  230. data/spec/unit/provider_resolver_spec.rb +41 -61
  231. data/spec/unit/resource/chef_sleep_spec.rb +30 -0
  232. data/spec/unit/resource/cookbook_file_spec.rb +3 -3
  233. data/spec/unit/resource/remote_file_spec.rb +3 -3
  234. data/spec/unit/resource/windows_firewall_rule_spec.rb +69 -12
  235. data/spec/unit/role_spec.rb +2 -2
  236. data/spec/unit/shell_spec.rb +1 -1
  237. data/spec/unit/util/selinux_spec.rb +2 -2
  238. data/spec/unit/win32/error_spec.rb +1 -1
  239. data/spec/unit/win32/link_spec.rb +1 -1
  240. data/spec/unit/win32/security_spec.rb +1 -1
  241. data/spec/unit/windows_service_spec.rb +1 -1
  242. data/tasks/docs.rb +10 -2
  243. data/tasks/rspec.rb +8 -6
  244. metadata +33 -9
  245. data/lib/chef/mixin/train_helpers.rb +0 -60
  246. data/spec/unit/mash_spec.rb +0 -51
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Edwards (<adamed@chef.io>)
3
- # Copyright:: Copyright 2013-2016, Chef Software Inc.
3
+ # Copyright:: Copyright 2013-2019, 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,8 +18,8 @@
18
18
 
19
19
  require_relative "../exceptions"
20
20
  require_relative "../platform/query_helpers"
21
- require_relative "../win32/process" if Chef::Platform.windows?
22
- require_relative "../win32/system" if Chef::Platform.windows?
21
+ require_relative "../win32/process" if ChefUtils.windows?
22
+ require_relative "../win32/system" if ChefUtils.windows?
23
23
 
24
24
  class Chef
25
25
  module Mixin
@@ -89,7 +89,7 @@ class Chef
89
89
  end
90
90
 
91
91
  def is_i386_process_on_x86_64_windows?
92
- if Chef::Platform.windows?
92
+ if ChefUtils.windows?
93
93
  Chef::ReservedNames::Win32::Process.is_wow64_process
94
94
  else
95
95
  false
@@ -97,13 +97,13 @@ class Chef
97
97
  end
98
98
 
99
99
  def disable_wow64_file_redirection( node )
100
- if ( node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?
100
+ if ( node_windows_architecture(node) == :x86_64) && ::ChefUtils.windows?
101
101
  Chef::ReservedNames::Win32::System.wow64_disable_wow64_fs_redirection
102
102
  end
103
103
  end
104
104
 
105
105
  def restore_wow64_file_redirection( node, original_redirection_state )
106
- if (node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?
106
+ if (node_windows_architecture(node) == :x86_64) && ::ChefUtils.windows?
107
107
  Chef::ReservedNames::Win32::System.wow64_revert_wow64_fs_redirection(original_redirection_state)
108
108
  end
109
109
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Edwards (<adamed@chef.io>)
3
- # Copyright:: Copyright 2013-2016, Chef Software Inc.
3
+ # Copyright:: Copyright 2013-2019, 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");
@@ -19,16 +19,16 @@
19
19
  require_relative "../exceptions"
20
20
  require_relative "wide_string"
21
21
  require_relative "../platform/query_helpers"
22
- require_relative "../win32/error" if Chef::Platform.windows?
23
- require_relative "../win32/api/system" if Chef::Platform.windows?
24
- require_relative "../win32/api/unicode" if Chef::Platform.windows?
22
+ require_relative "../win32/error" if ChefUtils.windows?
23
+ require_relative "../win32/api/system" if ChefUtils.windows?
24
+ require_relative "../win32/api/unicode" if ChefUtils.windows?
25
25
 
26
26
  class Chef
27
27
  module Mixin
28
28
  module WindowsEnvHelper
29
29
  include Chef::Mixin::WideString
30
30
 
31
- if Chef::Platform.windows?
31
+ if ChefUtils.windows?
32
32
  include Chef::ReservedNames::Win32::API::System
33
33
  end
34
34
 
@@ -199,14 +199,14 @@ class Chef
199
199
  @role_default = VividMash.new({}, self, node, :role_default)
200
200
  @force_default = VividMash.new({}, self, node, :force_default)
201
201
 
202
- @normal = VividMash.new(normal, self, node, :normal)
202
+ @normal = VividMash.new(normal, self, node, :normal)
203
203
 
204
204
  @override = VividMash.new(override, self, node, :override)
205
205
  @role_override = VividMash.new({}, self, node, :role_override)
206
206
  @env_override = VividMash.new({}, self, node, :env_override)
207
207
  @force_override = VividMash.new({}, self, node, :force_override)
208
208
 
209
- @automatic = VividMash.new(automatic, self, node, :automatic)
209
+ @automatic = VividMash.new(automatic, self, node, :automatic)
210
210
 
211
211
  super(nil, self, node, :merged)
212
212
  end
@@ -219,6 +219,11 @@ class Chef
219
219
 
220
220
  private
221
221
 
222
+ def platform_family_query_helper?(node, m)
223
+ method = "#{m}?".to_sym
224
+ ChefUtils::DSL::PlatformFamily.respond_to?(method) && ChefUtils::DSL::PlatformFamily.send(method, node)
225
+ end
226
+
222
227
  #
223
228
  # Succeeds if:
224
229
  # - no negative matches (!value)
@@ -235,11 +240,19 @@ class Chef
235
240
  # Split the blacklist and whitelist
236
241
  blacklist, whitelist = filter_values.partition { |v| v.is_a?(String) && v.start_with?("!") }
237
242
 
238
- # If any blacklist value matches, we don't match
239
- return false if blacklist.any? { |v| v[1..-1] == value }
243
+ if attribute == :platform_family
244
+ # If any blacklist value matches, we don't match
245
+ return false if blacklist.any? { |v| v[1..-1] == value || platform_family_query_helper?(node, v[1..-1]) }
240
246
 
241
- # If the whitelist is empty, or anything matches, we match.
242
- whitelist.empty? || whitelist.any? { |v| v == :all || v == value }
247
+ # If the whitelist is empty, or anything matches, we match.
248
+ whitelist.empty? || whitelist.any? { |v| v == :all || v == value || platform_family_query_helper?(node, v) }
249
+ else
250
+ # If any blacklist value matches, we don't match
251
+ return false if blacklist.any? { |v| v[1..-1] == value }
252
+
253
+ # If the whitelist is empty, or anything matches, we match.
254
+ whitelist.empty? || whitelist.any? { |v| v == :all || v == value }
255
+ end
243
256
  end
244
257
 
245
258
  def matches_version_list?(node, filters, attribute)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright 2008-2016, Chef Software Inc.
3
+ # Copyright:: Copyright 2008-2019, 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");
@@ -16,12 +16,14 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require "chef-utils" unless defined?(ChefUtils::CANARY)
20
+
19
21
  class Chef
20
22
  class Platform
21
23
 
22
24
  class << self
23
25
  def windows?
24
- ChefConfig.windows?
26
+ ChefUtils.windows?
25
27
  end
26
28
 
27
29
  def windows_nano_server?
@@ -35,7 +35,7 @@ class Chef
35
35
  reboot_info = node.run_context.reboot_info
36
36
 
37
37
  cmd = case
38
- when Chef::Platform.windows?
38
+ when ChefUtils.windows?
39
39
  # should this do /f as well? do we then need a minimum delay to let apps quit?
40
40
  # Use explicit path to shutdown.exe, to protect against https://github.com/chef/chef/issues/5594
41
41
  windows_shutdown_path = "#{ENV["SYSTEMROOT"]}/System32/shutdown.exe"
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Lamont Granquist (<lamont@chef.io>)
3
- # Copyright:: Copyright 2014-2016, Chef Software, Inc.
3
+ # Copyright:: Copyright 2014-2019, 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,53 +17,22 @@
17
17
  #
18
18
 
19
19
  require_relative "../chef_class"
20
- require_relative "../mixin/train_helpers"
20
+ require "chef-utils" if defined?(ChefUtils::CANARY)
21
21
 
22
22
  class Chef
23
23
  class Platform
24
+ # @deprecated, use ChefUtils::DSL::Service instead (via the ChefUtils Universal DSL)
24
25
  class ServiceHelpers
25
26
  class << self
26
- include Chef::Mixin::TrainHelpers
27
-
28
- # This helper is mostly used to sort out the mess of different
29
- # linux mechanisms that can be used to start services. It does
30
- # not necessarily need to linux-specific, but currently all our
31
- # other service providers are narrowly platform-specific with no
32
- # alternatives.
33
- #
34
- # NOTE: if a system has (for example) chkconfig installed then we
35
- # should report that chkconfig is installed. The fact that a system
36
- # may also have systemd installed does not mean that we do not
37
- # report that systemd is also installed. This module is purely for
38
- # discovery of all the alternatives, handling the priority of the
39
- # different services is NOT a design concern of this module.
40
- #
41
27
  def service_resource_providers
42
28
  providers = []
43
29
 
44
- if file_exist?(Chef.path_to("/usr/sbin/update-rc.d"))
45
- providers << :debian
46
- end
47
-
48
- if file_exist?(Chef.path_to("/usr/sbin/invoke-rc.d"))
49
- providers << :invokercd
50
- end
51
-
52
- if file_exist?(Chef.path_to("/sbin/initctl"))
53
- providers << :upstart
54
- end
55
-
56
- if file_exist?(Chef.path_to("/sbin/insserv"))
57
- providers << :insserv
58
- end
59
-
60
- if systemd_is_init?
61
- providers << :systemd
62
- end
63
-
64
- if file_exist?(Chef.path_to("/sbin/chkconfig"))
65
- providers << :redhat
66
- end
30
+ providers << :debian if ChefUtils::DSL::Service.debianrcd?
31
+ providers << :invokercd if ChefUtils::DSL::Service.invokercd?
32
+ providers << :upstart if ChefUtils::DSL::Service.upstart?
33
+ providers << :insserv if ChefUtils::DSL::Service.insserv?
34
+ providers << :systemd if ChefUtils.systemd?
35
+ providers << :redhat if ChefUtils::DSL::Service.redhatrcd?
67
36
 
68
37
  providers
69
38
  end
@@ -71,54 +40,14 @@ class Chef
71
40
  def config_for_service(service_name)
72
41
  configs = []
73
42
 
74
- if file_exist?(Chef.path_to("/etc/init.d/#{service_name}"))
75
- configs += %i{initd systemd}
76
- end
77
-
78
- if file_exist?(Chef.path_to("/etc/init/#{service_name}.conf"))
79
- configs << :upstart
80
- end
81
-
82
- if file_exist?(Chef.path_to("/etc/xinetd.d/#{service_name}"))
83
- configs << :xinetd
84
- end
85
-
86
- if file_exist?(Chef.path_to("/etc/rc.d/#{service_name}"))
87
- configs << :etc_rcd
88
- end
89
-
90
- if file_exist?(Chef.path_to("/usr/local/etc/rc.d/#{service_name}"))
91
- configs << :usr_local_etc_rcd
92
- end
93
-
94
- if has_systemd_service_unit?(service_name) || has_systemd_unit?(service_name)
95
- configs << :systemd
96
- end
43
+ configs << :initd if ChefUtils::DSL::Service.service_script_exist?(:initd, service_name)
44
+ configs << :upstart if ChefUtils::DSL::Service.service_script_exist?(:upstart, service_name)
45
+ configs << :xinetd if ChefUtils::DSL::Service.service_script_exist?(:xinetd, service_name)
46
+ configs << :systemd if ChefUtils::DSL::Service.service_script_exist?(:systemd, service_name)
47
+ configs << :etc_rcd if ChefUtils::DSL::Service.service_script_exist?(:etc_rcd, service_name)
97
48
 
98
49
  configs
99
50
  end
100
-
101
- private
102
-
103
- def systemd_is_init?
104
- file_exist?(Chef.path_to("/proc/1/comm")) &&
105
- file_open(Chef.path_to("/proc/1/comm")).gets.chomp == "systemd"
106
- end
107
-
108
- def has_systemd_service_unit?(svc_name)
109
- %w{ /etc /usr/lib /lib /run }.any? do |load_path|
110
- file_exist?(
111
- Chef.path_to("#{load_path}/systemd/system/#{svc_name.gsub(/@.*$/, "@")}.service")
112
- )
113
- end
114
- end
115
-
116
- def has_systemd_unit?(svc_name)
117
- # TODO: stop supporting non-service units with service resource
118
- %w{ /etc /usr/lib /lib /run }.any? do |load_path|
119
- file_exist?(Chef.path_to("#{load_path}/systemd/system/#{svc_name}"))
120
- end
121
- end
122
51
  end
123
52
  end
124
53
  end
@@ -46,6 +46,8 @@ class Chef
46
46
 
47
47
  # includes the "core" DSL and not the "recipe" DSL by design
48
48
  include Chef::DSL::Core
49
+ # the class only gets the Universal DSL (no resource_collection at class parsing time)
50
+ extend Chef::DSL::Universal
49
51
 
50
52
  # supports the given resource and action (late binding)
51
53
  def self.supports?(resource, action)
@@ -84,7 +84,7 @@ class Chef
84
84
  end
85
85
 
86
86
  # true if we are going to be creating a new file
87
- @needs_creating = !::File.exist?(new_resource.path) || needs_unlinking?
87
+ @needs_creating = !::File.exist?(new_resource.path) || needs_unlinking?
88
88
 
89
89
  # Let children resources override constructing the current_resource
90
90
  @current_resource ||= Chef::Resource::File.new(new_resource.name)
@@ -453,7 +453,7 @@ class Chef
453
453
  end
454
454
 
455
455
  def load_resource_attributes_from_file(resource)
456
- if Chef::Platform.windows?
456
+ if ChefUtils.windows?
457
457
  # This is a work around for CHEF-3554.
458
458
  # OC-6534: is tracking the real fix for this workaround.
459
459
  # Add support for Windows equivalent, or implicit resource
@@ -22,7 +22,7 @@ class Chef
22
22
  class Provider
23
23
  class Ifconfig
24
24
  class Redhat < Chef::Provider::Ifconfig
25
- provides :ifconfig, platform_family: %w{fedora rhel amazon}
25
+ provides :ifconfig, platform_family: "fedora_derived"
26
26
 
27
27
  def initialize(new_resource, run_context)
28
28
  super(new_resource, run_context)
@@ -82,7 +82,7 @@ class Chef
82
82
  end
83
83
 
84
84
  def canonicalize(path)
85
- Chef::Platform.windows? ? path.tr("/", '\\') : path
85
+ ChefUtils.windows? ? path.tr("/", '\\') : path
86
86
  end
87
87
 
88
88
  def action_create
@@ -101,7 +101,7 @@ class Chef
101
101
  # However if the new symlink will point to a file and the current symlink is pointing at a
102
102
  # directory we want to throw an exception and calling ::File.unlink on the directory symlink
103
103
  # will throw the correct ones.
104
- if Chef::Platform.windows? && ::File.directory?(new_resource.to) &&
104
+ if ChefUtils.windows? && ::File.directory?(new_resource.to) &&
105
105
  ::File.directory?(current_resource.target_file)
106
106
  converge_by("unlink existing windows symlink to dir at #{new_resource.target_file}") do
107
107
  ::Dir.unlink(new_resource.target_file)
@@ -143,7 +143,7 @@ class Chef
143
143
 
144
144
  def action_delete
145
145
  if current_resource.to # Exists
146
- if Chef::Platform.windows? && ::File.directory?(current_resource.target_file)
146
+ if ChefUtils.windows? && ::File.directory?(current_resource.target_file)
147
147
  converge_by("delete link to dir at #{new_resource.target_file}") do
148
148
  ::Dir.delete(new_resource.target_file)
149
149
  logger.info("#{new_resource} deleted")
@@ -27,7 +27,7 @@ class Chef
27
27
  class Mount
28
28
  # Mount Solaris File systems
29
29
  class Solaris < Chef::Provider::Mount
30
- provides :mount, platform: %w{openindiana opensolaris nexentacore omnios solaris2 smartos}
30
+ provides :mount, platform_family: "solaris_based"
31
31
 
32
32
  extend Forwardable
33
33
 
@@ -37,7 +37,7 @@ class Chef
37
37
  use_multipackage_api
38
38
  use_package_name_for_source
39
39
 
40
- provides :package, platform_family: %w{fedora amazon rhel}
40
+ provides :package, platform_family: "fedora_derived"
41
41
 
42
42
  provides :yum_package
43
43
 
@@ -36,7 +36,7 @@ class Chef
36
36
  include Chef::Mixin::Checksum
37
37
 
38
38
  def running_on_windows!
39
- unless Chef::Platform.windows?
39
+ unless ChefUtils.windows?
40
40
  raise Chef::Exceptions::Win32NotWindows, "Attempt to manipulate the windows registry on a non-windows node"
41
41
  end
42
42
  end
@@ -111,7 +111,7 @@ class Chef
111
111
  next if managed_files.include?(file)
112
112
 
113
113
  if ::File.directory?(file)
114
- if !Chef::Platform.windows? && file_class.symlink?(file.dup)
114
+ if !ChefUtils.windows? && file_class.symlink?(file.dup)
115
115
  # Unix treats dir symlinks as files
116
116
  purge_file(file)
117
117
  else
@@ -208,7 +208,7 @@ class Chef
208
208
  # Set the sensitivity level
209
209
  res.sensitive(new_resource.sensitive)
210
210
  res.source(::File.join(source, relative_source_path))
211
- if Chef::Platform.windows? && files_rights
211
+ if ChefUtils.windows? && files_rights
212
212
  files_rights.each_pair do |permission, *args|
213
213
  res.rights(permission, *args)
214
214
  end
@@ -244,7 +244,7 @@ class Chef
244
244
  def directory_resource(dir)
245
245
  res = Chef::Resource::Directory.new(dir, run_context)
246
246
  res.cookbook_name = resource_cookbook
247
- if Chef::Platform.windows? && rights
247
+ if ChefUtils.windows? && rights
248
248
  # rights are only meant to be applied to the toppest-level directory;
249
249
  # Windows will handle inheritance.
250
250
  if dir == path
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Jesse Campbell (<hikeit@gmail.com>)
3
3
  # Author:: Lamont Granquist (<lamont@chef.io>)
4
- # Copyright:: Copyright 2013-2016, Chef Software Inc.
4
+ # Copyright:: Copyright 2013-2019, 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");
@@ -24,7 +24,7 @@ class Chef
24
24
 
25
25
  def self.for_resource(uri, new_resource, current_resource)
26
26
  if network_share?(uri)
27
- unless Chef::Platform.windows?
27
+ unless ChefUtils.windows?
28
28
  raise Exceptions::UnsupportedPlatform, "Fetching the file on a network share is supported only on the Windows platform. Please change your source: #{uri}"
29
29
  end
30
30
 
@@ -41,7 +41,7 @@ class Chef
41
41
  def source_path
42
42
  @source_path ||= begin
43
43
  path = URI.unescape(uri.path)
44
- Chef::Platform.windows? ? fix_windows_path(path) : path
44
+ ChefUtils.windows? ? fix_windows_path(path) : path
45
45
  end
46
46
  end
47
47
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright 2008-2016, Chef Software Inc.
3
+ # Copyright:: Copyright 2008-2019, 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,7 +18,7 @@
18
18
 
19
19
  require "tempfile" unless defined?(Tempfile)
20
20
  require_relative "execute"
21
- require_relative "../win32/security" if Chef::Platform.windows?
21
+ require_relative "../win32/security" if ChefUtils.windows?
22
22
  require "forwardable" unless defined?(Forwardable)
23
23
 
24
24
  class Chef
@@ -63,7 +63,7 @@ class Chef
63
63
  end
64
64
 
65
65
  def set_owner_and_group
66
- if Chef::Platform.windows?
66
+ if ChefUtils.windows?
67
67
  # And on Windows also this is a no-op if there is no user specified.
68
68
  grant_alternate_user_read_access
69
69
  else