summaryrefslogtreecommitdiff
path: root/chef
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2014-07-01 12:41:02 -0700
committerPhil Dibowitz <phil@ipom.com>2014-07-01 15:47:29 -0700
commitdff2f0ad547ba389fe90a33995ea1c281e816a88 (patch)
tree3d51943b9bbcb3ede8fd8c790d40bef04f42a2c1 /chef
parentbfa0fa080706b265163431ce1c736f6a5ec4d4cf (diff)
downloadchef-dff2f0ad547ba389fe90a33995ea1c281e816a88.tar.gz
Backport CHEF-5223 to 10-stable
Diffstat (limited to 'chef')
-rw-r--r--chef/lib/chef/provider/service/macosx.rb6
-rw-r--r--chef/spec/unit/provider/service/macosx_spec.rb37
2 files changed, 42 insertions, 1 deletions
diff --git a/chef/lib/chef/provider/service/macosx.rb b/chef/lib/chef/provider/service/macosx.rb
index 0e2dccdc84..aebf82e38a 100644
--- a/chef/lib/chef/provider/service/macosx.rb
+++ b/chef/lib/chef/provider/service/macosx.rb
@@ -53,7 +53,7 @@ class Chef
a.failure_message Chef::Exceptions::Service, "Several plist files match service name. Please use full service name."
end
- requirements.assert(:all_actions) do |a|
+ requirements.assert(:enable, :disable) do |a|
a.assertion { !@service_label.to_s.empty? }
a.failure_message Chef::Exceptions::Service,
"Could not find service's label in plist file '#{@plist}'!"
@@ -166,6 +166,10 @@ class Chef
private
def find_service_label
+ # CHEF-5223 "you can't glob for a file that hasn't been converged
+ # onto the node yet."
+ return nil if @plist.nil?
+
# Most services have the same internal label as the name of the
# plist file. However, there is no rule saying that *has* to be
# the case, and some core services (notably, ssh) do not follow
diff --git a/chef/spec/unit/provider/service/macosx_spec.rb b/chef/spec/unit/provider/service/macosx_spec.rb
index c517b5a2c1..10f538b730 100644
--- a/chef/spec/unit/provider/service/macosx_spec.rb
+++ b/chef/spec/unit/provider/service/macosx_spec.rb
@@ -58,6 +58,43 @@ XML
let!(:current_resource) { Chef::Resource::Service.new(service_name) }
describe "#load_current_resource" do
+
+ # CHEF-5223 "you can't glob for a file that hasn't been converged
+ # onto the node yet."
+ context "when the plist doesn't exist" do
+
+ def run_resource_setup_for_action(action)
+ new_resource.action(action)
+ provider.action = action
+ provider.load_current_resource
+ provider.define_resource_requirements
+ provider.process_resource_requirements
+ end
+
+ before do
+ Dir.stub(:glob).and_return([])
+ provider.stub(:shell_out!).
+ with(/plutil -convert xml1 -o/).
+ and_raise(Mixlib::ShellOut::ShellCommandFailed)
+ end
+
+ it "works for action :nothing" do
+ lambda { run_resource_setup_for_action(:nothing) }.should_not raise_error
+ end
+
+ it "works for action :start" do
+ lambda { run_resource_setup_for_action(:start) }.should_not raise_error
+ end
+
+ it "errors if action is :enable" do
+ lambda { run_resource_setup_for_action(:enable) }.should raise_error(Chef::Exceptions::Service)
+ end
+
+ it "errors if action is :disable" do
+ lambda { run_resource_setup_for_action(:disable) }.should raise_error(Chef::Exceptions::Service)
+ end
+ end
+
context "when launchctl returns pid in service list" do
let(:launchctl_stdout) { StringIO.new <<-SVC_LIST }
12761 - 0x100114220.old.machinit.thing