summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Dodge <mikedodge04@fb.com>2015-04-01 13:35:03 -0700
committerMike Dodge <mikedodge04@fb.com>2015-04-01 13:35:03 -0700
commit455aaf2b879f341eea406b2004ff9524544da96e (patch)
tree8733dcdc986e8b0dcffcc4deb7c05e92e7ed542b
parent04bd76a051270d529333c943e27fc2154378954f (diff)
downloadchef-455aaf2b879f341eea406b2004ff9524544da96e.tar.gz
adding assert for plist
-rw-r--r--lib/chef/provider/service/macosx.rb14
-rw-r--r--spec/unit/provider/service/macosx_spec.rb2
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb
index 4c40c5c865..f6a4c1a9c3 100644
--- a/lib/chef/provider/service/macosx.rb
+++ b/lib/chef/provider/service/macosx.rb
@@ -79,6 +79,12 @@ 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|
+ a.assertion {::File.exists?(@plist.to_s) }
+ a.failure_message Chef::Exceptions::Service,
+ "Could not find plist for #{@new_resource}"
+ end
+
requirements.assert(:enable, :disable) do |a|
a.assertion { !@service_label.to_s.empty? }
a.failure_message Chef::Exceptions::Service,
@@ -94,11 +100,6 @@ class Chef
@current_resource.running(false)
end
end
-
- requirements.assert(:all_actions) do |a|
- a.assertion { @plist.nil? ? true : ::File.exists?(@plist) }
- a.failure_message Chef::Exceptions::Service, "#{@plist} does not exist"
- end
end
def start_service
@@ -209,6 +210,9 @@ class Chef
# onto the node yet."
return nil if @plist.nil?
+ # Plist must exist by this point
+ raise Chef::Exceptions::FileNotFound, "Cannot find #{@plist}!" unless ::File.exists?(@plist)
+
# 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/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb
index 76301a8129..42d45f09e0 100644
--- a/spec/unit/provider/service/macosx_spec.rb
+++ b/spec/unit/provider/service/macosx_spec.rb
@@ -81,6 +81,7 @@ XML
with(/(#{su_cmd} '#{cmd}'|#{cmd})/).
and_return(double("Status",
:stdout => launchctl_stdout, :exitstatus => 0))
+ allow(File).to receive(:exists?).and_return([true], [])
allow(provider).to receive(:shell_out_with_systems_locale!).
with(/plutil -convert xml1 -o/).
and_return(double("Status", :stdout => plutil_stdout))
@@ -106,6 +107,7 @@ XML
before do
allow(Dir).to receive(:glob).and_return([])
+ allow(File).to receive(:exists?).and_return([true], [])
allow(provider).to receive(:shell_out!).
with(/plutil -convert xml1 -o/).
and_raise(Mixlib::ShellOut::ShellCommandFailed)