summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarkgibbons <mark.gibbons@nordstrom.com>2017-02-06 15:05:46 -0800
committermarkgibbons <mark.gibbons@nordstrom.com>2017-02-17 11:42:33 -0800
commit2c63d86ffc1f1334216d401af364d5acffdf2c09 (patch)
tree4e48490b5b2404185a0810bf4fcd7a09594aeb3c
parent87e4d14ccb06053cf2837f5df1f629ae37f6e956 (diff)
downloadchef-2c63d86ffc1f1334216d401af364d5acffdf2c09.tar.gz
smf_recursive_dependencies: Separate the svcadm options passed to shell_out.
Signed-off-by: markgibbons <mark.gibbons@nordstrom.com>
-rw-r--r--lib/chef/provider/service/solaris.rb8
-rw-r--r--lib/chef/resource/service.rb18
-rw-r--r--spec/unit/provider/service/solaris_smf_service_spec.rb6
-rw-r--r--spec/unit/resource/service_spec.rb22
4 files changed, 29 insertions, 25 deletions
diff --git a/lib/chef/provider/service/solaris.rb b/lib/chef/provider/service/solaris.rb
index 207be43868..1cb6348a9d 100644
--- a/lib/chef/provider/service/solaris.rb
+++ b/lib/chef/provider/service/solaris.rb
@@ -56,13 +56,13 @@ class Chef
def enable_service
shell_out!(default_init_command, "clear", @new_resource.service_name) if @maintenance
- enable_flags = [ "-s", @new_resource.options ].compact.join(" ")
- shell_out!(default_init_command, "enable", enable_flags, @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
- disable_flags = [ "-s", @new_resource.options ].compact.join(" ")
- shell_out!(default_init_command, "disable", disable_flags, @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 460af74acd..5282b892c0 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -36,6 +36,7 @@ class Chef
@enabled = nil
@running = nil
@masked = nil
+ @options = nil
@parameters = nil
@pattern = service_name
@start_command = nil
@@ -49,7 +50,6 @@ class Chef
@run_levels = nil
@user = nil
@supports = { :restart => nil, :reload => nil, :status => nil }
- @recursive = nil
end
def service_name(arg = nil)
@@ -153,6 +153,14 @@ class Chef
)
end
+ def options(arg = nil)
+ set_or_return(
+ :options,
+ arg.respond_to?(:split) ? arg.split(/\s+/) : arg,
+ :kind_of => [ Array, String ]
+ )
+ end
+
# Priority arguments can have two forms:
#
# - a simple number, in which the default start runlevels get
@@ -213,14 +221,6 @@ class Chef
end
end
- def options(arg = nil)
- set_or_return(
- :options,
- arg,
- :kind_of => [ Array, String ]
- )
- end
-
end
end
end
diff --git a/spec/unit/provider/service/solaris_smf_service_spec.rb b/spec/unit/provider/service/solaris_smf_service_spec.rb
index aefdfb6e32..584176b944 100644
--- a/spec/unit/provider/service/solaris_smf_service_spec.rb
+++ b/spec/unit/provider/service/solaris_smf_service_spec.rb
@@ -207,7 +207,7 @@ describe Chef::Provider::Service::Solaris 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)
+ 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
@@ -217,7 +217,7 @@ describe Chef::Provider::Service::Solaris 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)
+ 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
@@ -249,7 +249,7 @@ describe Chef::Provider::Service::Solaris do
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)
+ 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
diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb
index 4114a8ec3e..cd49f276bf 100644
--- a/spec/unit/resource/service_spec.rb
+++ b/spec/unit/resource/service_spec.rb
@@ -124,19 +124,24 @@ describe Chef::Resource::Service do
end.to raise_error(ArgumentError)
end
- it "should accept true for recursive" do
- @resource.recursive true
- expect(@resource.send("recursive")).to eql(true)
+ it "should accept an array for options" do
+ @resource.options ["-r", "-s"]
+ expect(@resource.options).to eql(["-r", "-s"])
end
- it "should accept false for recursive" do
- @resource.recursive false
- expect(@resource.send("recursive")).to eql(false)
+ it "should accept a string for options" do
+ @resource.options "-r"
+ expect(@resource.options).to eql(["-r"])
end
- it "should not accept a string for recursive" do
+ 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.recursive "poop"
+ @resource.options true
end.to raise_error(ArgumentError)
end
@@ -191,5 +196,4 @@ describe Chef::Resource::Service do
expect(@resource.identity).to eq("superfriend")
end
end
-
end