chef 10.14.0.rc.1 → 10.14.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/distro/common/html/chef-client.8.html +4 -4
  2. data/distro/common/html/chef-expander.8.html +4 -4
  3. data/distro/common/html/chef-expanderctl.8.html +4 -4
  4. data/distro/common/html/chef-server-webui.8.html +4 -4
  5. data/distro/common/html/chef-server.8.html +4 -4
  6. data/distro/common/html/chef-solo.8.html +4 -4
  7. data/distro/common/html/chef-solr.8.html +4 -4
  8. data/distro/common/html/knife-bootstrap.1.html +5 -5
  9. data/distro/common/html/knife-client.1.html +5 -5
  10. data/distro/common/html/knife-configure.1.html +4 -4
  11. data/distro/common/html/knife-cookbook-site.1.html +7 -7
  12. data/distro/common/html/knife-cookbook.1.html +8 -8
  13. data/distro/common/html/knife-data-bag.1.html +4 -4
  14. data/distro/common/html/knife-environment.1.html +7 -7
  15. data/distro/common/html/knife-exec.1.html +5 -5
  16. data/distro/common/html/knife-index.1.html +5 -5
  17. data/distro/common/html/knife-node.1.html +5 -5
  18. data/distro/common/html/knife-role.1.html +7 -7
  19. data/distro/common/html/knife-search.1.html +4 -4
  20. data/distro/common/html/knife-ssh.1.html +4 -4
  21. data/distro/common/html/knife-status.1.html +5 -5
  22. data/distro/common/html/knife-tag.1.html +4 -4
  23. data/distro/common/html/knife.1.html +4 -4
  24. data/distro/common/html/shef.1.html +4 -4
  25. data/distro/common/man/man1/knife-bootstrap.1 +1 -1
  26. data/distro/common/man/man1/knife-client.1 +1 -1
  27. data/distro/common/man/man1/knife-configure.1 +1 -1
  28. data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
  29. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  30. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  31. data/distro/common/man/man1/knife-environment.1 +1 -1
  32. data/distro/common/man/man1/knife-exec.1 +1 -1
  33. data/distro/common/man/man1/knife-index.1 +1 -1
  34. data/distro/common/man/man1/knife-node.1 +1 -1
  35. data/distro/common/man/man1/knife-role.1 +1 -1
  36. data/distro/common/man/man1/knife-search.1 +1 -1
  37. data/distro/common/man/man1/knife-ssh.1 +1 -1
  38. data/distro/common/man/man1/knife-status.1 +1 -1
  39. data/distro/common/man/man1/knife-tag.1 +1 -1
  40. data/distro/common/man/man1/knife.1 +1 -1
  41. data/distro/common/man/man1/shef.1 +1 -1
  42. data/distro/common/man/man8/chef-client.8 +1 -1
  43. data/distro/common/man/man8/chef-expander.8 +1 -1
  44. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  45. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  46. data/distro/common/man/man8/chef-server.8 +1 -1
  47. data/distro/common/man/man8/chef-solo.8 +1 -1
  48. data/distro/common/man/man8/chef-solr.8 +1 -1
  49. data/lib/chef/application/client.rb +6 -0
  50. data/lib/chef/config.rb +5 -1
  51. data/lib/chef/knife/ssh.rb +2 -3
  52. data/lib/chef/provider/file.rb +55 -23
  53. data/lib/chef/provider/package.rb +0 -1
  54. data/lib/chef/provider/service/freebsd.rb +2 -2
  55. data/lib/chef/provider/service/redhat.rb +1 -1
  56. data/lib/chef/provider/service/upstart.rb +4 -4
  57. data/lib/chef/resource/file.rb +10 -0
  58. data/lib/chef/resource_reporter.rb +22 -13
  59. data/lib/chef/version.rb +1 -1
  60. data/spec/unit/provider/file_spec.rb +129 -3
  61. data/spec/unit/provider/remote_file_spec.rb +7 -0
  62. data/spec/unit/provider/service/freebsd_service_spec.rb +38 -10
  63. data/spec/unit/provider/service/redhat_spec.rb +47 -46
  64. metadata +4 -4
@@ -191,7 +191,7 @@ class Chef
191
191
  exit_status = 0
192
192
  subsession ||= session
193
193
  command = fixup_sudo(command)
194
- command.force_encoding('binary')
194
+ command.force_encoding('binary') if command.respond_to?(:force_encoding)
195
195
  subsession.open_channel do |ch|
196
196
  ch.request_pty
197
197
  ch.exec command do |ch, success|
@@ -382,7 +382,7 @@ class Chef
382
382
  end
383
383
 
384
384
  def configure_identity_file
385
- config[:identity_file] = get_stripped_unfrozen_value(config[:identity_file] ||
385
+ config[:identity_file] = get_stripped_unfrozen_value(config[:identity_file] ||
386
386
  Chef::Config[:knife][:ssh_identity_file])
387
387
  end
388
388
 
@@ -423,4 +423,3 @@ class Chef
423
423
  end
424
424
  end
425
425
  end
426
-
@@ -46,43 +46,75 @@ class Chef
46
46
 
47
47
  private :negative_complement, :octal_mode
48
48
 
49
- def diff_current_from_content source_content
49
+ def diff_current_from_content(new_content)
50
50
  result = nil
51
51
  Tempfile.open("chef-diff") do |file|
52
- file.write source_content
52
+ file.write new_content
53
53
  file.close
54
54
  result = diff_current file.path
55
55
  end
56
56
  result
57
57
  end
58
58
 
59
- def diff_current source_path
59
+ def is_binary?(path)
60
+ ::File.open(path) do |file|
61
+ buff = file.read(Chef::Config[:diff_filesize_threshold])
62
+ buff = "" if buff.nil?
63
+ return buff !~ /^[\r[:print:]]*$/
64
+ end
65
+ end
66
+
67
+ def diff_current(temp_path)
68
+ suppress_resource_reporting = false
69
+
70
+ return [ "(diff output suppressed by config)" ] if Chef::Config[:diff_disabled]
71
+ return [ "(no temp file with new content, diff output suppressed)" ] unless ::File.exists?(temp_path) # should never happen?
72
+
73
+ # solaris does not support diff -N, so create tempfile to diff against if we are creating a new file
74
+ target_path = if ::File.exists?(@current_resource.path)
75
+ @current_resource.path
76
+ else
77
+ suppress_resource_reporting = true # suppress big diffs going to resource reporting service
78
+ tempfile = Tempfile.new('chef-tempfile')
79
+ tempfile.path
80
+ end
81
+
82
+ diff_filesize_threshold = Chef::Config[:diff_filesize_threshold]
83
+ diff_output_threshold = Chef::Config[:diff_output_threshold]
84
+
85
+ if ::File.size(target_path) > diff_filesize_threshold || ::File.size(temp_path) > diff_filesize_threshold
86
+ return [ "(file sizes exceed #{diff_filesize_threshold} bytes, diff output suppressed)" ]
87
+ end
88
+
89
+ # MacOSX(BSD?) diff will *sometimes* happily spit out nasty binary diffs
90
+ return [ "(current file is binary, diff output suppressed)"] if is_binary?(target_path)
91
+ return [ "(new content is binary, diff output suppressed)"] if is_binary?(temp_path)
92
+
60
93
  begin
61
- # Solaris diff doesn't support -N (treat missing files as empty)
62
- # For compatibility we'll create a temp file if the file does not exist
63
- # and substitute it
64
- unless ::File.exists?(source_path)
65
- altfile = Tempfile.new('chef-tempfile')
66
- source_path = altfile.path
67
- end
68
94
  # -u: Unified diff format
69
- result = shell_out("diff -u #{@current_resource.path} #{source_path}" )
70
- # diff will set a non-zero return code even when there's
71
- # valid stdout results, if it encounters something unexpected
72
- # So as long as we have output, we'll show it.
73
- if not result.stdout.empty?
95
+ result = shell_out("diff -u #{target_path} #{temp_path}" )
96
+ rescue Exception => e
97
+ # Should *not* receive this, but in some circumstances it seems that
98
+ # an exception can be thrown even using shell_out instead of shell_out!
99
+ return [ "Could not determine diff. Error: #{e.message}" ]
100
+ end
101
+
102
+ # diff will set a non-zero return code even when there's
103
+ # valid stdout results, if it encounters something unexpected
104
+ # So as long as we have output, we'll show it.
105
+ if not result.stdout.empty?
106
+ if result.stdout.length > diff_output_threshold
107
+ [ "(long diff of over #{diff_output_threshold} characters, diff output suppressed)" ]
108
+ else
74
109
  val = result.stdout.split("\n")
75
110
  val.delete("\")
111
+ @new_resource.diff(val.join("\\n")) unless suppress_resource_reporting
76
112
  val
77
- elsif not result.stderr.empty?
78
- "Could not determine diff. Error: #{result.stderr}"
79
- else
80
- "(no diff)"
81
113
  end
82
- rescue Exception => e
83
- # Should *not* receive this, but in some circumstances it seems that
84
- # an exception can be thrown even using shell_out instead of shell_out!
85
- "Could not determine diff. Error: #{e.message}"
114
+ elsif not result.stderr.empty?
115
+ [ "Could not determine diff. Error: #{result.stderr}" ]
116
+ else
117
+ [ "(no diff)" ]
86
118
  end
87
119
  end
88
120
 
@@ -38,7 +38,6 @@ class Chef
38
38
  end
39
39
 
40
40
  def load_current_resource
41
-
42
41
  end
43
42
 
44
43
  def define_resource_requirements
@@ -70,7 +70,7 @@ class Chef
70
70
  def define_resource_requirements
71
71
  super
72
72
 
73
- requirements.assert(:all_actions) do |a|
73
+ requirements.assert(:start, :enable, :reload, :restart) do |a|
74
74
  a.assertion { @rcd_script_found }
75
75
  a.failure_message Chef::Exceptions::Service, "#{@new_resource}: unable to locate the rc.d script"
76
76
  end
@@ -82,7 +82,7 @@ class Chef
82
82
  a.whyrun "Unable to determine enabled/disabled state, assuming this will be correct for an actual run. Assuming disabled."
83
83
  end
84
84
 
85
- requirements.assert(:all_actions) do |a|
85
+ requirements.assert(:start, :enable, :reload, :restart) do |a|
86
86
  a.assertion { @rcd_script_found && service_enable_variable_name != nil }
87
87
  a.failure_message Chef::Exceptions::Service, "Could not find the service name in #{@init_command} and rcvar"
88
88
  # No recovery in whyrun mode - the init file is present but not correct.
@@ -45,7 +45,7 @@ class Chef
45
45
  a.failure_message Chef::Exceptions::Service, "#{chkconfig_file} does not exist!"
46
46
  end
47
47
 
48
- requirements.assert(:all_actions) do |a|
48
+ requirements.assert(:start, :enable, :reload, :restart) do |a|
49
49
  a.assertion { !@service_missing }
50
50
  a.failure_message Chef::Exceptions::Service, "#{@new_resource}: unable to locate the init.d script!"
51
51
  a.whyrun "Assuming service would be disabled. The init script is not presently installed."
@@ -65,10 +65,10 @@ class Chef
65
65
  @upstart_command_success = true
66
66
  end
67
67
 
68
- def define_resource_requirements
69
- super
70
-
71
- requirements.assert(:all_actions) do |a|
68
+ def define_resource_requirements
69
+ # Do not call super, only call shared requirements
70
+ shared_resource_requirements
71
+ requirements.assert(:all_actions) do |a|
72
72
  if !@command_success
73
73
  whyrun_msg = @new_resource.status_command ? "Provided status command #{@new_resource.status_command} failed." :
74
74
  "Could not determine upstart state for service"
@@ -46,6 +46,7 @@ class Chef
46
46
  @action = "create"
47
47
  @allowed_actions.push(:create, :delete, :touch, :create_if_missing)
48
48
  @provider = Chef::Provider::File
49
+ @diff = nil
49
50
  end
50
51
 
51
52
 
@@ -80,6 +81,15 @@ class Chef
80
81
  :kind_of => String
81
82
  )
82
83
  end
84
+
85
+ def diff(arg=nil)
86
+ set_or_return(
87
+ :diff,
88
+ arg,
89
+ :kind_of => String
90
+ )
91
+ end
92
+
83
93
 
84
94
  end
85
95
  end
@@ -56,8 +56,8 @@ class Chef
56
56
  as_hash["after"] = new_resource.state
57
57
  as_hash["before"] = current_resource ? current_resource.state : {}
58
58
  as_hash["duration"] = (elapsed_time * 1000).to_i.to_s
59
- # TODO: include diffs, etc. here:
60
- as_hash["delta"] = ""
59
+ as_hash["delta"] = new_resource.diff if new_resource.respond_to?("diff")
60
+ as_hash["delta"] = "" if as_hash["delta"].nil?
61
61
  # TODO: rename as "action"
62
62
  as_hash["result"] = action.to_s
63
63
  if success?
@@ -86,7 +86,11 @@ class Chef
86
86
  attr_reader :error_descriptions
87
87
 
88
88
  def initialize(rest_client)
89
- @reporting_enabled = true
89
+ if Chef::Config[:disable_reporting]
90
+ @reporting_enabled = false
91
+ else
92
+ @reporting_enabled = true
93
+ end
90
94
  @updated_resources = []
91
95
  @total_res_count = 0
92
96
  @pending_update = nil
@@ -100,15 +104,20 @@ class Chef
100
104
 
101
105
  def node_load_completed(node, expanded_run_list_with_versions, config)
102
106
  @node = node
103
- resource_history_url = "nodes/#{@node.name}/runs"
104
- server_response = @rest_client.post_rest(resource_history_url, {:action => :begin})
105
- run_uri = URI.parse(server_response["uri"])
106
- @run_id = ::File.basename(run_uri.path)
107
- Chef::Log.info("Chef server generated run history id: #{@run_id}")
108
- rescue Net::HTTPServerException => e
109
- raise unless e.response.code.to_s == "404"
110
- Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported.")
111
- @reporting_enabled = false
107
+
108
+ if reporting_enabled?
109
+ begin
110
+ resource_history_url = "reports/nodes/#{@node.name}/runs"
111
+ server_response = @rest_client.post_rest(resource_history_url, {:action => :begin})
112
+ run_uri = URI.parse(server_response["uri"])
113
+ @run_id = ::File.basename(run_uri.path)
114
+ Chef::Log.info("Chef server generated run history id: #{@run_id}")
115
+ rescue Net::HTTPServerException => e
116
+ raise unless e.response.code.to_s == "404"
117
+ Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported.")
118
+ @reporting_enabled = false
119
+ end
120
+ end
112
121
  end
113
122
 
114
123
  def resource_current_state_loaded(new_resource, action, current_resource)
@@ -151,7 +160,7 @@ class Chef
151
160
 
152
161
  def run_completed(node)
153
162
  if reporting_enabled?
154
- resource_history_url = "nodes/#{@node.name}/runs/#{run_id}"
163
+ resource_history_url = "reports/nodes/#{@node.name}/runs/#{run_id}"
155
164
  run_data = report(node)
156
165
  run_data["action"] = "end"
157
166
  Chef::Log.info("Sending resource update report (run-id: #{run_id})")
@@ -17,7 +17,7 @@
17
17
 
18
18
  class Chef
19
19
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '10.14.0.rc.1'
20
+ VERSION = '10.14.0.rc.2'
21
21
  end
22
22
 
23
23
  # NOTE: the Chef::Version class is defined in version_class.rb
@@ -276,7 +276,132 @@ describe Chef::Provider::File do
276
276
  end
277
277
 
278
278
  describe "when a diff is requested" do
279
-
279
+
280
+ before(:each) do
281
+ @original_config = Chef::Config.hash_dup
282
+ end
283
+
284
+ after(:each) do
285
+ Chef::Config.configuration = @original_config if @original_config
286
+ end
287
+
288
+ describe "when identifying files as binary or text" do
289
+
290
+ it "should identify zero-length files as text" do
291
+ Tempfile.open("some-temp") do |file|
292
+ @resource.path(file.path)
293
+ @provider = Chef::Provider::File.new(@resource, @run_context)
294
+ @provider.is_binary?(file.path).should be_false
295
+ end
296
+ end
297
+
298
+ it "should correctly identify text files as being text" do
299
+ Tempfile.open("some-temp") do |file|
300
+ @resource.path(file.path)
301
+ file.puts("This is a text file.")
302
+ file.puts("That has a couple of lines in it.")
303
+ file.puts("And lets make sure that other printable chars work too: ~!@\#$%^&*()`:\"<>?{}|_+,./;'[]\\-=")
304
+ file.close
305
+ @provider = Chef::Provider::File.new(@resource, @run_context)
306
+ @provider.is_binary?(file.path).should be_false
307
+ end
308
+ end
309
+
310
+ it "should identify a null-terminated string as binary" do
311
+ Tempfile.open("some-temp") do |file|
312
+ @resource.path(file.path)
313
+ file.write("This is a binary file.\0")
314
+ file.close
315
+ @provider = Chef::Provider::File.new(@resource, @run_context)
316
+ @provider.is_binary?(file.path).should be_true
317
+ end
318
+ end
319
+
320
+ end
321
+
322
+ it "should not return diff output when chef config has disabled it" do
323
+ Chef::Config[:diff_disabled] = true
324
+ Tempfile.open("some-temp") do |file|
325
+ @resource.path(file.path)
326
+ @provider = Chef::Provider::File.new(@resource, @run_context)
327
+ @provider.load_current_resource
328
+ result = @provider.diff_current_from_content "foo baz"
329
+ result.should == [ "(diff output suppressed by config)" ]
330
+ @resource.diff.should be_nil
331
+ end
332
+ end
333
+
334
+ it "should not return diff output when there is no new file to compare it to" do
335
+ Tempfile.open("some-temp") do |file|
336
+ Tempfile.open("other-temp") do |missing_file|
337
+ missing_path = missing_file.path
338
+ missing_file.close
339
+ missing_file.unlink
340
+ @resource.path(file.path)
341
+ @provider = Chef::Provider::File.new(@resource, @run_context)
342
+ @provider.load_current_resource
343
+ result = @provider.diff_current missing_path
344
+ result.should == [ "(no temp file with new content, diff output suppressed)" ]
345
+ @resource.diff.should be_nil
346
+ end
347
+ end
348
+ end
349
+
350
+ it "should produce diff output when the file does not exist yet, but suppress reporting it" do
351
+ Tempfile.open("some-temp") do |file|
352
+ @resource.path(file.path)
353
+ file.close
354
+ file.unlink
355
+ @provider = Chef::Provider::File.new(@resource, @run_context)
356
+ @provider.load_current_resource
357
+ result = @provider.diff_current_from_content "foo baz"
358
+ result.length.should == 4
359
+ @resource.diff.should be_nil
360
+ end
361
+ end
362
+
363
+ it "should not produce a diff when the current resource file is above the filesize threshold" do
364
+ Chef::Config[:diff_filesize_threshold] = 5
365
+ Tempfile.open("some-temp") do |file|
366
+ @resource.path(file.path)
367
+ file.puts("this is a line which is longer than 5 characters")
368
+ file.flush
369
+ @provider = Chef::Provider::File.new(@resource, @run_context)
370
+ @provider.load_current_resource
371
+ result = @provider.diff_current_from_content "foo" # not longer than 5
372
+ result.should == [ "(file sizes exceed 5 bytes, diff output suppressed)" ]
373
+ @resource.diff.should be_nil
374
+ end
375
+ end
376
+
377
+ it "should not produce a diff when the new content is above the filesize threshold" do
378
+ Chef::Config[:diff_filesize_threshold] = 5
379
+ Tempfile.open("some-temp") do |file|
380
+ @resource.path(file.path)
381
+ file.puts("foo")
382
+ file.flush
383
+ @provider = Chef::Provider::File.new(@resource, @run_context)
384
+ @provider.load_current_resource
385
+ result = @provider.diff_current_from_content "this is a line that is longer than 5 characters"
386
+ result.should == [ "(file sizes exceed 5 bytes, diff output suppressed)" ]
387
+ @resource.diff.should be_nil
388
+ end
389
+ end
390
+
391
+ it "should not produce a diff when the generated diff size is above the diff size threshold" do
392
+ Chef::Config[:diff_output_threshold] = 5
393
+ Tempfile.open("some-temp") do |file|
394
+ @resource.path(file.path)
395
+ file.puts("some text to increase the size of the diff")
396
+ file.flush
397
+ @provider = Chef::Provider::File.new(@resource, @run_context)
398
+ @provider.load_current_resource
399
+ result = @provider.diff_current_from_content "this is a line that is longer than 5 characters"
400
+ result.should == [ "(long diff of over 5 characters, diff output suppressed)" ]
401
+ @resource.diff.should be_nil
402
+ end
403
+ end
404
+
280
405
  it "should return valid diff output when content does not match the string content provided" do
281
406
  Tempfile.open("some-temp") do |file|
282
407
  @resource.path file.path
@@ -285,12 +410,13 @@ describe Chef::Provider::File do
285
410
  result = @provider.diff_current_from_content "foo baz"
286
411
  # remove the file name info which varies.
287
412
  result.shift(2)
288
- # Result appearance seems to vary slightly under solaris diff
413
+ # Result appearance seems to vary slightly under solaris diff
289
414
  # So we'll compare the second line which is common to both.
290
415
  # Solaris: -1,1 +1,0 @@, "+foo baz"
291
- # Linux/Mac: -1,0, +1 @@, "+foo baz"
416
+ # Linux/Mac: -1,0, +1 @@, "+foo baz"
292
417
  result.length.should == 2
293
418
  result[1].should == "+foo baz"
419
+ @resource.diff.should_not be_nil
294
420
  end
295
421
  end
296
422
  end
@@ -218,6 +218,13 @@ describe Chef::Provider::RemoteFile, "action_create" do
218
218
  describe "when the target file already exists" do
219
219
  before do
220
220
  ::File.stub!(:exists?).with(@resource.path).and_return(true)
221
+ @provider.stub!(:diff_current).and_return([
222
+ "--- /tmp/foo 2012-08-30 21:28:17.632782551 +0000",
223
+ "+++ /tmp/bar 2012-08-30 21:28:20.816975437 +0000",
224
+ "@@ -1 +1 @@",
225
+ "-foo bar",
226
+ "+bar foo"
227
+ ])
221
228
  @provider.stub!(:get_from_server).and_return(@tempfile)
222
229
  end
223
230
 
@@ -32,6 +32,8 @@ describe Chef::Provider::Service::Freebsd do
32
32
  @current_resource = Chef::Resource::Service.new("apache22")
33
33
 
34
34
  @provider = Chef::Provider::Service::Freebsd.new(@new_resource,@run_context)
35
+ @provider.action = :start
36
+ @init_command = "/usr/local/etc/rc.d/apache22"
35
37
  Chef::Resource::Service.stub!(:new).and_return(@current_resource)
36
38
  end
37
39
 
@@ -131,12 +133,24 @@ RC_SAMPLE
131
133
  @provider.load_current_resource
132
134
  end
133
135
 
134
- it "should raise an exception when init script is not found" do
135
- ::File.stub!(:exists?).and_return(false)
136
- @provider.load_current_resource
137
- @provider.define_resource_requirements
138
- @provider.instance_variable_get("@rcd_script_found").should be_false
139
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
136
+ context "and the init script is not found" do
137
+ [ "start", "reload", "restart", "enable" ].each do |action|
138
+ it "should raise an exception when the action is #{action}" do
139
+ ::File.stub!(:exists?).and_return(false)
140
+ @provider.load_current_resource
141
+ @provider.define_resource_requirements
142
+ @provider.instance_variable_get("@rcd_script_found").should be_false
143
+ @provider.action = action
144
+ lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
145
+ end
146
+ end
147
+
148
+ [ "stop", "disable" ].each do |action|
149
+ it "should not raise an error when the action is #{action}" do
150
+ @provider.action = action
151
+ lambda { @provider.process_resource_requirements }.should_not raise_error
152
+ end
153
+ end
140
154
  end
141
155
 
142
156
  it "update state when current resource enabled state could not be determined" do
@@ -146,6 +160,7 @@ RC_SAMPLE
146
160
  end
147
161
 
148
162
  it "update state when current resource enabled state could be determined" do
163
+ ::File.stub!(:exist?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true)
149
164
  ::File.should_receive(:exists?).with("/etc/rc.conf").and_return true
150
165
  @provider.load_current_resource
151
166
  @provider.instance_variable_get("@enabled_state_found").should be_false
@@ -293,10 +308,23 @@ RCVAR_SAMPLE
293
308
  @provider.stub!(:shell_out!).with("/usr/local/etc/rc.d/#{@current_resource.service_name} rcvar").and_return(@status)
294
309
  end
295
310
 
296
- it "should raise an exception if rcvar does not return foobar_enable" do
297
- @provider.load_current_resource
298
- @provider.define_resource_requirements
299
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
311
+ [ "start", "reload", "restart", "enable" ].each do |action|
312
+ it "should raise an exception when the action is #{action}" do
313
+ @provider.action = action
314
+ @provider.load_current_resource
315
+ @provider.define_resource_requirements
316
+ lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
317
+ end
318
+ end
319
+
320
+ [ "stop", "disable" ].each do |action|
321
+ it "should not raise an error when the action is #{action}" do
322
+ ::File.stub!(:exist?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true)
323
+ @provider.action = action
324
+ @provider.load_current_resource
325
+ @provider.define_resource_requirements
326
+ lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Service)
327
+ end
300
328
  end
301
329
  end
302
330
  end