chef 18.4.2 → 18.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -1
  3. data/chef.gemspec +7 -7
  4. data/lib/chef/application/client.rb +12 -0
  5. data/lib/chef/client.rb +10 -16
  6. data/lib/chef/compliance/runner.rb +10 -0
  7. data/lib/chef/cookbook/chefignore.rb +4 -1
  8. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  9. data/lib/chef/cookbook/synchronizer.rb +7 -1
  10. data/lib/chef/cookbook_manifest.rb +2 -2
  11. data/lib/chef/file_access_control/unix.rb +9 -9
  12. data/lib/chef/file_cache.rb +17 -2
  13. data/lib/chef/file_content_management/deploy/target_io.rb +29 -0
  14. data/lib/chef/file_content_management/deploy.rb +4 -1
  15. data/lib/chef/formatters/doc.rb +1 -1
  16. data/lib/chef/mixin/file_class.rb +3 -1
  17. data/lib/chef/mixin/get_source_from_package.rb +1 -1
  18. data/lib/chef/mixin/openssl_helper.rb +1 -1
  19. data/lib/chef/node/attribute.rb +3 -11
  20. data/lib/chef/node/immutable_collections.rb +15 -8
  21. data/lib/chef/node/mixin/state_tracking.rb +6 -3
  22. data/lib/chef/node.rb +1 -1
  23. data/lib/chef/policy_builder/policyfile.rb +8 -0
  24. data/lib/chef/provider/.gitkeep +0 -0
  25. data/lib/chef/provider/cookbook_file.rb +1 -1
  26. data/lib/chef/provider/cron.rb +1 -1
  27. data/lib/chef/provider/directory.rb +15 -15
  28. data/lib/chef/provider/file.rb +42 -29
  29. data/lib/chef/provider/git.rb +8 -8
  30. data/lib/chef/provider/group/aix.rb +1 -1
  31. data/lib/chef/provider/group/dscl.rb +1 -1
  32. data/lib/chef/provider/group/gpasswd.rb +2 -2
  33. data/lib/chef/provider/group/groupadd.rb +1 -1
  34. data/lib/chef/provider/group/groupmod.rb +2 -2
  35. data/lib/chef/provider/group/pw.rb +2 -2
  36. data/lib/chef/provider/group/solaris.rb +2 -2
  37. data/lib/chef/provider/group/usermod.rb +2 -2
  38. data/lib/chef/provider/group.rb +1 -1
  39. data/lib/chef/provider/http_request.rb +2 -3
  40. data/lib/chef/provider/ifconfig/aix.rb +1 -1
  41. data/lib/chef/provider/ifconfig/debian.rb +3 -3
  42. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  43. data/lib/chef/provider/ifconfig.rb +1 -1
  44. data/lib/chef/provider/link.rb +10 -10
  45. data/lib/chef/provider/mount/aix.rb +4 -4
  46. data/lib/chef/provider/mount/linux.rb +4 -4
  47. data/lib/chef/provider/mount/mount.rb +11 -11
  48. data/lib/chef/provider/package/apt.rb +2 -11
  49. data/lib/chef/provider/package/bff.rb +3 -3
  50. data/lib/chef/provider/package/chocolatey.rb +54 -24
  51. data/lib/chef/provider/package/dpkg.rb +3 -3
  52. data/lib/chef/provider/package/freebsd/base.rb +1 -1
  53. data/lib/chef/provider/package/habitat.rb +5 -3
  54. data/lib/chef/provider/package/ips.rb +2 -2
  55. data/lib/chef/provider/package/openbsd.rb +3 -2
  56. data/lib/chef/provider/package/pacman.rb +4 -4
  57. data/lib/chef/provider/package/paludis.rb +2 -2
  58. data/lib/chef/provider/package/portage.rb +1 -1
  59. data/lib/chef/provider/package/powershell.rb +1 -0
  60. data/lib/chef/provider/package/rpm.rb +2 -2
  61. data/lib/chef/provider/package/smartos.rb +2 -2
  62. data/lib/chef/provider/package/snap.rb +2 -1
  63. data/lib/chef/provider/package/snap_tm.rb +79 -0
  64. data/lib/chef/provider/package/solaris.rb +4 -4
  65. data/lib/chef/provider/package/zypper.rb +4 -5
  66. data/lib/chef/provider/package.rb +1 -1
  67. data/lib/chef/provider/remote_directory.rb +5 -5
  68. data/lib/chef/provider/remote_file/http.rb +2 -3
  69. data/lib/chef/provider/remote_file.rb +1 -1
  70. data/lib/chef/provider/route.rb +9 -9
  71. data/lib/chef/provider/service/aix.rb +1 -1
  72. data/lib/chef/provider/service/aixinit.rb +4 -4
  73. data/lib/chef/provider/service/arch.rb +6 -6
  74. data/lib/chef/provider/service/debian.rb +5 -5
  75. data/lib/chef/provider/service/freebsd.rb +7 -7
  76. data/lib/chef/provider/service/gentoo.rb +5 -5
  77. data/lib/chef/provider/service/init.rb +2 -2
  78. data/lib/chef/provider/service/insserv.rb +2 -2
  79. data/lib/chef/provider/service/invokercd.rb +1 -1
  80. data/lib/chef/provider/service/openbsd.rb +7 -7
  81. data/lib/chef/provider/service/redhat.rb +3 -3
  82. data/lib/chef/provider/service/solaris.rb +2 -2
  83. data/lib/chef/provider/service/systemd.rb +2 -2
  84. data/lib/chef/provider/service/upstart.rb +2 -2
  85. data/lib/chef/provider/service/windows.rb +0 -1
  86. data/lib/chef/provider/subversion.rb +8 -8
  87. data/lib/chef/provider/systemd_unit.rb +3 -3
  88. data/lib/chef/provider/template.rb +1 -1
  89. data/lib/chef/provider/user/aix.rb +3 -3
  90. data/lib/chef/provider/user/linux.rb +7 -2
  91. data/lib/chef/provider/user/pw.rb +3 -3
  92. data/lib/chef/provider/user/solaris.rb +7 -7
  93. data/lib/chef/provider/user.rb +7 -8
  94. data/lib/chef/provider/yum_repository.rb +1 -3
  95. data/lib/chef/provider/zypper_repository.rb +1 -1
  96. data/lib/chef/providers.rb +1 -0
  97. data/lib/chef/resource/.gitkeep +0 -0
  98. data/lib/chef/resource/alternatives.rb +2 -2
  99. data/lib/chef/resource/apt_preference.rb +1 -1
  100. data/lib/chef/resource/apt_repository.rb +7 -9
  101. data/lib/chef/resource/apt_update.rb +3 -3
  102. data/lib/chef/resource/bff_package.rb +1 -1
  103. data/lib/chef/resource/chef_client_config.rb +3 -2
  104. data/lib/chef/resource/chef_client_systemd_timer.rb +5 -0
  105. data/lib/chef/resource/chef_gem.rb +1 -1
  106. data/lib/chef/resource/chef_sleep.rb +1 -1
  107. data/lib/chef/resource/cookbook_file.rb +1 -1
  108. data/lib/chef/resource/cron/cron.rb +1 -1
  109. data/lib/chef/resource/cron/cron_d.rb +1 -1
  110. data/lib/chef/resource/cron_access.rb +1 -1
  111. data/lib/chef/resource/directory.rb +1 -1
  112. data/lib/chef/resource/dpkg_package.rb +1 -1
  113. data/lib/chef/resource/execute.rb +8 -6
  114. data/lib/chef/resource/file/verification/json.rb +1 -1
  115. data/lib/chef/resource/file/verification/systemd_unit.rb +1 -1
  116. data/lib/chef/resource/file/verification/yaml.rb +1 -1
  117. data/lib/chef/resource/file.rb +1 -1
  118. data/lib/chef/resource/freebsd_package.rb +2 -2
  119. data/lib/chef/resource/group.rb +1 -1
  120. data/lib/chef/resource/habitat/habitat_package.rb +1 -1
  121. data/lib/chef/resource/habitat/habitat_sup.rb +9 -9
  122. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +2 -2
  123. data/lib/chef/resource/habitat_install.rb +5 -4
  124. data/lib/chef/resource/hostname.rb +11 -10
  125. data/lib/chef/resource/http_request.rb +1 -1
  126. data/lib/chef/resource/ifconfig.rb +1 -1
  127. data/lib/chef/resource/inspec_input.rb +3 -1
  128. data/lib/chef/resource/inspec_waiver.rb +1 -1
  129. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  130. data/lib/chef/resource/ips_package.rb +2 -2
  131. data/lib/chef/resource/kernel_module.rb +2 -2
  132. data/lib/chef/resource/link.rb +1 -1
  133. data/lib/chef/resource/locale.rb +2 -2
  134. data/lib/chef/resource/mount.rb +1 -1
  135. data/lib/chef/resource/notify_group.rb +1 -1
  136. data/lib/chef/resource/ohai.rb +1 -1
  137. data/lib/chef/resource/ohai_hint.rb +1 -1
  138. data/lib/chef/resource/openbsd_package.rb +2 -2
  139. data/lib/chef/resource/package.rb +1 -1
  140. data/lib/chef/resource/pacman_package.rb +1 -1
  141. data/lib/chef/resource/paludis_package.rb +1 -1
  142. data/lib/chef/resource/portage_package.rb +1 -1
  143. data/lib/chef/resource/powershell_package.rb +4 -0
  144. data/lib/chef/resource/reboot.rb +1 -1
  145. data/lib/chef/resource/remote_directory.rb +1 -1
  146. data/lib/chef/resource/remote_file.rb +1 -1
  147. data/lib/chef/resource/rhsm_errata.rb +1 -1
  148. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  149. data/lib/chef/resource/rhsm_register.rb +1 -1
  150. data/lib/chef/resource/rhsm_repo.rb +3 -4
  151. data/lib/chef/resource/rhsm_subscription.rb +8 -9
  152. data/lib/chef/resource/route.rb +1 -1
  153. data/lib/chef/resource/rpm_package.rb +1 -1
  154. data/lib/chef/resource/scm/git.rb +1 -1
  155. data/lib/chef/resource/scm/subversion.rb +1 -1
  156. data/lib/chef/resource/selinux/common_helpers.rb +1 -1
  157. data/lib/chef/resource/selinux_boolean.rb +1 -1
  158. data/lib/chef/resource/selinux_fcontext.rb +3 -3
  159. data/lib/chef/resource/selinux_install.rb +1 -1
  160. data/lib/chef/resource/selinux_login.rb +1 -1
  161. data/lib/chef/resource/selinux_module.rb +5 -5
  162. data/lib/chef/resource/selinux_permissive.rb +2 -2
  163. data/lib/chef/resource/selinux_port.rb +2 -2
  164. data/lib/chef/resource/selinux_state.rb +2 -2
  165. data/lib/chef/resource/selinux_user.rb +1 -1
  166. data/lib/chef/resource/smartos_package.rb +2 -2
  167. data/lib/chef/resource/snap_package.rb +24 -1
  168. data/lib/chef/resource/solaris_package.rb +1 -1
  169. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  170. data/lib/chef/resource/sudo.rb +5 -5
  171. data/lib/chef/resource/support/client.erb +1 -1
  172. data/lib/chef/resource/swap_file.rb +6 -6
  173. data/lib/chef/resource/sysctl.rb +6 -5
  174. data/lib/chef/resource/systemd_unit.rb +1 -1
  175. data/lib/chef/resource/template.rb +1 -1
  176. data/lib/chef/resource/timezone.rb +5 -5
  177. data/lib/chef/resource/user/aix_user.rb +2 -2
  178. data/lib/chef/resource/user/linux_user.rb +2 -2
  179. data/lib/chef/resource/user/pw_user.rb +2 -2
  180. data/lib/chef/resource/user/solaris_user.rb +2 -2
  181. data/lib/chef/resource/user_ulimit.rb +1 -1
  182. data/lib/chef/resource/yum_repository.rb +1 -1
  183. data/lib/chef/resource/zypper_package.rb +2 -2
  184. data/lib/chef/resource/zypper_repository.rb +2 -2
  185. data/lib/chef/run_lock.rb +3 -0
  186. data/lib/chef/scan_access_control.rb +6 -6
  187. data/lib/chef/target_io/dir.rb +12 -0
  188. data/lib/chef/target_io/etc.rb +16 -0
  189. data/lib/chef/target_io/file.rb +12 -0
  190. data/lib/chef/target_io/fileutils.rb +12 -0
  191. data/lib/chef/target_io/http.rb +22 -0
  192. data/lib/chef/target_io/io.rb +12 -0
  193. data/lib/chef/target_io/shadow.rb +44 -0
  194. data/lib/chef/target_io/train/dir.rb +69 -0
  195. data/lib/chef/target_io/train/etc.rb +112 -0
  196. data/lib/chef/target_io/train/file.rb +219 -0
  197. data/lib/chef/target_io/train/fileutils.rb +220 -0
  198. data/lib/chef/target_io/train/http.rb +117 -0
  199. data/lib/chef/target_io/train/io.rb +13 -0
  200. data/lib/chef/target_io/train/shadow.rb +52 -0
  201. data/lib/chef/target_io/train_compat.rb +7 -0
  202. data/lib/chef/target_io.rb +9 -0
  203. data/lib/chef/util/backup.rb +1 -1
  204. data/lib/chef/util/diff.rb +14 -1
  205. data/lib/chef/util/file_edit.rb +4 -4
  206. data/lib/chef/version.rb +1 -1
  207. data/lib/chef.rb +2 -0
  208. data/spec/functional/resource/remote_file_spec.rb +1 -1
  209. data/spec/integration/client/fips_spec.rb +11 -2
  210. data/spec/integration/client/open_ssl_spec.rb +20 -0
  211. data/spec/spec_helper.rb +3 -1
  212. data/spec/support/platform_helpers.rb +20 -7
  213. data/spec/unit/client_spec.rb +0 -16
  214. data/spec/unit/file_cache_spec.rb +64 -0
  215. data/spec/unit/mixin/openssl_helper_spec.rb +6 -1
  216. data/spec/unit/provider/apt_repository_spec.rb +1 -1
  217. data/spec/unit/provider/package/chocolatey_spec.rb +17 -12
  218. data/spec/unit/provider/package/windows_spec.rb +5 -5
  219. data/spec/unit/provider/package/zypper_spec.rb +0 -10
  220. data/spec/unit/provider/route_spec.rb +6 -4
  221. data/spec/unit/resource/rhsm_repo_spec.rb +1 -0
  222. data/spec/unit/resource/rhsm_subscription_spec.rb +2 -0
  223. metadata +31 -10
@@ -30,8 +30,8 @@ class Chef
30
30
  use_package_name_for_source
31
31
  allow_nils
32
32
 
33
- provides :package, platform_family: "suse"
34
- provides :zypper_package
33
+ provides :package, platform_family: "suse", target_mode: true
34
+ provides :zypper_package, target_mode: true
35
35
 
36
36
  def define_resource_requirements
37
37
  super
@@ -91,7 +91,7 @@ class Chef
91
91
  # @return [Boolean] True if all sources exist
92
92
  def source_files_exist?
93
93
  if !new_resource.source.nil?
94
- resolved_source_array.all? { |s| s && ::File.exist?(s) }
94
+ resolved_source_array.all? { |s| s && ::TargetIO::File.exist?(s) }
95
95
  else
96
96
  true
97
97
  end
@@ -100,7 +100,7 @@ class Chef
100
100
  # Helper to return all the names of the missing sources for error messages.
101
101
  # @return [Array<String>] Array of missing sources
102
102
  def missing_sources
103
- resolved_source_array.select { |s| s.nil? || !::File.exist?(s) }
103
+ resolved_source_array.select { |s| s.nil? || !::TargetIO::File.exist?(s) }
104
104
  end
105
105
 
106
106
  def resolve_source_to_version
@@ -146,7 +146,6 @@ class Chef
146
146
  if md = line.match(/^(\S*)\s+\|\s+(\S+)\s+\|\s+(\S+)\s+\|\s+(\S+)\s+\|\s+(\S+)\s+\|\s+(.*)$/)
147
147
  (status, name, type, version, arch, repo) = [ md[1], md[2], md[3], md[4], md[5], md[6] ]
148
148
  next if version == "Version" # header
149
- next if name != package_name
150
149
 
151
150
  # sometimes even though we request a specific version in the search string above and have match exact, we wind up
152
151
  # with other versions in the output, particularly getting the installed version when downgrading.
@@ -648,7 +648,7 @@ class Chef
648
648
  source_array.each_with_index.map do |source, i|
649
649
  package_name = package_name_array[i]
650
650
  # we require at least one '/' in the package_name to avoid [XXX_]package 'foo' breaking due to a random 'foo' file in cwd
651
- if use_package_name_for_source? && source.nil? && package_name.match(/#{::File::SEPARATOR}/) && ::File.exist?(package_name)
651
+ if use_package_name_for_source? && source.nil? && package_name.match(/#{::File::SEPARATOR}/) && ::TargetIO::File.exist?(package_name)
652
652
  logger.trace("No package source specified, but #{package_name} exists on filesystem, using #{package_name} as source.")
653
653
  package_name
654
654
  else
@@ -32,7 +32,7 @@ class Chef
32
32
  extend Forwardable
33
33
  include Chef::Mixin::FileClass
34
34
 
35
- provides :remote_directory
35
+ provides :remote_directory, target_mode: true
36
36
 
37
37
  def_delegators :new_resource, :purge, :path, :source, :cookbook, :cookbook_name
38
38
  def_delegators :new_resource, :files_rights, :files_mode, :files_group, :files_owner, :files_backup
@@ -100,7 +100,7 @@ class Chef
100
100
  #
101
101
  def purge_unmanaged_files
102
102
  if purge
103
- Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob_dir(path), "**", "*"), ::File::FNM_DOTMATCH).sort!.reverse!.each do |file|
103
+ TargetIO::Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob_dir(path), "**", "*"), ::File::FNM_DOTMATCH).sort!.reverse!.each do |file|
104
104
  # skip '.' and '..'
105
105
  next if [".", ".."].include?(Pathname.new(file).basename.to_s)
106
106
 
@@ -110,7 +110,7 @@ class Chef
110
110
  # Skip files that we've sync'd and their parent dirs
111
111
  next if managed_files.include?(file)
112
112
 
113
- if ::File.directory?(file)
113
+ if ::TargetIO::File.directory?(file)
114
114
  if !ChefUtils.windows? && file_class.symlink?(file.dup)
115
115
  # Unix treats dir symlinks as files
116
116
  purge_file(file)
@@ -188,7 +188,7 @@ class Chef
188
188
  def create_cookbook_file(cookbook_file_relative_path)
189
189
  full_path = ::File.join(path, cookbook_file_relative_path)
190
190
 
191
- ensure_directory_exists(::File.dirname(full_path))
191
+ ensure_directory_exists(::TargetIO::File.dirname(full_path))
192
192
 
193
193
  res = cookbook_file_resource(full_path, cookbook_file_relative_path)
194
194
  res.run_action(action_for_cookbook_file)
@@ -228,7 +228,7 @@ class Chef
228
228
  #
229
229
  def ensure_directory_exists(dir)
230
230
  # doing the check here and skipping the resource should be more performant
231
- unless ::File.directory?(dir)
231
+ unless ::TargetIO::File.directory?(dir)
232
232
  res = directory_resource(dir)
233
233
  res.run_action(:create)
234
234
  new_resource.updated_by_last_action(true) if res.updated?
@@ -17,7 +17,6 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require_relative "../../http/simple"
21
20
  require_relative "../../digester"
22
21
  require_relative "../remote_file"
23
22
  require_relative "cache_control_data"
@@ -62,7 +61,7 @@ class Chef
62
61
  end
63
62
 
64
63
  def fetch
65
- http = Chef::HTTP::Simple.new(uri, http_client_opts)
64
+ http = TargetIO::HTTP.new(uri, http_client_opts)
66
65
  orig_tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile
67
66
  if want_progress?
68
67
  tempfile = http.streaming_request_with_progress(uri, headers, orig_tempfile) do |size, total|
@@ -97,7 +96,7 @@ class Chef
97
96
  end
98
97
 
99
98
  def want_progress?
100
- events.formatter? && (Chef::Config[:show_download_progress] || !!new_resource.show_progress)
99
+ !ChefConfig::Config.target_mode? && events.formatter? && (Chef::Config[:show_download_progress] || !!new_resource.show_progress)
101
100
  end
102
101
 
103
102
  def progress_interval
@@ -22,7 +22,7 @@ require_relative "file"
22
22
  class Chef
23
23
  class Provider
24
24
  class RemoteFile < Chef::Provider::File
25
- provides :remote_file
25
+ provides :remote_file, target_mode: true
26
26
 
27
27
  def initialize(new_resource, run_context)
28
28
  @content_class = Chef::Provider::RemoteFile::Content
@@ -25,7 +25,7 @@ class Chef
25
25
  class Provider
26
26
  class Route < Chef::Provider
27
27
 
28
- provides :route
28
+ provides :route, target_mode: true
29
29
 
30
30
  attr_accessor :is_running
31
31
 
@@ -98,7 +98,7 @@ class Chef
98
98
  # For linux, we use /proc/net/route file to read proc table info
99
99
  return unless linux?
100
100
 
101
- route_file = ::File.open("/proc/net/route", "r")
101
+ route_file = ::TargetIO::File.open("/proc/net/route", "r")
102
102
 
103
103
  # Read all routes
104
104
  while (line = route_file.gets)
@@ -186,24 +186,24 @@ class Chef
186
186
  network_file_name = "/etc/sysconfig/network"
187
187
  converge_by("write route default route to #{network_file_name}") do
188
188
  logger.trace("#{new_resource} writing default route #{new_resource.gateway} to #{network_file_name}")
189
- if ::File.exist?(network_file_name)
189
+ if ::TargetIO::File.exist?(network_file_name)
190
190
  network_file = ::Chef::Util::FileEdit.new(network_file_name)
191
191
  network_file.search_file_replace_line(/^GATEWAY=/, "GATEWAY=#{new_resource.gateway}")
192
192
  network_file.insert_line_if_no_match(/^GATEWAY=/, "GATEWAY=#{new_resource.gateway}")
193
193
  network_file.write_file
194
194
  else
195
- network_file = ::File.new(network_file_name, "w")
196
- network_file.puts("GATEWAY=#{new_resource.gateway}")
197
- network_file.close
195
+ ::TargetIO::File.open(network_file_name, "w") do |network_file|
196
+ network_file.puts("GATEWAY=#{new_resource.gateway}")
197
+ end
198
198
  end
199
199
  end
200
200
  else
201
201
  network_file_name = "/etc/sysconfig/network-scripts/route-#{k}"
202
202
  converge_by("write route route.#{k}\n#{conf[k]} to #{network_file_name}") do
203
- network_file = ::File.new(network_file_name, "w")
204
- network_file.puts(conf[k])
203
+ ::TargetIO::File.open(network_file_name, "w") do |network_file|
204
+ network_file.puts(conf[k])
205
+ end
205
206
  logger.trace("#{new_resource} writing route.#{k}\n#{conf[k]}")
206
- network_file.close
207
207
  end
208
208
  end
209
209
  end
@@ -24,7 +24,7 @@ class Chef
24
24
  class Aix < Chef::Provider::Service
25
25
  attr_reader :status_load_success
26
26
 
27
- provides :service, os: "aix"
27
+ provides :service, os: "aix", target_mode: true
28
28
 
29
29
  def initialize(new_resource, run_context)
30
30
  super
@@ -57,7 +57,7 @@ class Chef
57
57
  end
58
58
 
59
59
  def enable_service
60
- Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).each { |f| ::File.delete(f) }
60
+ TargetIO::Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).each { |f| ::File.delete(f) }
61
61
 
62
62
  if @new_resource.priority.is_a? Integer
63
63
  create_symlink(2, "S", @new_resource.priority)
@@ -72,7 +72,7 @@ class Chef
72
72
  end
73
73
 
74
74
  def disable_service
75
- Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).each { |f| ::File.delete(f) }
75
+ TargetIO::Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).each { |f| ::File.delete(f) }
76
76
 
77
77
  if @new_resource.priority.is_a? Integer
78
78
  create_symlink(2, "K", 100 - @new_resource.priority)
@@ -86,13 +86,13 @@ class Chef
86
86
  end
87
87
 
88
88
  def create_symlink(run_level, status, priority)
89
- ::File.symlink("/etc/rc.d/init.d/#{@new_resource.service_name}", "/etc/rc.d/rc#{run_level}.d/#{status}#{priority}#{@new_resource.service_name}")
89
+ ::TargetIO::File.symlink("/etc/rc.d/init.d/#{@new_resource.service_name}", "/etc/rc.d/rc#{run_level}.d/#{status}#{priority}#{@new_resource.service_name}")
90
90
  end
91
91
 
92
92
  def set_current_resource_attributes
93
93
  # assuming run level 2 for aix
94
94
  is_enabled = false
95
- files = Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"])
95
+ files = TargetIO::Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"])
96
96
 
97
97
  priority = {}
98
98
 
@@ -20,7 +20,7 @@ require_relative "init"
20
20
 
21
21
  class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
22
22
 
23
- provides :service, platform_family: "arch"
23
+ provides :service, platform_family: "arch", target_mode: true
24
24
 
25
25
  def self.supports?(resource, action)
26
26
  service_script_exist?(:etc_rcd, resource.service_name)
@@ -32,8 +32,8 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
32
32
  end
33
33
 
34
34
  def load_current_resource
35
- raise Chef::Exceptions::Service, "Could not find /etc/rc.conf" unless ::File.exist?("/etc/rc.conf")
36
- raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf" unless /DAEMONS=\((.*)\)/m.match?(::File.read("/etc/rc.conf"))
35
+ raise Chef::Exceptions::Service, "Could not find /etc/rc.conf" unless ::TargetIO::File.exist?("/etc/rc.conf")
36
+ raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf" unless /DAEMONS=\((.*)\)/m.match?(::TargetIO::File.read("/etc/rc.conf"))
37
37
 
38
38
  super
39
39
 
@@ -50,7 +50,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
50
50
  # )
51
51
  def daemons
52
52
  entries = []
53
- if ::File.read("/etc/rc.conf") =~ /DAEMONS=\((.*)\)/m
53
+ if ::TargetIO::File.read("/etc/rc.conf") =~ /DAEMONS=\((.*)\)/m
54
54
  entries += $1.gsub(/\\?[\r\n]/, " ").gsub(/# *[^ ]+/, " ").split(" ") if $1.length > 0
55
55
  end
56
56
 
@@ -61,8 +61,8 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
61
61
 
62
62
  # FIXME: Multiple entries of DAEMONS will cause very bad results :)
63
63
  def update_daemons(entries)
64
- content = ::File.read("/etc/rc.conf").gsub(/DAEMONS=\((.*)\)/m, "DAEMONS=(#{entries.join(" ")})")
65
- ::File.open("/etc/rc.conf", "w") do |f|
64
+ content = ::TargetIO::File.read("/etc/rc.conf").gsub(/DAEMONS=\((.*)\)/m, "DAEMONS=(#{entries.join(" ")})")
65
+ ::TargetIO::File.open("/etc/rc.conf", "w") do |f|
66
66
  f.write(content)
67
67
  end
68
68
  end
@@ -22,7 +22,7 @@ class Chef
22
22
  class Provider
23
23
  class Service
24
24
  class Debian < Chef::Provider::Service::Init
25
- provides :service, platform_family: "debian" do
25
+ provides :service, platform_family: "debian", target_mode: true do
26
26
  debianrcd?
27
27
  end
28
28
 
@@ -46,7 +46,7 @@ class Chef
46
46
  shared_resource_requirements
47
47
  requirements.assert(:all_actions) do |a|
48
48
  update_rcd = "/usr/sbin/update-rc.d"
49
- a.assertion { ::File.exist? update_rcd }
49
+ a.assertion { ::TargetIO::File.exist? update_rcd }
50
50
  a.failure_message Chef::Exceptions::Service, "#{update_rcd} does not exist!"
51
51
  # no whyrun recovery - this is a base system component of debian
52
52
  # distros and must be present
@@ -73,10 +73,10 @@ class Chef
73
73
 
74
74
  # returns a list of levels that the service should be stopped or started on
75
75
  def parse_init_file(path)
76
- return [] unless ::File.exist?(path)
76
+ return [] unless ::TargetIO::File.exist?(path)
77
77
 
78
78
  in_info = false
79
- ::File.readlines(path).each_with_object([]) do |line, acc|
79
+ ::TargetIO::File.readlines(path).each_with_object([]) do |line, acc|
80
80
  if /^### BEGIN INIT INFO/.match?(line)
81
81
  in_info = true
82
82
  elsif /^### END INIT INFO/.match?(line)
@@ -95,7 +95,7 @@ class Chef
95
95
 
96
96
  levels = parse_init_file(@init_command)
97
97
  levels.each do |level|
98
- rc_files.push Dir.glob("/etc/rc#{level}.d/[SK][0-9][0-9]#{current_resource.service_name}")
98
+ rc_files.push TargetIO::Dir.glob("/etc/rc#{level}.d/[SK][0-9][0-9]#{current_resource.service_name}")
99
99
  end
100
100
 
101
101
  rc_files.flatten.each do |line|
@@ -26,7 +26,7 @@ class Chef
26
26
 
27
27
  attr_reader :enabled_state_found
28
28
 
29
- provides :service, os: %w{freebsd netbsd}
29
+ provides :service, os: %w{freebsd netbsd}, target_mode: true
30
30
 
31
31
  include Chef::Mixin::ShellOut
32
32
 
@@ -34,9 +34,9 @@ class Chef
34
34
  super
35
35
  @enabled_state_found = false
36
36
  @init_command = nil
37
- if ::File.exist?("/etc/rc.d/#{new_resource.service_name}")
37
+ if ::TargetIO::File.exist?("/etc/rc.d/#{new_resource.service_name}")
38
38
  @init_command = "/etc/rc.d/#{new_resource.service_name}"
39
- elsif ::File.exist?("/usr/local/etc/rc.d/#{new_resource.service_name}")
39
+ elsif ::TargetIO::File.exist?("/usr/local/etc/rc.d/#{new_resource.service_name}")
40
40
  @init_command = "/usr/local/etc/rc.d/#{new_resource.service_name}"
41
41
  end
42
42
  end
@@ -118,11 +118,11 @@ class Chef
118
118
  private
119
119
 
120
120
  def read_rc_conf
121
- ::File.open("/etc/rc.conf", "r", &:readlines)
121
+ ::TargetIO::File.open("/etc/rc.conf", "r", &:readlines)
122
122
  end
123
123
 
124
124
  def write_rc_conf(lines)
125
- ::File.open("/etc/rc.conf", "w") do |file|
125
+ ::TargetIO::File.open("/etc/rc.conf", "w") do |file|
126
126
  lines.each { |line| file.puts(line) }
127
127
  end
128
128
  end
@@ -131,7 +131,7 @@ class Chef
131
131
  def service_enable_variable_name
132
132
  @service_enable_variable_name ||=
133
133
  if init_command
134
- ::File.open(init_command) do |rcscript|
134
+ ::TargetIO::File.open(init_command) do |rcscript|
135
135
  rcscript.each_line do |line|
136
136
  if line =~ /^name="?(\w+)"?/
137
137
  return $1 + "_enable"
@@ -150,7 +150,7 @@ class Chef
150
150
 
151
151
  def determine_enabled_status!
152
152
  var_name = service_enable_variable_name
153
- if ::File.exist?("/etc/rc.conf") && var_name
153
+ if ::TargetIO::File.exist?("/etc/rc.conf") && var_name
154
154
  read_rc_conf.each do |line|
155
155
  case line
156
156
  when /^#{Regexp.escape(var_name)}="(\w+)"/
@@ -22,7 +22,7 @@ require_relative "../../util/path_helper"
22
22
 
23
23
  class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
24
24
 
25
- provides :service, platform_family: "gentoo"
25
+ provides :service, platform_family: "gentoo", target_mode: true
26
26
 
27
27
  def load_current_resource
28
28
  supports[:status] = true if supports[:status].nil?
@@ -32,10 +32,10 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
32
32
  super
33
33
 
34
34
  @current_resource.enabled(
35
- Dir.glob("/etc/runlevels/**/#{Chef::Util::PathHelper.escape_glob_dir(@current_resource.service_name)}").any? do |file|
35
+ TargetIO::Dir.glob("/etc/runlevels/**/#{Chef::Util::PathHelper.escape_glob_dir(@current_resource.service_name)}").any? do |file|
36
36
  @found_script = true
37
- exists = ::File.exist? file
38
- readable = ::File.readable? file
37
+ exists = ::TargetIO::File.exist? file
38
+ readable = ::TargetIO::File.readable? file
39
39
  logger.trace "#{@new_resource} exists: #{exists}, readable: #{readable}"
40
40
  exists && readable
41
41
  end
@@ -47,7 +47,7 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
47
47
 
48
48
  def define_resource_requirements
49
49
  requirements.assert(:all_actions) do |a|
50
- a.assertion { ::File.exist?("/sbin/rc-update") }
50
+ a.assertion { ::TargetIO::File.exist?("/sbin/rc-update") }
51
51
  a.failure_message Chef::Exceptions::Service, "/sbin/rc-update does not exist"
52
52
  # no whyrun recovery -t his is a core component whose presence is
53
53
  # unlikely to be affected by what we do in the course of a chef run
@@ -26,7 +26,7 @@ class Chef
26
26
 
27
27
  attr_accessor :init_command
28
28
 
29
- provides :service, os: "!windows"
29
+ provides :service, os: "!windows", target_mode: true
30
30
 
31
31
  def self.supports?(resource, action)
32
32
  service_script_exist?(:initd, resource.service_name)
@@ -42,7 +42,7 @@ class Chef
42
42
  shared_resource_requirements
43
43
  requirements.assert(:start, :stop, :restart, :reload) do |a|
44
44
  a.assertion do
45
- custom_command_for_action?(action) || ::File.exist?(default_init_command)
45
+ custom_command_for_action?(action) || ::TargetIO::File.exist?(default_init_command)
46
46
  end
47
47
  a.failure_message(Chef::Exceptions::Service, "#{default_init_command} does not exist!")
48
48
  a.whyrun("Init script '#{default_init_command}' doesn't exist, assuming a prior action would have created it.") do
@@ -24,7 +24,7 @@ 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 amazon} do
27
+ provides :service, platform_family: %w{debian rhel fedora suse amazon}, target_mode: true do
28
28
  insserv?
29
29
  end
30
30
 
@@ -38,7 +38,7 @@ class Chef
38
38
  # Look for a /etc/rc.*/SnnSERVICE link to signify that the service would be started in a runlevel
39
39
  service_name = Chef::Util::PathHelper.escape_glob_dir(current_resource.service_name)
40
40
 
41
- if Dir.glob("/etc/rc*/**/S*#{service_name}").empty?
41
+ if TargetIO::Dir.glob("/etc/rc*/**/S*#{service_name}").empty?
42
42
  current_resource.enabled false
43
43
  else
44
44
  current_resource.enabled true
@@ -23,7 +23,7 @@ class Chef
23
23
  class Service
24
24
  class Invokercd < Chef::Provider::Service::Init
25
25
 
26
- provides :service, platform_family: "debian", override: true do
26
+ provides :service, platform_family: "debian", override: true, target_mode: true do
27
27
  invokercd?
28
28
  end
29
29
 
@@ -24,7 +24,7 @@ class Chef
24
24
  class Service
25
25
  class Openbsd < Chef::Provider::Service::Init
26
26
 
27
- provides :service, os: "openbsd"
27
+ provides :service, os: "openbsd", target_mode: true
28
28
 
29
29
  attr_reader :init_command, :rc_conf, :rc_conf_local, :enabled_state_found
30
30
 
@@ -33,9 +33,9 @@ class Chef
33
33
 
34
34
  def initialize(new_resource, run_context)
35
35
  super
36
- @rc_conf = ::File.read(RC_CONF_PATH) rescue ""
37
- @rc_conf_local = ::File.read(RC_CONF_LOCAL_PATH) rescue ""
38
- @init_command = ::File.exist?(rcd_script_path) ? rcd_script_path : nil
36
+ @rc_conf = ::TargetIO::File.read(RC_CONF_PATH) rescue ""
37
+ @rc_conf_local = ::TargetIO::File.read(RC_CONF_LOCAL_PATH) rescue ""
38
+ @init_command = ::TargetIO::File.exist?(rcd_script_path) ? rcd_script_path : nil
39
39
  new_resource.status_command("#{default_init_command} check")
40
40
  end
41
41
 
@@ -129,8 +129,8 @@ class Chef
129
129
  end
130
130
 
131
131
  def update_rcl(value)
132
- FileUtils.touch RC_CONF_LOCAL_PATH unless ::File.exist? RC_CONF_LOCAL_PATH
133
- ::File.write(RC_CONF_LOCAL_PATH, value)
132
+ TargetIO::FileUtils.touch RC_CONF_LOCAL_PATH unless ::TargetIO::File.exist? RC_CONF_LOCAL_PATH
133
+ ::TargetIO::File.write(RC_CONF_LOCAL_PATH, value)
134
134
  @rc_conf_local = value
135
135
  end
136
136
 
@@ -139,7 +139,7 @@ class Chef
139
139
  @bsevn ||= begin
140
140
  result = nil
141
141
  if rcd_script_found?
142
- ::File.open(init_command) do |rcscript|
142
+ ::TargetIO::File.open(init_command) do |rcscript|
143
143
  if m = rcscript.read.match(/^# \$OpenBSD: (\w+)[(.rc),]?/)
144
144
  result = m[1] + "_flags"
145
145
  end
@@ -28,7 +28,7 @@ class Chef
28
28
  # @api private
29
29
  attr_accessor :current_run_levels
30
30
 
31
- provides :service, platform_family: "rpm_based" do
31
+ provides :service, platform_family: "rpm_based", target_mode: true do
32
32
  redhatrcd?
33
33
  end
34
34
 
@@ -56,7 +56,7 @@ class Chef
56
56
 
57
57
  requirements.assert(:all_actions) do |a|
58
58
  chkconfig_file = "/sbin/chkconfig"
59
- a.assertion { ::File.exist? chkconfig_file }
59
+ a.assertion { ::TargetIO::File.exist? chkconfig_file }
60
60
  a.failure_message Chef::Exceptions::Service, "#{chkconfig_file} does not exist!"
61
61
  end
62
62
 
@@ -80,7 +80,7 @@ class Chef
80
80
 
81
81
  super
82
82
 
83
- if ::File.exist?("/sbin/chkconfig")
83
+ if ::TargetIO::File.exist?("/sbin/chkconfig")
84
84
  chkconfig = shell_out!("/sbin/chkconfig --list #{current_resource.service_name}", returns: [0, 1])
85
85
  unless run_levels.nil? || run_levels.empty?
86
86
  all_levels_match = true
@@ -25,7 +25,7 @@ class Chef
25
25
  class Solaris < Chef::Provider::Service
26
26
  attr_reader :maintenance
27
27
 
28
- provides :service, os: "solaris2"
28
+ provides :service, os: "solaris2", target_mode: true
29
29
 
30
30
  def initialize(new_resource, run_context = nil)
31
31
  super
@@ -39,7 +39,7 @@ class Chef
39
39
  @current_resource.service_name(@new_resource.service_name)
40
40
 
41
41
  [@init_command, @status_command].each do |cmd|
42
- unless ::File.executable? cmd
42
+ unless ::TargetIO::File.executable? cmd
43
43
  raise Chef::Exceptions::Service, "#{cmd} not executable!"
44
44
  end
45
45
  end
@@ -26,7 +26,7 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
26
26
 
27
27
  include Chef::Mixin::Which
28
28
 
29
- provides :service, os: "linux", target_mode: true do |node|
29
+ provides(:service, os: "linux", target_mode: true) do |node|
30
30
  systemd?
31
31
  end
32
32
 
@@ -106,7 +106,7 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
106
106
  if new_resource.user
107
107
  raise NotImplementedError, "#{new_resource} does not support the user property on a target_mode host (yet)" if Chef::Config.target_mode?
108
108
 
109
- uid = Etc.getpwnam(new_resource.user).uid
109
+ uid = TargetIO::Etc.getpwnam(new_resource.user).uid
110
110
  options = {
111
111
  environment: {
112
112
  "DBUS_SESSION_BUS_ADDRESS" => "unix:path=/run/user/#{uid}/bus",
@@ -124,9 +124,9 @@ class Chef
124
124
  end
125
125
  end
126
126
  # Get enabled/disabled state by reading job configuration file
127
- if ::File.exist?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
127
+ if ::TargetIO::File.exist?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
128
128
  logger.trace("#{@new_resource} found #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}")
129
- ::File.open("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}", "r") do |file|
129
+ ::TargetIO::File.open("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}", "r") do |file|
130
130
  while line = file.gets
131
131
  case line
132
132
  when /^start on/
@@ -74,7 +74,6 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
74
74
  current_resource.run_as_user(config_info.service_start_name) if config_info.service_start_name
75
75
  current_resource.display_name(config_info.display_name) if config_info.display_name
76
76
  current_resource.delayed_start(current_delayed_start) if current_delayed_start
77
- current_resource.description(config_info.description) if new_resource.description
78
77
  end
79
78
 
80
79
  current_resource
@@ -27,7 +27,7 @@ class Chef
27
27
  class Provider
28
28
  class Subversion < Chef::Provider
29
29
 
30
- provides :subversion
30
+ provides :subversion, target_mode: true
31
31
 
32
32
  SVN_INFO_PATTERN = /^([\w\s]+): (.+)$/.freeze
33
33
 
@@ -48,7 +48,7 @@ class Chef
48
48
  # Make sure the parent dir exists, or else fail.
49
49
  # for why run, print a message explaining the potential error.
50
50
  parent_directory = ::File.dirname(new_resource.destination)
51
- a.assertion { ::File.directory?(parent_directory) }
51
+ a.assertion { ::TargetIO::File.directory?(parent_directory) }
52
52
  a.failure_message(Chef::Exceptions::MissingParentDirectory,
53
53
  "Cannot clone #{new_resource} to #{new_resource.destination}, the enclosing directory #{parent_directory} does not exist")
54
54
  a.whyrun("Directory #{parent_directory} does not exist, assuming it would have been created")
@@ -81,7 +81,7 @@ class Chef
81
81
 
82
82
  action :sync, description: "Update the source to the specified version, or get a new clone or checkout. This action causes a hard reset of the index and working tree, discarding any uncommitted changes." do
83
83
  assert_target_directory_valid!
84
- if ::File.exist?(::File.join(new_resource.destination, ".svn"))
84
+ if ::TargetIO::File.exist?(::File.join(new_resource.destination, ".svn"))
85
85
  current_rev = find_current_revision
86
86
  logger.trace "#{new_resource} current revision: #{current_rev} target revision: #{revision_int}"
87
87
  unless current_revision_matches_target_revision?
@@ -134,7 +134,7 @@ class Chef
134
134
  alias :revision_slug :revision_int
135
135
 
136
136
  def find_current_revision
137
- return nil unless ::File.exist?(::File.join(new_resource.destination, ".svn"))
137
+ return nil unless ::TargetIO::File.exist?(::File.join(new_resource.destination, ".svn"))
138
138
 
139
139
  command = scm(:info)
140
140
  svn_info = shell_out!(command, **run_options(cwd: cwd, returns: [0, 1])).stdout
@@ -214,7 +214,7 @@ class Chef
214
214
  end
215
215
 
216
216
  def target_dir_non_existent_or_empty?
217
- !::File.exist?(new_resource.destination) || Dir.entries(new_resource.destination).sort == [".", ".."]
217
+ !::TargetIO::File.exist?(new_resource.destination) || TargetIO::Dir.entries(new_resource.destination).sort == [".", ".."]
218
218
  end
219
219
 
220
220
  def svn_binary
@@ -224,7 +224,7 @@ class Chef
224
224
 
225
225
  def assert_target_directory_valid!
226
226
  target_parent_directory = ::File.dirname(new_resource.destination)
227
- unless ::File.directory?(target_parent_directory)
227
+ unless ::TargetIO::File.directory?(target_parent_directory)
228
228
  msg = "Cannot clone #{new_resource} to #{new_resource.destination}, the enclosing directory #{target_parent_directory} does not exist"
229
229
  raise Chef::Exceptions::MissingParentDirectory, msg
230
230
  end
@@ -238,9 +238,9 @@ class Chef
238
238
  require "etc" unless defined?(Etc)
239
239
  case user
240
240
  when Integer
241
- Etc.getpwuid(user).dir
241
+ TargetIO::Etc.getpwuid(user).dir
242
242
  else
243
- Etc.getpwnam(user.to_s).dir
243
+ TargetIO::Etc.getpwnam(user.to_s).dir
244
244
  end
245
245
  end
246
246
  end