diff options
-rw-r--r-- | lib/chef/provider/service/solaris.rb | 18 | ||||
-rw-r--r-- | spec/unit/provider/service/solaris_smf_service_spec.rb | 45 |
2 files changed, 46 insertions, 17 deletions
diff --git a/lib/chef/provider/service/solaris.rb b/lib/chef/provider/service/solaris.rb index 4bdb6fbfd1..7f06ac561b 100644 --- a/lib/chef/provider/service/solaris.rb +++ b/lib/chef/provider/service/solaris.rb @@ -25,11 +25,13 @@ class Chef class Service class Solaris < Chef::Provider::Service include Chef::Mixin::ShellOut + attr_reader :maintenance def initialize(new_resource, run_context=nil) super @init_command = "/usr/sbin/svcadm" @status_command = "/bin/svcs -l" + @maintenace = false end @@ -44,6 +46,7 @@ class Chef end def enable_service + shell_out!("#{default_init_command} clear #{@new_resource.service_name}") if @maintenance shell_out!("#{default_init_command} enable -s #{@new_resource.service_name}") end @@ -65,13 +68,14 @@ class Chef end def service_status - status = popen4("#{@status_command} #{@current_resource.service_name}") do |pid, stdin, stdout, stderr| - stdout.each do |line| - case line - when /state\s+online/ - @current_resource.enabled(true) - @current_resource.running(true) - end + status = shell_out!("#{@status_command} #{@current_resource.service_name}") + status.stdout.each_line do |line| + case line + when /state\s+online/ + @current_resource.enabled(true) + @current_resource.running(true) + when /state\s+maintenance/ + @maintenance = true end end unless @current_resource.enabled diff --git a/spec/unit/provider/service/solaris_smf_service_spec.rb b/spec/unit/provider/service/solaris_smf_service_spec.rb index 887c1f6b5f..af1351a4ff 100644 --- a/spec/unit/provider/service/solaris_smf_service_spec.rb +++ b/spec/unit/provider/service/solaris_smf_service_spec.rb @@ -54,34 +54,47 @@ 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(:popen4).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(:popen4).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 popen4 '/bin/svcs -l service_name'" do - @provider.should_receive(:popen4).with("/bin/svcs -l chef").and_return(@status) + it "should call '/bin/svcs -l service_name'" do + @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(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).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 - @stdout.stub(:each).and_yield("state online") - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @status = mock("Status", :exitstatus => 0, :stdout => 'state online') + @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.load_current_resource + @provider.maintenance.should be_false + end + + it "should mark service as maintenance" do + @status = mock("Status", :exitstatus => 0, :stdout => 'state maintenance') + @provider.stub!(:shell_out!).and_return(@status) + @provider.load_current_resource + @provider.maintenance.should be_true + end end describe "when enabling the service" do @@ -91,19 +104,31 @@ describe Chef::Provider::Service::Solaris do end it "should call svcadm enable -s chef" do - @new_resource.stub(:enable_command).and_return("#{@new_resource.enable_command}") + @new_resource.stub!(:enable_command).and_return("#{@new_resource.enable_command}") + @provider.should_not_receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}") @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status) - @provider.enable_service.should be_true + @provider.enable_service.should be_true @current_resource.enabled.should be_true end it "should call svcadm enable -s chef for start_service" do - @new_resource.stub(:start_command).and_return("#{@new_resource.start_command}") + @new_resource.stub!(:start_command).and_return("#{@new_resource.start_command}") + @provider.should_not_receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}") @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status) @provider.start_service.should be_true @current_resource.enabled.should be_true end + it "should call svcadm clear chef for start_service when state maintenance" do + @status = mock("Status", :exitstatus => 0, :stdout => 'state maintenance') + @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) + @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status) + @provider.enable_service.should be_true + @current_resource.enabled.should be_true + end end |