diff options
-rw-r--r-- | lib/chef/provider/service/solaris.rb | 5 | ||||
-rw-r--r-- | spec/unit/provider/service/solaris_smf_service_spec.rb | 11 |
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/chef/provider/service/solaris.rb b/lib/chef/provider/service/solaris.rb index 70b40f11ca..f2b1ec4262 100644 --- a/lib/chef/provider/service/solaris.rb +++ b/lib/chef/provider/service/solaris.rb @@ -54,6 +54,8 @@ class Chef end def enable_service + # Running service status to update maintenance status to invoke svcadm clear + service_status shell_out!(default_init_command, "clear", @new_resource.service_name) if @maintenance enable_flags = [ "-s", @new_resource.options ].flatten.compact shell_out!(default_init_command, "enable", *enable_flags, @new_resource.service_name) @@ -93,6 +95,9 @@ class Chef # dependency require_all/error svc:/milestone/multi-user:default (online) # $ + # Set the default value for maintenance + @maintenance = false + # load output into hash status = {} cmd.stdout.each_line do |line| diff --git a/spec/unit/provider/service/solaris_smf_service_spec.rb b/spec/unit/provider/service/solaris_smf_service_spec.rb index 584176b944..a5148c236a 100644 --- a/spec/unit/provider/service/solaris_smf_service_spec.rb +++ b/spec/unit/provider/service/solaris_smf_service_spec.rb @@ -118,6 +118,7 @@ describe Chef::Provider::Service::Solaris do it "should create a current resource with the name of the new resource" do expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) expect(Chef::Resource::Service).to receive(:new).and_return(@current_resource) + expect(@provider.maintenance).to be_falsey @provider.load_current_resource end @@ -162,7 +163,7 @@ describe Chef::Provider::Service::Solaris do end it "should call svcadm enable -s chef" do - expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) + expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name) expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", @current_resource.service_name).and_return(@success) @provider.load_current_resource @@ -172,7 +173,7 @@ describe Chef::Provider::Service::Solaris do end it "should call svcadm enable -s chef for start_service" do - expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) + expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name) expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", @current_resource.service_name).and_return(@success) @provider.load_current_resource @@ -182,7 +183,7 @@ describe Chef::Provider::Service::Solaris do it "should call svcadm clear chef for start_service when state maintenance" do # we are in maint mode - expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@maintenance_svc_status) + expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@maintenance_svc_status) expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name).and_return(@success) expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", @current_resource.service_name).and_return(@success) @@ -205,7 +206,7 @@ describe Chef::Provider::Service::Solaris do it "should call svcadm enable -s -r chef" do @new_resource.options("-r") - expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) + expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name) expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", "-r", @current_resource.service_name).and_return(@success) @provider.load_current_resource @@ -215,7 +216,7 @@ describe Chef::Provider::Service::Solaris do it "should call svcadm enable -s -r -t chef when passed an array of options" do @new_resource.options(["-r", "-t"]) - expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) + expect(@provider).to receive(:shell_out!).twice.with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name) expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", "-r", "-t", @current_resource.service_name).and_return(@success) @provider.load_current_resource |