mcollective-client 2.0.0 → 2.2.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.

Files changed (140) hide show
  1. data/lib/mcollective.rb +32 -23
  2. data/lib/mcollective/agent.rb +5 -0
  3. data/lib/mcollective/agents.rb +5 -16
  4. data/lib/mcollective/aggregate.rb +61 -0
  5. data/lib/mcollective/aggregate/base.rb +40 -0
  6. data/lib/mcollective/aggregate/result.rb +9 -0
  7. data/lib/mcollective/aggregate/result/base.rb +25 -0
  8. data/lib/mcollective/aggregate/result/collection_result.rb +19 -0
  9. data/lib/mcollective/aggregate/result/numeric_result.rb +13 -0
  10. data/lib/mcollective/application.rb +7 -4
  11. data/lib/mcollective/applications.rb +3 -14
  12. data/lib/mcollective/cache.rb +145 -0
  13. data/lib/mcollective/client.rb +10 -87
  14. data/lib/mcollective/config.rb +22 -8
  15. data/lib/mcollective/data.rb +87 -0
  16. data/lib/mcollective/data/base.rb +67 -0
  17. data/lib/mcollective/data/result.rb +40 -0
  18. data/lib/mcollective/ddl.rb +113 -0
  19. data/lib/mcollective/ddl/agentddl.rb +185 -0
  20. data/lib/mcollective/ddl/base.rb +220 -0
  21. data/lib/mcollective/ddl/dataddl.rb +56 -0
  22. data/lib/mcollective/ddl/discoveryddl.rb +52 -0
  23. data/lib/mcollective/ddl/validatorddl.rb +6 -0
  24. data/lib/mcollective/discovery.rb +143 -0
  25. data/lib/mcollective/generators.rb +7 -0
  26. data/lib/mcollective/generators/agent_generator.rb +51 -0
  27. data/lib/mcollective/generators/base.rb +46 -0
  28. data/lib/mcollective/generators/data_generator.rb +51 -0
  29. data/lib/mcollective/generators/templates/action_snippet.erb +13 -0
  30. data/lib/mcollective/generators/templates/data_input_snippet.erb +7 -0
  31. data/lib/mcollective/generators/templates/ddl.erb +8 -0
  32. data/lib/mcollective/generators/templates/plugin.erb +7 -0
  33. data/lib/mcollective/logger/console_logger.rb +15 -15
  34. data/lib/mcollective/matcher.rb +167 -0
  35. data/lib/mcollective/matcher/parser.rb +60 -25
  36. data/lib/mcollective/matcher/scanner.rb +156 -78
  37. data/lib/mcollective/message.rb +47 -6
  38. data/lib/mcollective/monkey_patches.rb +17 -0
  39. data/lib/mcollective/optionparser.rb +18 -1
  40. data/lib/mcollective/pluginmanager.rb +3 -3
  41. data/lib/mcollective/pluginpackager.rb +10 -3
  42. data/lib/mcollective/pluginpackager/agent_definition.rb +28 -20
  43. data/lib/mcollective/pluginpackager/standard_definition.rb +11 -9
  44. data/lib/mcollective/registration/base.rb +3 -1
  45. data/lib/mcollective/rpc.rb +18 -24
  46. data/lib/mcollective/rpc/agent.rb +37 -113
  47. data/lib/mcollective/rpc/client.rb +186 -64
  48. data/lib/mcollective/rpc/helpers.rb +42 -80
  49. data/lib/mcollective/rpc/progress.rb +3 -3
  50. data/lib/mcollective/rpc/reply.rb +37 -13
  51. data/lib/mcollective/rpc/request.rb +17 -6
  52. data/lib/mcollective/rpc/result.rb +9 -5
  53. data/lib/mcollective/rpc/stats.rb +71 -24
  54. data/lib/mcollective/security/base.rb +41 -34
  55. data/lib/mcollective/shell.rb +1 -1
  56. data/lib/mcollective/ssl.rb +34 -0
  57. data/lib/mcollective/util.rb +194 -23
  58. data/lib/mcollective/validator.rb +80 -0
  59. data/spec/fixtures/util/1.in +10 -0
  60. data/spec/fixtures/util/1.out +10 -0
  61. data/spec/fixtures/util/2.in +1 -0
  62. data/spec/fixtures/util/2.out +1 -0
  63. data/spec/fixtures/util/3.in +1 -0
  64. data/spec/fixtures/util/3.out +2 -0
  65. data/spec/fixtures/util/4.in +5 -0
  66. data/spec/fixtures/util/4.out +9 -0
  67. data/spec/spec.opts +1 -1
  68. data/spec/spec_helper.rb +2 -0
  69. data/spec/unit/agents_spec.rb +34 -19
  70. data/spec/unit/aggregate/base_spec.rb +57 -0
  71. data/spec/unit/aggregate/result/base_spec.rb +28 -0
  72. data/spec/unit/aggregate/result/collection_result_spec.rb +18 -0
  73. data/spec/unit/aggregate/result/numeric_result_spec.rb +22 -0
  74. data/spec/unit/aggregate_spec.rb +110 -0
  75. data/spec/unit/application_spec.rb +8 -3
  76. data/spec/unit/applications_spec.rb +2 -2
  77. data/spec/unit/cache_spec.rb +115 -0
  78. data/spec/unit/client_spec.rb +78 -0
  79. data/spec/unit/config_spec.rb +32 -34
  80. data/spec/unit/data/base_spec.rb +90 -0
  81. data/spec/unit/data/result_spec.rb +64 -0
  82. data/spec/unit/data_spec.rb +158 -0
  83. data/spec/unit/ddl/agentddl_spec.rb +217 -0
  84. data/spec/unit/{rpc/ddl_spec.rb → ddl/base_spec.rb} +238 -224
  85. data/spec/unit/ddl/dataddl_spec.rb +65 -0
  86. data/spec/unit/ddl/discoveryddl_spec.rb +58 -0
  87. data/spec/unit/ddl_spec.rb +84 -0
  88. data/spec/unit/discovery_spec.rb +196 -0
  89. data/spec/unit/facts/base_spec.rb +1 -1
  90. data/spec/unit/generators/agent_generator_spec.rb +72 -0
  91. data/spec/unit/generators/base_spec.rb +83 -0
  92. data/spec/unit/generators/data_generator_spec.rb +37 -0
  93. data/spec/unit/generators/snippets/agent_ddl +19 -0
  94. data/spec/unit/generators/snippets/data_ddl +20 -0
  95. data/spec/unit/logger/console_logger_spec.rb +76 -0
  96. data/spec/unit/logger/syslog_logger_spec.rb +2 -2
  97. data/spec/unit/matcher/parser_spec.rb +27 -10
  98. data/spec/unit/matcher/scanner_spec.rb +108 -5
  99. data/spec/unit/matcher_spec.rb +260 -0
  100. data/spec/unit/message_spec.rb +35 -13
  101. data/spec/unit/optionparser_spec.rb +2 -2
  102. data/spec/unit/pluginpackager/agent_definition_spec.rb +59 -42
  103. data/spec/unit/pluginpackager/standard_definition_spec.rb +10 -8
  104. data/spec/unit/pluginpackager_spec.rb +131 -0
  105. data/spec/unit/plugins/mcollective/aggregate/average_spec.rb +45 -0
  106. data/spec/unit/plugins/mcollective/aggregate/sum_spec.rb +31 -0
  107. data/spec/unit/plugins/mcollective/aggregate/summary_spec.rb +45 -0
  108. data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +1 -1
  109. data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +478 -0
  110. data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +2 -0
  111. data/spec/unit/plugins/mcollective/data/agent_data_spec.rb +43 -0
  112. data/spec/unit/plugins/mcollective/data/fstat_data_spec.rb +135 -0
  113. data/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb +48 -0
  114. data/spec/unit/plugins/mcollective/discovery/mc_spec.rb +40 -0
  115. data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +41 -15
  116. data/spec/unit/plugins/mcollective/packagers/ospackage_spec.rb +1 -1
  117. data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +22 -38
  118. data/spec/unit/plugins/mcollective/validator/array_validator_spec.rb +19 -0
  119. data/spec/unit/plugins/mcollective/validator/ipv4address_validator_spec.rb +19 -0
  120. data/spec/unit/plugins/mcollective/validator/ipv6address_validator_spec.rb +19 -0
  121. data/spec/unit/plugins/mcollective/validator/length_validator_spec.rb +19 -0
  122. data/spec/unit/plugins/mcollective/validator/regex_validator_spec.rb +19 -0
  123. data/spec/unit/plugins/mcollective/validator/shellsafe_validator_spec.rb +21 -0
  124. data/spec/unit/plugins/mcollective/validator/typecheck_validator_spec.rb +23 -0
  125. data/spec/unit/registration/base_spec.rb +1 -1
  126. data/spec/unit/rpc/actionrunner_spec.rb +2 -2
  127. data/spec/unit/rpc/agent_spec.rb +41 -65
  128. data/spec/unit/rpc/client_spec.rb +430 -134
  129. data/spec/unit/rpc/reply_spec.rb +31 -1
  130. data/spec/unit/rpc/request_spec.rb +33 -12
  131. data/spec/unit/rpc/result_spec.rb +7 -0
  132. data/spec/unit/rpc/stats_spec.rb +14 -14
  133. data/spec/unit/rpc_spec.rb +16 -0
  134. data/spec/unit/security/base_spec.rb +8 -8
  135. data/spec/unit/ssl_spec.rb +20 -2
  136. data/spec/unit/string_spec.rb +15 -0
  137. data/spec/unit/util_spec.rb +141 -21
  138. data/spec/unit/validator_spec.rb +67 -0
  139. metadata +145 -7
  140. data/lib/mcollective/rpc/ddl.rb +0 -258
@@ -102,6 +102,7 @@ module MCollective
102
102
  "stomp.pool.max_reconnect_attempts" => "5",
103
103
  "stomp.pool.randomize" => "true",
104
104
  "stomp.pool.backup" => "true",
105
+ "stomp.pool.connect_timeout" => 30,
105
106
  "stomp.pool.timeout" => "1"}
106
107
 
107
108
 
@@ -120,6 +121,7 @@ module MCollective
120
121
  :use_exponential_back_off => false,
121
122
  :max_reconnect_attempts => 5,
122
123
  :initial_reconnect_delay => 0.02,
124
+ :connect_timeout => 30,
123
125
  :randomize => true,
124
126
  :reliable => true,
125
127
  :logger => "logger",
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ require File.dirname(__FILE__) + "/../../../../../plugins/mcollective/data/agent_data.rb"
6
+
7
+ module MCollective
8
+ module Data
9
+ describe Agent_data do
10
+ describe "#query_data" do
11
+ before do
12
+ @ddl = mock
13
+ @ddl.stubs(:meta).returns({:timeout => 1})
14
+ DDL.stubs(:new).returns(@ddl)
15
+ @plugin = Agent_data.new
16
+ end
17
+
18
+ it "should fail for unknown agents" do
19
+ expect { @plugin.query_data("rspec") }.to raise_error("No agent called rspec found")
20
+ end
21
+
22
+ it "should retrieve the correct agent and data" do
23
+ agent = mock
24
+ agent.stubs(:meta).returns({:license => "license",
25
+ :timeout => "timeout",
26
+ :description => "description",
27
+ :url => "url",
28
+ :version => "version",
29
+ :author => "author"})
30
+
31
+ PluginManager.stubs(:[]).with("rspec_agent").returns(agent)
32
+ PluginManager.expects(:include?).with("rspec_agent").returns(true)
33
+
34
+ @plugin.query_data("rspec")
35
+
36
+ [:license, :timeout, :description, :url, :version, :author].each do |item|
37
+ @plugin.result[item].should == item.to_s
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ require File.dirname(__FILE__) + "/../../../../../plugins/mcollective/data/fstat_data.rb"
6
+
7
+ module MCollective
8
+ module Data
9
+ describe Fstat_data do
10
+ describe "#query_data" do
11
+ before do
12
+ @ddl = mock
13
+ @ddl.stubs(:meta).returns({:timeout => 1})
14
+ DDL.stubs(:new).returns(@ddl)
15
+ @plugin = Fstat_data.new
16
+
17
+ @time = Time.now
18
+
19
+ @stat = mock
20
+ @stat.stubs(:size).returns(123)
21
+ @stat.stubs(:uid).returns(0)
22
+ @stat.stubs(:gid).returns(0)
23
+ @stat.stubs(:mtime).returns(@time)
24
+ @stat.stubs(:ctime).returns(@time)
25
+ @stat.stubs(:atime).returns(@time)
26
+ @stat.stubs(:mode).returns(33188)
27
+ @stat.stubs(:directory?).returns(false)
28
+ @stat.stubs(:file?).returns(false)
29
+ @stat.stubs(:symlink?).returns(false)
30
+ @stat.stubs(:socket?).returns(false)
31
+ @stat.stubs(:chardev?).returns(false)
32
+ @stat.stubs(:blockdev?).returns(false)
33
+ end
34
+
35
+ it "should detect missing files" do
36
+ File.expects(:exists?).with("/nonexisting").returns(false)
37
+ @plugin.query_data("/nonexisting")
38
+ @plugin.result.output.should == "not present"
39
+ end
40
+
41
+ it "should provide correct file stats" do
42
+ File.expects(:exists?).with("rspec").returns(true)
43
+ File.expects(:symlink?).with("rspec").returns(false)
44
+ File.expects(:stat).with("rspec").returns(@stat)
45
+ File.expects(:read).with("rspec").returns("rspec")
46
+
47
+ @stat.stubs(:file?).returns(true)
48
+
49
+ @plugin.query_data("rspec")
50
+ @plugin.result.output.should == "present"
51
+ @plugin.result.size.should == 123
52
+ @plugin.result.uid.should == 0
53
+ @plugin.result.gid.should == 0
54
+ @plugin.result.mtime.should == @time.strftime("%F %T")
55
+ @plugin.result.mtime_seconds.should == @time.to_i
56
+ @plugin.result.mtime_age.should <= 5
57
+ @plugin.result.ctime.should == @time.strftime("%F %T")
58
+ @plugin.result.ctime_seconds.should == @time.to_i
59
+ @plugin.result.ctime_age.should <= 5
60
+ @plugin.result.atime.should == @time.strftime("%F %T")
61
+ @plugin.result.atime_seconds.should == @time.to_i
62
+ @plugin.result.atime_age.should <= 5
63
+ @plugin.result.mode.should == "100644"
64
+ @plugin.result.md5.should == "2bc84dc69b73db9383b9c6711d2011b7"
65
+ @plugin.result.type.should == "file"
66
+ end
67
+
68
+ it "should provide correct link stats" do
69
+ File.expects(:exists?).with("rspec").returns(true)
70
+ File.expects(:symlink?).with("rspec").returns(true)
71
+ File.expects(:lstat).with("rspec").returns(@stat)
72
+
73
+ @stat.stubs(:symlink?).returns(true)
74
+
75
+ @plugin.query_data("rspec")
76
+ @plugin.result.output.should == "present"
77
+ @plugin.result.md5.should == 0
78
+ @plugin.result.type.should == "symlink"
79
+ end
80
+
81
+ it "should provide correct directory stats" do
82
+ File.expects(:exists?).with("rspec").returns(true)
83
+ File.expects(:symlink?).with("rspec").returns(false)
84
+ File.expects(:stat).with("rspec").returns(@stat)
85
+
86
+ @stat.stubs(:directory?).returns(true)
87
+
88
+ @plugin.query_data("rspec")
89
+ @plugin.result.output.should == "present"
90
+ @plugin.result.md5.should == 0
91
+ @plugin.result.type.should == "directory"
92
+ end
93
+
94
+ it "should provide correct socket stats" do
95
+ File.expects(:exists?).with("rspec").returns(true)
96
+ File.expects(:symlink?).with("rspec").returns(false)
97
+ File.expects(:stat).with("rspec").returns(@stat)
98
+
99
+ @stat.stubs(:socket?).returns(true)
100
+
101
+ @plugin.query_data("rspec")
102
+ @plugin.result.output.should == "present"
103
+ @plugin.result.md5.should == 0
104
+ @plugin.result.type.should == "socket"
105
+ end
106
+
107
+ it "should provide correct chardev stats" do
108
+ File.expects(:exists?).with("rspec").returns(true)
109
+ File.expects(:symlink?).with("rspec").returns(false)
110
+ File.expects(:stat).with("rspec").returns(@stat)
111
+
112
+ @stat.stubs(:chardev?).returns(true)
113
+
114
+ @plugin.query_data("rspec")
115
+ @plugin.result.output.should == "present"
116
+ @plugin.result.md5.should == 0
117
+ @plugin.result.type.should == "chardev"
118
+ end
119
+
120
+ it "should provide correct blockdev stats" do
121
+ File.expects(:exists?).with("rspec").returns(true)
122
+ File.expects(:symlink?).with("rspec").returns(false)
123
+ File.expects(:stat).with("rspec").returns(@stat)
124
+
125
+ @stat.stubs(:blockdev?).returns(true)
126
+
127
+ @plugin.query_data("rspec")
128
+ @plugin.result.output.should == "present"
129
+ @plugin.result.md5.should == 0
130
+ @plugin.result.type.should == "blockdev"
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/discovery/flatfile.rb'
6
+
7
+ module MCollective
8
+ class Discovery
9
+ describe Flatfile do
10
+ describe "#discover" do
11
+ before do
12
+ @client = mock
13
+ @client.stubs(:options).returns({})
14
+ @client.stubs(:options).returns({:discovery_options => ["/nonexisting"]})
15
+
16
+
17
+ File.stubs(:readable?).with("/nonexisting").returns(true)
18
+ File.stubs(:readlines).with("/nonexisting").returns(["one", "two"])
19
+ end
20
+
21
+ it "should use a file specified in discovery_options" do
22
+ File.expects(:readable?).with("/nonexisting").returns(true)
23
+ File.expects(:readlines).with("/nonexisting").returns(["one", "two"])
24
+ Flatfile.discover(Util.empty_filter, 0, 0, @client).should == ["one", "two"]
25
+ end
26
+
27
+ it "should fail unless a file is specified" do
28
+ @client.stubs(:options).returns({:discovery_options => []})
29
+ expect { Flatfile.discover(Util.empty_filter, 0, 0, @client) }.to raise_error("The flatfile discovery method needs a path to a text file")
30
+ end
31
+
32
+ it "should fail for unreadable files" do
33
+ File.expects(:readable?).with("/nonexisting").returns(false)
34
+
35
+ expect { Flatfile.discover(Util.empty_filter, 0, 0, @client) }.to raise_error("Cannot read the file /nonexisting specified as discovery source")
36
+ end
37
+
38
+ it "should regex filters" do
39
+ Flatfile.discover(Util.empty_filter.merge("identity" => [/one/]), 0, 0, @client).should == ["one"]
40
+ end
41
+
42
+ it "should filter against non regex nodes" do
43
+ Flatfile.discover(Util.empty_filter.merge("identity" => ["one"]), 0, 0, @client).should == ["one"]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/discovery/mc.rb'
6
+
7
+ module MCollective
8
+ class Discovery
9
+ describe Mc do
10
+ describe "#discover" do
11
+ before do
12
+ @reply = mock
13
+ @reply.stubs(:payload).returns({:senderid => "rspec"})
14
+
15
+ @client = mock
16
+ @client.stubs(:sendreq)
17
+ @client.stubs(:unsubscribe)
18
+ @client.stubs(:receive).returns(@reply)
19
+
20
+ Log.stubs(:debug)
21
+ end
22
+
23
+ it "should send the ping request via the supplied client" do
24
+ @client.expects(:sendreq).with("ping", "discovery", Util.empty_filter).returns("123456")
25
+ Mc.discover(Util.empty_filter, 1, 1, @client)
26
+ end
27
+
28
+ it "should stop early if a limit is supplied" do
29
+ @client.stubs(:receive).returns(@reply).times(10)
30
+ Mc.discover(Util.empty_filter, 1, 10, @client).should == ("rspec," * 10).split(",")
31
+ end
32
+
33
+ it "should unsubscribe from the discovery reply source" do
34
+ @client.expects(:unsubscribe).with("discovery", :reply)
35
+ Mc.discover(Util.empty_filter, 1, 10, @client).should == ("rspec," * 10).split(",")
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -19,6 +19,7 @@ module MCollective
19
19
  before :each do
20
20
  PluginPackager.stubs(:build_tool?).with("debuild").returns(true)
21
21
  @plugin = mock()
22
+ @plugin.stubs(:mcname).returns("mcollective")
22
23
  end
23
24
 
24
25
  after :all do
@@ -30,7 +31,7 @@ module MCollective
30
31
  PluginPackager.expects(:build_tool?).with("debuild").returns(false)
31
32
  expect{
32
33
  DebpackagePackager.new("plugin")
33
- }.to raise_error RuntimeError, "package 'debuild' is not installed"
34
+ }.to raise_error(RuntimeError, "package 'debuild' is not installed")
34
35
  end
35
36
 
36
37
  it "should set the correct libdir and verbose value" do
@@ -49,6 +50,7 @@ module MCollective
49
50
  @plugin.stubs(:iteration).returns("1")
50
51
  @packager.stubs(:prepare_tmpdirs)
51
52
  @packager.stubs(:create_package)
53
+ @packager.stubs(:move_packages)
52
54
  @packager.stubs(:cleanup_tmpdirs)
53
55
  Dir.stubs(:mktmpdir).with("mcollective_packager").returns("/tmp")
54
56
  Dir.stubs(:mkdir)
@@ -63,7 +65,7 @@ module MCollective
63
65
  end
64
66
 
65
67
  it "Should create the build dir" do
66
- Dir.expects(:mkdir).with("/tmp/mcollective-test_plugin-test_1-1")
68
+ Dir.expects(:mkdir).with("/tmp/mcollective-test_plugin-test_1")
67
69
  @packager.create_packages
68
70
  end
69
71
 
@@ -79,7 +81,7 @@ module MCollective
79
81
  packager.stubs(:create_file).raises("test exception")
80
82
  expect{
81
83
  packager.create_package
82
- }.to raise_error RuntimeError, "Could not build package - test exception"
84
+ }.to raise_error(RuntimeError, "Could not build package - test exception")
83
85
  end
84
86
 
85
87
  it "should correctly create a package" do
@@ -99,7 +101,6 @@ module MCollective
99
101
  packager.tmpdir = "/tmp"
100
102
  packager.current_package_fullname = "test"
101
103
  PluginPackager.expects(:safe_system).with("debuild -i -us -uc")
102
- FileUtils.expects(:cp).with(File.join("/tmp", "test_all.deb"), ".")
103
104
  packager.expects(:puts).with("Created package test")
104
105
 
105
106
  packager.create_package
@@ -122,7 +123,6 @@ module MCollective
122
123
  packager.tmpdir = "/tmp"
123
124
  packager.current_package_fullname = "test"
124
125
  PluginPackager.expects(:safe_system).with("debuild -i -ktest")
125
- FileUtils.expects(:cp).with(File.join("/tmp", "test_all.deb"), ".")
126
126
  packager.expects(:puts).with("Created package test")
127
127
 
128
128
  packager.create_package
@@ -139,7 +139,7 @@ module MCollective
139
139
  File.expects(:exists?).with("myscript").returns(false)
140
140
  expect{
141
141
  @packager.create_preandpost_install
142
- }.to raise_error RuntimeError, "pre-install script 'myscript' not found"
142
+ }.to raise_error(RuntimeError, "pre-install script 'myscript' not found")
143
143
  end
144
144
 
145
145
  it "should raise an exception if postinstall is not null and postinstall script isn't present" do
@@ -148,7 +148,7 @@ module MCollective
148
148
  File.expects(:exists?).with("myscript").returns(false)
149
149
  expect{
150
150
  @packager.create_preandpost_install
151
- }.to raise_error RuntimeError, "post-install script 'myscript' not found"
151
+ }.to raise_error(RuntimeError, "post-install script 'myscript' not found")
152
152
  end
153
153
 
154
154
  it "should copy the preinstall and postinstall scripts to the correct directory with the correct name" do
@@ -166,13 +166,14 @@ module MCollective
166
166
  describe "#create_install" do
167
167
  before :each do
168
168
  @packager = DebpackagePackager.new(@plugin)
169
+ @plugin.stubs(:path).returns("")
169
170
  end
170
171
 
171
172
  it "should raise an exception if the install file can't be created" do
172
173
  File.expects(:join).raises("test error")
173
174
  expect{
174
175
  @packager.create_install
175
- }.to raise_error RuntimeError, "Could not create install file - test error"
176
+ }.to raise_error(RuntimeError, "Could not create install file - test error")
176
177
  end
177
178
 
178
179
  it "should copy the package install file to the correct location" do
@@ -183,7 +184,29 @@ module MCollective
183
184
  @packager.current_package_data = {:files => ["foo.rb"]}
184
185
  @packager.create_install
185
186
  install_file = File.read("#{tmpdir}/debian/test.install")
186
- install_file.should == "/usr/share/mcollective/plugins/mcollective/foo.rb /usr/share/mcollective/plugins/mcollective/.\n"
187
+ install_file.should == "/usr/share/mcollective/plugins/mcollective/foo.rb /usr/share/mcollective/plugins/mcollective\n"
188
+ end
189
+ end
190
+
191
+ describe "#move_packages" do
192
+ before :each do
193
+ @plugin = mock()
194
+ end
195
+
196
+ it "should move the packages to the working directory" do
197
+ Dir.expects(:glob)
198
+ File.expects(:join)
199
+ FileUtils.expects(:cp)
200
+ @packager = DebpackagePackager.new(@plugin)
201
+ @packager.move_packages
202
+ end
203
+
204
+ it "should raise an error if the packages could not be moved" do
205
+ @packager = DebpackagePackager.new(@plugin)
206
+ File.expects(:join).raises("error")
207
+ expect{
208
+ @packager.move_packages
209
+ }.to raise_error(RuntimeError, "Could not copy packages to working directory: 'error'")
187
210
  end
188
211
  end
189
212
 
@@ -196,7 +219,7 @@ module MCollective
196
219
  PluginPackager.expects(:do_quietly?).raises("test error")
197
220
  expect{
198
221
  @packager.create_tar
199
- }.to raise_error RuntimeError, "Could not create tarball - test error"
222
+ }.to raise_error(RuntimeError, "Could not create tarball - test error")
200
223
  end
201
224
 
202
225
  it "should create a tarball containing the package files" do
@@ -206,7 +229,7 @@ module MCollective
206
229
  @plugin.stubs(:metadata).returns(@plugin)
207
230
  @plugin.stubs(:[]).with(:version).returns("1")
208
231
  @plugin.stubs(:iteration).returns("1")
209
- PluginPackager.expects(:safe_system).with("tar -Pcvzf /tmp/test_1.orig.tar.gz /build_dir")
232
+ PluginPackager.expects(:safe_system).with("tar -Pcvzf /tmp/test_1.orig.tar.gz test_1")
210
233
  @packager.create_tar
211
234
  end
212
235
  end
@@ -220,7 +243,7 @@ module MCollective
220
243
  File.expects(:dirname).raises("test error")
221
244
  expect{
222
245
  @packager.create_file("test")
223
- }.to raise_error RuntimeError, "could not create test file - test error"
246
+ }.to raise_error(RuntimeError, "could not create test file - test error")
224
247
  end
225
248
 
226
249
  it "should place a build file in the debian directory" do
@@ -237,12 +260,15 @@ module MCollective
237
260
  end
238
261
 
239
262
  describe "#prepare_tmpdirs" do
240
- before :all do
263
+ before :each do
241
264
  @tmpfile = Tempfile.new("mc-file").path
242
265
  end
243
266
 
244
- after :all do
245
- FileUtils.rm(@tmpfile)
267
+ after :each do
268
+ begin
269
+ FileUtils.rm(@tmpfile)
270
+ rescue Exception
271
+ end
246
272
  end
247
273
 
248
274
  it "should create the correct tmp dirs and copy package contents to correct dir" do