mcollective-client 1.3.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mcollective-client might be problematic. Click here for more details.
- data/bin/mc-call-agent +27 -27
- data/bin/mco +21 -11
- data/lib/mcollective.rb +2 -2
- data/lib/mcollective/pluginpackager.rb +35 -0
- data/lib/mcollective/pluginpackager/agent_definition.rb +18 -11
- data/lib/mcollective/pluginpackager/standard_definition.rb +15 -8
- data/lib/mcollective/rpc/client.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/application_spec.rb +2 -9
- data/spec/unit/{array.rb → array_spec.rb} +0 -0
- data/spec/unit/pluginpackager/agent_definition_spec.rb +27 -13
- data/spec/unit/pluginpackager/standard_definition_spec.rb +29 -16
- data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +285 -0
- data/spec/unit/plugins/mcollective/packagers/ospackage_spec.rb +33 -205
- data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +183 -0
- data/spec/unit/rpc/client_spec.rb +3 -3
- data/spec/unit/rpc/helpers_spec.rb +3 -3
- data/spec/unit/security/base_spec.rb +1 -1
- data/spec/unit/ssl_spec.rb +1 -1
- data/spec/unit/{symbol.rb → symbol_spec.rb} +0 -0
- data/spec/unit/{unix_daemon.rb → unix_daemon_spec.rb} +0 -0
- data/spec/unit/{windows_daemon.rb → windows_daemon_spec.rb} +0 -0
- metadata +20 -16
@@ -9,9 +9,22 @@ module MCollective
|
|
9
9
|
PluginPackager.expects(:get_metadata).once.returns({:name => "foo"})
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
describe "#initialize" do
|
13
|
+
it "should replace spaces in the package name with dashes" do
|
14
|
+
plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {}, "testplugin")
|
15
|
+
plugin.metadata[:name].should == "test-plugin"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set dependencies if present" do
|
19
|
+
plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, ["foo"], {}, "testplugin")
|
20
|
+
plugin.dependencies.should == ["foo"]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set mc server, client and common dependencies" do
|
24
|
+
plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {:server => "pe-mcollective"}, "testplugin")
|
25
|
+
plugin.mcserver.should == "pe-mcollective"
|
26
|
+
plugin.mccommon.should == "mcollective-common"
|
27
|
+
end
|
15
28
|
end
|
16
29
|
|
17
30
|
describe "#identify_packages" do
|
@@ -19,9 +32,9 @@ module MCollective
|
|
19
32
|
StandardDefinition.any_instance.expects(:common).once.returns(:check)
|
20
33
|
StandardDefinition.any_instance.expects(:plugin).once.returns(:check)
|
21
34
|
|
22
|
-
plugin = StandardDefinition.new(".", nil, nil, nil, nil,
|
35
|
+
plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
|
23
36
|
plugin.packagedata[:common].should == :check
|
24
|
-
plugin.packagedata[
|
37
|
+
plugin.packagedata["testplugin"].should == :check
|
25
38
|
end
|
26
39
|
end
|
27
40
|
|
@@ -30,25 +43,25 @@ module MCollective
|
|
30
43
|
it "should return nil if the plugin doesn't contain any files" do
|
31
44
|
StandardDefinition.any_instance.expects(:common).returns(nil)
|
32
45
|
PluginPackager.expects(:check_dir_present).returns(false)
|
33
|
-
plugin = StandardDefinition.new(".", nil, nil, nil, nil,
|
34
|
-
plugin.packagedata[
|
46
|
+
plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
|
47
|
+
plugin.packagedata["testplugin"].should == nil
|
35
48
|
end
|
36
49
|
|
37
50
|
it "should add plugin files to the file list" do
|
38
51
|
StandardDefinition.any_instance.expects(:common).returns(nil)
|
39
52
|
PluginPackager.expects(:check_dir_present).returns(true)
|
40
|
-
Dir.expects(:glob).with("./
|
41
|
-
plugin = StandardDefinition.new(".", nil, nil, nil, nil,
|
42
|
-
plugin.packagedata[
|
53
|
+
Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"])
|
54
|
+
plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
|
55
|
+
plugin.packagedata["testplugin"][:files].should == ["file.rb"]
|
43
56
|
end
|
44
57
|
|
45
58
|
it "should add common package as dependency if present" do
|
46
59
|
StandardDefinition.any_instance.expects(:common).returns(true)
|
47
60
|
PluginPackager.expects(:check_dir_present).returns(true)
|
48
|
-
Dir.expects(:glob).with("./
|
49
|
-
plugin = StandardDefinition.new(".", nil, nil, nil, nil,
|
50
|
-
plugin.packagedata[
|
51
|
-
plugin.packagedata[
|
61
|
+
Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"])
|
62
|
+
plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
|
63
|
+
plugin.packagedata["testplugin"][:files].should == ["file.rb"]
|
64
|
+
plugin.packagedata["testplugin"][:dependencies].should == ["mcollective", "mcollective-foo-common"]
|
52
65
|
end
|
53
66
|
end
|
54
67
|
|
@@ -59,14 +72,14 @@ module MCollective
|
|
59
72
|
|
60
73
|
it "should return nil if common doesn't contain any files" do
|
61
74
|
PluginPackager.expects(:check_dir_present).returns(false)
|
62
|
-
plugin = StandardDefinition.new(".", nil, nil, nil, nil,
|
75
|
+
plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
|
63
76
|
plugin.packagedata[:common].should == nil
|
64
77
|
end
|
65
78
|
|
66
79
|
it "should add common files to the file list" do
|
67
80
|
PluginPackager.expects(:check_dir_present).returns(true)
|
68
81
|
Dir.expects(:glob).with("./util/*").returns(["common.rb"])
|
69
|
-
plugin = StandardDefinition.new(".", nil, nil, nil, nil,
|
82
|
+
plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
|
70
83
|
plugin.packagedata[:common][:files].should == ["common.rb"]
|
71
84
|
end
|
72
85
|
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/pluginpackager/debpackage_packager.rb'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module PluginPackager
|
7
|
+
describe DebpackagePackager do
|
8
|
+
|
9
|
+
let(:maketmpdir) do
|
10
|
+
tmpdir = Dir.mktmpdir("mc-test")
|
11
|
+
@tmpdirs << tmpdir
|
12
|
+
tmpdir
|
13
|
+
end
|
14
|
+
|
15
|
+
before :all do
|
16
|
+
@tmpdirs = []
|
17
|
+
end
|
18
|
+
|
19
|
+
before :each do
|
20
|
+
PluginPackager.stubs(:build_tool?).with("debuild").returns(true)
|
21
|
+
@plugin = mock()
|
22
|
+
end
|
23
|
+
|
24
|
+
after :all do
|
25
|
+
@tmpdirs.each{|tmpdir| FileUtils.rm_rf tmpdir if File.directory? tmpdir}
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#initialize" do
|
29
|
+
it "should raise an exception if debuild isn't present" do
|
30
|
+
PluginPackager.expects(:build_tool?).with("debuild").returns(false)
|
31
|
+
expect{
|
32
|
+
DebpackagePackager.new("plugin")
|
33
|
+
}.to raise_error RuntimeError, "package 'debuild' is not installed"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should set the correct libdir and verbose value" do
|
37
|
+
PluginPackager.expects(:build_tool?).with("debuild").returns(true)
|
38
|
+
packager = DebpackagePackager.new("plugin", nil, nil, true)
|
39
|
+
packager.libdir.should == "/usr/share/mcollective/plugins/mcollective/"
|
40
|
+
packager.verbose.should == true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#create_packages" do
|
45
|
+
before :each do
|
46
|
+
@packager = DebpackagePackager.new(@plugin)
|
47
|
+
@plugin.stubs(:packagedata).returns({:test => {:files => ["test.rb"]}})
|
48
|
+
@plugin.stubs(:metadata).returns({:name => "test_plugin", :version => "1"})
|
49
|
+
@plugin.stubs(:iteration).returns("1")
|
50
|
+
@packager.stubs(:prepare_tmpdirs)
|
51
|
+
@packager.stubs(:create_package)
|
52
|
+
@packager.stubs(:cleanup_tmpdirs)
|
53
|
+
Dir.stubs(:mktmpdir).with("mcollective_packager").returns("/tmp")
|
54
|
+
Dir.stubs(:mkdir)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set the package instance variables" do
|
58
|
+
@packager.create_packages
|
59
|
+
@packager.current_package_type.should == :test
|
60
|
+
@packager.current_package_data.should == {:files => ["test.rb"]}
|
61
|
+
@packager.current_package_shortname.should == "mcollective-test_plugin-test"
|
62
|
+
@packager.current_package_fullname.should == "mcollective-test_plugin-test_1-1"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "Should create the build dir" do
|
66
|
+
Dir.expects(:mkdir).with("/tmp/mcollective-test_plugin-test_1-1")
|
67
|
+
@packager.create_packages
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should create packages" do
|
71
|
+
@packager.expects(:create_package)
|
72
|
+
@packager.create_packages
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#create_package" do
|
77
|
+
it "should raise an exception if the package cannot be created" do
|
78
|
+
packager = DebpackagePackager.new(@plugin)
|
79
|
+
packager.stubs(:create_file).raises("test exception")
|
80
|
+
expect{
|
81
|
+
packager.create_package
|
82
|
+
}.to raise_error RuntimeError, "Could not build package - test exception"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should correctly create a package" do
|
86
|
+
packager = DebpackagePackager.new(@plugin, nil, nil, true)
|
87
|
+
|
88
|
+
packager.expects(:create_file).with("control")
|
89
|
+
packager.expects(:create_file).with("Makefile")
|
90
|
+
packager.expects(:create_file).with("compat")
|
91
|
+
packager.expects(:create_file).with("rules")
|
92
|
+
packager.expects(:create_file).with("copyright")
|
93
|
+
packager.expects(:create_file).with("changelog")
|
94
|
+
packager.expects(:create_tar)
|
95
|
+
packager.expects(:create_install)
|
96
|
+
packager.expects(:create_preandpost_install)
|
97
|
+
|
98
|
+
packager.build_dir = "/tmp"
|
99
|
+
packager.tmpdir = "/tmp"
|
100
|
+
packager.current_package_fullname = "test"
|
101
|
+
PluginPackager.expects(:safe_system).with("debuild -i -us -uc")
|
102
|
+
FileUtils.expects(:cp).with(File.join("/tmp", "test_all.deb"), ".")
|
103
|
+
packager.expects(:puts).with("Created package test")
|
104
|
+
|
105
|
+
packager.create_package
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should add a signature if one is given" do
|
109
|
+
packager = DebpackagePackager.new(@plugin, nil, "test", true)
|
110
|
+
|
111
|
+
packager.expects(:create_file).with("control")
|
112
|
+
packager.expects(:create_file).with("Makefile")
|
113
|
+
packager.expects(:create_file).with("compat")
|
114
|
+
packager.expects(:create_file).with("rules")
|
115
|
+
packager.expects(:create_file).with("copyright")
|
116
|
+
packager.expects(:create_file).with("changelog")
|
117
|
+
packager.expects(:create_tar)
|
118
|
+
packager.expects(:create_install)
|
119
|
+
packager.expects(:create_preandpost_install)
|
120
|
+
|
121
|
+
packager.build_dir = "/tmp"
|
122
|
+
packager.tmpdir = "/tmp"
|
123
|
+
packager.current_package_fullname = "test"
|
124
|
+
PluginPackager.expects(:safe_system).with("debuild -i -ktest")
|
125
|
+
FileUtils.expects(:cp).with(File.join("/tmp", "test_all.deb"), ".")
|
126
|
+
packager.expects(:puts).with("Created package test")
|
127
|
+
|
128
|
+
packager.create_package
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#create_preandpost_install" do
|
133
|
+
before :each do
|
134
|
+
@packager = DebpackagePackager.new(@plugin)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should raise an exception if preinstall is not null and preinstall script isn't present" do
|
138
|
+
@plugin.stubs(:preinstall).returns("myscript")
|
139
|
+
File.expects(:exists?).with("myscript").returns(false)
|
140
|
+
expect{
|
141
|
+
@packager.create_preandpost_install
|
142
|
+
}.to raise_error RuntimeError, "pre-install script 'myscript' not found"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should raise an exception if postinstall is not null and postinstall script isn't present" do
|
146
|
+
@plugin.stubs(:preinstall).returns(nil)
|
147
|
+
@plugin.stubs(:postinstall).returns("myscript")
|
148
|
+
File.expects(:exists?).with("myscript").returns(false)
|
149
|
+
expect{
|
150
|
+
@packager.create_preandpost_install
|
151
|
+
}.to raise_error RuntimeError, "post-install script 'myscript' not found"
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should copy the preinstall and postinstall scripts to the correct directory with the correct name" do
|
155
|
+
@plugin.stubs(:postinstall).returns("myscript")
|
156
|
+
@plugin.stubs(:preinstall).returns("myscript")
|
157
|
+
@packager.build_dir = "/tmp/"
|
158
|
+
@packager.current_package_shortname = "test"
|
159
|
+
File.expects(:exists?).with("myscript").twice.returns(true)
|
160
|
+
FileUtils.expects(:cp).with("myscript", "/tmp/debian/test.preinst")
|
161
|
+
FileUtils.expects(:cp).with("myscript", "/tmp/debian/test.postinst")
|
162
|
+
@packager.create_preandpost_install
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "#create_install" do
|
167
|
+
before :each do
|
168
|
+
@packager = DebpackagePackager.new(@plugin)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should raise an exception if the install file can't be created" do
|
172
|
+
File.expects(:join).raises("test error")
|
173
|
+
expect{
|
174
|
+
@packager.create_install
|
175
|
+
}.to raise_error RuntimeError, "Could not create install file - test error"
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should copy the package install file to the correct location" do
|
179
|
+
tmpdir = maketmpdir
|
180
|
+
Dir.mkdir(File.join(tmpdir, "debian"))
|
181
|
+
@packager.build_dir = tmpdir
|
182
|
+
@packager.current_package_shortname = "test"
|
183
|
+
@packager.current_package_data = {:files => ["foo.rb"]}
|
184
|
+
@packager.create_install
|
185
|
+
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
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "#create_tar" do
|
191
|
+
before :each do
|
192
|
+
@packager = DebpackagePackager.new(@plugin, nil, true)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should raise an exception if the tarball can't be built" do
|
196
|
+
PluginPackager.expects(:do_quietly?).raises("test error")
|
197
|
+
expect{
|
198
|
+
@packager.create_tar
|
199
|
+
}.to raise_error RuntimeError, "Could not create tarball - test error"
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should create a tarball containing the package files" do
|
203
|
+
@packager.tmpdir = "/tmp"
|
204
|
+
@packager.build_dir = "/build_dir"
|
205
|
+
@packager.current_package_shortname = "test"
|
206
|
+
@plugin.stubs(:metadata).returns(@plugin)
|
207
|
+
@plugin.stubs(:[]).with(:version).returns("1")
|
208
|
+
@plugin.stubs(:iteration).returns("1")
|
209
|
+
PluginPackager.expects(:safe_system).with("tar -Pcvzf /tmp/test_1.orig.tar.gz /build_dir")
|
210
|
+
@packager.create_tar
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "#create_file" do
|
215
|
+
before :each do
|
216
|
+
@packager = DebpackagePackager.new(@plugin)
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should raise an exception if the file can't be created" do
|
220
|
+
File.expects(:dirname).raises("test error")
|
221
|
+
expect{
|
222
|
+
@packager.create_file("test")
|
223
|
+
}.to raise_error RuntimeError, "could not create test file - test error"
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should place a build file in the debian directory" do
|
227
|
+
tmpdir = maketmpdir
|
228
|
+
Dir.mkdir(File.join(tmpdir, "debian"))
|
229
|
+
@packager.build_dir = tmpdir
|
230
|
+
File.expects(:read).returns("testfile")
|
231
|
+
@packager.create_file("testfile")
|
232
|
+
File.unstub(:read)
|
233
|
+
result = File.read(File.join(tmpdir, "debian", "testfile"))
|
234
|
+
result.stubs(:result)
|
235
|
+
result.should == "testfile\n"
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe "#prepare_tmpdirs" do
|
240
|
+
before :all do
|
241
|
+
@tmpfile = Tempfile.new("mc-file").path
|
242
|
+
end
|
243
|
+
|
244
|
+
after :all do
|
245
|
+
FileUtils.rm(@tmpfile)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should create the correct tmp dirs and copy package contents to correct dir" do
|
249
|
+
packager = DebpackagePackager.new(@plugin)
|
250
|
+
tmpdir = maketmpdir
|
251
|
+
packager.build_dir = tmpdir
|
252
|
+
@plugin.stubs(:target_path).returns("")
|
253
|
+
|
254
|
+
packager.prepare_tmpdirs({:files => [@tmpfile]})
|
255
|
+
File.directory?(tmpdir).should == true
|
256
|
+
File.directory?(File.join(tmpdir, "debian")).should == true
|
257
|
+
File.exists?(File.join(tmpdir, packager.libdir, "tmp", File.basename(@tmpfile))).should == true
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe "#cleanup_tmpdirs" do
|
262
|
+
before :all do
|
263
|
+
@tmpdir = maketmpdir
|
264
|
+
end
|
265
|
+
|
266
|
+
before :each do
|
267
|
+
@packager = DebpackagePackager.new(@plugin)
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should cleanup temp directories" do
|
271
|
+
@packager.tmpdir = @tmpdir
|
272
|
+
@packager.cleanup_tmpdirs
|
273
|
+
File.directory?(@tmpdir).should == false
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should not delete any directories if @tmpdir isn't present" do
|
277
|
+
@packager = DebpackagePackager.new(@plugin)
|
278
|
+
@packager.tmpdir = rand.to_s
|
279
|
+
FileUtils.expects(:rm_r).never
|
280
|
+
@packager.cleanup_tmpdirs
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
@@ -7,222 +7,50 @@ require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/pluginpack
|
|
7
7
|
|
8
8
|
module MCollective
|
9
9
|
module PluginPackager
|
10
|
-
describe
|
11
|
-
before :all do
|
12
|
-
|
13
|
-
class OspackagePackager
|
14
|
-
ENV = {"PATH" => "."}
|
15
|
-
end
|
16
|
-
|
17
|
-
class TestPlugin
|
18
|
-
attr_accessor :path, :packagedata, :metadata, :target_path, :vendor, :iteration
|
19
|
-
attr_accessor :postinstall
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
@path = "/tmp"
|
23
|
-
@packagedata = {:testpackage => {:files => ["/tmp/test.rb"],
|
24
|
-
:dependencies => ["mcollective"],
|
25
|
-
:description => "testpackage"}}
|
26
|
-
@iteration = 1
|
27
|
-
@postinstall = "/tmp/test.sh"
|
28
|
-
@metadata = {:name => "testplugin",
|
29
|
-
:description => "A Test Plugin",
|
30
|
-
:author => "Psy",
|
31
|
-
:license => "Apache 2",
|
32
|
-
:version => "0",
|
33
|
-
:url => "http://foo.bar.com",
|
34
|
-
:timeout => 5}
|
35
|
-
@vendor = "Puppet Labs"
|
36
|
-
@target_path = "/tmp"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
@testplugin = TestPlugin.new
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "#initialize" do
|
44
|
-
it "should correctly identify a RedHat system" do
|
45
|
-
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
46
|
-
OspackagePackager.any_instance.expects(:build_tool?).with("rpmbuild").returns(true)
|
47
|
-
|
48
|
-
ospackage = OspackagePackager.new(@testplugin)
|
49
|
-
ospackage.libdir.should == "usr/libexec/mcollective/mcollective/"
|
50
|
-
ospackage.package_type.should == "RPM"
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should correctly identify a Debian System" do
|
54
|
-
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
55
|
-
File.expects(:exists?).with("/etc/debian_version").returns(true)
|
56
|
-
OspackagePackager.any_instance.expects(:build_tool?).with("ar").returns(true)
|
10
|
+
describe "#initialize" do
|
57
11
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should raise an exception if it cannot identify the operating system" do
|
64
|
-
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
65
|
-
File.expects(:exists?).with("/etc/debian_version").returns(false)
|
66
|
-
|
67
|
-
expect{
|
68
|
-
ospackage = OspackagePackager.new(@testplugin)
|
69
|
-
}.to raise_exception "error: cannot identify operating system."
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should identify if rpmbuild is present for RedHat systems" do
|
73
|
-
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
74
|
-
File.expects(:exists?).with("./rpmbuild").returns(true)
|
75
|
-
ospackage = OspackagePackager.new(@testplugin)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should raise an exception if rpmbuild is not present for RedHat systems" do
|
79
|
-
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
80
|
-
File.expects(:exists?).with("./rpmbuild").returns(false)
|
81
|
-
expect{
|
82
|
-
ospackage = OspackagePackager.new(@testplugin)
|
83
|
-
}.to raise_error "error: package 'rpm-build' is not installed."
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should identify if ar is present for Debian systems" do
|
87
|
-
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
88
|
-
File.expects(:exists?).with("/etc/debian_version").returns(true)
|
89
|
-
File.expects(:exists?).with("./ar").returns(true)
|
90
|
-
|
91
|
-
ospackage = OspackagePackager.new(@testplugin)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should raise an exception if the build tool is not present" do
|
95
|
-
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
96
|
-
File.expects(:exists?).with("/etc/debian_version").returns(true)
|
97
|
-
File.expects(:exists?).with("./ar").returns(false)
|
98
|
-
expect{
|
99
|
-
ospackage = OspackagePackager.new(@testplugin)
|
100
|
-
}.to raise_error "error: package 'ar' is not installed."
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "#create_packages" do
|
105
|
-
it "should prepare temp directories, create a package and clean up when done" do
|
106
|
-
OspackagePackager.any_instance.stubs(:gem).with("fpm", "= 0.4.3")
|
107
|
-
OspackagePackager.any_instance.stubs(:require).with("fpm")
|
108
|
-
OspackagePackager.any_instance.stubs(:require).with("tmpdir")
|
109
|
-
|
110
|
-
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
111
|
-
OspackagePackager.any_instance.expects(:build_tool?).with("rpmbuild").returns(true)
|
112
|
-
Dir.expects(:mktmpdir).with("mcollective_packager").returns("/tmp/mcollective_packager")
|
113
|
-
FileUtils.expects(:mkdir_p).with("/tmp/mcollective_packager/usr/libexec/mcollective/mcollective/")
|
114
|
-
|
115
|
-
ospackage = OspackagePackager.new(@testplugin)
|
116
|
-
ospackage.expects(:prepare_tmpdirs).once
|
117
|
-
ospackage.expects(:create_package).once
|
118
|
-
ospackage.expects(:cleanup_tmpdirs).once
|
119
|
-
|
120
|
-
ospackage.create_packages
|
121
|
-
end
|
12
|
+
before :all do
|
13
|
+
@packager = mock()
|
14
|
+
@packager.stubs(:new)
|
122
15
|
end
|
123
16
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
class RPM
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
@fpm_dir = mock
|
136
|
-
@fpm_type = mock
|
137
|
-
@package = mock
|
138
|
-
@fpm_dir.stubs(:convert).returns(@fpm_type)
|
139
|
-
@fpm_dir.stubs(:attributes).returns({:chdir => nil})
|
140
|
-
@fpm_dir.stubs(:input)
|
141
|
-
@package.stubs(:metadata).returns({:name => "testpackage", :version => "1"})
|
142
|
-
@package.stubs(:iteration).returns("1")
|
143
|
-
OspackagePackager.any_instance.stubs(:package).returns(@package)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should run fpm with the correct parameters" do
|
147
|
-
File.stubs(:exists?).returns(true)
|
148
|
-
OspackagePackager.any_instance.expects(:build_tool?).returns(true)
|
149
|
-
ospackage = OspackagePackager.new(@testpackage)
|
150
|
-
::FPM::Package::Dir.stubs(:new).returns(@fpm_dir)
|
151
|
-
ospackage.expects(:params)
|
152
|
-
ospackage.expects(:do_quietly?)
|
153
|
-
@fpm_dir.expects(:cleanup)
|
154
|
-
@fpm_type.expects(:cleanup)
|
155
|
-
ospackage.expects(:puts).with("Successfully built RPM 'mcollective-testpackage-testpackage-1-1.noarch.rpm'")
|
156
|
-
ospackage.create_package(:testpackage, {:files => ["/tmp/test.rb"], :description => "testpackage", :dependencies =>"dependencies"})
|
157
|
-
end
|
17
|
+
it "should correctly set members and create the correct packager on redhat" do
|
18
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
19
|
+
PluginPackager.expects(:[]).with("RpmpackagePackager").returns(@packager)
|
20
|
+
ospackager = OspackagePackager.new("package")
|
21
|
+
ospackager.package_type.should == "RPM"
|
158
22
|
end
|
159
23
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
ospackage = OspackagePackager.new(@testplugin)
|
167
|
-
|
168
|
-
old_stdout = $stdout
|
169
|
-
new_stdout = File.open("/tmp/output.txt", "w+")
|
170
|
-
$stdout = new_stdout
|
171
|
-
ospackage.do_quietly?{puts "teststring"}
|
172
|
-
$stdout = old_stdout
|
173
|
-
File.read("/tmp/output.txt").should == ""
|
174
|
-
FileUtils.rm("/tmp/output.txt")
|
175
|
-
end
|
24
|
+
it "should correctly set members and create the correct packager on debian" do
|
25
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
26
|
+
File.expects(:exists?).with("/etc/debian_version").returns(true)
|
27
|
+
PluginPackager.expects(:[]).with("DebpackagePackager").returns(@packager)
|
28
|
+
ospackager = OspackagePackager.new("package")
|
29
|
+
ospackager.package_type.should == "Deb"
|
176
30
|
end
|
177
31
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
fpm_type = mock
|
185
|
-
fpm_type.expects(:name=).with("mcollective-testplugin-testpackage")
|
186
|
-
fpm_type.expects(:maintainer=).with("Psy")
|
187
|
-
fpm_type.expects(:version=).with("0")
|
188
|
-
fpm_type.expects(:url=).with("http://foo.bar.com")
|
189
|
-
fpm_type.expects(:license=).with("Apache 2")
|
190
|
-
fpm_type.expects(:iteration=).with(1)
|
191
|
-
fpm_type.expects(:vendor=).with("Puppet Labs")
|
192
|
-
fpm_type.expects(:architecture=).with("all")
|
193
|
-
fpm_type.expects(:description=).with("A Test Plugin\n\ntestpackage")
|
194
|
-
fpm_type.expects(:dependencies=).with(["mcollective"])
|
195
|
-
fpm_type.expects(:scripts).returns({"post-install" => nil})
|
196
|
-
|
197
|
-
ospackage.params(fpm_type,:testpackage, @testplugin.packagedata[:testpackage])
|
198
|
-
|
199
|
-
end
|
32
|
+
it "should raise an exception if the os can't be identified" do
|
33
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(false)
|
34
|
+
File.expects(:exists?).with("/etc/debian_version").returns(false)
|
35
|
+
expect{
|
36
|
+
OspackagePackager.new("package")
|
37
|
+
}.to raise_error RuntimeError
|
200
38
|
end
|
39
|
+
end
|
201
40
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
File.expects(:directory?).with("/tmp/mcollective_packager/").returns(false)
|
207
|
-
FileUtils.expects(:mkdir_p).with("/tmp/mcollective_packager/")
|
208
|
-
FileUtils.expects(:cp_r).with("/tmp/test.rb", "/tmp/mcollective_packager/")
|
209
|
-
|
210
|
-
ospackage = OspackagePackager.new(@testplugin)
|
211
|
-
ospackage.workingdir = "/tmp/mcollective_packager/"
|
212
|
-
ospackage.prepare_tmpdirs(@testplugin.packagedata[:testpackage])
|
213
|
-
end
|
41
|
+
describe "#create_packages" do
|
42
|
+
before :all do
|
43
|
+
@packager = mock
|
44
|
+
@packager.stubs(:new).returns(@packager)
|
214
45
|
end
|
215
46
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
ospackage.tmpdir = "/tmp/mcollective_packager/"
|
224
|
-
ospackage.cleanup_tmpdirs
|
225
|
-
end
|
47
|
+
it "should call a packagers create_packages class" do
|
48
|
+
File.expects(:exists?).with("/etc/redhat-release").returns(true)
|
49
|
+
PluginPackager.expects(:[]).with("RpmpackagePackager").returns(@packager)
|
50
|
+
@packager.expects(:create_packages)
|
51
|
+
ospackager = OspackagePackager.new("package")
|
52
|
+
ospackager.class.should == OspackagePackager
|
53
|
+
ospackager.create_packages
|
226
54
|
end
|
227
55
|
end
|
228
56
|
end
|