[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:32:54 UTC 2010


The following commit has been merged in the upstream branch:
commit 44f1465e937c0d7157de0caf7d2e6af9a38f09d8
Author: Andrew Forgue <andrew.forgue at gmail.com>
Date:   Tue Nov 24 18:28:30 2009 -0500

    Fixing #2864 Added support for AIX System Resource Controller (SRC) - service start stop
    
    This provider supports start/stop and restart of AIX services using the
    native AIX service manager, called the System Resource Controller.
    Currently it will not stop and start (but only refresh) a service that
    uses sockets or message queues as its communication method.  It will run
    stopsrc and then startsrc for services that use signals as their
    communication method.
    
    Signed-off-by: Andrew Forgue <andrew.forgue at gmail.com>

diff --git a/lib/puppet/provider/service/src.rb b/lib/puppet/provider/service/src.rb
new file mode 100755
index 0000000..eadce8e
--- /dev/null
+++ b/lib/puppet/provider/service/src.rb
@@ -0,0 +1,91 @@
+# AIX System Resource controller (SRC)
+Puppet::Type.type(:service).provide :src, :parent => :base do
+
+    desc "Support for AIX's System Resource controller.  
+
+    Services are started/stopped based on the stopsrc and startsrc
+    commands, and some services can be refreshed with refresh command.
+
+    * Enabling and disableing services is not supported, as it requires
+    modifications to /etc/inittab.
+
+    * Starting and stopping groups of subsystems is not yet supported
+    "
+
+    defaultfor :operatingsystem => :aix
+    confine :operatingsystem => :aix
+
+    commands :stopsrc  => "/usr/bin/stopsrc"
+    commands :startsrc => "/usr/bin/startsrc"
+    commands :refresh  => "/usr/bin/refresh"
+    commands :lssrc    => "/usr/bin/lssrc"
+
+    has_feature :refreshable
+
+    def startcmd
+        [command(:startsrc), "-s", @resource[:name]]
+    end
+
+    def stopcmd
+        [command(:stopsrc), "-s", @resource[:name]]
+    end
+
+    def restart
+        begin 
+            execute([command(:lssrc), "-Ss", @resource[:name]]).each do |line|
+                args = line.split(":")
+
+                next unless args[0] == @resource[:name]
+
+                # Subsystems with the -K flag can get refreshed (HUPed)
+                # While subsystems with -S (signals) must be stopped/started
+                method = args[11]
+                do_refresh = case method
+                    when "-K" then :true
+                    when "-S" then :false
+                    else self.fail("Unknown service communication method #{method}")
+                end
+
+                begin
+                    if do_refresh == :true
+                        execute([command(:refresh), "-s", @resource[:name]])
+                    else
+                        self.stop
+                        self.start
+                    end
+                    return :true
+                rescue Puppet::ExecutionFailure => detail
+                    raise Puppet::Error.new("Unable to restart service %s, error was: %s" % [ @resource[:name], detail ] )
+                end
+            end
+            self.fail("No such service found")
+        rescue Puppet::ExecutionFailure => detail
+            raise Puppet::Error.new("Cannot get status of %s, error was: %s" % [ @resource[:name], detail ] )
+        end
+    end
+
+    def status
+        begin 
+            execute([command(:lssrc), "-s", @resource[:name]]).each do |line|
+                args = line.split
+
+                # This is the header line
+                next unless args[0] == @resource[:name]
+
+                # PID is the 3rd field, but inoperative subsystems 
+                # skip this so split doesn't work right
+                state = case args[-1]
+                    when "active" then :running
+                    when "inoperative" then :stopped
+                end
+                Puppet.debug("Service #{@resource[:name]} is #{args[-1]}")
+                return state
+            end
+            self.fail("No such service found")
+        rescue Puppet::ExecutionFailure => detail
+            raise Puppet::Error.new("Cannot get status of %s, error was: %s" % [ @resource[:name], detail ] )
+        end
+    end
+
+end
+
diff --git a/spec/unit/provider/service/src.rb b/spec/unit/provider/service/src.rb
new file mode 100755
index 0000000..76a6cf8
--- /dev/null
+++ b/spec/unit/provider/service/src.rb
@@ -0,0 +1,97 @@
+#!/usr/bin/env ruby
+#
+# Unit testing for the AIX System Resource Controller (src) provider
+#
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+provider_class = Puppet::Type.type(:service).provider(:src)
+
+describe provider_class do
+
+    before :each do
+        @resource = stub 'resource'
+        @resource.stubs(:[]).returns(nil)
+        @resource.stubs(:[]).with(:name).returns "myservice"
+
+        @provider = provider_class.new
+        @provider.resource = @resource
+
+        @provider.stubs(:command).with(:stopsrc).returns "/usr/bin/stopsrc"
+        @provider.stubs(:command).with(:startsrc).returns "/usr/bin/startsrc"
+        @provider.stubs(:command).with(:lssrc).returns "/usr/bin/lssrc"
+        @provider.stubs(:command).with(:refresh).returns "/usr/bin/refresh"
+
+        @provider.stubs(:stopsrc)
+        @provider.stubs(:startsrc)
+        @provider.stubs(:lssrc)
+        @provider.stubs(:refresh)
+    end
+
+    [:start, :stop, :status, :restart].each do |method|
+        it "should have a #{method} method" do
+            @provider.should respond_to(method)
+        end
+    end
+
+    it "should execute the startsrc command" do 
+        @provider.expects(:execute).with(['/usr/bin/startsrc', '-s', "myservice"], {:squelch => true, :failonfail => true})
+        @provider.start
+    end            
+
+    it "should execute the stopsrc command" do 
+        @provider.expects(:execute).with(['/usr/bin/stopsrc', '-s', "myservice"], {:squelch => true, :failonfail => true})
+        @provider.stop
+    end
+
+    it "should execute status and return running if the subsystem is active" do
+        sample_output = <<_EOF_
+Subsystem         Group            PID          Status
+myservice         tcpip            1234         active
+_EOF_
+
+        @provider.expects(:execute).with(['/usr/bin/lssrc', '-s', "myservice"]).returns sample_output
+        @provider.status.should == :running
+    end
+
+    it "should execute status and return stopped if the subsystem is inoperative" do
+        sample_output = <<_EOF_
+Subsystem         Group            PID          Status
+myservice         tcpip                         inoperative
+_EOF_
+
+        @provider.expects(:execute).with(['/usr/bin/lssrc', '-s', "myservice"]).returns sample_output
+        @provider.status.should == :stopped
+    end
+
+    it "should execute status and return nil if the status is not known" do
+        sample_output = <<_EOF_
+Subsystem         Group            PID          Status
+myservice         tcpip                         randomdata
+_EOF_
+
+        @provider.expects(:execute).with(['/usr/bin/lssrc', '-s', "myservice"]).returns sample_output
+        @provider.status.should == nil
+    end
+
+    it "should execute restart which runs refresh" do
+        sample_output = <<_EOF_
+#subsysname:synonym:cmdargs:path:uid:auditid:standin:standout:standerr:action:multi:contact:svrkey:svrmtype:priority:signorm:sigforce:display:waittime:grpname:
+myservice:::/usr/sbin/inetd:0:0:/dev/console:/dev/console:/dev/console:-O:-Q:-K:0:0:20:0:0:-d:20:tcpip:
+_EOF_
+        @provider.expects(:execute).with(['/usr/bin/lssrc', '-Ss', "myservice"]).returns sample_output
+        @provider.expects(:execute).with(['/usr/bin/refresh', '-s', "myservice"])
+        @provider.restart
+    end
+
+    it "should execute restart which runs stopsrc then startsrc" do
+        sample_output =  <<_EOF_
+#subsysname:synonym:cmdargs:path:uid:auditid:standin:standout:standerr:action:multi:contact:svrkey:svrmtype:priority:signorm:sigforce:display:waittime:grpname:
+myservice::--no-daemonize:/usr/sbin/puppetd:0:0:/dev/null:/var/log/puppet.log:/var/log/puppet.log:-O:-Q:-S:0:0:20:15:9:-d:20::"
+_EOF_
+        @provider.expects(:execute).with(['/usr/bin/lssrc', '-Ss', "myservice"]).returns sample_output
+        @provider.expects(:execute).with(['/usr/bin/stopsrc', '-s', "myservice"], {:squelch => true, :failonfail => true})
+        @provider.expects(:execute).with(['/usr/bin/startsrc', '-s', "myservice"], {:squelch => true, :failonfail => true})
+        @provider.restart
+    end
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list