mcollective-client 1.3.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mcollective-client might be problematic. Click here for more details.

data/bin/mc-call-agent CHANGED
@@ -6,49 +6,49 @@ require 'pp'
6
6
  oparser = MCollective::Optionparser.new({:verbose => true}, "filter")
7
7
 
8
8
  options = oparser.parse{|parser, options|
9
- parser.define_head "Call an agent parsing an argument to it"
10
- parser.banner = "Usage: mc-call-agent [options] --agent agent --argument arg"
9
+ parser.define_head "Call an agent parsing an argument to it"
10
+ parser.banner = "Usage: mc-call-agent [options] --agent agent --argument arg"
11
11
 
12
- parser.on('-a', '--agent AGENT', 'Agent to call') do |v|
13
- options[:agent] = v
14
- end
12
+ parser.on('-a', '--agent AGENT', 'Agent to call') do |v|
13
+ options[:agent] = v
14
+ end
15
15
 
16
- parser.on('--arg', '--argument ARGUMENT', 'Argument to pass to agent') do |v|
17
- options[:argument] = v
18
- end
16
+ parser.on('--arg', '--argument ARGUMENT', 'Argument to pass to agent') do |v|
17
+ options[:argument] = v
18
+ end
19
19
  }
20
20
 
21
21
  if options[:agent] == nil || options[:argument] == nil
22
- puts("Please use either --agent or --argument")
23
- exit 1
22
+ puts("Please use either --agent or --argument")
23
+ exit 1
24
24
  end
25
25
 
26
26
  begin
27
- options[:filter]["agent"] << options[:agent]
27
+ options[:filter]["agent"] << options[:agent]
28
28
 
29
- client = MCollective::Client.new(options[:config])
30
- client.options = options
29
+ client = MCollective::Client.new(options[:config])
30
+ client.options = options
31
31
 
32
- c = 0
32
+ c = 0
33
33
 
34
- stats = client.discovered_req(options[:argument], options[:agent]) do |resp|
35
- next if resp == nil
34
+ stats = client.discovered_req(options[:argument], options[:agent]) do |resp|
35
+ next if resp == nil
36
36
 
37
- c += 1
37
+ c += 1
38
38
 
39
- if options[:verbose]
40
- puts("#{resp[:senderid]}>")
41
- pp resp[:body]
42
- else
43
- puts if c % 4 == 1
44
- printf("%-30s", resp[:senderid])
45
- end
39
+ if options[:verbose]
40
+ puts("#{resp[:senderid]}>")
41
+ pp resp[:body]
42
+ else
43
+ puts if c % 4 == 1
44
+ printf("%-30s", resp[:senderid])
46
45
  end
46
+ end
47
47
 
48
- client.disconnect
48
+ client.disconnect
49
49
  rescue Exception => e
50
- STDERR.puts "Could not call remote agent: #{e}"
51
- exit 1
50
+ STDERR.puts "Could not call remote agent: #{e}"
51
+ exit 1
52
52
  end
53
53
 
54
54
  client.display_stats(stats)
data/bin/mco CHANGED
@@ -7,21 +7,31 @@ known_applications = MCollective::Applications.list
7
7
 
8
8
  # links from mc-ping to mc will result in ping being run
9
9
  if $0 =~ /mc\-([a-zA-Z\-_\.]+)$/
10
- app_name = $1
10
+ app_name = $1
11
11
  else
12
- app_name = ARGV.first
13
- ARGV.delete_at(0)
12
+ app_name = ARGV.first
13
+ ARGV.delete_at(0)
14
14
  end
15
15
 
16
16
  if known_applications.include?(app_name)
17
- # make sure the various options classes shows the right help etc
18
- $0 = app_name
17
+ # make sure the various options classes shows the right help etc
18
+ $0 = app_name
19
19
 
20
- MCollective::Applications.run(app_name)
20
+ MCollective::Applications.run(app_name)
21
21
  else
22
- puts "The Marionette Collective version #{MCollective.version}"
23
- puts
24
- puts "#{$0}: command (options)"
25
- puts
26
- puts "Known commands: #{known_applications.join " "}"
22
+ puts "The Marionette Collective version #{MCollective.version}"
23
+ puts
24
+ puts "usage: #{$0} command <options>"
25
+ puts
26
+ puts "Known commands:"
27
+ puts
28
+
29
+ known_applications.sort.uniq.in_groups_of(3) do |apps|
30
+ puts " %-20s %-20s %-20s" % [apps[0], apps[1], apps[2]]
31
+ end
32
+
33
+ puts
34
+ puts "Type '#{$0} help' for a detailed list of commands and '#{$0} help command'"
35
+ puts "to get detailed help for a command"
36
+ puts
27
37
  end
data/lib/mcollective.rb CHANGED
@@ -7,10 +7,10 @@ require 'singleton'
7
7
  require 'socket'
8
8
  require 'erb'
9
9
  require 'shellwords'
10
- require 'mcollective/monkey_patches'
11
- require 'tempfile'
12
10
  require 'rbconfig'
11
+ require 'tempfile'
13
12
  require 'tmpdir'
13
+ require 'mcollective/monkey_patches'
14
14
 
15
15
  # == The Marionette Collective
16
16
  #
@@ -13,14 +13,49 @@ module MCollective
13
13
  const_get("#{klass}")
14
14
  end
15
15
 
16
+ # Fetch and return metadata from plugin DDL
16
17
  def self.get_metadata(path, type)
17
18
  ddl = MCollective::RPC::DDL.new("package", false)
18
19
  ddl.instance_eval File.read(Dir.glob(File.join(path, type, "*.ddl")).first)
19
20
  ddl.meta
20
21
  end
21
22
 
23
+ # Checks if a directory is present and not empty
22
24
  def self.check_dir_present(path)
23
25
  (File.directory?(path) && !Dir.glob(File.join(path, "*")).empty?)
24
26
  end
27
+
28
+ # Quietly calls a block if verbose parameter is false
29
+ def self.do_quietly?(verbose, &block)
30
+ unless verbose
31
+ old_stdout = $stdout.clone
32
+ $stdout.reopen(File.new("/dev/null", "w"))
33
+ begin
34
+ block.call
35
+ rescue Exception => e
36
+ $stdout.reopen old_stdout
37
+ raise e
38
+ ensure
39
+ $stdout.reopen old_stdout
40
+ end
41
+ else
42
+ block.call
43
+ end
44
+ end
45
+
46
+ # Checks if a build tool is present on the system
47
+ def self.build_tool?(build_tool)
48
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
49
+ builder = File.join(path, build_tool)
50
+ if File.exists?(builder)
51
+ return true
52
+ end
53
+ end
54
+ false
55
+ end
56
+
57
+ def self.safe_system(*args)
58
+ raise RuntimeError, "Failed: #{args.join(' ')}" unless system *args
59
+ end
25
60
  end
26
61
  end
@@ -2,33 +2,41 @@ module MCollective
2
2
  module PluginPackager
3
3
  # MCollective Agent Plugin package
4
4
  class AgentDefinition
5
- attr_accessor :path, :packagedata, :metadata, :target_path, :vendor, :iteration, :postinstall
6
- attr_accessor :plugintype
5
+ attr_accessor :path, :packagedata, :metadata, :target_path, :vendor, :iteration, :preinstall
6
+ attr_accessor :plugintype, :dependencies, :postinstall, :mcserver, :mcclient, :mccommon
7
7
 
8
- def initialize(path, name, vendor, postinstall, iteration, plugintype)
8
+ def initialize(path, name, vendor, preinstall, postinstall, iteration, dependencies, mcodependency, plugintype)
9
9
  @plugintype = plugintype
10
10
  @path = path
11
11
  @packagedata = {}
12
12
  @iteration = iteration || 1
13
+ @preinstall = preinstall
13
14
  @postinstall = postinstall
14
15
  @vendor = vendor || "Puppet Labs"
16
+ @mcserver = mcodependency[:server] || "mcollective"
17
+ @mcclient = mcodependency[:client] || "mcollective-client"
18
+ @mccommon = mcodependency[:common] || "mcollective-common"
19
+ @dependencies = dependencies || []
15
20
  @target_path = File.expand_path(@path)
16
21
  @metadata = PluginPackager.get_metadata(@path, "agent")
17
- @metadata[:name] = (name || @metadata[:name]).downcase.gsub(" ", "_")
22
+ @metadata[:name] = (name || @metadata[:name]).downcase.gsub(" ", "-")
18
23
  identify_packages
19
24
  end
20
25
 
21
26
  # Identify present packages and populate packagedata hash.
22
27
  def identify_packages
23
- @packagedata[:common] = common
24
- @packagedata[:agent] = agent
25
- @packagedata[:client] = client
28
+ common_package = common
29
+ @packagedata[:common] = common_package if common_package
30
+ agent_package = agent
31
+ @packagedata[:agent] = agent_package if agent_package
32
+ client_package = client
33
+ @packagedata[:client] = client_package if client_package
26
34
  end
27
35
 
28
36
  # Obtain Agent package files and dependencies.
29
37
  def agent
30
38
  agent = {:files => [],
31
- :dependencies => ["mcollective"],
39
+ :dependencies => @dependencies.clone << @mcserver,
32
40
  :description => "Agent plugin for #{@metadata[:name]}"}
33
41
 
34
42
  agentdir = File.join(@path, "agent")
@@ -41,7 +49,6 @@ module MCollective
41
49
  else
42
50
  return nil
43
51
  end
44
-
45
52
  agent[:dependencies] << "mcollective-#{@metadata[:name]}-common" if @packagedata[:common]
46
53
  agent
47
54
  end
@@ -49,7 +56,7 @@ module MCollective
49
56
  # Obtain client package files and dependencies.
50
57
  def client
51
58
  client = {:files => [],
52
- :dependencies => ["mcollective-client"],
59
+ :dependencies => @dependencies.clone << @mcclient,
53
60
  :description => "Client plugin for #{@metadata[:name]}"}
54
61
 
55
62
  clientdir = File.join(@path, "application")
@@ -66,7 +73,7 @@ module MCollective
66
73
  # Obtain common package files and dependencies.
67
74
  def common
68
75
  common = {:files =>[],
69
- :dependencies => ["mcollective-common"],
76
+ :dependencies => @dependencies.clone << @mccommon,
70
77
  :description => "Common libraries for #{@metadata[:name]}"}
71
78
 
72
79
  commondir = File.join(@path, "util")
@@ -1,32 +1,39 @@
1
1
  module MCollective
2
2
  module PluginPackager
3
3
  class StandardDefinition
4
- attr_accessor :path, :packagedata, :metadata, :target_path, :vendor, :iteration, :postinstall
5
- attr_accessor :plugintype
4
+ attr_accessor :path, :packagedata, :metadata, :target_path, :vendor, :iteration
5
+ attr_accessor :plugintype, :preinstall, :postinstall, :dependencies, :mcserver
6
+ attr_accessor :mccommon
6
7
 
7
- def initialize(path, name, vendor, postinstall, iteration, plugintype)
8
+ def initialize(path, name, vendor, preinstall, postinstall, iteration, dependencies, mcodependency, plugintype)
8
9
  @plugintype = plugintype
9
10
  @path = path
10
11
  @packagedata = {}
11
12
  @iteration = iteration || 1
13
+ @preinstall = preinstall
12
14
  @postinstall = postinstall
13
15
  @vendor = vendor || "Puppet Labs"
16
+ @dependencies = dependencies || []
17
+ @mcserver = mcodependency[:server] || "mcollective"
18
+ @mccommon = mcodependency[:common] || "mcollective-common"
14
19
  @target_path = File.expand_path(@path)
15
20
  @metadata = PluginPackager.get_metadata(@path, @plugintype)
16
- @metadata[:name] = (name || @metadata[:name]).downcase.gsub(" ", "_")
21
+ @metadata[:name] = (name || @metadata[:name]).downcase.gsub(" ", "-")
17
22
  identify_packages
18
23
  end
19
24
 
20
25
  # Identify present packages and populate the packagedata hash
21
26
  def identify_packages
22
- @packagedata[:common] = common
23
- @packagedata[@plugintype] = plugin
27
+ common_package = common
28
+ @packagedata[:common] = common_package if common_package
29
+ plugin_package = plugin
30
+ @packagedata[@plugintype] = plugin_package if plugin_package
24
31
  end
25
32
 
26
33
  # Obtain standard plugin files and dependencies
27
34
  def plugin
28
35
  plugindata = {:files => [],
29
- :dependencies => ["mcollective"],
36
+ :dependencies => @dependencies.clone << @mcserver,
30
37
  :description => "#{@name} #{@plugintype} plugin for the Marionette Collective."}
31
38
 
32
39
  plugindir = File.join(@path, @plugintype.to_s)
@@ -43,7 +50,7 @@ module MCollective
43
50
  # Obtain list of common files
44
51
  def common
45
52
  common = {:files => [],
46
- :dependencies => ["mcolelctive-common"],
53
+ :dependencies => @dependencies.clone << @mccommon,
47
54
  :description => "Common libraries for #{@name} connector plugin"}
48
55
 
49
56
  commondir = File.join(@path, "util")
@@ -359,7 +359,7 @@ module MCollective
359
359
 
360
360
  # Set a compound filter
361
361
  def compound_filter(filter)
362
- @filter["compound"] = Matcher::Parser.new(filter).execution_stack
362
+ @filter["compound"] << Matcher::Parser.new(filter).execution_stack
363
363
  reset
364
364
  end
365
365
 
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,7 @@ require 'mocha'
13
13
  require 'ostruct'
14
14
  require 'tmpdir'
15
15
  require 'tempfile'
16
+ require 'fileutils'
16
17
 
17
18
  require 'monkey_patches/instance_variable_defined'
18
19
 
@@ -613,22 +613,15 @@ module MCollective
613
613
  end
614
614
 
615
615
  it "should catch handle exit() correctly" do
616
- Application.send(:define_method, :main) do
617
- exit 1
618
- end
619
-
616
+ @app.expects(:main).raises(SystemExit)
620
617
  @app.expects(:disconnect).once
621
618
 
622
619
  expect { @app.run }.to raise_error(SystemExit)
623
620
  end
624
621
 
625
622
  it "should catch all exceptions and process them correctly" do
623
+ @app.expects(:main).raises("rspec")
626
624
  @app.expects(:application_failure).once
627
-
628
- Application.send(:define_method, :main) do
629
- raise "rspec"
630
- end
631
-
632
625
  @app.run
633
626
  end
634
627
  end
File without changes
@@ -9,9 +9,23 @@ module MCollective
9
9
  PluginPackager.expects(:get_metadata).once.returns({:name => "foo"})
10
10
  end
11
11
 
12
- it "should replace spaces in the package name with underscores" do
13
- agent = AgentDefinition.new(".", "test package", nil, nil, nil, "agent")
14
- agent.metadata[:name].should == "test_package"
12
+ describe "#initialize" do
13
+ it "should replace spaces in the package name with dashes" do
14
+ agent = AgentDefinition.new(".", "test package", nil, nil, nil, nil, [], {}, "agent")
15
+ agent.metadata[:name].should == "test-package"
16
+ end
17
+
18
+ it "should set dependencies if present" do
19
+ agent = AgentDefinition.new(".", "test-package", nil, nil, nil, nil, ["foo"], {}, "agent")
20
+ agent.dependencies.should == ["foo"]
21
+ end
22
+
23
+ it "should set mc server, client and common dependencies" do
24
+ agent = AgentDefinition.new(".", "test-package", nil, nil, nil, nil, [], {:server => "pe-mcollective"}, "agent")
25
+ agent.mcserver.should == "pe-mcollective"
26
+ agent.mcclient.should == "mcollective-client"
27
+ agent.mccommon.should == "mcollective-common"
28
+ end
15
29
  end
16
30
 
17
31
  describe "#identify_packages" do
@@ -20,7 +34,7 @@ module MCollective
20
34
  AgentDefinition.any_instance.expects(:agent).once.returns(:check)
21
35
  AgentDefinition.any_instance.expects(:client).once.returns(:check)
22
36
 
23
- agent = AgentDefinition.new(".", nil, nil, nil, nil, "agent")
37
+ agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
24
38
  agent.packagedata[:common].should == :check
25
39
  agent.packagedata[:agent].should == :check
26
40
  agent.packagedata[:client].should == :check
@@ -35,7 +49,7 @@ module MCollective
35
49
  it "should not populate the agent files if the agent directory is empty" do
36
50
  AgentDefinition.any_instance.expects(:common).returns(nil)
37
51
  PluginPackager.expects(:check_dir_present).returns(false)
38
- agent = AgentDefinition.new(".", nil, nil, nil, nil, "agent")
52
+ agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
39
53
  agent.packagedata[:agent].should == nil
40
54
  end
41
55
 
@@ -45,17 +59,17 @@ module MCollective
45
59
  File.stubs(:join).returns("tmpdir")
46
60
  Dir.stubs(:glob).returns(["file.rb", "implementation.rb"])
47
61
 
48
- agent = AgentDefinition.new(".", nil, nil, nil, nil, "agent")
62
+ agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
49
63
  agent.packagedata[:agent][:files].should == ["file.rb", "implementation.rb"]
50
64
  end
51
65
 
52
66
  it "should add common package as dependency if present" do
53
- AgentDefinition.any_instance.expects(:common).returns(true)
67
+ AgentDefinition.any_instance.expects(:common).returns({:files=> ["test.rb"]})
54
68
  PluginPackager.expects(:check_dir_present).returns(true)
55
69
  File.stubs(:join).returns("tmpdir")
56
70
  Dir.stubs(:glob).returns([])
57
71
 
58
- agent = AgentDefinition.new(".", nil, nil, nil, nil, "agent")
72
+ agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
59
73
  agent.packagedata[:agent][:dependencies].should == ["mcollective", "mcollective-foo-common"]
60
74
  end
61
75
  end
@@ -68,7 +82,7 @@ module MCollective
68
82
 
69
83
  it "should not populate the commong files if the util directory is empty" do
70
84
  PluginPackager.expects(:check_dir_present).returns(false)
71
- common = AgentDefinition.new(".", nil, nil, nil, nil, "agent")
85
+ common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
72
86
  common.packagedata[:common].should == nil
73
87
  end
74
88
 
@@ -76,7 +90,7 @@ module MCollective
76
90
  PluginPackager.expects(:check_dir_present).returns(true)
77
91
  File.stubs(:join).returns("tmpdir")
78
92
  Dir.stubs(:glob).returns(["file.rb"])
79
- common = AgentDefinition.new(".", nil, nil, nil, nil, "agent")
93
+ common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
80
94
  common.packagedata[:common][:files].should == ["file.rb"]
81
95
  end
82
96
  end
@@ -99,7 +113,7 @@ module MCollective
99
113
  Dir.expects(:glob).with("bindir/*").returns(["bin.rb"])
100
114
  Dir.expects(:glob).with("agentdir/*.ddl").returns(["agent.ddl"])
101
115
 
102
- client = AgentDefinition.new(".", nil, nil, nil, nil, "agent")
116
+ client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
103
117
  client.packagedata[:client][:files].should == ["client.rb", "bin.rb", "agent.ddl"]
104
118
  end
105
119
 
@@ -107,7 +121,7 @@ module MCollective
107
121
  AgentDefinition.any_instance.expects(:common).returns(nil)
108
122
  PluginPackager.expects(:check_dir_present).times(3).returns(false)
109
123
 
110
- client = AgentDefinition.new(".", nil, nil, nil, nil, "agent")
124
+ client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
111
125
  client.packagedata[:client].should == nil
112
126
  end
113
127
 
@@ -121,7 +135,7 @@ module MCollective
121
135
  Dir.expects(:glob).with("bindir/*").returns(["bin.rb"])
122
136
  Dir.expects(:glob).with("agentdir/*.ddl").returns(["agent.ddl"])
123
137
 
124
- client = AgentDefinition.new(".", nil, nil, nil, nil, "agent")
138
+ client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
125
139
  client.packagedata[:client][:dependencies].should == ["mcollective-client", "mcollective-foo-common"]
126
140
  end
127
141
  end