choria-mcorpc-support 2.20.3 → 2.20.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d62fe592f222f86ab9be58dba46bf2e328558806
4
- data.tar.gz: f18f3623e930fd5d71e5241dff3c8b80d261aa89
3
+ metadata.gz: a3f6b0f73405083156308dae503d0498332bc81c
4
+ data.tar.gz: 7c780d21ec775ddbc5b17640682be709a343c94b
5
5
  SHA512:
6
- metadata.gz: '081312bf41443aaf3e70ad790bd294309d96d02d9e8aeb509fc52d81add8d92ab8509b4e695518479cf48937ba650d2e14679c7f6dd4985555e9e9f691f4db24'
7
- data.tar.gz: cd63595156866613e99116174cc879e57ac47159f91aa23f422a386fb986cafdb5c2f33312e63f068b60db3904b59d29b459e169c0e8ce1fc97f385b699d8a59
6
+ metadata.gz: 70b7fb634326c07bf3940692641a4e66b734d2388647186d25080025f019c66ad39b07f4b7d60b90e6a8da7171f6f6dbfbb7f5f79aced3e146149f5cc94828be
7
+ data.tar.gz: de2c15f4c16831773119ce0c167d3a17f9b55aa9f3546e0a90b017353879b74b198fd50b65839f251d387c93f3247faf81941bd54c7de4c85958953038da8b8c
@@ -1,20 +1,20 @@
1
- require 'rubygems'
2
- require 'json'
3
- require 'timeout'
4
- require 'digest/md5'
5
- require 'optparse'
6
- require 'singleton'
7
- require 'socket'
8
- require 'erb'
9
- require 'shellwords'
10
- require 'stringio'
11
- require 'rbconfig'
12
- require 'tempfile'
13
- require 'tmpdir'
14
- require 'mcollective/monkey_patches'
15
- require 'mcollective/cache'
16
- require 'mcollective/exceptions'
17
- require 'systemu'
1
+ require "rubygems"
2
+ require "json"
3
+ require "timeout"
4
+ require "digest/md5"
5
+ require "optparse"
6
+ require "singleton"
7
+ require "socket"
8
+ require "erb"
9
+ require "shellwords"
10
+ require "stringio"
11
+ require "rbconfig"
12
+ require "tempfile"
13
+ require "tmpdir"
14
+ require "mcollective/monkey_patches"
15
+ require "mcollective/cache"
16
+ require "mcollective/exceptions"
17
+ require "systemu"
18
18
 
19
19
  # == The Marionette Collective
20
20
  #
@@ -26,7 +26,6 @@ require 'systemu'
26
26
  # For an overview of the idea behind this and what it enables please see:
27
27
  # http://www.devco.net/archives/2009/10/18/middleware_for_systems_administration.php
28
28
  module MCollective
29
-
30
29
  require "mcollective/agent"
31
30
  require "mcollective/agents"
32
31
  require "mcollective/aggregate"
@@ -55,7 +54,7 @@ module MCollective
55
54
  require "mcollective/util"
56
55
  require "mcollective/validator"
57
56
 
58
- VERSION="2.20.3"
57
+ VERSION = "2.20.4".freeze
59
58
 
60
59
  def self.version
61
60
  VERSION
@@ -1,5 +1,4 @@
1
1
  module MCollective
2
2
  module Agent
3
-
4
3
  end
5
4
  end
@@ -2,11 +2,11 @@ module MCollective
2
2
  # A collection of agents, loads them, reloads them and dispatches messages to them.
3
3
  # It uses the PluginManager to store, load and manage instances of plugins.
4
4
  class Agents
5
- def initialize(agents = {})
5
+ def initialize(agents={})
6
6
  @config = Config.instance
7
- raise ("Configuration has not been loaded, can't load agents") unless @config.configured
7
+ raise "Configuration has not been loaded, can't load agents" unless @config.configured
8
8
 
9
- @@agents = agents
9
+ @@agents = agents # rubocop:disable Style/ClassVars
10
10
 
11
11
  loadagents
12
12
  end
@@ -18,7 +18,7 @@ module MCollective
18
18
  Util.unsubscribe(Util.make_subscriptions(agent, :broadcast))
19
19
  end
20
20
 
21
- @@agents = {}
21
+ @@agents = {} # rubocop:disable Style/ClassVars
22
22
  end
23
23
 
24
24
  # Loads all agents from disk
@@ -67,9 +67,10 @@ module MCollective
67
67
  Log.debug("Not activating agent #{agentname} due to agent policy in activate? method")
68
68
  return false
69
69
  end
70
- rescue Exception => e
71
- Log.error("Loading agent #{agentname} failed: #{e}")
72
- PluginManager.delete("#{agentname}_agent")
70
+ rescue Exception # rubocop:disable Lint/RescueException
71
+ Log.error("Loading agent %s failed: %s" % [agentname, $!])
72
+ PluginManager.delete("%s_agent" % agentname)
73
+
73
74
  return false
74
75
  end
75
76
  end
@@ -91,8 +92,8 @@ module MCollective
91
92
  Log.debug("#{klass} does not have an activate? method, activating as default")
92
93
  return true
93
94
  end
94
- rescue Exception => e
95
- Log.warn("Agent activation check for #{agent} failed: #{e.class}: #{e}")
95
+ rescue Exception # rubocop:disable Lint/RescueException
96
+ Log.warn("Agent activation check for %s #{agent} failed: %s: %s" % [agent, $!.class, $!])
96
97
  return false
97
98
  end
98
99
 
@@ -105,7 +106,7 @@ module MCollective
105
106
  return agentfile
106
107
  end
107
108
  end
108
- return false
109
+ false
109
110
  end
110
111
 
111
112
  # Determines if we have an agent with a certain name
@@ -122,20 +123,18 @@ module MCollective
122
123
  begin
123
124
  agent = PluginManager["#{request.agent}_agent"]
124
125
 
125
- Timeout::timeout(agent.timeout) do
126
+ Timeout.timeout(agent.timeout) do
126
127
  replies = agent.handlemsg(request.payload, connection)
127
128
 
128
129
  # Agents can decide if they wish to reply or not,
129
130
  # returning nil will mean nothing goes back to the
130
131
  # requestor
131
- unless replies == nil
132
- yield(replies)
133
- end
132
+ yield(replies) unless replies.nil?
134
133
  end
135
- rescue Timeout::Error => e
136
- Log.warn("Timeout while handling message for #{request.agent}")
137
- rescue Exception => e
138
- Log.error("Execution of #{request.agent} failed: #{e}")
134
+ rescue Timeout::Error
135
+ Log.warn("Timeout while handling message for %s" % request.agent)
136
+ rescue Exception # rubocop:disable Lint/RescueException
137
+ Log.error("Execution of %s failed: %s" % [request.agent, $!])
139
138
  Log.error(e.backtrace.join("\n\t\t"))
140
139
  end
141
140
  end
@@ -1,7 +1,7 @@
1
1
  module MCollective
2
2
  class Aggregate
3
- require 'mcollective/aggregate/result'
4
- require 'mcollective/aggregate/base'
3
+ require "mcollective/aggregate/result"
4
+ require "mcollective/aggregate/base"
5
5
 
6
6
  attr_accessor :ddl, :functions, :action, :failed
7
7
 
@@ -17,7 +17,7 @@ module MCollective
17
17
  # Creates instances of the Aggregate functions and stores them in the function array.
18
18
  # All aggregate call and summarize method calls operate on these function as a batch.
19
19
  def create_functions
20
- @ddl[:aggregate].each_with_index do |agg, i|
20
+ @ddl[:aggregate].each_with_index do |agg, _i|
21
21
  output = agg[:args][0]
22
22
 
23
23
  if contains_output?(output)
@@ -26,11 +26,11 @@ module MCollective
26
26
  begin
27
27
  @functions << load_function(agg[:function]).new(output, arguments, format, @action)
28
28
  rescue Exception => e
29
- Log.error("Cannot create aggregate function '#{output}'. #{e.to_s}")
29
+ Log.error("Cannot create aggregate function '%s': %s" % [output, e])
30
30
  @failed << {:name => output, :type => :startup}
31
31
  end
32
32
  else
33
- Log.error("Cannot create aggregate function '#{output}'. '#{output}' has not been specified as a valid ddl output.")
33
+ Log.error("Cannot create aggregate function '%s'. '%s' has not been specified as a valid ddl output." % [output, output])
34
34
  @failed << {:name => output, :type => :create}
35
35
  end
36
36
  end
@@ -44,11 +44,11 @@ module MCollective
44
44
  # Call all the appropriate functions with the reply data received from RPC::Client
45
45
  def call_functions(reply)
46
46
  @functions.each do |function|
47
- Log.debug("Calling aggregate function #{function} for result")
47
+ Log.debug("Calling aggregate function %s for result" % function)
48
48
  begin
49
49
  function.process_result(reply[:data][function.output_name], reply)
50
50
  rescue Exception => e
51
- Log.error("Could not process aggregate function for '#{function.output_name}'. #{e.to_s}")
51
+ Log.error("Could not process aggregate function for '%s': %s" % [function.output_name, e])
52
52
  @failed << {:name => function.output_name, :type => :process_result}
53
53
  @functions.delete(function)
54
54
  end
@@ -61,13 +61,13 @@ module MCollective
61
61
  begin
62
62
  function.summarize
63
63
  rescue Exception => e
64
- Log.error("Could not summarize aggregate result for '#{function.output_name}'. #{e.to_s}")
64
+ Log.error("Could not summarize aggregate result for '%s': %s" % [function.output_name, e])
65
65
  @failed << {:name => function.output_name, :type => :summarize}
66
66
  nil
67
67
  end
68
68
  end
69
69
 
70
- summary.reject{|x| x.nil?}.sort do |x,y|
70
+ summary.reject(&:nil?).sort do |x, y|
71
71
  x.result[:output] <=> y.result[:output]
72
72
  end
73
73
  end
@@ -76,10 +76,10 @@ module MCollective
76
76
  def load_function(function_name)
77
77
  function_name = function_name.to_s.capitalize
78
78
 
79
- PluginManager.loadclass("MCollective::Aggregate::#{function_name}") unless Aggregate.const_defined?(function_name)
79
+ PluginManager.loadclass("MCollective::Aggregate::%s" % function_name) unless Aggregate.const_defined?(function_name)
80
80
  Aggregate.const_get(function_name)
81
81
  rescue Exception
82
- raise "Aggregate function file '#{function_name.downcase}.rb' cannot be loaded"
82
+ raise("Aggregate function file '%s.rb' cannot be loaded" % function_name.downcase)
83
83
  end
84
84
  end
85
85
  end
@@ -1,4 +1,4 @@
1
- require 'mcollective/rpc'
1
+ require "mcollective/rpc"
2
2
 
3
3
  module MCollective
4
4
  class Application
@@ -70,9 +70,9 @@ module MCollective
70
70
  :arguments => [],
71
71
  :type => String,
72
72
  :required => false,
73
- :validate => Proc.new { true }}
73
+ :validate => proc { true }}
74
74
 
75
- arguments.each_pair{|k,v| opt[k] = v}
75
+ arguments.each_pair {|k, v| opt[k] = v}
76
76
 
77
77
  self[:cli_arguments] << opt
78
78
  end
@@ -93,9 +93,7 @@ module MCollective
93
93
  end
94
94
 
95
95
  # The active options hash used for MC::Client and other configuration
96
- def options
97
- @options
98
- end
96
+ attr_reader :options
99
97
 
100
98
  # Calls the supplied block in an option for validation, an error raised
101
99
  # will log to STDERR and exit the application
@@ -113,12 +111,10 @@ module MCollective
113
111
  def clioptions(help)
114
112
  oparser = Optionparser.new({:verbose => false, :progress_bar => true}, "filter", application_options[:exclude_arg_sections])
115
113
 
116
- options = oparser.parse do |parser, options|
117
- if block_given?
118
- yield(parser, options)
119
- end
114
+ options = oparser.parse do |parser, opts|
115
+ yield(parser, opts) if block_given?
120
116
 
121
- RPC::Helpers.add_simplerpc_options(parser, options) unless application_options[:exclude_arg_sections].include?("rpc")
117
+ RPC::Helpers.add_simplerpc_options(parser, opts) unless application_options[:exclude_arg_sections].include?("rpc")
122
118
  end
123
119
 
124
120
  return oparser.parser.help if help
@@ -128,8 +124,8 @@ module MCollective
128
124
  post_option_parser(configuration) if respond_to?(:post_option_parser)
129
125
 
130
126
  return options
131
- rescue Exception => e
132
- application_failure(e)
127
+ rescue Exception # rubocop:disable Lint/RescueException
128
+ application_failure($!)
133
129
  end
134
130
 
135
131
  # Builds an ObjectParser config, parse the CLI options and validates based
@@ -137,7 +133,7 @@ module MCollective
137
133
  def application_parse_options(help=false)
138
134
  @options ||= {:verbose => false}
139
135
 
140
- @options = clioptions(help) do |parser, options|
136
+ @options = clioptions(help) do |parser, _options|
141
137
  parser.define_head application_description if application_description
142
138
  parser.banner = ""
143
139
 
@@ -156,16 +152,13 @@ module MCollective
156
152
  parser.define_tail ""
157
153
  parser.define_tail "The Marionette Collective #{MCollective.version}"
158
154
 
159
-
160
155
  application_cli_arguments.each do |carg|
161
156
  opts_array = []
162
157
 
163
158
  opts_array << :on
164
159
 
165
160
  # if a default is set from the application set it up front
166
- if carg.include?(:default)
167
- configuration[carg[:name]] = carg[:default]
168
- end
161
+ configuration[carg[:name]] = carg[:default] if carg.include?(:default)
169
162
 
170
163
  # :arguments are multiple possible ones
171
164
  if carg[:arguments].is_a?(Array)
@@ -211,11 +204,10 @@ module MCollective
211
204
  validation_passed = true
212
205
  application_cli_arguments.each do |carg|
213
206
  # Check for required arguments
214
- if carg[:required]
215
- unless configuration[ carg[:name] ]
216
- validation_passed = false
217
- STDERR.puts "The #{carg[:name]} option is mandatory"
218
- end
207
+ next unless carg[:required]
208
+ unless configuration[carg[:name]]
209
+ validation_passed = false
210
+ STDERR.puts "The #{carg[:name]} option is mandatory"
219
211
  end
220
212
  end
221
213
 
@@ -223,8 +215,6 @@ module MCollective
223
215
  STDERR.puts "\nPlease run with --help for detailed help"
224
216
  exit 1
225
217
  end
226
-
227
-
228
218
  end
229
219
 
230
220
  # Retrieves the full hash of application options
@@ -260,15 +250,15 @@ module MCollective
260
250
  end
261
251
 
262
252
  if options[:verbose]
263
- err_dest.puts "\nThe %s application failed to run: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
253
+ err_dest.puts "\nThe %s application failed to run: %s\n" % [Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
264
254
  else
265
- err_dest.puts "\nThe %s application failed to run, use -v for full error backtrace details: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
255
+ err_dest.puts "\nThe %s application failed to run, use -v for full error backtrace details: %s\n" % [Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
266
256
  end
267
257
 
268
258
  if options.nil? || options[:verbose]
269
259
  e.backtrace.first << Util.colorize(:red, " <----")
270
- err_dest.puts "\n%s %s" % [ Util.colorize(:red, e.to_s), Util.colorize(:bold, "(#{e.class.to_s})")]
271
- e.backtrace.each{|l| err_dest.puts "\tfrom #{l}"}
260
+ err_dest.puts "\n%s %s" % [Util.colorize(:red, e.to_s), Util.colorize(:bold, "(#{e.class})")]
261
+ e.backtrace.each {|l| err_dest.puts "\tfrom #{l}"}
272
262
  end
273
263
 
274
264
  disconnect
@@ -293,14 +283,13 @@ module MCollective
293
283
  main
294
284
 
295
285
  disconnect
296
-
297
- rescue Exception => e
298
- application_failure(e)
286
+ rescue Exception # rubocop:disable Lint/RescueException
287
+ application_failure($!)
299
288
  end
300
289
 
301
290
  def disconnect
302
291
  MCollective::PluginManager["connector_plugin"].disconnect
303
- rescue
292
+ rescue # rubocop:disable Lint/HandleExceptions
304
293
  end
305
294
 
306
295
  # Fake abstract class that logs if the user tries to use an application without
@@ -316,27 +305,27 @@ module MCollective
316
305
  :okcount => 0,
317
306
  :failcount => 0}.merge(stats.to_hash)
318
307
 
319
- if (request_stats[:discoverytime] == 0 && request_stats[:responses] == 0)
308
+ if request_stats[:discoverytime] == 0 && request_stats[:responses] == 0
320
309
  return 4
321
310
  end
322
311
 
323
- if (request_stats[:discovered] > 0)
324
- if (request_stats[:responses] == 0)
312
+ if request_stats[:discovered] > 0
313
+ if request_stats[:responses] == 0
325
314
  return 3
326
- elsif (request_stats[:failcount] > 0)
315
+ elsif request_stats[:failcount] > 0
327
316
  return 2
328
317
  end
329
318
  end
330
319
 
331
- if (request_stats[:discovered] == 0)
332
- if (request_stats[:responses] && request_stats[:responses] > 0)
320
+ if request_stats[:discovered] == 0
321
+ if request_stats[:responses] && request_stats[:responses] > 0
333
322
  return 0
334
323
  else
335
324
  return 1
336
325
  end
337
326
  end
338
327
 
339
- return 0
328
+ 0
340
329
  end
341
330
 
342
331
  # A helper that creates a consistent exit code for applications by looking at an
@@ -355,7 +344,7 @@ module MCollective
355
344
  # Wrapper around MC::RPC#rpcclient that forcably supplies our options hash
356
345
  # if someone forgets to pass in options in an application the filters and other
357
346
  # cli options wouldnt take effect which could have a disasterous outcome
358
- def rpcclient(agent, flags = {})
347
+ def rpcclient(agent, flags={})
359
348
  flags[:options] = options unless flags.include?(:options)
360
349
  flags[:exit_on_failure] = false
361
350
 
@@ -10,17 +10,17 @@ module MCollective
10
10
 
11
11
  begin
12
12
  load_application(appname)
13
- rescue Exception => e
13
+ rescue Exception # rubocop:disable Lint/RescueException
14
14
  e.backtrace.first << Util.colorize(:red, " <----")
15
- STDERR.puts "Application '#{appname}' failed to load:"
15
+ STDERR.puts "Application '%s' failed to load:" % appname
16
16
  STDERR.puts
17
- STDERR.puts Util.colorize(:red, " #{e} (#{e.class})")
17
+ STDERR.puts Util.colorize(:red, " %s (%s)" % [$!, $!.class])
18
18
  STDERR.puts
19
- STDERR.puts " %s" % [e.backtrace.join("\n ")]
19
+ STDERR.puts " %s" % [$!.backtrace.join("\n ")]
20
20
  exit 1
21
21
  end
22
22
 
23
- PluginManager["#{appname}_application"].run
23
+ PluginManager["%s_application" % appname].run
24
24
  end
25
25
 
26
26
  def self.load_application(appname)
@@ -39,17 +39,16 @@ module MCollective
39
39
  PluginManager.find("application")
40
40
  rescue SystemExit
41
41
  exit 1
42
- rescue Exception => e
43
- STDERR.puts "Failed to generate application list: #{e.class}: #{e}"
42
+ rescue Exception # rubocop:disable Lint/RescueException
43
+ STDERR.puts("Failed to generate application list: %s: %s" % [$!.class, $!])
44
44
  exit 1
45
45
  end
46
46
 
47
47
  # Filters a string of opts out using Shellwords
48
48
  # keeping only things related to --config and -c
49
49
  def self.filter_extra_options(opts)
50
- res = ""
51
50
  words = Shellwords.shellwords(opts)
52
- words.each_with_index do |word,idx|
51
+ words.each_with_index do |word, idx|
53
52
  if word == "-c"
54
53
  return "--config=#{words[idx + 1]}"
55
54
  elsif word == "--config"
@@ -61,7 +60,7 @@ module MCollective
61
60
  end
62
61
  end
63
62
 
64
- return ""
63
+ ""
65
64
  end
66
65
 
67
66
  # We need to know the config file in order to know the libdir
@@ -110,8 +109,8 @@ module MCollective
110
109
  # am done with it
111
110
  ENV["MCOLLECTIVE_EXTRA_OPTS"] = filter_extra_options(ENV["MCOLLECTIVE_EXTRA_OPTS"].clone)
112
111
  parser.environment("MCOLLECTIVE_EXTRA_OPTS")
113
- rescue Exception => e
114
- Log.error("Failed to parse MCOLLECTIVE_EXTRA_OPTS: #{e}")
112
+ rescue Exception # rubocop:disable Lint/RescueException
113
+ Log.error("Failed to parse MCOLLECTIVE_EXTRA_OPTS: %s" % $!)
115
114
  end
116
115
 
117
116
  ENV["MCOLLECTIVE_EXTRA_OPTS"] = original_extra_opts.clone
@@ -119,14 +118,14 @@ module MCollective
119
118
 
120
119
  begin
121
120
  parser.parse!
122
- rescue OptionParser::InvalidOption => e
121
+ rescue OptionParser::InvalidOption
123
122
  retry
124
123
  end
125
124
 
126
125
  ARGV.clear
127
126
  original_argv.each {|a| ARGV << a}
128
127
 
129
- configfile = Util.config_file_for_user unless configfile
128
+ configfile ||= Util.config_file_for_user
130
129
 
131
130
  Config.instance.loadconfig(configfile)
132
131
  end