chef 11.14.0.alpha.2-x86-mingw32 → 11.14.0.alpha.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/bin/chef-service-manager +1 -1
  3. data/lib/chef/application.rb +8 -2
  4. data/lib/chef/chef_fs/command_line.rb +4 -4
  5. data/lib/chef/chef_fs/file_system.rb +3 -3
  6. data/lib/chef/chef_fs/parallelizer.rb +66 -90
  7. data/lib/chef/chef_fs/parallelizer/flatten_enumerable.rb +35 -0
  8. data/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb +279 -0
  9. data/lib/chef/config.rb +36 -2
  10. data/lib/chef/cookbook/cookbook_version_loader.rb +0 -1
  11. data/lib/chef/cookbook/synchronizer.rb +64 -42
  12. data/lib/chef/cookbook_uploader.rb +4 -25
  13. data/lib/chef/cookbook_version.rb +12 -11
  14. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +18 -1
  15. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -3
  16. data/lib/chef/knife/bootstrap.rb +23 -1
  17. data/lib/chef/knife/bootstrap/chef-aix.erb +58 -0
  18. data/lib/chef/knife/bootstrap/chef-full.erb +16 -13
  19. data/lib/chef/knife/core/bootstrap_context.rb +25 -1
  20. data/lib/chef/knife/list.rb +9 -8
  21. data/lib/chef/knife/serve.rb +44 -0
  22. data/lib/chef/knife/show.rb +2 -3
  23. data/lib/chef/knife/ssh.rb +1 -0
  24. data/lib/chef/mixin/create_path.rb +20 -4
  25. data/lib/chef/node.rb +19 -3
  26. data/lib/chef/platform/provider_mapping.rb +0 -1
  27. data/lib/chef/platform/query_helpers.rb +4 -3
  28. data/lib/chef/provider/env/windows.rb +10 -3
  29. data/lib/chef/provider/file.rb +1 -1
  30. data/lib/chef/provider/mount.rb +84 -42
  31. data/lib/chef/provider/package/freebsd/base.rb +92 -0
  32. data/lib/chef/provider/package/freebsd/pkg.rb +113 -0
  33. data/lib/chef/provider/package/freebsd/pkgng.rb +80 -0
  34. data/lib/chef/provider/package/freebsd/port.rb +70 -0
  35. data/lib/chef/providers.rb +3 -1
  36. data/lib/chef/resource/chef_gem.rb +2 -1
  37. data/lib/chef/resource/freebsd_package.rb +39 -3
  38. data/lib/chef/resource/lwrp_base.rb +2 -2
  39. data/lib/chef/resource/mount.rb +9 -9
  40. data/lib/chef/util/threaded_job_queue.rb +61 -0
  41. data/lib/chef/version.rb +1 -1
  42. data/lib/chef/version/platform.rb +2 -0
  43. data/lib/chef/whitelist.rb +82 -0
  44. data/lib/chef/win32/registry.rb +0 -1
  45. data/lib/chef/win32/version.rb +4 -3
  46. data/spec/functional/win32/versions_spec.rb +4 -4
  47. data/spec/integration/client/ipv6_spec.rb +1 -1
  48. data/spec/integration/knife/chef_fs_data_store_spec.rb +1 -1
  49. data/spec/integration/knife/chef_repo_path_spec.rb +4 -1
  50. data/spec/integration/knife/common_options_spec.rb +9 -9
  51. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +2 -2
  52. data/spec/integration/knife/deps_spec.rb +3 -0
  53. data/spec/integration/knife/list_spec.rb +3 -0
  54. data/spec/integration/knife/raw_spec.rb +5 -2
  55. data/spec/integration/knife/redirection_spec.rb +4 -1
  56. data/spec/integration/knife/serve_spec.rb +57 -0
  57. data/spec/integration/knife/show_spec.rb +3 -0
  58. data/spec/support/pedant/run_pedant.rb +1 -0
  59. data/spec/support/platform_helpers.rb +7 -5
  60. data/spec/support/shared/context/config.rb +21 -0
  61. data/spec/support/shared/functional/file_resource.rb +52 -0
  62. data/spec/unit/chef_fs/parallelizer.rb +482 -0
  63. data/spec/unit/client_spec.rb +4 -2
  64. data/spec/unit/config_spec.rb +66 -12
  65. data/spec/unit/knife/bootstrap_spec.rb +6 -0
  66. data/spec/unit/knife/core/bootstrap_context_spec.rb +31 -1
  67. data/spec/unit/node_spec.rb +73 -3
  68. data/spec/unit/provider/mount_spec.rb +102 -79
  69. data/spec/unit/provider/package/{freebsd_spec.rb → freebsd/pkg_spec.rb} +19 -32
  70. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +155 -0
  71. data/spec/unit/provider/package/freebsd/port_spec.rb +160 -0
  72. data/spec/unit/resource/chef_gem_spec.rb +5 -0
  73. data/spec/unit/resource/freebsd_package_spec.rb +63 -11
  74. data/spec/unit/resource/mount_spec.rb +11 -0
  75. data/spec/unit/role_spec.rb +5 -1
  76. data/spec/unit/run_lock_spec.rb +2 -0
  77. data/spec/unit/util/threaded_job_queue_spec.rb +51 -0
  78. data/spec/unit/version/platform_spec.rb +1 -1
  79. metadata +176 -161
  80. data/lib/chef/provider/package/freebsd.rb +0 -149
@@ -19,20 +19,23 @@ exists() {
19
19
  fi
20
20
  }
21
21
 
22
- install_sh="https://www.opscode.com/chef/install.sh"
23
- version_string="-v <%= chef_version %>"
24
-
25
- if ! exists /usr/bin/chef-client; then
26
- echo "Installing Chef Client..."
27
- if exists wget; then
28
- bash <(wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %> ${install_sh} -O -) ${version_string}
29
- elif exists curl; then
30
- bash <(curl -L <%= "--proxy \"#{knife_config[:bootstrap_proxy]}\" " if knife_config[:bootstrap_proxy] %> ${install_sh}) ${version_string}
31
- else
32
- echo "Neither wget nor curl found. Please install one and try again." >&2
33
- exit 1
22
+ <% if knife_config[:bootstrap_install_command] %>
23
+ <%= knife_config[:bootstrap_install_command] %>
24
+ <% else %>
25
+ install_sh="<%= knife_config[:bootstrap_url] ? knife_config[:bootstrap_url] : "https://www.opscode.com/chef/install.sh" %>"
26
+ version_string="-v <%= chef_version %>"
27
+ if ! exists /usr/bin/chef-client; then
28
+ echo "Installing Chef Client..."
29
+ if exists wget; then
30
+ bash <(wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %> <%= knife_config[:bootstrap_wget_options] %> ${install_sh} -O -) <%= latest_current_chef_version_string %>
31
+ elif exists curl; then
32
+ bash <(curl -L <%= "--proxy \"#{knife_config[:bootstrap_proxy]}\" " if knife_config[:bootstrap_proxy] %> <%= knife_config[:bootstrap_curl_options] %> ${install_sh}) <%= latest_current_chef_version_string %>
33
+ else
34
+ echo "Neither wget nor curl found. Please install one and try again." >&2
35
+ exit 1
36
+ fi
34
37
  fi
35
- fi
38
+ <% end %>
36
39
 
37
40
  mkdir -p /etc/chef
38
41
 
@@ -101,10 +101,35 @@ CONFIG
101
101
  @chef_config.key?(:knife) ? @chef_config[:knife] : {}
102
102
  end
103
103
 
104
+ #
105
+ # This function is used by older bootstrap templates other than chef-full
106
+ # and potentially by custom templates as well hence it's logic needs to be
107
+ # preserved for backwards compatibility reasons until we hit Chef 12.
104
108
  def chef_version
105
109
  knife_config[:bootstrap_version] || Chef::VERSION
106
110
  end
107
111
 
112
+ #
113
+ # chef version string to fetch the latest current version from omnitruck
114
+ # If user is on X.Y.Z bootstrap will use the latest X release
115
+ # X here can be 10 or 11
116
+ def latest_current_chef_version_string
117
+ chef_version_string = if knife_config[:bootstrap_version]
118
+ knife_config[:bootstrap_version]
119
+ else
120
+ Chef::VERSION.split(".").first
121
+ end
122
+
123
+ installer_version_string = ["-v", chef_version_string]
124
+
125
+ # If bootstrapping a pre-release version add -p to the installer string
126
+ if chef_version_string.split(".").length > 3
127
+ installer_version_string << "-p"
128
+ end
129
+
130
+ installer_version_string.join(" ")
131
+ end
132
+
108
133
  def first_boot
109
134
  (@config[:first_boot_attributes] || {}).merge(:run_list => @run_list)
110
135
  end
@@ -113,4 +138,3 @@ CONFIG
113
138
  end
114
139
  end
115
140
  end
116
-
@@ -43,21 +43,23 @@ class Chef
43
43
  def run
44
44
  patterns = name_args.length == 0 ? [""] : name_args
45
45
 
46
- # Get the matches (recursively)
47
- all_results = parallelize(pattern_args_from(patterns), :flatten => true) do |pattern|
48
- pattern_results = Chef::ChefFS::FileSystem.list(config[:local] ? local_fs : chef_fs, pattern)
46
+ # Get the top-level matches
47
+ args = pattern_args_from(patterns)
48
+ all_results = parallelize(pattern_args_from(patterns)) do |pattern|
49
+ pattern_results = Chef::ChefFS::FileSystem.list(config[:local] ? local_fs : chef_fs, pattern).to_a
49
50
  if pattern_results.first && !pattern_results.first.exists? && pattern.exact_path
50
51
  ui.error "#{format_path(pattern_results.first)}: No such file or directory"
51
52
  self.exit_code = 1
52
53
  end
53
54
  pattern_results
54
- end
55
+ end.flatten(1).to_a
55
56
 
56
57
  # Process directories
57
58
  if !config[:bare_directories]
58
- dir_results = parallelize(all_results.select { |result| result.dir? }, :flatten => true) do |result|
59
+ dir_results = parallelize(all_results.select { |result| result.dir? }) do |result|
59
60
  add_dir_result(result)
60
- end.to_a
61
+ end.flatten(1)
62
+
61
63
  else
62
64
  dir_results = []
63
65
  end
@@ -109,7 +111,7 @@ class Chef
109
111
  result = [ [ result, children ] ]
110
112
  if config[:recursive]
111
113
  child_dirs = children.select { |child| child.dir? }
112
- result += parallelize(child_dirs, :flatten => true) { |child| add_dir_result(child) }.to_a
114
+ result += parallelize(child_dirs) { |child| add_dir_result(child) }.flatten(1).to_a
113
115
  end
114
116
  result
115
117
  end
@@ -152,4 +154,3 @@ class Chef
152
154
  end
153
155
  end
154
156
  end
155
-
@@ -0,0 +1,44 @@
1
+ require 'chef/knife'
2
+
3
+ class Chef
4
+ class Knife
5
+ class Serve < Knife
6
+ option :repo_mode,
7
+ :long => '--repo-mode MODE',
8
+ :description => "Specifies the local repository layout. Values: static (only environments/roles/data_bags/cookbooks), everything (includes nodes/clients/users), hosted_everything (includes acls/groups/etc. for Enterprise/Hosted Chef). Default: everything/hosted_everything"
9
+
10
+ option :chef_repo_path,
11
+ :long => '--chef-repo-path PATH',
12
+ :description => 'Overrides the location of chef repo. Default is specified by chef_repo_path in the config'
13
+
14
+ option :chef_zero_host,
15
+ :long => '--chef-zero-host IP',
16
+ :description => 'Overrides the host upon which chef-zero listens. Default is 127.0.0.1.'
17
+
18
+ def configure_chef
19
+ super
20
+ Chef::Config.local_mode = true
21
+ Chef::Config[:repo_mode] = config[:repo_mode] if config[:repo_mode]
22
+
23
+ # --chef-repo-path forcibly overrides all other paths
24
+ if config[:chef_repo_path]
25
+ Chef::Config.chef_repo_path = config[:chef_repo_path]
26
+ %w(acl client cookbook container data_bag environment group node role user).each do |variable_name|
27
+ Chef::Config.delete("#{variable_name}_path".to_sym)
28
+ end
29
+ end
30
+ end
31
+
32
+ def run
33
+ begin
34
+ server = Chef::Application.chef_zero_server
35
+ output "Serving files from:\n#{server.options[:data_store].chef_fs.fs_description}"
36
+ server.stop
37
+ server.start(stdout) # to print header
38
+ ensure
39
+ server.stop
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -20,7 +20,7 @@ class Chef
20
20
  def run
21
21
  # Get the matches (recursively)
22
22
  error = false
23
- entry_values = parallelize(pattern_args, :flatten => true) do |pattern|
23
+ entry_values = parallelize(pattern_args) do |pattern|
24
24
  parallelize(Chef::ChefFS::FileSystem.list(config[:local] ? local_fs : chef_fs, pattern)) do |entry|
25
25
  if entry.dir?
26
26
  ui.error "#{format_path(entry)}: is a directory" if pattern.exact_path
@@ -40,7 +40,7 @@ class Chef
40
40
  end
41
41
  end
42
42
  end
43
- end
43
+ end.flatten(1)
44
44
  entry_values.each do |entry, value|
45
45
  if entry
46
46
  output "#{format_path(entry)}:"
@@ -54,4 +54,3 @@ class Chef
54
54
  end
55
55
  end
56
56
  end
57
-
@@ -30,6 +30,7 @@ class Chef
30
30
  require 'chef/exceptions'
31
31
  require 'chef/search/query'
32
32
  require 'chef/mixin/shell_out'
33
+ require 'chef/mixin/command'
33
34
  require 'mixlib/shellout'
34
35
  end
35
36
 
@@ -44,14 +44,30 @@ class Chef
44
44
 
45
45
  file_path.each_index do |i|
46
46
  create_path = File.join(file_path[0, i + 1])
47
- unless File.directory?(create_path)
48
- Chef::Log.debug("Creating directory #{create_path}")
49
- Dir.mkdir(create_path)
50
- end
47
+ create_dir(create_path) unless File.directory?(create_path)
51
48
  end
49
+
52
50
  File.expand_path(File.join(file_path))
53
51
  end
54
52
 
53
+ private
54
+
55
+ def create_dir(path)
56
+ begin
57
+ # When doing multithreaded downloads into the file cache, the following
58
+ # interleaving raises an error here:
59
+ #
60
+ # thread1 thread2
61
+ # File.directory?(create_path) <- false
62
+ # File.directory?(create_path) <- false
63
+ # Dir.mkdir(create_path)
64
+ # Dir.mkdir(create_path) <- raises Errno::EEXIST
65
+ Chef::Log.debug("Creating directory #{path}")
66
+ Dir.mkdir(path)
67
+ rescue Errno::EEXIST
68
+ end
69
+ end
70
+
55
71
  end
56
72
  end
57
73
  end
data/lib/chef/node.rb CHANGED
@@ -34,6 +34,7 @@ require 'chef/node/attribute'
34
34
  require 'chef/mash'
35
35
  require 'chef/json_compat'
36
36
  require 'chef/search/query'
37
+ require 'chef/whitelist'
37
38
 
38
39
  class Chef
39
40
  class Node
@@ -520,18 +521,18 @@ class Chef
520
521
  if Chef::Config[:why_run]
521
522
  Chef::Log.warn("In whyrun mode, so NOT performing node save.")
522
523
  else
523
- chef_server_rest.put_rest("nodes/#{name}", self)
524
+ chef_server_rest.put_rest("nodes/#{name}", data_for_save)
524
525
  end
525
526
  rescue Net::HTTPServerException => e
526
527
  raise e unless e.response.code == "404"
527
- chef_server_rest.post_rest("nodes", self)
528
+ chef_server_rest.post_rest("nodes", data_for_save)
528
529
  end
529
530
  self
530
531
  end
531
532
 
532
533
  # Create the node via the REST API
533
534
  def create
534
- chef_server_rest.post_rest("nodes", self)
535
+ chef_server_rest.post_rest("nodes", data_for_save)
535
536
  self
536
537
  end
537
538
 
@@ -543,5 +544,20 @@ class Chef
543
544
  self.name <=> other_node.name
544
545
  end
545
546
 
547
+ private
548
+
549
+ def data_for_save
550
+ data = for_json
551
+ ["automatic", "default", "normal", "override"].each do |level|
552
+ whitelist_config_option = "#{level}_attribute_whitelist".to_sym
553
+ whitelist = Chef::Config[whitelist_config_option]
554
+ unless whitelist.nil? # nil => save everything
555
+ Chef::Log.info("Whitelisting #{level} node attributes for save.")
556
+ data[level] = Chef::Whitelist.filter(data[level], whitelist)
557
+ end
558
+ end
559
+ data
560
+ end
561
+
546
562
  end
547
563
  end
@@ -57,7 +57,6 @@ class Chef
57
57
  :freebsd => {
58
58
  :default => {
59
59
  :group => Chef::Provider::Group::Pw,
60
- :package => Chef::Provider::Package::Freebsd,
61
60
  :service => Chef::Provider::Service::Freebsd,
62
61
  :user => Chef::Provider::User::Pw,
63
62
  :cron => Chef::Provider::Cron
@@ -30,15 +30,16 @@ class Chef
30
30
 
31
31
  def windows_server_2003?
32
32
  return false unless windows?
33
- require 'ruby-wmi'
33
+ require 'wmi-lite/wmi'
34
34
 
35
35
  # CHEF-4888: Work around ruby #2618, expected to be fixed in Ruby 2.1.0
36
36
  # https://github.com/ruby/ruby/commit/588504b20f5cc880ad51827b93e571e32446e5db
37
37
  # https://github.com/ruby/ruby/commit/27ed294c7134c0de582007af3c915a635a6506cd
38
38
  WIN32OLE.ole_initialize
39
39
 
40
- host = WMI::Win32_OperatingSystem.find(:first)
41
- is_server_2003 = (host.version && host.version.start_with?("5.2"))
40
+ wmi = WmiLite::Wmi.new
41
+ host = wmi.first_of('Win32_OperatingSystem')
42
+ is_server_2003 = (host['version'] && host['version'].start_with?("5.2"))
42
43
 
43
44
  WIN32OLE.ole_uninitialize
44
45
 
@@ -17,7 +17,6 @@
17
17
  #
18
18
 
19
19
  if RUBY_PLATFORM =~ /mswin|mingw32|windows/
20
- require 'ruby-wmi'
21
20
  require 'Win32API'
22
21
  end
23
22
 
@@ -51,9 +50,17 @@ class Chef
51
50
  return obj ? obj.variablevalue : nil
52
51
  end
53
52
 
53
+ def find_env(environment_variables, key_name)
54
+ environment_variables.find do | environment_variable |
55
+ environment_variable['name'].downcase == key_name
56
+ end
57
+ end
58
+
54
59
  def env_obj(key_name)
55
- WMI::Win32_Environment.find(:first,
56
- :conditions => { :name => key_name })
60
+ wmi = WmiLite::Wmi.new
61
+ environment_variables = wmi.instances_of('Win32_Environment')
62
+ existing_variable = find_env(environment_variables, key_name)
63
+ existing_variable.nil? ? nil : existing_variable.wmi_ole_object
57
64
  end
58
65
 
59
66
  #see: http://msdn.microsoft.com/en-us/library/ms682653%28VS.85%29.aspx
@@ -296,7 +296,7 @@ class Chef
296
296
  def do_unlink
297
297
  @file_unlinked = false
298
298
  if @new_resource.force_unlink
299
- if !real_file?(@new_resource.path)
299
+ if l_exist?(@new_resource.path) && !real_file?(@new_resource.path)
300
300
  # unlink things that aren't normal files
301
301
  description = "unlink #{file_type_string(@new_resource.path)} at #{@new_resource.path}"
302
302
  converge_by(description) do
@@ -1,6 +1,7 @@
1
1
  #
2
- # Author:: Joshua Timberman (<joshua@opscode.com>)
3
- # Copyright:: Copyright (c) 2009 Opscode, Inc
2
+ # Author:: Joshua Timberman (<joshua@getchef.com>)
3
+ # Author:: Lamont Granquist (<lamont@getchef.com>)
4
+ # Copyright:: Copyright (c) 2009-2014 Chef Software, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,6 +27,7 @@ class Chef
26
27
 
27
28
  include Chef::Mixin::Command
28
29
 
30
+ attr_accessor :unmount_retries
29
31
 
30
32
  def whyrun_supported?
31
33
  true
@@ -35,94 +37,134 @@ class Chef
35
37
  true
36
38
  end
37
39
 
40
+ def initialize(new_resource, run_context)
41
+ super
42
+ self.unmount_retries = 20
43
+ end
44
+
38
45
  def action_mount
39
- unless @current_resource.mounted
40
- converge_by("mount #{@current_resource.device} to #{@current_resource.mount_point}") do
41
- status = mount_fs()
42
- if status
43
- Chef::Log.info("#{@new_resource} mounted")
44
- end
46
+ unless current_resource.mounted
47
+ converge_by("mount #{current_resource.device} to #{current_resource.mount_point}") do
48
+ mount_fs
49
+ Chef::Log.info("#{new_resource} mounted")
45
50
  end
46
51
  else
47
- Chef::Log.debug("#{@new_resource} is already mounted")
52
+ Chef::Log.debug("#{new_resource} is already mounted")
48
53
  end
49
54
  end
50
55
 
51
56
  def action_umount
52
- if @current_resource.mounted
53
- converge_by("unmount #{@current_resource.device}") do
54
- status = umount_fs()
55
- if status
56
- Chef::Log.info("#{@new_resource} unmounted")
57
- end
57
+ if current_resource.mounted
58
+ converge_by("unmount #{current_resource.device}") do
59
+ umount_fs
60
+ Chef::Log.info("#{new_resource} unmounted")
58
61
  end
59
62
  else
60
- Chef::Log.debug("#{@new_resource} is already unmounted")
63
+ Chef::Log.debug("#{new_resource} is already unmounted")
61
64
  end
62
65
  end
63
66
 
64
67
  def action_remount
65
- unless @new_resource.supports[:remount]
66
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remount"
67
- else
68
- if @current_resource.mounted
69
- converge_by("remount #{@current_resource.device}") do
70
- status = remount_fs()
71
- if status
72
- Chef::Log.info("#{@new_resource} remounted")
73
- end
68
+ if current_resource.mounted
69
+ if new_resource.supports[:remount]
70
+ converge_by("remount #{current_resource.device}") do
71
+ remount_fs
72
+ Chef::Log.info("#{new_resource} remounted")
74
73
  end
75
74
  else
76
- Chef::Log.debug("#{@new_resource} not mounted, nothing to remount")
75
+ converge_by("unmount #{current_resource.device}") do
76
+ umount_fs
77
+ Chef::Log.info("#{new_resource} unmounted")
78
+ end
79
+ wait_until_unmounted(unmount_retries)
80
+ converge_by("mount #{current_resource.device}") do
81
+ mount_fs
82
+ Chef::Log.info("#{new_resource} mounted")
83
+ end
77
84
  end
85
+ else
86
+ Chef::Log.debug("#{new_resource} not mounted, nothing to remount")
78
87
  end
79
88
  end
80
89
 
81
90
  def action_enable
82
- unless @current_resource.enabled && mount_options_unchanged?
83
- converge_by("remount #{@current_resource.device}") do
84
- status = enable_fs
85
- if status
86
- Chef::Log.info("#{@new_resource} enabled")
87
- else
88
- Chef::Log.debug("#{@new_resource} already enabled")
89
- end
91
+ unless current_resource.enabled && mount_options_unchanged?
92
+ converge_by("enable #{current_resource.device}") do
93
+ enable_fs
94
+ Chef::Log.info("#{new_resource} enabled")
90
95
  end
96
+ else
97
+ Chef::Log.debug("#{new_resource} already enabled")
91
98
  end
92
99
  end
93
100
 
94
101
  def action_disable
95
- if @current_resource.enabled
96
- converge_by("remount #{@current_resource.device}") do
97
- status = disable_fs
98
- if status
99
- Chef::Log.info("#{@new_resource} disabled")
100
- else
101
- Chef::Log.debug("#{@new_resource} already disabled")
102
- end
102
+ if current_resource.enabled
103
+ converge_by("disable #{current_resource.device}") do
104
+ disable_fs
105
+ Chef::Log.info("#{new_resource} disabled")
103
106
  end
107
+ else
108
+ Chef::Log.debug("#{new_resource} already disabled")
104
109
  end
105
110
  end
106
111
 
112
+ #
113
+ # Abstract Methods to be implemented by subclasses
114
+ #
115
+
116
+ # should actually check if the filesystem is mounted (not just return current_resource) and return true/false
117
+ def mounted?
118
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not implement #mounted?"
119
+ end
120
+
121
+ # should check new_resource against current_resource to see if mount options need updating, returns true/false
122
+ def mount_options_unchanged?
123
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not implement #mount_options_unchanged?"
124
+ end
125
+
126
+ #
127
+ # NOTE: for the following methods, this superclass will already have checked if the filesystem is
128
+ # enabled and/or mounted and they will be called in converge_by blocks, so most defensive checking
129
+ # does not need to be done in the subclass implementation -- just do the thing.
130
+ #
131
+
132
+ # should implement mounting of the filesystem, raises if action does not succeed
107
133
  def mount_fs
108
134
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :mount"
109
135
  end
110
136
 
137
+ # should implement unmounting of the filesystem, raises if action does not succeed
111
138
  def umount_fs
112
139
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :umount"
113
140
  end
114
141
 
142
+ # should implement remounting of the filesystem (via a -o remount or some other atomic-ish action that isn't
143
+ # simply a umount/mount style remount), raises if action does not succeed
115
144
  def remount_fs
116
145
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remount"
117
146
  end
118
147
 
148
+ # should implement enabling of the filesystem (e.g. in /etc/fstab), raises if action does not succeed
119
149
  def enable_fs
120
150
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
121
151
  end
122
152
 
153
+ # should implement disabling of the filesystem (e.g. in /etc/fstab), raises if action does not succeed
123
154
  def disable_fs
124
155
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
125
156
  end
157
+
158
+ private
159
+
160
+ def wait_until_unmounted(tries)
161
+ while mounted?
162
+ if (tries -= 1) < 0
163
+ raise Chef::Exceptions::Mount, "Retries exceeded waiting for filesystem to unmount"
164
+ end
165
+ sleep 0.1
166
+ end
167
+ end
126
168
  end
127
169
  end
128
170
  end