Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'feature/master/9923-puppetd-support-for-puppet-as-daemon'

* feature/master/9923-puppetd-support-for-puppet-as-daemon:
  Making cleaner status logic
  Increment puppetd agent version number
  Adding spec test for dead process
  Check the running PID, else start --onetime
  Handle cases for Puppet running vs idling
  (#9923) Support puppet agent as a daemon from puppetd
  Use 2-space indenting everywhere in the plugins.
  Fix bad input stub => failing test for puppetd agent.

Conflicts:
	agent/puppetral/agent/puppetral.rb
  • Loading branch information...
commit c292205d700699fc7cba023df4e0417dd93f00ae 2 parents 89477b3 + c42efde
Matt Robinson authored
Showing with 3,993 additions and 3,886 deletions.
  1. +118 −118 agent/filemgr/agent/filemgr.rb
  2. +46 −46 agent/filemgr/application/filemgr.rb
  3. +149 −149 agent/iptables-junkfilter/agent/iptables.rb
  4. +43 −43 agent/iptables-junkfilter/application/iptables.rb
  5. +42 −43 agent/nettest/agent/nettest.rb
  6. +149 −149 agent/nettest/application/nettest.rb
  7. +74 −74 agent/nrpe/agent/nrpe.rb
  8. +42 −42 agent/nrpe/application/nrpe.rb
  9. +71 −71 agent/nrpe/spec/nrpe_agent_spec.rb
  10. +147 −147 agent/package/agent/puppet-package.rb
  11. +50 −50 agent/package/application/package.rb
  12. +328 −328 agent/package/spec/package_agent_spec.rb
  13. +126 −126 agent/package/spec/package_application_spec.rb
  14. +112 −112 agent/process/process.rb
  15. +100 −100 agent/puppetca/agent/puppetca.rb
  16. +138 −138 agent/puppetca/spec/puppetca_agent_spec.rb
  17. +1 −1  agent/puppetd/agent/puppetd.ddl
  18. +173 −127 agent/puppetd/agent/puppetd.rb
  19. +120 −120 agent/puppetd/application/puppetd.rb
  20. +132 −132 agent/puppetd/commander/puppetcommanderd
  21. +83 −83 agent/puppetd/sbin/mc-puppetd
  22. +215 −161 agent/puppetd/spec/puppetd_agent_spec.rb
  23. +179 −179 agent/puppetd/spec/puppetd_application_spec.rb
  24. +14 −6 agent/puppetral/agent/puppetral.rb
  25. +18 −18 agent/puppetral/spec/puppetral_spec.rb
  26. +27 −27 agent/registration-mongodb/check_mcollective.rb
  27. +8 −8 agent/registration-mongodb/puppet/load_node.rb
  28. +61 −61 agent/registration-mongodb/puppet/mongoquery.rb
  29. +5 −5 agent/registration-mongodb/puppet/search_nodes.rb
  30. +10 −10 agent/registration-mongodb/puppet/search_setup.rb
  31. +84 −84 agent/registration-mongodb/registration.rb
  32. +30 −30 agent/registration-monitor/check_mcollective.rb
  33. +26 −26 agent/registration-monitor/registration.rb
  34. +61 −61 agent/service/agent/puppet-service.rb
  35. +105 −105 agent/service/application/service.rb
  36. +97 −97 agent/service/spec/service_agent_spec.rb
  37. +117 −117 agent/service/spec/service_application_spec.rb
  38. +36 −36 agent/stomputil/stomputil.rb
  39. +39 −39 audit/centralrpclog/agent/centralrpclog-mongodb.rb
  40. +26 −26 audit/centralrpclog/agent/centralrpclog.rb
  41. +30 −30 audit/centralrpclog/audit/centralrpclog.rb
  42. +35 −35 audit/logstash/logstash.rb
  43. +60 −60 facts/facter/facter.rb
  44. +26 −26 facts/facter/facter_facts.rb
  45. +55 −55 facts/ohai/opscodeohai.rb
  46. +42 −42 facts/ohai/opscodeohai_facts.rb
  47. +27 −27 registration/meta.rb
  48. +34 −34 security/none/none.rb
  49. +142 −142 security/sshkey/sshkey.rb
  50. +135 −135 simplerpc_authorization/action_policy/actionpolicy.rb
  51. +5 −5 spec/spec_helper.rb
View
236 agent/filemgr/agent/filemgr.rb
@@ -2,125 +2,125 @@
require 'digest/md5'
module MCollective
- module Agent
- # A basic file management agent, you can touch, remove or inspec files.
- #
- # A common use case for this plugin is to test your mcollective setup
- # as such if you just call the touch/info/remove actions with no arguments
- # it will default to the file /var/run/mcollective.plugin.filemgr.touch
- # or whatever is specified in the plugin.filemgr.touch_file setting
- class Filemgr<RPC::Agent
- metadata :name => "filemgr",
- :description => "File Manager",
- :author => "Mike Pountney <mike.pountney@gmail.com>",
- :license => "Apache 2",
- :version => "0.3",
- :url => "http://www.puppetlabs.com/mcollective",
- :timeout => 5
-
- # Basic file touch action - create (empty) file if it doesn't exist,
- # update last mod time otherwise.
- # useful for checking if mcollective is operational, via NRPE or similar.
- action "touch" do
- touch
- end
-
- # Basic file removal action
- action "remove" do
- remove
- end
-
- # Basic status of a file
- action "status" do
- status
- end
-
- private
- def get_filename
- request[:file] || config.pluginconf["filemgr.touch_file"] || "/var/run/mcollective.plugin.filemgr.touch"
- end
-
- def status
- file = get_filename
- reply[:name] = file
- reply[:output] = "not present"
- reply[:type] = "unknown"
- reply[:mode] = "0000"
- reply[:present] = 0
- reply[:size] = 0
- reply[:mtime] = 0
- reply[:ctime] = 0
- reply[:atime] = 0
- reply[:mtime_seconds] = 0
- reply[:ctime_seconds] = 0
- reply[:atime_seconds] = 0
- reply[:md5] = 0
- reply[:uid] = 0
- reply[:gid] = 0
-
-
- if File.exists?(file)
- logger.debug("Asked for status of '#{file}' - it is present")
- reply[:output] = "present"
- reply[:present] = 1
-
- if File.symlink?(file)
- stat = File.lstat(file)
- else
- stat = File.stat(file)
- end
-
- [:size, :mtime, :ctime, :atime, :uid, :gid].each do |item|
- reply[item] = stat.send(item)
- end
-
- [:mtime, :ctime, :atime].each do |item|
- reply["#{item}_seconds".to_sym] = stat.send(item).to_i
- end
-
- reply[:mode] = "%o" % [stat.mode]
- reply[:md5] = Digest::MD5.hexdigest(File.read(file)) if stat.file?
-
- reply[:type] = "directory" if stat.directory?
- reply[:type] = "file" if stat.file?
- reply[:type] = "symlink" if stat.symlink?
- reply[:type] = "socket" if stat.socket?
- reply[:type] = "chardev" if stat.chardev?
- reply[:type] = "blockdev" if stat.blockdev?
- else
- logger.debug("Asked for status of '#{file}' - it is not present")
- reply.fail! "#{file} does not exist"
- end
- end
-
- def remove
- file = get_filename
- if ! File.exists?(file)
- logger.debug("Asked to remove file '#{file}', but it does not exist")
- reply.statusmsg = "OK"
- end
-
- begin
- FileUtils.rm(file)
- logger.debug("Removed file '#{file}'")
- reply.statusmsg = "OK"
- rescue
- logger.warn("Could not remove file '#{file}'")
- reply.fail! "Could not remove file '#{file}'"
- end
- end
-
- def touch
- file = get_filename
- begin
- FileUtils.touch(file)
- logger.debug("Touched file '#{file}'")
- rescue
- logger.warn("Could not touch file '#{file}'")
- reply.fail! "Could not touch file '#{file}'"
- end
- end
+ module Agent
+ # A basic file management agent, you can touch, remove or inspec files.
+ #
+ # A common use case for this plugin is to test your mcollective setup
+ # as such if you just call the touch/info/remove actions with no arguments
+ # it will default to the file /var/run/mcollective.plugin.filemgr.touch
+ # or whatever is specified in the plugin.filemgr.touch_file setting
+ class Filemgr<RPC::Agent
+ metadata :name => "filemgr",
+ :description => "File Manager",
+ :author => "Mike Pountney <mike.pountney@gmail.com>",
+ :license => "Apache 2",
+ :version => "0.3",
+ :url => "http://www.puppetlabs.com/mcollective",
+ :timeout => 5
+
+ # Basic file touch action - create (empty) file if it doesn't exist,
+ # update last mod time otherwise.
+ # useful for checking if mcollective is operational, via NRPE or similar.
+ action "touch" do
+ touch
+ end
+
+ # Basic file removal action
+ action "remove" do
+ remove
+ end
+
+ # Basic status of a file
+ action "status" do
+ status
+ end
+
+ private
+ def get_filename
+ request[:file] || config.pluginconf["filemgr.touch_file"] || "/var/run/mcollective.plugin.filemgr.touch"
+ end
+
+ def status
+ file = get_filename
+ reply[:name] = file
+ reply[:output] = "not present"
+ reply[:type] = "unknown"
+ reply[:mode] = "0000"
+ reply[:present] = 0
+ reply[:size] = 0
+ reply[:mtime] = 0
+ reply[:ctime] = 0
+ reply[:atime] = 0
+ reply[:mtime_seconds] = 0
+ reply[:ctime_seconds] = 0
+ reply[:atime_seconds] = 0
+ reply[:md5] = 0
+ reply[:uid] = 0
+ reply[:gid] = 0
+
+
+ if File.exists?(file)
+ logger.debug("Asked for status of '#{file}' - it is present")
+ reply[:output] = "present"
+ reply[:present] = 1
+
+ if File.symlink?(file)
+ stat = File.lstat(file)
+ else
+ stat = File.stat(file)
+ end
+
+ [:size, :mtime, :ctime, :atime, :uid, :gid].each do |item|
+ reply[item] = stat.send(item)
+ end
+
+ [:mtime, :ctime, :atime].each do |item|
+ reply["#{item}_seconds".to_sym] = stat.send(item).to_i
+ end
+
+ reply[:mode] = "%o" % [stat.mode]
+ reply[:md5] = Digest::MD5.hexdigest(File.read(file)) if stat.file?
+
+ reply[:type] = "directory" if stat.directory?
+ reply[:type] = "file" if stat.file?
+ reply[:type] = "symlink" if stat.symlink?
+ reply[:type] = "socket" if stat.socket?
+ reply[:type] = "chardev" if stat.chardev?
+ reply[:type] = "blockdev" if stat.blockdev?
+ else
+ logger.debug("Asked for status of '#{file}' - it is not present")
+ reply.fail! "#{file} does not exist"
end
+ end
+
+ def remove
+ file = get_filename
+ if ! File.exists?(file)
+ logger.debug("Asked to remove file '#{file}', but it does not exist")
+ reply.statusmsg = "OK"
+ end
+
+ begin
+ FileUtils.rm(file)
+ logger.debug("Removed file '#{file}'")
+ reply.statusmsg = "OK"
+ rescue
+ logger.warn("Could not remove file '#{file}'")
+ reply.fail! "Could not remove file '#{file}'"
+ end
+ end
+
+ def touch
+ file = get_filename
+ begin
+ FileUtils.touch(file)
+ logger.debug("Touched file '#{file}'")
+ rescue
+ logger.warn("Could not touch file '#{file}'")
+ reply.fail! "Could not touch file '#{file}'"
+ end
+ end
end
+ end
end
View
92 agent/filemgr/application/filemgr.rb
@@ -1,51 +1,51 @@
class MCollective::Application::Filemgr<MCollective::Application
- description "Generic File Manager Client"
- usage "Usage: mc-filemgr [--file FILE] [touch|remove|status]"
-
- option :file,
- :description => "File to manage",
- :arguments => ["--file FILE", "-f FILE"],
- :required => true
-
- option :details,
- :description => "Show full file details",
- :arguments => ["--details", "-d"],
- :type => :bool
-
- def post_option_parser(configuration)
- configuration[:command] = ARGV.shift if ARGV.size > 0
- end
-
- def validate_configuration(configuration)
- configuration[:command] = "touch" unless configuration.include?(:command)
- end
-
- def main
- mc = rpcclient("filemgr", :options => options)
-
- case configuration[:command]
- when "remove"
- printrpc mc.remove(:file => configuration[:file])
-
- when "touch"
- printrpc mc.touch(:file => configuration[:file])
-
- when "status"
- if configuration[:details]
- printrpc mc.status(:file => configuration[:file])
- else
- mc.status(:file => configuration[:file]).each do |resp|
- printf("%-40s: %s\n", resp[:sender], resp[:data][:output] || resp[:statusmsg] )
- end
- end
-
- else
- mc.disconnect
- puts "Valid commands are 'touch', 'status', and 'remove'"
- exit 1
+ description "Generic File Manager Client"
+ usage "Usage: mc-filemgr [--file FILE] [touch|remove|status]"
+
+ option :file,
+ :description => "File to manage",
+ :arguments => ["--file FILE", "-f FILE"],
+ :required => true
+
+ option :details,
+ :description => "Show full file details",
+ :arguments => ["--details", "-d"],
+ :type => :bool
+
+ def post_option_parser(configuration)
+ configuration[:command] = ARGV.shift if ARGV.size > 0
+ end
+
+ def validate_configuration(configuration)
+ configuration[:command] = "touch" unless configuration.include?(:command)
+ end
+
+ def main
+ mc = rpcclient("filemgr", :options => options)
+
+ case configuration[:command]
+ when "remove"
+ printrpc mc.remove(:file => configuration[:file])
+
+ when "touch"
+ printrpc mc.touch(:file => configuration[:file])
+
+ when "status"
+ if configuration[:details]
+ printrpc mc.status(:file => configuration[:file])
+ else
+ mc.status(:file => configuration[:file]).each do |resp|
+ printf("%-40s: %s\n", resp[:sender], resp[:data][:output] || resp[:statusmsg] )
end
+ end
- mc.disconnect
- printrpcstats
+ else
+ mc.disconnect
+ puts "Valid commands are 'touch', 'status', and 'remove'"
+ exit 1
end
+
+ mc.disconnect
+ printrpcstats
+ end
end
View
298 agent/iptables-junkfilter/agent/iptables.rb
@@ -1,156 +1,156 @@
require 'socket'
module MCollective
- module Agent
- # An agent that manipulates a chain called 'junkfilter' with iptables
- #
- # See http://code.google.com/p/mcollective-plugins/wiki/AgentIptablesJunkfilter
- #
- # Released under the terms of the GPL
- class Iptables<RPC::Agent
- metadata :name => "SimpleRPC IP Tables Agent",
- :description => "An agent that manipulates a chain called 'junkfilter' with iptables",
- :author => "R.I.Pienaar",
- :license => "Apache 2",
- :version => "1.3",
- :url => "http://projects.puppetlabs.com/projects/mcollective-plugins/wiki",
- :timeout => 2
-
- action "block" do
- validate :ipaddr, :ipv4address
-
- blockip(request[:ipaddr])
- end
-
- action "unblock" do
- validate :ipaddr, :ipv4address
-
- unblockip(request[:ipaddr])
- end
-
- action "isblocked" do
- validate :ipaddr, :ipv4address
-
- isblocked(request[:ipaddr])
- end
-
- action "listblocked" do
- reply[:blocked] = listblocked
- end
-
- private
- # Deals with requests to block an ip
- def blockip(ip)
- logger.debug("Blocking #{ip} with target #{target}")
-
- out = nil
-
- # if he's already blocked we just dont bother doing it again
- unless isblocked?(ip)
- if respond_to?(:run)
- run("/sbin/iptables -A junk_filter -s #{ip} -j #{target} 2>&1", :stdout => out, :chomp => true)
- run("/usr/bin/logger -i -t mcollective 'Attempted to add #{ip} to iptables junk_filter chain on #{Socket.gethostname}'")
- else
- out = %x[/sbin/iptables -A junk_filter -s #{ip} -j #{target} 2>&1]
- system("/usr/bin/logger -i -t mcollective 'Attempted to add #{ip} to iptables junk_filter chain on #{Socket.gethostname}'")
- end
- else
- reply.fail! "#{ip} was already blocked"
- return
- end
-
- if isblocked?(ip)
- if out
- reply[:output] = out
- else
- reply[:output] = "#{ip} was blocked"
- end
- else
- reply.fail! "Failed to add #{ip}: #{out}"
- end
- end
-
- # Deals with requests to unblock an ip
- def unblockip(ip)
- logger.debug("Unblocking #{ip} with target #{target}")
-
- out = nil
-
- # remove it if it's blocked
- if isblocked?(ip)
- if respond_to?(:run)
- out = run("/sbin/iptables -D junk_filter -s #{ip} -j #{target} 2>&1", :stdout => out, :chomp => true)
- run("/usr/bin/logger -i -t mcollective 'Attempted to remove #{ip} from iptables junk_filter chain on #{Socket.gethostname}'")
- else
- out = %x[/sbin/iptables -D junk_filter -s #{ip} -j #{target} 2>&1]
- system("/usr/bin/logger -i -t mcollective 'Attempted to remove #{ip} from iptables junk_filter chain on #{Socket.gethostname}'")
- end
- else
- reply.fail! "#{ip} was already unblocked"
- return
- end
-
- # check it was removed
- if isblocked?(ip)
- reply.fail! "IP left blocked, iptables says: #{out}"
- else
- if out
- reply[:output] = out
- else
- reply[:output] = "#{ip} was unblocked"
- end
- end
- end
-
- # Deals with requests for status of a ip
- def isblocked(ip)
- if isblocked?(ip)
- reply[:output] = "#{ip} is blocked"
- else
- reply[:output] = "#{ip} is not blocked"
- end
- end
-
- # Utility to figure out if a ip is blocked or not, just return true or false
- def isblocked?(ip)
- logger.debug("Checking if #{ip} is blocked with target #{target}")
-
- if respond_to?(:run)
- prematches = ""
- run("/sbin/iptables -L junk_filter -n 2>&1", :stdout => prematches, :chomp => true)
- else
- prematches = %x[/sbin/iptables -L junk_filter -n 2>&1]
- end
-
- matches = prematches.split("\n").grep(/^#{target}.+#{ip}/).size
- matches >= 1
- end
-
- # Returns a list of blocked ips
- def listblocked
- if respond_to?(:run)
- preout = ""
- run("/sbin/iptables -L junk_filter -n 2>&1", :stdout => preout, :chomp => true)
- else
- preout = %x[/sbin/iptables -L junk_filter -n 2>&1]
- end
-
- out = preout.split("\n").grep(/^#{target}/)
- out.map {|l| l.split(/\s+/)[3]}
- end
-
- # Returns the target to use for rules
- def target
- target = "DROP"
-
- if @config.pluginconf.include?("iptables.target")
- target = @config.pluginconf["iptables.target"]
- end
-
- target
- end
+ module Agent
+ # An agent that manipulates a chain called 'junkfilter' with iptables
+ #
+ # See http://code.google.com/p/mcollective-plugins/wiki/AgentIptablesJunkfilter
+ #
+ # Released under the terms of the GPL
+ class Iptables<RPC::Agent
+ metadata :name => "SimpleRPC IP Tables Agent",
+ :description => "An agent that manipulates a chain called 'junkfilter' with iptables",
+ :author => "R.I.Pienaar",
+ :license => "Apache 2",
+ :version => "1.3",
+ :url => "http://projects.puppetlabs.com/projects/mcollective-plugins/wiki",
+ :timeout => 2
+
+ action "block" do
+ validate :ipaddr, :ipv4address
+
+ blockip(request[:ipaddr])
+ end
+
+ action "unblock" do
+ validate :ipaddr, :ipv4address
+
+ unblockip(request[:ipaddr])
+ end
+
+ action "isblocked" do
+ validate :ipaddr, :ipv4address
+
+ isblocked(request[:ipaddr])
+ end
+
+ action "listblocked" do
+ reply[:blocked] = listblocked
+ end
+
+ private
+ # Deals with requests to block an ip
+ def blockip(ip)
+ logger.debug("Blocking #{ip} with target #{target}")
+
+ out = nil
+
+ # if he's already blocked we just dont bother doing it again
+ unless isblocked?(ip)
+ if respond_to?(:run)
+ run("/sbin/iptables -A junk_filter -s #{ip} -j #{target} 2>&1", :stdout => out, :chomp => true)
+ run("/usr/bin/logger -i -t mcollective 'Attempted to add #{ip} to iptables junk_filter chain on #{Socket.gethostname}'")
+ else
+ out = %x[/sbin/iptables -A junk_filter -s #{ip} -j #{target} 2>&1]
+ system("/usr/bin/logger -i -t mcollective 'Attempted to add #{ip} to iptables junk_filter chain on #{Socket.gethostname}'")
+ end
+ else
+ reply.fail! "#{ip} was already blocked"
+ return
end
+
+ if isblocked?(ip)
+ if out
+ reply[:output] = out
+ else
+ reply[:output] = "#{ip} was blocked"
+ end
+ else
+ reply.fail! "Failed to add #{ip}: #{out}"
+ end
+ end
+
+ # Deals with requests to unblock an ip
+ def unblockip(ip)
+ logger.debug("Unblocking #{ip} with target #{target}")
+
+ out = nil
+
+ # remove it if it's blocked
+ if isblocked?(ip)
+ if respond_to?(:run)
+ out = run("/sbin/iptables -D junk_filter -s #{ip} -j #{target} 2>&1", :stdout => out, :chomp => true)
+ run("/usr/bin/logger -i -t mcollective 'Attempted to remove #{ip} from iptables junk_filter chain on #{Socket.gethostname}'")
+ else
+ out = %x[/sbin/iptables -D junk_filter -s #{ip} -j #{target} 2>&1]
+ system("/usr/bin/logger -i -t mcollective 'Attempted to remove #{ip} from iptables junk_filter chain on #{Socket.gethostname}'")
+ end
+ else
+ reply.fail! "#{ip} was already unblocked"
+ return
+ end
+
+ # check it was removed
+ if isblocked?(ip)
+ reply.fail! "IP left blocked, iptables says: #{out}"
+ else
+ if out
+ reply[:output] = out
+ else
+ reply[:output] = "#{ip} was unblocked"
+ end
+ end
+ end
+
+ # Deals with requests for status of a ip
+ def isblocked(ip)
+ if isblocked?(ip)
+ reply[:output] = "#{ip} is blocked"
+ else
+ reply[:output] = "#{ip} is not blocked"
+ end
+ end
+
+ # Utility to figure out if a ip is blocked or not, just return true or false
+ def isblocked?(ip)
+ logger.debug("Checking if #{ip} is blocked with target #{target}")
+
+ if respond_to?(:run)
+ prematches = ""
+ run("/sbin/iptables -L junk_filter -n 2>&1", :stdout => prematches, :chomp => true)
+ else
+ prematches = %x[/sbin/iptables -L junk_filter -n 2>&1]
+ end
+
+ matches = prematches.split("\n").grep(/^#{target}.+#{ip}/).size
+ matches >= 1
+ end
+
+ # Returns a list of blocked ips
+ def listblocked
+ if respond_to?(:run)
+ preout = ""
+ run("/sbin/iptables -L junk_filter -n 2>&1", :stdout => preout, :chomp => true)
+ else
+ preout = %x[/sbin/iptables -L junk_filter -n 2>&1]
+ end
+
+ out = preout.split("\n").grep(/^#{target}/)
+ out.map {|l| l.split(/\s+/)[3]}
+ end
+
+ # Returns the target to use for rules
+ def target
+ target = "DROP"
+
+ if @config.pluginconf.include?("iptables.target")
+ target = @config.pluginconf["iptables.target"]
+ end
+
+ target
+ end
end
+ end
end
-# vi:tabstop=4:expandtab:ai:filetype=ruby
+# vi:tabstop=2:expandtab:ai:filetype=ruby
View
86 agent/iptables-junkfilter/application/iptables.rb
@@ -1,50 +1,50 @@
class MCollective::Application::Iptables<MCollective::Application
- description "Linux IP Tables Junkfilter Client"
- usage "iptables [block|unblock|isblocked] 1.2.3.4"
-
- option :silent,
- :description => "Do not wait for results",
- :arguments => "-s",
- :type => :bool
-
- def post_option_parser(configuration)
- if ARGV.size == 2
- configuration[:command] = ARGV.shift
- configuration[:ipaddress] = ARGV.shift
- end
- end
-
- def validate_configuration(configuration)
- raise "Command should be one of block, unblock or isblocked" unless configuration[:command] =~ /^block|unblock|isblocked$/
-
- require 'ipaddr'
- ip = IPAddr.new(configuration[:ipaddress])
- raise "#{configuration[:ipaddress]} should be an ipv4 address" unless ip.ipv4?
+ description "Linux IP Tables Junkfilter Client"
+ usage "iptables [block|unblock|isblocked] 1.2.3.4"
+
+ option :silent,
+ :description => "Do not wait for results",
+ :arguments => "-s",
+ :type => :bool
+
+ def post_option_parser(configuration)
+ if ARGV.size == 2
+ configuration[:command] = ARGV.shift
+ configuration[:ipaddress] = ARGV.shift
end
-
- def main
- iptables = rpcclient("iptables")
-
- if configuration[:silent]
- puts "Sent request " << iptables.send(configuration[:command], {:ipaddr => configuration[:ipaddress], :process_results => false})
+ end
+
+ def validate_configuration(configuration)
+ raise "Command should be one of block, unblock or isblocked" unless configuration[:command] =~ /^block|unblock|isblocked$/
+
+ require 'ipaddr'
+ ip = IPAddr.new(configuration[:ipaddress])
+ raise "#{configuration[:ipaddress]} should be an ipv4 address" unless ip.ipv4?
+ end
+
+ def main
+ iptables = rpcclient("iptables")
+
+ if configuration[:silent]
+ puts "Sent request " << iptables.send(configuration[:command], {:ipaddr => configuration[:ipaddress], :process_results => false})
+ else
+ iptables.send(configuration[:command], {:ipaddr => configuration[:ipaddress]}).each do |node|
+ if iptables.verbose
+ printf("%-40s %s\n", node[:sender], node[:statusmsg])
+ puts "\t\t#{node[:data][:output]}" if node[:data][:output]
else
- iptables.send(configuration[:command], {:ipaddr => configuration[:ipaddress]}).each do |node|
- if iptables.verbose
- printf("%-40s %s\n", node[:sender], node[:statusmsg])
- puts "\t\t#{node[:data][:output]}" if node[:data][:output]
- else
- case configuration[:command]
- when /^block|unblock/
- printf("%-40s %s\n", node[:sender], node[:statusmsg]) unless node[:statuscode] == 0
- when "isblocked"
- printf("%-40s %s\n", node[:sender], node[:data][:output])
- end
- end
- end
-
- printrpcstats
+ case configuration[:command]
+ when /^block|unblock/
+ printf("%-40s %s\n", node[:sender], node[:statusmsg]) unless node[:statuscode] == 0
+ when "isblocked"
+ printf("%-40s %s\n", node[:sender], node[:data][:output])
+ end
end
+ end
+
+ printrpcstats
end
+ end
end
-# vi:tabstop=4:expandtab:ai
+# vi:tabstop=2:expandtab:ai
View
85 agent/nettest/agent/nettest.rb
@@ -4,57 +4,56 @@
require 'timeout'
module MCollective
- module Agent
- class Nettest<RPC::Agent
+ module Agent
+ class Nettest<RPC::Agent
- metadata :name => "Ping",
- :description => "Agent to do network tests from a mcollective host",
- :author => "Dean Smith",
- :license => "BSD",
- :version => "1.0",
- :url => "http://github.com/deasmi",
- :timeout => 60
+ metadata :name => "Ping",
+ :description => "Agent to do network tests from a mcollective host",
+ :author => "Dean Smith",
+ :license => "BSD",
+ :version => "1.0",
+ :url => "http://github.com/deasmi",
+ :timeout => 60
- action "ping" do
- validate :fqdn,String
+ action "ping" do
+ validate :fqdn,String
- fqdn = request[:fqdn]
+ fqdn = request[:fqdn]
- icmp = Net::Ping::ICMP.new(fqdn)
+ icmp = Net::Ping::ICMP.new(fqdn)
- if icmp.ping? then
- reply[:rtt] = (icmp.duration*1000).to_s
- else
- reply[:rtt]="Host did not respond"
- end
- end
+ if icmp.ping? then
+ reply[:rtt] = (icmp.duration*1000).to_s
+ else
+ reply[:rtt]="Host did not respond"
+ end
+ end
+
+ action "connect" do
+
+ validate :fqdn,String
+ validate :port,String
+
+ fqdn = request[:fqdn]
+ port = request[:port]
+
+ begin
+ Timeout::timeout(2) do
- action "connect" do
-
- validate :fqdn,String
- validate :port,String
-
- fqdn = request[:fqdn]
- port = request[:port]
-
- begin
- Timeout::timeout(2) do
-
- begin
- t=TCPSocket.new(fqdn,port)
- rescue
- reply[:connect]="Connection Refused"
- else
- reply[:connect] = "Connected"
- t.close
- end
- end
- rescue Timeout::Error
- reply[:connect]="Connection timeout"
- end
+ begin
+ t=TCPSocket.new(fqdn,port)
+ rescue
+ reply[:connect]="Connection Refused"
+ else
+ reply[:connect] = "Connected"
+ t.close
end
+ end
+ rescue Timeout::Error
+ reply[:connect]="Connection timeout"
end
+ end
end
+ end
end
-
View
298 agent/nettest/application/nettest.rb
@@ -1,8 +1,8 @@
module MCollective
- class Application::Nettest < Application
- description "Network tests from a mcollective host"
+ class Application::Nettest < Application
+ description "Network tests from a mcollective host"
- usage <<-END_OF_USAGE
+ usage <<-END_OF_USAGE
mco nettest [OPTIONS] [FILTERS] <ACTION> <HOST NAME> [PORT]
The ACTION can be one of the following:
@@ -11,161 +11,161 @@ class Application::Nettest < Application
connect - check connectivity of remote host on specific port
END_OF_USAGE
- def print_statistics(statistics, action_statistics, type)
- print "\n---- nettest summary ----\n"
- puts " Nodes: #{statistics[:responses] +
+ def print_statistics(statistics, action_statistics, type)
+ print "\n---- nettest summary ----\n"
+ puts " Nodes: #{statistics[:responses] +
statistics[:noresponsefrom].size} / #{statistics[:responses]}"
- print " Results: "
-
- if action_statistics.size > 0
- case type
- when /^ping$/
- times = action_statistics[:ping]
-
- sum = times.inject(0) { |v, i| v + i }
- average = sum / times.size.to_f
-
- printf("replies=%d, maximum=%.3f ms, " +
- "minimum=%.3f ms, average=%.3f ms", times.size,
- times.max, times.min, average)
-
- when /^connect$/
- printf("connected=%d, connection refused=%d, " +
- "timed out=%d", action_statistics[:connect][0],
- action_statistics[:connect][1],
- action_statistics[:connect][2])
- end
- else
- print "No responses received"
- end
-
- printf("\n Elapsed Time: %.2f s\n\n", statistics[:blocktime])
+ print " Results: "
+
+ if action_statistics.size > 0
+ case type
+ when /^ping$/
+ times = action_statistics[:ping]
+
+ sum = times.inject(0) { |v, i| v + i }
+ average = sum / times.size.to_f
+
+ printf("replies=%d, maximum=%.3f ms, " +
+ "minimum=%.3f ms, average=%.3f ms", times.size,
+ times.max, times.min, average)
+
+ when /^connect$/
+ printf("connected=%d, connection refused=%d, " +
+ "timed out=%d", action_statistics[:connect][0],
+ action_statistics[:connect][1],
+ action_statistics[:connect][2])
+ end
+ else
+ print "No responses received"
+ end
+
+ printf("\n Elapsed Time: %.2f s\n\n", statistics[:blocktime])
+ end
+
+ def post_option_parser(configuration)
+ if ARGV.size < 2
+ raise "Please specify an action and optional arguments"
+ else
+ #
+ # We trust that validation will be handled correctly
+ # as per accompanying DDL file ...
+ #
+ action = ARGV.shift
+
+ host_name = ARGV.shift
+ remote_port = ARGV.shift
+
+ unless action.match(/^(ping|connect)$/)
+ raise "Action can only to be ping or connect"
end
- def post_option_parser(configuration)
- if ARGV.size < 2
- raise "Please specify an action and optional arguments"
- else
- #
- # We trust that validation will be handled correctly
- # as per accompanying DDL file ...
- #
- action = ARGV.shift
-
- host_name = ARGV.shift
- remote_port = ARGV.shift
-
- unless action.match(/^(ping|connect)$/)
- raise "Action can only to be ping or connect"
- end
-
- case action
- when /^ping$/
- arguments = { :fqdn => host_name }
- when /^connect$/
- arguments = { :fqdn => host_name,
- :port => remote_port }
- end
-
- configuration[:action] = action
- configuration[:arguments] = arguments
- end
+ case action
+ when /^ping$/
+ arguments = { :fqdn => host_name }
+ when /^connect$/
+ arguments = { :fqdn => host_name,
+ :port => remote_port }
end
- def validate_configuration(configuration)
- #
- # We have to ask this question because you do NOT want
- # your entire network of bazillion machines to simply
- # go and hammer some poor remote host ... You may get
- # your network blocked or whatnot, and that would be
- # quite an unpleasant thing to have place so better to
- # be sorry and safe ...
- #
- if MCollective::Util.empty_filter?(options[:filter])
- print "Do you really want to perform network " +
- "tests unfiltered? (y/n): "
-
- STDOUT.flush
-
- # Only match letter "y" or complete word "yes" ...
- exit! unless STDIN.gets.strip.match(/^(?:y|yes)$/i)
- end
+ configuration[:action] = action
+ configuration[:arguments] = arguments
+ end
+ end
+
+ def validate_configuration(configuration)
+ #
+ # We have to ask this question because you do NOT want
+ # your entire network of bazillion machines to simply
+ # go and hammer some poor remote host ... You may get
+ # your network blocked or whatnot, and that would be
+ # quite an unpleasant thing to have place so better to
+ # be sorry and safe ...
+ #
+ if MCollective::Util.empty_filter?(options[:filter])
+ print "Do you really want to perform network " +
+ "tests unfiltered? (y/n): "
+
+ STDOUT.flush
+
+ # Only match letter "y" or complete word "yes" ...
+ exit! unless STDIN.gets.strip.match(/^(?:y|yes)$/i)
+ end
+ end
+
+ def main
+ action_statistics = {}
+
+ action = configuration[:action]
+ arguments = configuration[:arguments]
+
+ rpc_nettest = rpcclient("nettest", { :options => options })
+
+ rpc_nettest.send(action, arguments).each do |node|
+
+ # We want new line here ...
+ puts if action_statistics.size.zero? and not rpc_nettest.progress
+
+ sender = node[:sender]
+ data = node[:data]
+
+ #
+ # If the status code is non-zero and data is empty then we
+ # assume that something out of an ordinary had place and
+ # therefore assume that there was some sort of error ...
+ #
+ unless node[:statuscode].zero? and data
+ result = "error"
+ else
+ result = data[:rtt] || data[:connect]
end
- def main
- action_statistics = {}
-
- action = configuration[:action]
- arguments = configuration[:arguments]
-
- rpc_nettest = rpcclient("nettest", { :options => options })
-
- rpc_nettest.send(action, arguments).each do |node|
-
- # We want new line here ...
- puts if action_statistics.size.zero? and not rpc_nettest.progress
-
- sender = node[:sender]
- data = node[:data]
-
- #
- # If the status code is non-zero and data is empty then we
- # assume that something out of an ordinary had place and
- # therefore assume that there was some sort of error ...
- #
- unless node[:statuscode].zero? and data
- result = "error"
- else
- result = data[:rtt] || data[:connect]
- end
-
- case action
- when /^ping$/
- action_statistics[:ping] ||= []
-
- if result.match(/^[0-9\.]+$/)
- action_statistics[:ping] << result.to_f
- result = sprintf("%.3f", result)
- else
- action_statistics[:ping] << 0.0
- end
-
- if rpc_nettest.verbose
- printf("%-40s time=%s\n", sender, result)
- puts "\t\t#{node[:statusmsg]}"
- else
- printf("%-40s time=%s\n", sender, result)
- end
-
- when /^connect$/
- action_statistics[:connect] ||= [ 0, 0, 0 ]
-
- # This is to be in line with the usual format of output ...
- result = result.tr("A-Z", "a-z")
-
- case result
- when /^connected$/
- action_statistics[:connect][0] += 1
- when /refused$/
- action_statistics[:connect][1] += 1
- when /timeout$/
- action_statistics[:connect][2] += 1
- end
-
- if rpc_nettest.verbose
- printf("%-40s status=%s\n", sender, result)
- puts "\t\t#{node[:statusmsg]}"
- else
- printf("%-40s status=%s\n", sender, result)
- end
- end
- end
-
- rpc_nettest.disconnect
-
- print_statistics(rpc_nettest.stats, action_statistics, action)
+ case action
+ when /^ping$/
+ action_statistics[:ping] ||= []
+
+ if result.match(/^[0-9\.]+$/)
+ action_statistics[:ping] << result.to_f
+ result = sprintf("%.3f", result)
+ else
+ action_statistics[:ping] << 0.0
+ end
+
+ if rpc_nettest.verbose
+ printf("%-40s time=%s\n", sender, result)
+ puts "\t\t#{node[:statusmsg]}"
+ else
+ printf("%-40s time=%s\n", sender, result)
+ end
+
+ when /^connect$/
+ action_statistics[:connect] ||= [ 0, 0, 0 ]
+
+ # This is to be in line with the usual format of output ...
+ result = result.tr("A-Z", "a-z")
+
+ case result
+ when /^connected$/
+ action_statistics[:connect][0] += 1
+ when /refused$/
+ action_statistics[:connect][1] += 1
+ when /timeout$/
+ action_statistics[:connect][2] += 1
+ end
+
+ if rpc_nettest.verbose
+ printf("%-40s status=%s\n", sender, result)
+ puts "\t\t#{node[:statusmsg]}"
+ else
+ printf("%-40s status=%s\n", sender, result)
+ end
end
+ end
+
+ rpc_nettest.disconnect
+
+ print_statistics(rpc_nettest.stats, action_statistics, action)
end
+ end
end
# vim: set ts=4 sw=4 et :
View
148 agent/nrpe/agent/nrpe.rb
@@ -1,85 +1,85 @@
module MCollective
- module Agent
- class Nrpe<RPC::Agent
- metadata :name => "SimpleRPC Agent For NRPE Commands",
- :description => "Agent to query NRPE commands via MCollective",
- :author => "R.I.Pienaar",
- :license => "Apache 2",
- :version => "2.0",
- :url => "http://projects.puppetlabs.com/projects/mcollective-plugins/wiki",
- :timeout => 5
-
- action "runcommand" do
- validate :command, :shellsafe
-
- command = plugin_for_command(request[:command])
-
- if command == nil
- reply[:output] = "No such command: #{request[:command]}" if command == nil
- reply[:exitcode] = 3
-
- reply.fail "UNKNOWN"
-
- return
- end
-
- if respond_to?(:run)
- reply[:exitcode] = run(command[:cmd], :stdout => :output, :chomp => true)
- else
- reply[:output] = %x[#{command[:cmd]}].chomp
- reply[:exitcode] = $?.exitstatus
- end
-
- case reply[:exitcode]
- when 0
- reply.statusmsg = "OK"
-
- when 1
- reply.fail "WARNING"
-
- when 2
- reply.fail "CRITICAL"
-
- else
- reply.fail "UNKNOWN"
-
- end
-
- if reply[:output] =~ /^(.+)\|(.+)$/
- reply[:output] = $1
- reply[:perfdata] = $2
- else
- reply[:perfdata] = ""
- end
- end
+ module Agent
+ class Nrpe<RPC::Agent
+ metadata :name => "SimpleRPC Agent For NRPE Commands",
+ :description => "Agent to query NRPE commands via MCollective",
+ :author => "R.I.Pienaar",
+ :license => "Apache 2",
+ :version => "2.0",
+ :url => "http://projects.puppetlabs.com/projects/mcollective-plugins/wiki",
+ :timeout => 5
+
+ action "runcommand" do
+ validate :command, :shellsafe
+
+ command = plugin_for_command(request[:command])
+
+ if command == nil
+ reply[:output] = "No such command: #{request[:command]}" if command == nil
+ reply[:exitcode] = 3
+
+ reply.fail "UNKNOWN"
+
+ return
+ end
+
+ if respond_to?(:run)
+ reply[:exitcode] = run(command[:cmd], :stdout => :output, :chomp => true)
+ else
+ reply[:output] = %x[#{command[:cmd]}].chomp
+ reply[:exitcode] = $?.exitstatus
+ end
- private
- def plugin_for_command(req)
- ret = nil
- fname = nil
+ case reply[:exitcode]
+ when 0
+ reply.statusmsg = "OK"
- fdir = config.pluginconf["nrpe.conf_dir"] || "/etc/nagios/nrpe.d"
+ when 1
+ reply.fail "WARNING"
- if config.pluginconf["nrpe.conf_file"]
- fname = "#{fdir}/#{config.pluginconf['nrpe.conf_file']}"
- else
- fname = "#{fdir}/#{req}.cfg"
- end
+ when 2
+ reply.fail "CRITICAL"
- if File.exist?(fname)
- t = File.readlines(fname)
- t.each do |check|
- check.chomp!
+ else
+ reply.fail "UNKNOWN"
- if check =~ /command\[#{request[:command]}\]=(.+)$/
- ret = {:cmd => $1}
- end
- end
- end
+ end
+
+ if reply[:output] =~ /^(.+)\|(.+)$/
+ reply[:output] = $1
+ reply[:perfdata] = $2
+ else
+ reply[:perfdata] = ""
+ end
+ end
+
+ private
+ def plugin_for_command(req)
+ ret = nil
+ fname = nil
+
+ fdir = config.pluginconf["nrpe.conf_dir"] || "/etc/nagios/nrpe.d"
- ret
+ if config.pluginconf["nrpe.conf_file"]
+ fname = "#{fdir}/#{config.pluginconf['nrpe.conf_file']}"
+ else
+ fname = "#{fdir}/#{req}.cfg"
+ end
+
+ if File.exist?(fname)
+ t = File.readlines(fname)
+ t.each do |check|
+ check.chomp!
+
+ if check =~ /command\[#{request[:command]}\]=(.+)$/
+ ret = {:cmd => $1}
end
+ end
end
+
+ ret
+ end
end
+ end
end
-# vi:tabstop=4:expandtab:ai
+# vi:tabstop=2:expandtab:ai
View
84 agent/nrpe/application/nrpe.rb
@@ -1,57 +1,57 @@
class MCollective::Application::Nrpe<MCollective::Application
- description "Client to the Nagios Remote Plugin Execution system"
- usage "Usage: nrpe <check_name>"
+ description "Client to the Nagios Remote Plugin Execution system"
+ usage "Usage: nrpe <check_name>"
- def post_option_parser(configuration)
- configuration[:command] = ARGV.shift if ARGV.size > 0
- end
+ def post_option_parser(configuration)
+ configuration[:command] = ARGV.shift if ARGV.size > 0
+ end
- def validate_configuration(configuration)
- raise "Please specify a check name" unless configuration.include?(:command)
- end
+ def validate_configuration(configuration)
+ raise "Please specify a check name" unless configuration.include?(:command)
+ end
- def main
- nrpe = rpcclient("nrpe")
+ def main
+ nrpe = rpcclient("nrpe")
- stats = [0, 0, 0, 0]
- statuscodes = [0]
+ stats = [0, 0, 0, 0]
+ statuscodes = [0]
- nrpe_results = nrpe.runcommand(:command => configuration[:command])
+ nrpe_results = nrpe.runcommand(:command => configuration[:command])
- puts
+ puts
- nrpe_results.each do |result|
- exitcode = result[:data][:exitcode].to_i
- statuscodes << exitcode
- if exitcode >=0 and exitcode < 4
- stats[exitcode] += 1
- end
+ nrpe_results.each do |result|
+ exitcode = result[:data][:exitcode].to_i
+ statuscodes << exitcode
+ if exitcode >=0 and exitcode < 4
+ stats[exitcode] += 1
+ end
- if nrpe.verbose
- printf("%-40s status=%s\n", result[:sender], result[:statusmsg])
- printf(" %-40s\n\n", result[:data][:output])
- else
- if [1,2,3].include?(exitcode)
- printf("%-40s status=%s\n", result[:sender], result[:statusmsg])
- printf(" %-40s\n\n", result[:data][:output]) if result[:data][:output]
- end
- end
+ if nrpe.verbose
+ printf("%-40s status=%s\n", result[:sender], result[:statusmsg])
+ printf(" %-40s\n\n", result[:data][:output])
+ else
+ if [1,2,3].include?(exitcode)
+ printf("%-40s status=%s\n", result[:sender], result[:statusmsg])
+ printf(" %-40s\n\n", result[:data][:output]) if result[:data][:output]
end
+ end
+ end
- puts
+ puts
- # Nodes that don't respond are UNKNOWNs
- if nrpe.stats[:noresponsefrom].size > 0
- stats[3] += nrpe.stats[:noresponsefrom].size
- statuscodes << 3
- end
+ # Nodes that don't respond are UNKNOWNs
+ if nrpe.stats[:noresponsefrom].size > 0
+ stats[3] += nrpe.stats[:noresponsefrom].size
+ statuscodes << 3
+ end
- printrpcstats :caption => "#{configuration[:command]} NRPE results"
+ printrpcstats :caption => "#{configuration[:command]} NRPE results"
- printf("\nNagios Statusses:\n") if nrpe.verbose
- printf(" OK: %d\n", stats[0])
- printf(" WARNING: %d\n", stats[1])
- printf(" CRITICAL: %d\n", stats[2])
- printf(" UNKNOWN: %d\n", stats[3])
- end
+ printf("\nNagios Statusses:\n") if nrpe.verbose
+ printf(" OK: %d\n", stats[0])
+ printf(" WARNING: %d\n", stats[1])
+ printf(" CRITICAL: %d\n", stats[2])
+ printf(" UNKNOWN: %d\n", stats[3])
+ end
end
View
142 agent/nrpe/spec/nrpe_agent_spec.rb
@@ -3,87 +3,87 @@
require File.join([File.dirname(__FILE__), '/../../../spec/spec_helper'])
describe "nrpe agent" do
- before do
- agent_file = File.join([File.dirname(__FILE__), "../agent/nrpe.rb"])
- @agent = MCollective::Test::LocalAgentTest.new("nrpe", :agent_file => agent_file).plugin
- end
+ before do
+ agent_file = File.join([File.dirname(__FILE__), "../agent/nrpe.rb"])
+ @agent = MCollective::Test::LocalAgentTest.new("nrpe", :agent_file => agent_file).plugin
+ end
- describe "#metda" do
- it "should have valid metadata" do
- @agent.should have_valid_metadata
- end
+ describe "#metda" do
+ it "should have valid metadata" do
+ @agent.should have_valid_metadata
end
+ end
- describe "#runcommand" do
- it "should reply with statusmessage 'OK' of exitcode is 0" do
- @agent.expects(:plugin_for_command).with("foo").returns:cmd => ("foo")
- @agent.expects(:run).with("foo", :stdout => :output, :chomp => true).returns(0)
- result = @agent.call(:runcommand, :command => "foo")
- result.should be_successful
- result.should have_data_items(:exitcode=>0, :perfdata=>"")
- result[:statusmsg].should == "OK"
- end
-
- it "should reply with statusmessage 'WARNING' of exitcode is 1" do
- @agent.expects(:plugin_for_command).with("foo").returns:cmd => ("foo")
- @agent.expects(:run).with("foo", :stdout => :output, :chomp => true).returns(1)
- result = @agent.call(:runcommand, :command => "foo")
- result.should be_aborted_error
- result.should have_data_items(:exitcode=>1, :perfdata=>"")
- result[:statusmsg].should == "WARNING"
- end
+ describe "#runcommand" do
+ it "should reply with statusmessage 'OK' of exitcode is 0" do
+ @agent.expects(:plugin_for_command).with("foo").returns:cmd => ("foo")
+ @agent.expects(:run).with("foo", :stdout => :output, :chomp => true).returns(0)
+ result = @agent.call(:runcommand, :command => "foo")
+ result.should be_successful
+ result.should have_data_items(:exitcode=>0, :perfdata=>"")
+ result[:statusmsg].should == "OK"
+ end
- it "should reply with statusmessage 'CRITICAL' of exitcode is 2" do
- @agent.expects(:plugin_for_command).with("foo").returns:cmd => ("foo")
- @agent.expects(:run).with("foo", :stdout => :output, :chomp => true).returns(2)
- result = @agent.call(:runcommand, :command => "foo")
- result.should be_aborted_error
- result.should have_data_items(:exitcode=>2, :perfdata=>"")
- result[:statusmsg].should == "CRITICAL"
- end
+ it "should reply with statusmessage 'WARNING' of exitcode is 1" do
+ @agent.expects(:plugin_for_command).with("foo").returns:cmd => ("foo")
+ @agent.expects(:run).with("foo", :stdout => :output, :chomp => true).returns(1)
+ result = @agent.call(:runcommand, :command => "foo")
+ result.should be_aborted_error
+ result.should have_data_items(:exitcode=>1, :perfdata=>"")
+ result[:statusmsg].should == "WARNING"
+ end
- it "should reply with statusmessage UKNOWN if exitcode is something else" do
- @agent.expects(:plugin_for_command).with("foo").returns:cmd => ("foo")
- @agent.expects(:run).with("foo", :stdout => :output, :chomp => true)
- result = @agent.call(:runcommand, :command => "foo")
- result.should be_aborted_error
- result.should have_data_items(:exitcode=>nil, :perfdata=>"")
- result[:statusmsg].should == "UNKNOWN"
- end
+ it "should reply with statusmessage 'CRITICAL' of exitcode is 2" do
+ @agent.expects(:plugin_for_command).with("foo").returns:cmd => ("foo")
+ @agent.expects(:run).with("foo", :stdout => :output, :chomp => true).returns(2)
+ result = @agent.call(:runcommand, :command => "foo")
+ result.should be_aborted_error
+ result.should have_data_items(:exitcode=>2, :perfdata=>"")
+ result[:statusmsg].should == "CRITICAL"
+ end
- it "should fail on an unknown command" do
- @agent.expects(:plugin_for_command).with("foo").returns(nil)
- result = @agent.call(:runcommand, :command => "foo")
- result.should be_aborted_error
- result.should have_data_items(:output => "No such command: foo", :exitcode => 3)
- end
+ it "should reply with statusmessage UKNOWN if exitcode is something else" do
+ @agent.expects(:plugin_for_command).with("foo").returns:cmd => ("foo")
+ @agent.expects(:run).with("foo", :stdout => :output, :chomp => true)
+ result = @agent.call(:runcommand, :command => "foo")
+ result.should be_aborted_error
+ result.should have_data_items(:exitcode=>nil, :perfdata=>"")
+ result[:statusmsg].should == "UNKNOWN"
end
- describe "#plugin_for_command" do
- it "should return the command from nrpe.conf_dir if it is set" do
- @agent.config.stubs(:pluginconf).returns("nrpe.conf_dir" => "/foo", "nrpe.conf_file" => "bar.cfg")
- @agent.stubs(:request).returns(:command => "command")
- File.expects(:exist?).with("/foo/bar.cfg").returns(true)
- File.expects(:readlines).with("/foo/bar.cfg").returns(["command[command]=run"])
- @agent.expects(:run).with("run", :stdout => :output, :chomp => true).returns(0)
- result = @agent.call(:runcommand, :command => "run")
- result.should be_successful
- result.should have_data_items(:exitcode=>0, :perfdata=>"")
- result[:statusmsg].should == "OK"
- end
+ it "should fail on an unknown command" do
+ @agent.expects(:plugin_for_command).with("foo").returns(nil)
+ result = @agent.call(:runcommand, :command => "foo")
+ result.should be_aborted_error
+ result.should have_data_items(:output => "No such command: foo", :exitcode => 3)
+ end
+ end
- it "should return the command from /etc/nagios/nrpe.d if nrpe.conf_dir is unset" do
- @agent.config.stubs(:pluginconf).returns("")
- @agent.stubs(:request).returns(:command => "command")
- File.expects(:exist?).with("/etc/nagios/nrpe.d/command.cfg").returns(true)
- File.expects(:readlines).with("/etc/nagios/nrpe.d/command.cfg").returns(["command[command]=run"])
- @agent.expects(:run).with("run", :stdout => :output, :chomp => true).returns(0)
- result = @agent.call(:runcommand, :command => "run")
- result.should be_successful
- result.should have_data_items(:exitcode=>0, :perfdata=>"")
- result[:statusmsg].should == "OK"
- end
+ describe "#plugin_for_command" do
+ it "should return the command from nrpe.conf_dir if it is set" do
+ @agent.config.stubs(:pluginconf).returns("nrpe.conf_dir" => "/foo", "nrpe.conf_file" => "bar.cfg")
+ @agent.stubs(:request).returns(:command => "command")
+ File.expects(:exist?).with("/foo/bar.cfg").returns(true)
+ File.expects(:readlines).with("/foo/bar.cfg").returns(["command[command]=run"])
+ @agent.expects(:run).with("run", :stdout => :output, :chomp => true).returns(0)
+ result = @agent.call(:runcommand, :command => "run")
+ result.should be_successful
+ result.should have_data_items(:exitcode=>0, :perfdata=>"")
+ result[:statusmsg].should == "OK"
+ end
+ it "should return the command from /etc/nagios/nrpe.d if nrpe.conf_dir is unset" do
+ @agent.config.stubs(:pluginconf).returns("")
+ @agent.stubs(:request).returns(:command => "command")
+ File.expects(:exist?).with("/etc/nagios/nrpe.d/command.cfg").returns(true)
+ File.expects(:readlines).with("/etc/nagios/nrpe.d/command.cfg").returns(["command[command]=run"])
+ @agent.expects(:run).with("run", :stdout => :output, :chomp => true).returns(0)
+ result = @agent.call(:runcommand, :command => "run")
+ result.should be_successful
+ result.should have_data_items(:exitcode=>0, :perfdata=>"")
+ result[:statusmsg].should == "OK"
end
+ end
+
end
View
294 agent/package/agent/puppet-package.rb
@@ -1,169 +1,169 @@
module MCollective
- module Agent
- # An agent that uses Reductive Labs Puppet to manage packages
- #
- # See http://code.google.com/p/mcollective-plugins/
- #
- # Released under the terms of the GPL, same as Puppet
- class Package<RPC::Agent
- metadata :name => "SimpleRPC Agent For Package Management",
- :description => "Agent To Manage Packages",
- :author => "R.I.Pienaar",
- :license => "Apache 2",
- :version => "1.4",
- :url => "http://projects.puppetlabs.com/projects/mcollective-plugins/wiki",
- :timeout => 180
-
- ["install", "update", "uninstall", "purge", "status"].each do |act|
- action act do
- validate :package, :shellsafe
- do_pkg_action(request[:package], act.to_sym)
- end
- end
-
- action "yum_clean" do
- reply.fail! "Cannot find yum at /usr/bin/yum" unless File.exist?("/usr/bin/yum")
- if respond_to?(:run)
- reply[:exitcode] = run("/usr/bin/yum clean all", :stdout => :output, :chomp => true)
- else
- reply[:output] = %x[/usr/bin/yum clean all]
- reply[:exitcode] = $?.exitstatus
- end
+ module Agent
+ # An agent that uses Reductive Labs Puppet to manage packages
+ #
+ # See http://code.google.com/p/mcollective-plugins/
+ #
+ # Released under the terms of the GPL, same as Puppet
+ class Package<RPC::Agent
+ metadata :name => "SimpleRPC Agent For Package Management",
+ :description => "Agent To Manage Packages",
+ :author => "R.I.Pienaar",
+ :license => "Apache 2",
+ :version => "1.4",
+ :url => "http://projects.puppetlabs.com/projects/mcollective-plugins/wiki",
+ :timeout => 180
+
+ ["install", "update", "uninstall", "purge", "status"].each do |act|
+ action act do
+ validate :package, :shellsafe
+ do_pkg_action(request[:package], act.to_sym)
+ end
+ end
+
+ action "yum_clean" do
+ reply.fail! "Cannot find yum at /usr/bin/yum" unless File.exist?("/usr/bin/yum")
+ if respond_to?(:run)
+ reply[:exitcode] = run("/usr/bin/yum clean all", :stdout => :output, :chomp => true)
+ else
+ reply[:output] = %x[/usr/bin/yum clean all]
+ reply[:exitcode] = $?.exitstatus
+ end
- reply.fail! "Yum clean failed, exit code was #{reply[:exitcode]}" unless reply[:exitcode] == 0
- end
+ reply.fail! "Yum clean failed, exit code was #{reply[:exitcode]}" unless reply[:exitcode] == 0
+ end
- action "apt_update" do
- reply.fail! "Cannot find apt-get at /usr/bin/apt-get" unless File.exist?("/usr/bin/apt-get")
- if respond_to?(:run)
- reply[:exitcode] = run("/usr/bin/apt-get update", :stdout => :output, :chomp => true)
- else
- reply[:output] = %x[/usr/bin/apt-get update]
- reply[:exitcode] = $?.exitstatus
- end
+ action "apt_update" do
+ reply.fail! "Cannot find apt-get at /usr/bin/apt-get" unless File.exist?("/usr/bin/apt-get")
+ if respond_to?(:run)
+ reply[:exitcode] = run("/usr/bin/apt-get update", :stdout => :output, :chomp => true)
+ else
+ reply[:output] = %x[/usr/bin/apt-get update]
+ reply[:exitcode] = $?.exitstatus
+ end
- reply.fail! "apt-get update failed, exit code was #{reply[:exitcode]}" unless reply[:exitcode] == 0
- end
+ reply.fail! "apt-get update failed, exit code was #{reply[:exitcode]}" unless reply[:exitcode] == 0
+ end
+
+ action "checkupdates" do
+ if File.exist?("/usr/bin/yum")
+ reply[:package_manager] = "yum"
+ yum_checkupdates_action
+ elsif File.exist?("/usr/bin/apt-get")
+ reply[:package_manager] = "apt"
+ apt_checkupdates_action
+ else
+ reply.fail! "Cannot find a compatible package system to check updates for"
+ end
+ end
+
+ action "yum_checkupdates" do
+ reply.fail! "Cannot find yum at /usr/bin/yum" unless File.exist?("/usr/bin/yum")
+ if respond_to?(:run)
+ reply[:exitcode] = run("/usr/bin/yum -q check-update", :stdout => :output, :chomp => true)
+ else
+ reply[:output] = %x[/usr/bin/yum -q check-update]
+ reply[:exitcode] = $?.exitstatus
+ end
- action "checkupdates" do
- if File.exist?("/usr/bin/yum")
- reply[:package_manager] = "yum"
- yum_checkupdates_action
- elsif File.exist?("/usr/bin/apt-get")
- reply[:package_manager] = "apt"
- apt_checkupdates_action
- else
- reply.fail! "Cannot find a compatible package system to check updates for"
- end
- end
+ if reply[:exitcode] == 0
+ reply[:outdated_packages] = []
+ # Exit code 100 means package updates available
+ elsif reply[:exitcode] == 100
+ reply[:outdated_packages] = do_yum_outdated_packages(reply[:output])
+ else
+ reply.fail! "Yum check-update failed, exit code was #{reply[:exitcode]}"
+ end
+ end
+
+ action "apt_checkupdates" do
+ reply.fail! "Cannot find apt at /usr/bin/apt-get" unless File.exist?("/usr/bin/apt-get")
+ if respond_to?(:run)
+ reply[:exitcode] = run("/usr/bin/apt-get --simulate dist-upgrade", :stdout => :output, :chomp => true)
+ else
+ reply[:output] = %x[/usr/bin/apt-get --simulate dist-upgrade]
+ reply[:exitcode] = $?.exitstatus
+ end
+ reply[:outdated_packages] = []
- action "yum_checkupdates" do
- reply.fail! "Cannot find yum at /usr/bin/yum" unless File.exist?("/usr/bin/yum")
- if respond_to?(:run)
- reply[:exitcode] = run("/usr/bin/yum -q check-update", :stdout => :output, :chomp => true)
- else
- reply[:output] = %x[/usr/bin/yum -q check-update]
- reply[:exitcode] = $?.exitstatus
- end
-
- if reply[:exitcode] == 0
- reply[:outdated_packages] = []
- # Exit code 100 means package updates available
- elsif reply[:exitcode] == 100
- reply[:outdated_packages] = do_yum_outdated_packages(reply[:output])
- else
- reply.fail! "Yum check-update failed, exit code was #{reply[:exitcode]}"
- end
- end
+ if reply[:exitcode] == 0
+ reply[:output].each_line do |line|
+ next unless line =~ /^Inst/
- action "apt_checkupdates" do
- reply.fail! "Cannot find apt at /usr/bin/apt-get" unless File.exist?("/usr/bin/apt-get")
- if respond_to?(:run)
- reply[:exitcode] = run("/usr/bin/apt-get --simulate dist-upgrade", :stdout => :output, :chomp => true)
- else
- reply[:output] = %x[/usr/bin/apt-get --simulate dist-upgrade]
- reply[:exitcode] = $?.exitstatus
- end
- reply[:outdated_packages] = []
-
- if reply[:exitcode] == 0
- reply[:output].each_line do |line|
- next unless line =~ /^Inst/
-
- # Inst emacs23 [23.1+1-4ubuntu7] (23.1+1-4ubuntu7.1 Ubuntu:10.04/lucid-updates) []
- if line =~ /Inst (.+?) \[.+?\] \((.+?)\s(.+?)\)/
- reply[:outdated_packages] << {:package => $1.strip,
- :version => $2.strip,
- :repo => $3.strip}
- end
- end
- else
- reply.fail! "APT check-update failed, exit code was #{reply[:exitcode]}"
- end
+ # Inst emacs23 [23.1+1-4ubuntu7] (23.1+1-4ubuntu7.1 Ubuntu:10.04/lucid-updates) []
+ if line =~ /Inst (.+?) \[.+?\] \((.+?)\s(.+?)\)/
+ reply[:outdated_packages] << {:package => $1.strip,
+ :version => $2.strip,
+ :repo => $3.strip}
end
+ end
+ else
+ reply.fail! "APT check-update failed, exit code was #{reply[:exitcode]}"
+ end
+ end
- private
- def do_pkg_action(package, action)
- begin
- require 'puppet'
-
- if ::Puppet.version =~ /0.24/
- ::Puppet::Type.type(:package).clear
- pkg = ::Puppet::Type.type(:package).create(:name => package).provider
- else
- pkg = ::Puppet::Type.type(:package).new(:name => package).provider
- end
+ private
+ def do_pkg_action(package, action)
+ begin
+ require 'puppet'
- reply[:output] = ""
- reply[:properties] = "unknown"
+ if ::Puppet.version =~ /0.24/
+ ::Puppet::Type.type(:package).clear
+ pkg = ::Puppet::Type.type(:package).create(:name => package).provider
+ else
+ pkg = ::Puppet::Type.type(:package).new(:name => package).provider
+ end
- case action
- when :install
- reply[:output] = pkg.install if pkg.properties[:ensure] == :absent
+ reply[:output] = ""
+ reply[:properties] = "unknown"
- when :update
- reply[:output] = pkg.update unless pkg.properties[:ensure] == :absent
+ case action
+ when :install
+ reply[:output] = pkg.install if pkg.properties[:ensure] == :absent
- when :uninstall
- reply[:output] = pkg.uninstall unless pkg.properties[:ensure] == :absent
+ when :update
+ reply[:output] = pkg.update unless pkg.properties[:ensure] == :absent
- when :status
- pkg.flush
- reply[:output] = pkg.properties
+ when :uninstall
+ reply[:output] = pkg.uninstall unless pkg.properties[:ensure] == :absent
- when :purge
- reply[:output] = pkg.purge
+ when :status
+ pkg.flush
+ reply[:output] = pkg.properties
- else
- reply.fail "Unknown action #{action}"
- end
+ when :purge
+ reply[:output] = pkg.purge
- pkg.flush
- reply[:properties] = pkg.properties
- rescue Exception => e
- reply.fail e.to_s
- end
- end
+ else
+ reply.fail "Unknown action #{action}"
+ end
- def do_yum_outdated_packages(packages)
- outdated_pkgs = []
- packages.strip.each_line do |line|
- # Don't handle obsoleted packages for now
- break if line =~ /^Obsoleting\sPackages/i
-
- pkg, ver, repo = line.split
- if pkg && ver && repo
- pkginfo = { :package => pkg.strip,
- :version => ver.strip,
- :repo => repo.strip
- }
- outdated_pkgs << pkginfo
- end
- end
- outdated_pkgs
- end
+ pkg.flush
+ reply[:properties] = pkg.properties
+ rescue Exception => e
+ reply.fail e.to_s
+ end
+ end
+
+ def do_yum_outdated_packages(packages)
+ outdated_pkgs = []
+ packages.strip.each_line do |line|
+ # Don't handle obsoleted packages for now
+ break if line =~ /^Obsoleting\sPackages/i
+
+ pkg, ver, repo = line.split
+ if pkg && ver && repo
+ pkginfo = { :package => pkg.strip,
+ :version => ver.strip,
+ :repo => repo.strip
+ }
+ outdated_pkgs << pkginfo
+ end
end
+ outdated_pkgs
+ end
end
+ end
end
-# vi:tabstop=4:expandtab:ai:filetype=ruby
+# vi:tabstop=2:expandtab:ai:filetype=ruby
View
100 agent/package/application/package.rb
@@ -1,69 +1,69 @@
class MCollective::Application::Package<MCollective::Application
- description "Generic Package Manager"
- usage "Usage: mc package [options] action package"
+ description "Generic Package Manager"
+ usage "Usage: mc package [options] action package"
- def post_option_parser(configuration)
- if ARGV.length == 2
- configuration[:action] = ARGV.shift
- configuration[:package] = ARGV.shift
+ def post_option_parser(configuration)
+ if ARGV.length == 2
+ configuration[:action] = ARGV.shift
+ configuration[:package] = ARGV.shift
- unless configuration[:action] =~ /^(install|update|uninstall|purge|status)$/
- puts("Action has to be install, update, uninstall, purge or status")
- exit 1
- end
- else
- puts("Please specify a package and action")
- exit 1
- end
+ unless configuration[:action] =~ /^(install|update|uninstall|purge|status)$/
+ puts("Action has to be install, update, uninstall, purge or status")
+ exit 1
+ end
+ else
+ puts("Please specify a package and action")
+ exit 1
end
+ end
- def validate_configuration(configuration)
- if MCollective::Util.empty_filter?(options[:filter])
- print("Do you really want to operate on packages unfiltered? (y/n): ")
- STDOUT.flush
+ def validate_configuration(configuration)
+ if MCollective::Util.empty_filter?(options[:filter])
+ print("Do you really want to operate on packages unfiltered? (y/n): ")
+ STDOUT.flush
- exit unless STDIN.gets.chomp =~ /^y$/
- end
+ exit unless STDIN.gets.chomp =~ /^y$/
end
+ end
- def summarize(stats, versions)
- puts("\n---- package agent summary ----")
- puts(" Nodes: #{stats[:discovered]} / #{stats[:responses]}")
- print(" Versions: ")
+ def summarize(stats, versions)
+ puts("\n---- package agent summary ----")
+ puts(" Nodes: #{stats[:discovered]} / #{stats[:responses]}")
+ print(" Versions: ")
- puts versions.keys.sort.map {|s| "#{versions[s]} * #{s}" }.join(", ")
+ puts versions.keys.sort.map {|s| "#{versions[s]} * #{s}" }.join(", ")
- printf(" Elapsed Time: %.2f s\n\n", stats[:blocktime])
- end
+ printf(" Elapsed Time: %.2f s\n\n", stats[:blocktime])
+ end
- def main
- pkg = rpcclient("package", :options => options)
+ def main
+ pkg = rpcclient("package", :options => options)
- versions = {}
+ versions = {}
- pkg.send(configuration[:action], {:package => configuration[:package]}).each do |resp|
- status = resp[:data][:properties]
+ pkg.send(configuration[:action], {:package => configuration[:package]}).each do |resp|
+ status = resp[:data][:properties]
- if resp[:statuscode] == 0
- if status.include?(:version)
- version = "#{status[:version]}-#{status[:release]}"
- elsif status.include?(:ensure)
- version = status[:ensure].to_s
- end
+ if resp[:statuscode] == 0
+ if status.include?(:version)
+ version = "#{status[:version]}-#{status[:release]}"
+ elsif status.include?(:ensure)
+ version = status[:ensure].to_s
+ end
- versions.include?(version) ? versions[version] += 1 : versions[version] = 1
+ versions.include?(version) ? versions[version] += 1 : versions[version] = 1
- if status[:name]
- printf("%-40s version = %s-%s\n", resp[:sender], status[:name], version)
- else
- printf("%-40s version = %s\n", resp[:sender], version)
- end
- else
- printf("%-40s error = %s\n", resp[:sender], resp[:statusmsg])
- end
+ if status[:name]
+ printf("%-40s version = %s-%s\n", resp[:sender], status[:name], version)
+ else
+ printf("%-40s version = %s\n", resp[:sender], version)
end
-
- summarize(pkg.stats, versions)
+ else
+ printf("%-40s error = %s\n", resp[:sender], resp[:statusmsg])
+ end
end
+
+ summarize(pkg.stats, versions)
+ end
end
-# vi:tabstop=4:expandtab:ai
+# vi:tabstop=2:expandtab:ai
View
656 agent/package/spec/package_agent_spec.rb 100644 → 100755
@@ -3,376 +3,376 @@
require File.join([File.dirname(__FILE__), '/../../../spec/spec_helper'])
describe "package agent" do
- before do
- agent_file = File.join([File.dirname(__FILE__), "../agent/puppet-package.rb"])
- @agent = MCollective::Test::LocalAgentTest.new("package", :agent_file => agent_file).plugin
+ before do
+ agent_file = File.join([File.dirname(__FILE__), "../agent/puppet-package.rb"])
+ @agent = MCollective::Test::LocalAgentTest.new("package", :agent_file => agent_file).plugin
+ end
+ describe "#yum_clean" do
+ it "should fail if /usr/bin/yum doesn't exist" do
+ File.expects(:exist?).with("/usr/bin/yum").returns(false)
+ result = @agent.call(:yum_clean)
+ result.should be_aborted_error
+ result[:statusmsg].should == "Cannot find yum at /usr/bin/yum"
end
- describe "#yum_clean" do
- it "should fail if /usr/bin/yum doesn't exist" do
- File.expects(:exist?).with("/usr/bin/yum").returns(false)
- result = @agent.call(:yum_clean)
- result.should be_aborted_error
- result[:statusmsg].should == "Cannot find yum at /usr/bin/yum"
- end
-
- it "should succeed if the agent responds to 'run' and the run method returns 0" do
- File.expects(:exist?).with("/usr/bin/yum").returns(true)
- @agent.expects(:run).with("/usr/bin/yum clean all", :stdout => :output, :chomp => true).returns(0)
- result = @agent.call(:yum_clean)
- result.should have_data_items(:exitcode => 0)
- result.should be_successful
- end
- it "should fail if the agent responds to 'run' and the run method doesn't return 0" do
- File.expects(:exist?).with("/usr/bin/yum").returns(true)
- @agent.expects(:run).with("/usr/bin/yum clean all", :stdout => :output, :chomp => true).returns(1)
- result = @agent.call(:yum_clean)
- result.should have_data_items(:exitcode => 1)
- result.should be_aborted_error
- end
+ it "should succeed if the agent responds to 'run' and the run method returns 0" do
+ File.expects(:exist?).with("/usr/bin/yum").returns(true)
+ @agent.expects(:run).with("/usr/bin/yum clean all", :stdout => :output, :chomp => true).returns(0)
+ result = @agent.call(:yum_clean)
+ result.should have_data_items(:exitcode => 0)
+ result.should be_successful
end
- describe "#apt_update" do
- it "should fail if /usr/bin/apt-get doesn't exist" do
- File.expects(:exist?).with("/usr/bin/apt-get").returns(false)
- result = @agent.call(:apt_update)
- result.should be_aborted_error
- result[:statusmsg].should == "Cannot find apt-get at /usr/bin/apt-get"
- end
-
- it "should succeed if the agent responds to 'run' and the run method returns 0" do
- File.expects(:exist?).with("/usr/bin/apt-get").returns(true)
- @agent.expects(:run).with("/usr/bin/apt-get update", :stdout => :output, :chomp => true).returns(0)
- result = @agent.call(:apt_update)
- result.should have_data_items(:exitcode => 0)
- result.should be_successful
- end
-
- it "should fail if the agent responds to 'run' and the run method doesn't return 0" do
- File.expects(:exist?).with("/usr/bin/apt-get").returns(true)
- @agent.expects(:run).with("/usr/bin/apt-get update", :stdout => :output, :chomp => true).returns(1)
- result = @agent.call(:apt_update)
- result.should have_data_items(:exitcode => 1)
- result.should be_aborted_error
- end
+ it "should fail if the agent responds to 'run' and the run method doesn't return 0" do
+ File.expects(:exist?).with("/usr/bin/yum").returns(true)
+ @agent.expects(:run).with("/usr/bin/yum clean all", :stdout => :output, :chomp => true).returns(1)
+ result = @agent.call(:yum_clean)
+ result.should have_data_items(:exitcode => 1)
+ result.should be_aborted_error
+ end
+ end
+
+ describe "#apt_update" do
+ it "should fail if /usr/bin/apt-get doesn't exist" do
+ File.expects(:exist?).with("/usr/bin/apt-get").returns(false)
+ result = @agent.call(:apt_update)
+ result.should be_aborted_error
+ result[:statusmsg].should == "Cannot find apt-get at /usr/bin/apt-get"
end
- describe "#checkupdates" do
- it "should fail if neither /usr/bin/yum or /usr/bin/apt-get are present" do
- File.expects(:exist?).with("/usr/bin/yum").returns(false)
- File.expects(:exist?).with("/usr/bin/apt-get").returns(false)
- result = @agent.call(:checkupdates)
- result.should be_aborted_error
- result[:statusmsg].should == "Cannot find a compatible package system to check updates for"
- end
-
- it "should call yum_checkupdates if /usr/bin/yum exists" do
- File.expects(:exist?).with("/usr/bin/yum").returns(true)
- @agent.expects(:yum_checkupdates_action).returns(true)
- result = @agent.call(:checkupdates)
- result.should be_true
- result.should have_data_items(:package_manager=>"yum")
- end
+ it "should succeed if the agent responds to 'run' and the run method returns 0" do
+ File.expects(:exist?).with("/usr/bin/apt-get").returns(true)
+ @agent.expects(:run).with("/usr/bin/apt-get update", :stdout => :output, :chomp => true).returns(0)
+ result = @agent.call(:apt_update)
+ result.should have_data_items(:exitcode => 0)
+ result.should be_successful
+ end
- it "should call apt_checkupdates if /usr/bin/apt-get exists" do
- File.expects(:exist?).with("/usr/bin/yum").returns(false)
- File.expects(:exist?).with("/usr/bin/apt-get").returns(true)
- @agent.expects(:apt_checkupdates_action).returns(true)
- result = @agent.call(:checkupdates)
- result.should have_data_items(:package_manager=>"apt")
- result.should be_true
- end
+ it "should fail if the agent responds to 'run' and the run method doesn't return 0" do
+ File.expects(:exist?).with("/usr/bin/apt-get").returns(