diff options
author | markgibbons <mark.gibbons@nordstrom.com> | 2014-06-07 19:56:35 -0700 |
---|---|---|
committer | markgibbons <mark.gibbons@nordstrom.com> | 2014-06-07 19:56:35 -0700 |
commit | 97088f458afffcc73d49c53c594f08bf969084aa (patch) | |
tree | 501365792e233f96253873e601e3831e70762720 | |
parent | 7588211ecb83c9592065359622ff6cef98d773af (diff) | |
download | chef-97088f458afffcc73d49c53c594f08bf969084aa.tar.gz |
CHEF-5347: Allow for undefined solaris services in the service resource.
-rw-r--r-- | lib/chef/provider/service/solaris.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/service/solaris_smf_service_spec.rb | 41 |
2 files changed, 32 insertions, 11 deletions
diff --git a/lib/chef/provider/service/solaris.rb b/lib/chef/provider/service/solaris.rb index 05a91eb756..6672b0f084 100644 --- a/lib/chef/provider/service/solaris.rb +++ b/lib/chef/provider/service/solaris.rb @@ -69,7 +69,7 @@ class Chef end def service_status - status = shell_out!("#{@status_command} #{@current_resource.service_name}") + status = shell_out("#{@status_command} #{@current_resource.service_name}") status.stdout.each_line do |line| case line when /state\s+online/ diff --git a/spec/unit/provider/service/solaris_smf_service_spec.rb b/spec/unit/provider/service/solaris_smf_service_spec.rb index 8e66289a80..0f68535b1a 100644 --- a/spec/unit/provider/service/solaris_smf_service_spec.rb +++ b/spec/unit/provider/service/solaris_smf_service_spec.rb @@ -38,7 +38,7 @@ describe Chef::Provider::Service::Solaris do @stdout_string = "state disabled" @stdout.stub(:gets).and_return(@stdout_string) @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:shell_out).and_return(@status) end it "should raise an error if /bin/svcs does not exist" do @@ -54,44 +54,44 @@ describe Chef::Provider::Service::Solaris do describe "when discovering the current service state" do it "should create a current resource with the name of the new resource" do - @provider.stub(:shell_out!).with("/bin/svcs -l chef").and_return(@status) + @provider.stub(:shell_out).with("/bin/svcs -l chef").and_return(@status) Chef::Resource::Service.should_receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should return the current resource" do - @provider.stub(:shell_out!).with("/bin/svcs -l chef").and_return(@status) + @provider.stub(:shell_out).with("/bin/svcs -l chef").and_return(@status) @provider.load_current_resource.should eql(@current_resource) end it "should call '/bin/svcs -l service_name'" do - @provider.should_receive(:shell_out!).with("/bin/svcs -l chef").and_return(@status) + @provider.should_receive(:shell_out).with("/bin/svcs -l chef").and_return(@status) @provider.load_current_resource end it "should mark service as not running" do - @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:shell_out).and_return(@status) @current_resource.should_receive(:running).with(false) @provider.load_current_resource end it "should mark service as running" do @status = double("Status", :exitstatus => 0, :stdout => 'state online') - @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:shell_out).and_return(@status) @current_resource.should_receive(:running).with(true) @provider.load_current_resource end it "should not mark service as maintenance" do - @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:shell_out).and_return(@status) @provider.load_current_resource @provider.maintenance.should be_false end it "should mark service as maintenance" do @status = double("Status", :exitstatus => 0, :stdout => 'state maintenance') - @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:shell_out).and_return(@status) @provider.load_current_resource @provider.maintenance.should be_true end @@ -121,7 +121,7 @@ describe Chef::Provider::Service::Solaris do it "should call svcadm clear chef for start_service when state maintenance" do @status = double("Status", :exitstatus => 0, :stdout => 'state maintenance') - @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:shell_out).and_return(@status) @provider.load_current_resource @new_resource.stub(:enable_command).and_return("#{@new_resource.enable_command}") @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}").and_return(@status) @@ -145,7 +145,7 @@ describe Chef::Provider::Service::Solaris do end it "should call svcadm disable -s chef for stop_service" do - @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm disable -s chef") + @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm disable -s chef").and_return(@status) @provider.stop_service.should be_true @current_resource.enabled.should be_false end @@ -164,5 +164,26 @@ describe Chef::Provider::Service::Solaris do end end + + describe "when the service doesn't exist" do + before(:each) do + @stdout_string = "" + @status = double("Status", :exitstatus => 1, :stdout => @stdout) + @provider.current_resource = @current_resource + end + + it "should be marked not running" do + @provider.should_receive(:shell_out).with("/bin/svcs -l chef").and_return(@status) + @provider.service_status + @current_resource.running.should be_false + end + + it "should be marked not enabled" do + @provider.should_receive(:shell_out).with("/bin/svcs -l chef").and_return(@status) + @provider.service_status + @current_resource.enabled.should be_false + end + + end end end |