Please review pull request #373: Tickets/2.7.x/2056 launchd supporting stop commands opened by (lak)
Description:
- Opened: Sat Jan 21 21:19:31 UTC 2012
- Based on: puppetlabs:2.7.x (470a6646b4faa34874ab853355730dc0471b1246)
- Requested merge: lak:tickets/2.7.x/2056-launchd_supporting_stop_commands (93454974d10e4d1bba545faadceaf2baf7bc4880)
Diff follows:
diff --git a/lib/puppet/provider/service/launchd.rb b/lib/puppet/provider/service/launchd.rb
index 79dcf87..f993022 100644
--- a/lib/puppet/provider/service/launchd.rb
+++ b/lib/puppet/provider/service/launchd.rb
@@ -35,6 +35,8 @@
Note that this allows you to do something `launchctl` can't do, which is to
be in a state of "stopped/enabled" or "running/disabled".
+ Note that this provider does not support overriding 'restart' or 'status'.
+
EOT
include Puppet::Util::Warnings
@@ -192,6 +194,7 @@ def plist_from_label(label)
# conditionally enable at load, then disable by modifying the plist file
# directly.
def start
+ return ucommand(:start) if resource[:start]
job_path, job_plist = plist_from_label(resource[:name])
did_enable_job = false
cmds = []
@@ -212,6 +215,7 @@ def start
def stop
+ return ucommand(:stop) if resource[:stop]
job_path, job_plist = plist_from_label(resource[:name])
did_disable_job = false
cmds = []
diff --git a/spec/unit/provider/service/launchd_spec.rb b/spec/unit/provider/service/launchd_spec.rb
index 8651ac5..bc24676 100755
--- a/spec/unit/provider/service/launchd_spec.rb
+++ b/spec/unit/provider/service/launchd_spec.rb
@@ -7,6 +7,8 @@
let (:joblabel) { "com.foo.food" }
let (:provider) { subject.class }
let (:launchd_overrides) { '/var/db/launchd.db/com.apple.launchd/overrides.plist' }
+ let(:resource) { Puppet::Type.type(:service).new(:name => joblabel) }
+ subject { Puppet::Type.type(:service).provider(:launchd).new(resource) }
describe "the type interface" do
%w{ start stop enabled? enable disable status}.each do |method|
@@ -39,18 +41,15 @@
it "should return true in if the job plist says disabled is false" do
subject.expects(:has_macosx_plist_overrides?).returns(false)
subject.expects(:plist_from_label).with(joblabel).returns(["foo", {"Disabled" => false}])
- subject.expects(:resource).returns({:name => joblabel})
subject.enabled?.should == :true
end
it "should return true in if the job plist has no disabled key" do
subject.expects(:has_macosx_plist_overrides?).returns(false)
- subject.expects(:resource).returns({:name => joblabel})
subject.expects(:plist_from_label).returns(["foo", {}])
subject.enabled?.should == :true
end
it "should return false in if the job plist says disabled is true" do
subject.expects(:has_macosx_plist_overrides?).returns(false)
- subject.expects(:resource).returns({:name => joblabel})
subject.expects(:plist_from_label).returns(["foo", {"Disabled" => true}])
subject.enabled?.should == :false
end
@@ -62,7 +61,6 @@
subject.expects(:plist_from_label).returns([joblabel, {"Disabled" => true}])
provider.expects(:read_plist).returns({joblabel => {"Disabled" => false}})
FileTest.expects(:file?).with(launchd_overrides).returns(true)
- subject.stubs(:resource).returns({:name => joblabel})
subject.enabled?.should == :true
end
it "should return false if the job plist says disabled is false and the global overrides says disabled is true" do
@@ -70,7 +68,6 @@
subject.expects(:plist_from_label).returns([joblabel, {"Disabled" => false}])
provider.expects(:read_plist).returns({joblabel => {"Disabled" => true}})
FileTest.expects(:file?).with(launchd_overrides).returns(true)
- subject.stubs(:resource).returns({:name => joblabel})
subject.enabled?.should == :false
end
it "should return true if the job plist and the global overrides have no disabled keys" do
@@ -78,38 +75,40 @@
subject.expects(:plist_from_label).returns([joblabel, {}])
provider.expects(:read_plist).returns({})
FileTest.expects(:file?).with(launchd_overrides).returns(true)
- subject.stubs(:resource).returns({:name => joblabel})
subject.enabled?.should == :true
end
end
describe "when starting the service" do
+ it "should call any explicit 'start' command" do
+ resource[:start] = "/bin/false"
+ subject.expects(:texecute).with(:start, ["/bin/false"], true)
+ subject.start
+ end
+
it "should look for the relevant plist once" do
subject.expects(:plist_from_label).returns([joblabel, {}]).once
subject.expects(:enabled?).returns :true
subject.expects(:execute).with([:launchctl, :load, joblabel])
- subject.stubs(:resource).returns({:name => joblabel})
subject.start
end
it "should execute 'launchctl load' once without writing to the plist if the job is enabled" do
subject.expects(:plist_from_label).returns([joblabel, {}])
subject.expects(:enabled?).returns :true
subject.expects(:execute).with([:launchctl, :load, joblabel]).once
- subject.stubs(:resource).returns({:name => joblabel})
subject.start
end
it "should execute 'launchctl load' with writing to the plist once if the job is disabled" do
subject.expects(:plist_from_label).returns([joblabel, {}])
subject.expects(:enabled?).returns(:false)
- subject.stubs(:resource).returns({:name => joblabel})
subject.expects(:execute).with([:launchctl, :load, "-w", joblabel]).once
subject.start
end
it "should disable the job once if the job is disabled and should be disabled at boot" do
+ resource[:enable] = false
subject.expects(:plist_from_label).returns([joblabel, {"Disabled" => true}])
subject.expects(:enabled?).returns :false
subject.expects(:execute).with([:launchctl, :load, "-w", joblabel])
- subject.stubs(:resource).returns({:name => joblabel, :enable => :false})
subject.expects(:disable).once
subject.start
end
@@ -117,39 +116,41 @@
subject.expects(:plist_from_label).returns([joblabel, {}])
subject.expects(:enabled?).returns(:true)
subject.expects(:status).returns(:stopped)
- subject.expects(:resource).returns({:name => joblabel}).twice
subject.expects(:execute).with([:launchctl, :load, '-w', joblabel])
subject.start
end
end
describe "when stopping the service" do
+ it "should call any explicit 'stop' command" do
+ resource[:stop] = "/bin/false"
+ subject.expects(:texecute).with(:stop, ["/bin/false"], true)
+ subject.stop
+ end
+
it "should look for the relevant plist once" do
subject.expects(:plist_from_label).returns([joblabel, {}]).once
subject.expects(:enabled?).returns :true
subject.expects(:execute).with([:launchctl, :unload, '-w', joblabel])
- subject.stubs(:resource).returns({:name => joblabel})
subject.stop
end
it "should execute 'launchctl unload' once without writing to the plist if the job is disabled" do
subject.expects(:plist_from_label).returns([joblabel, {}])
subject.expects(:enabled?).returns :false
subject.expects(:execute).with([:launchctl, :unload, joblabel]).once
- subject.stubs(:resource).returns({:name => joblabel})
subject.stop
end
it "should execute 'launchctl unload' with writing to the plist once if the job is enabled" do
subject.expects(:plist_from_label).returns([joblabel, {}])
subject.expects(:enabled?).returns :true
subject.expects(:execute).with([:launchctl, :unload, '-w', joblabel]).once
- subject.stubs(:resource).returns({:name => joblabel})
subject.stop
end
it "should enable the job once if the job is enabled and should be enabled at boot" do
+ resource[:enable] = true
subject.expects(:plist_from_label).returns([joblabel, {"Disabled" => false}])
subject.expects(:enabled?).returns :true
subject.expects(:execute).with([:launchctl, :unload, "-w", joblabel])
- subject.stubs(:resource).returns({:name => joblabel, :enable => :true})
subject.expects(:enable).once
subject.stop
end
@@ -157,47 +158,47 @@
describe "when enabling the service" do
it "should look for the relevant plist once" do ### Do we need this test? Differentiating it?
+ resource[:enable] = true
subject.expects(:plist_from_label).returns([joblabel, {}]).once
subject.expects(:enabled?).returns :false
subject.expects(:execute).with([:launchctl, :unload, joblabel])
- subject.stubs(:resource).returns({:name => joblabel, :enable => :true})
subject.stop
end
it "should check if the job is enabled once" do
+ resource[:enable] = true
subject.expects(:plist_from_label).returns([joblabel, {}]).once
subject.expects(:enabled?).once
subject.expects(:execute).with([:launchctl, :unload, joblabel])
- subject.stubs(:resource).returns({:name => joblabel, :enable => :true})
subject.stop
end
end
describe "when disabling the service" do
it "should look for the relevant plist once" do
+ resource[:enable] = false
subject.expects(:plist_from_label).returns([joblabel, {}]).once
subject.expects(:enabled?).returns :true
subject.expects(:execute).with([:launchctl, :unload, '-w', joblabel])
- subject.stubs(:resource).returns({:name => joblabel, :enable => :false})
subject.stop
end
end
describe "when enabling the service on OS X 10.6" do
it "should write to the global launchd overrides file once" do
+ resource[:enable] = true
provider.expects(:get_macosx_version_major).returns("10.6")
provider.expects(:read_plist).returns({})
Plist::Emit.expects(:save_plist).once
- subject.stubs(:resource).returns({:name => joblabel, :enable => :true})
subject.enable
end
end
describe "when disabling the service on OS X 10.6" do
it "should write to the global launchd overrides file once" do
+ resource[:enable] = false
provider.stubs(:get_macosx_version_major).returns("10.6")
provider.stubs(:read_plist).returns({})
Plist::Emit.expects(:save_plist).once
- subject.stubs(:resource).returns({:name => joblabel, :enable => :false})
subject.enable
end
end
@@ -207,6 +208,7 @@
provider.instance_variable_set(:@macosx_version_major, nil)
end
it "should display a deprecation warning" do
+ resource[:enable] = true
Facter.expects(:value).with(:macosx_productversion_major).returns(nil)
Facter.expects(:value).with(:macosx_productversion).returns('10.5.8')
Facter.expects(:loadfacts)
@@ -214,7 +216,6 @@
subject.expects(:plist_from_label).returns([joblabel, {"Disabled" => false}])
subject.expects(:enabled?).returns :false
File.expects(:open).returns('')
- subject.stubs(:resource).returns({:name => joblabel, :enable => :true})
subject.enable
end
end
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
