summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-03-21 08:30:43 +0000
committerGitHub <noreply@github.com>2017-03-21 08:30:43 +0000
commit9ecff295ce191c3648a19402ac5412c77689cb59 (patch)
tree51cd14f8cb31656537ecf9de79dcba7216e3f386
parentc9aceb575404fbdde99ec3bec969e1ee97bca68b (diff)
parent8b7485575ac607bbf518f08832f4746d2a33af30 (diff)
downloadchef-9ecff295ce191c3648a19402ac5412c77689cb59.tar.gz
Merge pull request #5551 from MarkGibbons/smf_recursive_dependencies
smf_recursive_dependencies: Allow solaris services to start recursively.
-rw-r--r--lib/chef/provider/service/solaris.rb6
-rw-r--r--lib/chef/resource/service.rb10
-rw-r--r--spec/unit/provider/service/solaris_smf_service_spec.rb38
-rw-r--r--spec/unit/resource/service_spec.rb22
4 files changed, 72 insertions, 4 deletions
diff --git a/lib/chef/provider/service/solaris.rb b/lib/chef/provider/service/solaris.rb
index f7f8eaf31b..c560bed011 100644
--- a/lib/chef/provider/service/solaris.rb
+++ b/lib/chef/provider/service/solaris.rb
@@ -56,11 +56,13 @@ class Chef
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)
+ enable_flags = [ "-s", @new_resource.options ].flatten.compact
+ shell_out!(default_init_command, "enable", *enable_flags, @new_resource.service_name)
end
def disable_service
- shell_out!(default_init_command, "disable", "-s", @new_resource.service_name)
+ disable_flags = [ "-s", @new_resource.options ].flatten.compact
+ shell_out!(default_init_command, "disable", *disable_flags, @new_resource.service_name)
end
alias_method :stop_service, :disable_service
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index d9f0969ecb..0231964fdf 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -18,6 +18,7 @@
#
require "chef/resource"
+require "shellwords"
class Chef
class Resource
@@ -40,6 +41,7 @@ class Chef
@enabled = nil
@running = nil
@masked = nil
+ @options = nil
@parameters = nil
@pattern = service_name
@start_command = nil
@@ -155,6 +157,14 @@ class Chef
)
end
+ def options(arg = nil)
+ set_or_return(
+ :options,
+ arg.respond_to?(:split) ? arg.shellsplit : arg,
+ :kind_of => [ Array, String ]
+ )
+ end
+
# Priority arguments can have two forms:
#
# - a simple number, in which the default start runlevels get
diff --git a/spec/unit/provider/service/solaris_smf_service_spec.rb b/spec/unit/provider/service/solaris_smf_service_spec.rb
index c6835bed64..584176b944 100644
--- a/spec/unit/provider/service/solaris_smf_service_spec.rb
+++ b/spec/unit/provider/service/solaris_smf_service_spec.rb
@@ -198,6 +198,33 @@ describe Chef::Provider::Service::Solaris do
end
end
+ describe "when enabling the service recursively" do
+ before(:each) do
+ @provider.current_resource = @current_resource
+ end
+
+ 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).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
+ expect(@provider.enable_service).to be_truthy
+ expect(@current_resource.enabled).to be_truthy
+ end
+
+ 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).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
+ expect(@provider.enable_service).to be_truthy
+ expect(@current_resource.enabled).to be_truthy
+ end
+
+ end
+
describe "when disabling the service" do
before(:each) do
@provider.current_resource = @current_resource
@@ -215,7 +242,16 @@ describe Chef::Provider::Service::Solaris do
expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@disabled_svc_status)
expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "disable", "-s", "chef").and_return(@success)
@provider.load_current_resource
- expect(@provider.stop_service).to be_truthy
+ expect(@provider.disable_service).to be_truthy
+ expect(@current_resource.enabled).to be_falsey
+ end
+
+ it "should call svcadm disable chef with options" do
+ @new_resource.options("-t")
+ expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@disabled_svc_status)
+ expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "disable", "-s", "-t", "chef").and_return(@success)
+ @provider.load_current_resource
+ expect(@provider.disable_service).to be_truthy
expect(@current_resource.enabled).to be_falsey
end
diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb
index 205282b99f..67a4635983 100644
--- a/spec/unit/resource/service_spec.rb
+++ b/spec/unit/resource/service_spec.rb
@@ -124,6 +124,27 @@ describe Chef::Resource::Service do
end.to raise_error(ArgumentError)
end
+ it "should accept an array for options" do
+ @resource.options ["-r", "-s"]
+ expect(@resource.options).to eql(["-r", "-s"])
+ end
+
+ it "should accept a string for options" do
+ @resource.options "-r"
+ expect(@resource.options).to eql(["-r"])
+ end
+
+ it "should accept a string with multiple flags for options" do
+ @resource.options "-r -s"
+ expect(@resource.options).to eql(["-r", "-s"])
+ end
+
+ it "should not accept a boolean for options" do
+ expect do
+ @resource.options true
+ end.to raise_error(ArgumentError)
+ end
+
%w{enabled running}.each do |attrib|
it "should accept true for #{attrib}" do
@resource.send(attrib, true)
@@ -175,5 +196,4 @@ describe Chef::Resource::Service do
expect(@resource.identity).to eq("superfriend")
end
end
-
end