mcollective-client 2.2.4 → 2.4.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.
- checksums.yaml +7 -0
- data/lib/mcollective/application.rb +25 -34
- data/lib/mcollective/client.rb +91 -33
- data/lib/mcollective/config.rb +42 -43
- data/lib/mcollective/data/base.rb +1 -1
- data/lib/mcollective/data/result.rb +6 -2
- data/lib/mcollective/ddl/agentddl.rb +28 -1
- data/lib/mcollective/ddl/base.rb +8 -6
- data/lib/mcollective/log.rb +11 -3
- data/lib/mcollective/logger/file_logger.rb +4 -4
- data/lib/mcollective/matcher.rb +9 -1
- data/lib/mcollective/message.rb +14 -23
- data/lib/mcollective/optionparser.rb +9 -1
- data/lib/mcollective/pluginpackager.rb +24 -3
- data/lib/mcollective/pluginpackager/agent_definition.rb +12 -12
- data/lib/mcollective/pluginpackager/standard_definition.rb +12 -12
- data/lib/mcollective/rpc/agent.rb +15 -12
- data/lib/mcollective/rpc/client.rb +67 -31
- data/lib/mcollective/rpc/helpers.rb +7 -1
- data/lib/mcollective/rpc/reply.rb +3 -1
- data/lib/mcollective/shell.rb +45 -8
- data/lib/mcollective/util.rb +37 -1
- data/lib/mcollective/windows_daemon.rb +14 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/application_spec.rb +45 -26
- data/spec/unit/cache_spec.rb +3 -3
- data/spec/unit/client_spec.rb +269 -24
- data/spec/unit/config_spec.rb +89 -26
- data/spec/unit/data/base_spec.rb +1 -0
- data/spec/unit/data/result_spec.rb +19 -1
- data/spec/unit/data_spec.rb +3 -0
- data/spec/unit/ddl/agentddl_spec.rb +32 -0
- data/spec/unit/ddl/base_spec.rb +4 -0
- data/spec/unit/ddl/dataddl_spec.rb +1 -1
- data/spec/unit/log_spec.rb +44 -27
- data/spec/unit/logger/base_spec.rb +1 -1
- data/spec/unit/matcher_spec.rb +14 -0
- data/spec/unit/message_spec.rb +24 -0
- data/spec/unit/optionparser_spec.rb +99 -0
- data/spec/unit/pluginpackager/agent_definition_spec.rb +48 -17
- data/spec/unit/pluginpackager/standard_definition_spec.rb +44 -20
- data/spec/unit/pluginpackager_spec.rb +31 -7
- data/spec/unit/plugins/mcollective/agent/rpcutil_spec.rb +176 -0
- data/spec/unit/plugins/mcollective/application/plugin_spec.rb +81 -0
- data/spec/unit/plugins/mcollective/audit/logfile_spec.rb +44 -0
- data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +118 -27
- data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +168 -34
- data/spec/unit/plugins/mcollective/data/agent_data_spec.rb +1 -0
- data/spec/unit/plugins/mcollective/data/fstat_data_spec.rb +1 -0
- data/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb +10 -0
- data/spec/unit/plugins/mcollective/discovery/stdin_spec.rb +65 -0
- data/spec/unit/plugins/mcollective/facts/yaml_facts_spec.rb +65 -0
- data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +240 -219
- data/spec/unit/plugins/mcollective/packagers/modulepackage_packager_spec.rb +209 -0
- data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +223 -109
- data/spec/unit/rpc/actionrunner_spec.rb +2 -1
- data/spec/unit/rpc/agent_spec.rb +130 -1
- data/spec/unit/rpc/client_spec.rb +169 -3
- data/spec/unit/security/base_spec.rb +0 -1
- data/spec/unit/shell_spec.rb +76 -3
- data/spec/unit/util_spec.rb +69 -1
- data/spec/unit/windows_daemon_spec.rb +30 -9
- metadata +104 -90
- data/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb +0 -34
- data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +0 -424
- data/spec/unit/plugins/mcollective/validator/any_validator_spec.rb +0 -15
@@ -0,0 +1,209 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/pluginpackager/modulepackage_packager.rb'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module PluginPackager
|
7
|
+
describe ModulepackagePackager, :unless => MCollective::Util.windows? do
|
8
|
+
let(:data) do
|
9
|
+
{:agent => {:files => ['./agent/rspec.rb']},
|
10
|
+
:common => {:files => ['./agent/rspec.ddl']},
|
11
|
+
:client => {:files => ['./application/rspec.rb']}}
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:plugin) do
|
15
|
+
p = mock
|
16
|
+
p.stubs(:mcname).returns('mcollective')
|
17
|
+
p.stubs(:metadata).returns({
|
18
|
+
:version => '1.0',
|
19
|
+
:name => 'rspec',
|
20
|
+
:description => 'An rspec.',
|
21
|
+
:url => 'http://example.com/rspec/',
|
22
|
+
})
|
23
|
+
p.stubs(:revision).returns(1)
|
24
|
+
p.stubs(:target_path).returns('rspec_build')
|
25
|
+
p.stubs(:vendor).returns('puppetlabs')
|
26
|
+
p.stubs(:packagedata).returns(data)
|
27
|
+
p
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:packager) do
|
31
|
+
p = ModulepackagePackager.new(plugin)
|
32
|
+
p.instance_variable_set(:@tmpdir, 'rspec_tmp')
|
33
|
+
p
|
34
|
+
end
|
35
|
+
|
36
|
+
before :each do
|
37
|
+
ModulepackagePackager.any_instance.stubs(:assert_new_enough_puppet)
|
38
|
+
@packager = packager
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#initialize' do
|
42
|
+
it 'should set the instance variables' do
|
43
|
+
new_packager = ModulepackagePackager.new(plugin)
|
44
|
+
new_packager.instance_variable_get(:@plugin).should == plugin
|
45
|
+
new_packager.instance_variable_get(:@package_name).should == 'mcollective_rspec'
|
46
|
+
new_packager.instance_variable_get(:@verbose).should == false
|
47
|
+
new_packager.instance_variable_get(:@keep_artifacts).should == nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should fail if no build command is present' do
|
51
|
+
ModulepackagePackager.any_instance.stubs(:assert_new_enough_puppet).raises("Cannot build package. 'puppet' is not present on the system")
|
52
|
+
expect{
|
53
|
+
new_packager = ModulepackagePackager.new(plugin)
|
54
|
+
}.to raise_error("Cannot build package. 'puppet' is not present on the system")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#create_packages' do
|
59
|
+
before :each do
|
60
|
+
@packager.stubs(:puts)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should run through the complete build process' do
|
64
|
+
Dir.expects(:mktmpdir).with('mcollective_packager').returns('rspec_tmp')
|
65
|
+
@packager.expects(:make_module)
|
66
|
+
@packager.expects(:run_build)
|
67
|
+
@packager.expects(:move_package)
|
68
|
+
@packager.expects(:cleanup_tmpdirs)
|
69
|
+
@packager.create_packages
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should clean up tmpdirs if keep_artifacts is false' do
|
73
|
+
Dir.stubs(:mktmpdir).raises('error')
|
74
|
+
@packager.expects(:cleanup_tmpdirs)
|
75
|
+
expect{
|
76
|
+
packager.create_packages
|
77
|
+
}.to raise_error('error')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should keep the build artifacts if keep_artifacts is true' do
|
81
|
+
@packager.instance_variable_set(:@keep_artifacts, true)
|
82
|
+
Dir.stubs(:mktmpdir).raises('error')
|
83
|
+
@packager.expects(:cleanup_tmpdirs).never
|
84
|
+
expect{
|
85
|
+
@packager.create_packages
|
86
|
+
}.to raise_error('error')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#assert_new_enough_puppet' do
|
91
|
+
before :each do
|
92
|
+
ModulepackagePackager.any_instance.unstub(:assert_new_enough_puppet)
|
93
|
+
end
|
94
|
+
|
95
|
+
let(:shell) do
|
96
|
+
s = mock
|
97
|
+
s.stubs(:runcommand)
|
98
|
+
s
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should ensure we have a puppet' do
|
102
|
+
PluginPackager.expects(:command_available?).with('puppet').returns(false)
|
103
|
+
expect {
|
104
|
+
packager.send(:assert_new_enough_puppet)
|
105
|
+
}.to raise_error('Cannot build package. \'puppet\' is not present on the system.')
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should find the version of puppet' do
|
109
|
+
PluginPackager.stubs(:command_available?).with('puppet').returns(true)
|
110
|
+
shell.expects(:stdout).returns("3.3.0\n")
|
111
|
+
Shell.stubs(:new).with('puppet --version').returns(shell)
|
112
|
+
packager.send(:assert_new_enough_puppet)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should assert the version of puppet is >= 3.3.0' do
|
116
|
+
PluginPackager.expects(:command_available?).with('puppet').returns(true)
|
117
|
+
Shell.stubs(:new).with('puppet --version').returns(shell)
|
118
|
+
shell.stubs(:stdout).returns("3.2.0\n")
|
119
|
+
expect {
|
120
|
+
packager.send(:assert_new_enough_puppet)
|
121
|
+
}.to raise_error('Cannot build package. puppet 3.3.0 or greater required. We have 3.2.0.')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#make_module' do
|
126
|
+
it 'should copy the package content to the tmp build dir' do
|
127
|
+
file = mock()
|
128
|
+
File.stubs(:directory?).with('rspec_tmp/manifests').returns(false, true)
|
129
|
+
File.stubs(:directory?).with('rspec_tmp/files/agent/mcollective/agent').returns(false, true)
|
130
|
+
File.stubs(:directory?).with('rspec_tmp/files/common/mcollective/agent').returns(false, true)
|
131
|
+
File.stubs(:directory?).with('rspec_tmp/files/client/mcollective/application').returns(false)
|
132
|
+
FileUtils.expects(:mkdir_p).with('rspec_tmp/manifests')
|
133
|
+
FileUtils.expects(:mkdir_p).with('rspec_tmp/files/common/mcollective/agent')
|
134
|
+
FileUtils.expects(:mkdir_p).with('rspec_tmp/files/agent/mcollective/agent')
|
135
|
+
FileUtils.expects(:mkdir_p).with('rspec_tmp/files/client/mcollective/application')
|
136
|
+
FileUtils.expects(:cp_r).with('./agent/rspec.rb', 'rspec_tmp/files/agent/mcollective/agent')
|
137
|
+
FileUtils.expects(:cp_r).with('./agent/rspec.ddl', 'rspec_tmp/files/common/mcollective/agent')
|
138
|
+
FileUtils.expects(:cp_r).with('./application/rspec.rb', 'rspec_tmp/files/client/mcollective/application')
|
139
|
+
File.stubs(:open).with('rspec_tmp/manifests/common.pp', 'w').yields(file)
|
140
|
+
File.stubs(:open).with('rspec_tmp/manifests/agent.pp', 'w').yields(file)
|
141
|
+
File.stubs(:open).with('rspec_tmp/manifests/client.pp', 'w').yields(file)
|
142
|
+
File.stubs(:open).with('rspec_tmp/Modulefile', 'w').yields(file)
|
143
|
+
File.stubs(:open).with('rspec_tmp/README.md', 'w').yields(file)
|
144
|
+
file.expects(:puts).times(5)
|
145
|
+
@packager.send(:make_module)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#run_build' do
|
150
|
+
before :each do
|
151
|
+
Dir.stubs(:chdir).yields
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should build the packages' do
|
155
|
+
PluginPackager.expects(:execute_verbosely).with(false).yields
|
156
|
+
PluginPackager.expects(:safe_system).with('puppet module build')
|
157
|
+
@packager.send(:run_build)
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should not build silently if verbose is false' do
|
161
|
+
@packager.instance_variable_set(:@verbose, true)
|
162
|
+
PluginPackager.expects(:execute_verbosely).with(true).yields
|
163
|
+
PluginPackager.expects(:safe_system).with('puppet module build')
|
164
|
+
@packager.send(:run_build)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should write a message and raise an exception if the build fails' do
|
168
|
+
Dir.stubs(:chdir).raises('error')
|
169
|
+
@packager.expects(:puts).with('Build process has failed')
|
170
|
+
expect{
|
171
|
+
@packager.send(:run_build)
|
172
|
+
}.to raise_error('error')
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#move_package' do
|
177
|
+
it 'should copy all the build artifacts to the cwd' do
|
178
|
+
File.stubs(:join).with('rspec_tmp', 'pkg', 'puppetlabs-mcollective_rspec-1.0.tar.gz').returns('1.tar.gz')
|
179
|
+
FileUtils.expects(:cp).with('1.tar.gz', '.')
|
180
|
+
@packager.send(:move_package)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should write a message and raise an exception if the artifacts cannot be copied' do
|
184
|
+
FileUtils.stubs(:cp).raises('error')
|
185
|
+
@packager.expects(:puts).with('Could not copy package to working directory')
|
186
|
+
expect{
|
187
|
+
@packager.send(:move_package)
|
188
|
+
}.to raise_error('error')
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe '#cleanup_tmpdirs' do
|
193
|
+
it 'should remove the tmp dirs' do
|
194
|
+
File.stubs(:directory?).with('rspec_tmp').returns(true)
|
195
|
+
FileUtils.expects(:rm_r).with('rspec_tmp')
|
196
|
+
@packager.send(:cleanup_tmpdirs)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should write a message and raise an exception if it cannot remove the tmp dirs' do
|
200
|
+
File.stubs(:directory?).raises('error')
|
201
|
+
@packager.expects(:puts).with("Could not remove temporary build directory - 'rspec_tmp'")
|
202
|
+
expect{
|
203
|
+
@packager.send(:cleanup_tmpdirs)
|
204
|
+
}.to raise_error('error')
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -4,164 +4,278 @@ require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/pluginpack
|
|
4
4
|
|
5
5
|
module MCollective
|
6
6
|
module PluginPackager
|
7
|
-
describe RpmpackagePackager do
|
8
|
-
let(:
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
describe RpmpackagePackager, :unless => MCollective::Util.windows? do
|
8
|
+
let(:plugin) do
|
9
|
+
p = mock
|
10
|
+
p.stubs(:mcname).returns('mcollective')
|
11
|
+
p.stubs(:metadata).returns({:version => '1.0', :name => 'rspec'})
|
12
|
+
p.stubs(:revision).returns(1)
|
13
|
+
p.stubs(:target_path).returns('rspec_build')
|
14
|
+
p
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
|
17
|
+
let(:packager) do
|
18
|
+
p = RpmpackagePackager.new(plugin)
|
19
|
+
p.instance_variable_set(:@tmpdir, 'rspec_tmp')
|
20
|
+
p
|
16
21
|
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@plugin = mock()
|
22
|
-
@plugin.stubs(:iteration).returns("1")
|
23
|
-
@plugin.stubs(:metadata).returns({:name => "test", :version => "1"})
|
24
|
-
@plugin.stubs(:mcname).returns("mcollective")
|
25
|
-
RpmpackagePackager.any_instance.stubs(:rpmdir).returns('rpmdir')
|
26
|
-
RpmpackagePackager.any_instance.stubs(:srpmdir).returns('srpmdir')
|
23
|
+
let(:data) do
|
24
|
+
{:agent => {:files => ['agent/rspec.rb', 'agent/rspec.ddl']},
|
25
|
+
:client => {:files => ['application/rspec.rb']}}
|
27
26
|
end
|
28
27
|
|
29
|
-
|
30
|
-
|
28
|
+
before :each do
|
29
|
+
RpmpackagePackager.any_instance.stubs(:select_command).returns('rpmbuild')
|
30
|
+
RpmpackagePackager.any_instance.stubs(:rpmdir).returns('rspec_rpm')
|
31
|
+
RpmpackagePackager.any_instance.stubs(:srpmdir).returns('rspec_srpm')
|
32
|
+
@packager = packager
|
31
33
|
end
|
32
34
|
|
33
|
-
describe
|
35
|
+
describe '#initialize' do
|
36
|
+
it 'should set the instance variables' do
|
37
|
+
new_packager = RpmpackagePackager.new(plugin)
|
38
|
+
new_packager.instance_variable_get(:@plugin).should == plugin
|
39
|
+
new_packager.instance_variable_get(:@package_name).should == 'mcollective-rspec'
|
40
|
+
new_packager.instance_variable_get(:@package_name_and_version).should == 'mcollective-rspec-1.0'
|
41
|
+
new_packager.instance_variable_get(:@verbose).should == false
|
42
|
+
new_packager.instance_variable_get(:@libdir).should == '/usr/libexec/mcollective/mcollective/'
|
43
|
+
new_packager.instance_variable_get(:@signature).should == nil
|
44
|
+
new_packager.instance_variable_get(:@rpmdir).should == 'rspec_rpm'
|
45
|
+
new_packager.instance_variable_get(:@srpmdir).should == 'rspec_srpm'
|
46
|
+
new_packager.instance_variable_get(:@keep_artifacts).should == nil
|
47
|
+
end
|
34
48
|
|
35
|
-
it
|
36
|
-
|
37
|
-
PluginPackager.expects(:build_tool?).with("rpmbuild").returns(false)
|
49
|
+
it 'should fail if no build command is present' do
|
50
|
+
RpmpackagePackager.any_instance.stubs(:select_command).returns(nil)
|
38
51
|
expect{
|
39
|
-
RpmpackagePackager.new(
|
40
|
-
}.to
|
52
|
+
new_packager = RpmpackagePackager.new(plugin)
|
53
|
+
}.to raise_error("Cannot build package. 'rpmbuild' or 'rpmbuild-md5' is not present on the system")
|
41
54
|
end
|
55
|
+
end
|
42
56
|
|
43
|
-
|
44
|
-
|
45
|
-
|
57
|
+
describe '#select_command' do
|
58
|
+
it 'should return the command string for rpmbuild if its present' do
|
59
|
+
RpmpackagePackager.any_instance.unstub(:select_command)
|
60
|
+
PluginPackager.stubs(:command_available?).with('rpmbuild-md5').returns(false)
|
61
|
+
PluginPackager.stubs(:command_available?).with('rpmbuild').returns(true)
|
62
|
+
@packager.select_command.should == 'rpmbuild'
|
63
|
+
end
|
46
64
|
|
47
|
-
|
48
|
-
|
65
|
+
it 'should return the command string for rpmbuild-md5 if its present' do
|
66
|
+
RpmpackagePackager.any_instance.unstub(:select_command)
|
67
|
+
PluginPackager.stubs(:command_available?).with('rpmbuild-md5').returns(true)
|
68
|
+
@packager.select_command.should == 'rpmbuild-md5'
|
49
69
|
end
|
50
70
|
|
71
|
+
it 'should return nil if neither are present' do
|
72
|
+
RpmpackagePackager.any_instance.unstub(:select_command)
|
73
|
+
PluginPackager.stubs(:command_available?).with('rpmbuild-md5').returns(false)
|
74
|
+
PluginPackager.stubs(:command_available?).with('rpmbuild').returns(false)
|
75
|
+
@packager.select_command.should == nil
|
76
|
+
end
|
51
77
|
end
|
52
78
|
|
53
|
-
describe
|
79
|
+
describe '#create_packages' do
|
54
80
|
before :each do
|
55
|
-
@packager
|
56
|
-
@packager.tmpdir = maketmpdir
|
57
|
-
@packager.stubs(:create_package)
|
58
|
-
@packager.stubs(:cleanup_tmpdirs)
|
59
|
-
@plugin.stubs(:packagedata).returns(:test => {:files => ["test.rb"]})
|
60
|
-
@packager.stubs(:prepare_tmpdirs)
|
61
|
-
Dir.stubs(:mktmpdir)
|
81
|
+
@packager.stubs(:puts)
|
62
82
|
end
|
63
83
|
|
64
|
-
it
|
84
|
+
it 'should run through the complete build process' do
|
85
|
+
Dir.expects(:mktmpdir).with('mcollective_packager').returns('rspec_tmp')
|
86
|
+
@packager.expects(:prepare_tmpdirs)
|
87
|
+
@packager.expects(:make_spec_file)
|
88
|
+
@packager.expects(:run_build)
|
89
|
+
@packager.expects(:move_packages)
|
90
|
+
@packager.expects(:cleanup_tmpdirs)
|
65
91
|
@packager.create_packages
|
66
|
-
@packager.current_package_type.should == :test
|
67
|
-
@packager.current_package_data.should == {:files => ["test.rb"]}
|
68
|
-
@packager.current_package_name.should == "mcollective-test-test"
|
69
92
|
end
|
70
93
|
|
71
|
-
it
|
72
|
-
|
73
|
-
@packager.
|
94
|
+
it 'should clean up tmpdirs if keep_artifacts is false' do
|
95
|
+
Dir.stubs(:mktmpdir).raises('error')
|
96
|
+
@packager.expects(:cleanup_tmpdirs)
|
97
|
+
expect{
|
98
|
+
packager.create_packages
|
99
|
+
}.to raise_error('error')
|
74
100
|
end
|
75
101
|
|
76
|
-
it
|
77
|
-
@packager.
|
78
|
-
|
102
|
+
it 'should keep the build artifacts if keep_artifacts is true' do
|
103
|
+
@packager.instance_variable_set(:@keep_artifacts, true)
|
104
|
+
Dir.stubs(:mktmpdir).raises('error')
|
105
|
+
@packager.expects(:cleanup_tmpdirs).never
|
106
|
+
expect{
|
107
|
+
@packager.create_packages
|
108
|
+
}.to raise_error('error')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#run_build' do
|
113
|
+
it 'should build the packages' do
|
114
|
+
@packager.expects(:create_tar).returns('rspec.tgz')
|
115
|
+
PluginPackager.expects(:execute_verbosely).with(false).yields
|
116
|
+
PluginPackager.expects(:safe_system).with('rpmbuild -ta --quiet rspec.tgz')
|
117
|
+
@packager.send(:run_build)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should sign the packages if a signature is defined' do
|
121
|
+
@packager.instance_variable_set(:@signature, true)
|
122
|
+
@packager.expects(:create_tar).returns('rspec.tgz')
|
123
|
+
PluginPackager.expects(:execute_verbosely).with(false).yields
|
124
|
+
PluginPackager.expects(:safe_system).with('rpmbuild -ta --quiet --sign rspec.tgz')
|
125
|
+
@packager.send(:run_build)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should not build silently if verbose is false' do
|
129
|
+
@packager.instance_variable_set(:@verbose, true)
|
130
|
+
@packager.expects(:create_tar).returns('rspec.tgz')
|
131
|
+
PluginPackager.expects(:execute_verbosely).with(true).yields
|
132
|
+
PluginPackager.expects(:safe_system).with('rpmbuild -ta rspec.tgz')
|
133
|
+
@packager.send(:run_build)
|
79
134
|
end
|
80
135
|
|
136
|
+
it 'should write a message and raise an exception if the build fails' do
|
137
|
+
@packager.stubs(:create_tar).raises('error')
|
138
|
+
@packager.expects(:puts).with('Build process has failed')
|
139
|
+
expect{
|
140
|
+
@packager.send(:run_build)
|
141
|
+
}.to raise_error('error')
|
142
|
+
end
|
81
143
|
end
|
82
144
|
|
83
|
-
describe
|
84
|
-
|
85
|
-
|
145
|
+
describe '#create_tar' do
|
146
|
+
it 'should create the tarball' do
|
147
|
+
PluginPackager.expects(:execute_verbosely).with(false).yields
|
148
|
+
Dir.expects(:chdir).with('rspec_tmp').yields
|
149
|
+
PluginPackager.expects(:safe_system).with('tar -cvzf rspec_tmp/mcollective-rspec-1.0.tgz mcollective-rspec-1.0')
|
150
|
+
@packager.send(:create_tar)
|
86
151
|
end
|
87
152
|
|
88
|
-
it
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
@packager.expects(:make_spec_file)
|
95
|
-
@packager.current_package_name = "mcollective-testplugin-test"
|
96
|
-
@packager.expects(:puts).with('Created RPM and SRPM packages for mcollective-testplugin-test')
|
97
|
-
@packager.create_package(:test, {:files => ["foo.rb"]})
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should sign the package if a signature is given" do
|
101
|
-
Dir.expects(:chdir)
|
102
|
-
PluginPackager.expects(:safe_system).with("rpmbuild-md5 -ta --sign /tmp/mcollective-testplugin-test-1.tgz")
|
103
|
-
FileUtils.expects(:cp).times(2)
|
104
|
-
@packager.signature = true
|
105
|
-
@packager.tmpdir = "/tmp"
|
106
|
-
@packager.verbose = "true"
|
107
|
-
@packager.expects(:make_spec_file)
|
108
|
-
@packager.current_package_name = "mcollective-testplugin-test"
|
109
|
-
@packager.expects(:puts).with('Created RPM and SRPM packages for mcollective-testplugin-test')
|
110
|
-
@packager.create_package(:test, {:files => ["foo.rb"]})
|
153
|
+
it 'should write a message and raise an exception if the tarball cannot be built' do
|
154
|
+
PluginPackager.expects(:execute_verbosely).with(false).raises('error')
|
155
|
+
@packager.expects(:puts).with("Could not create tarball - 'rspec_tmp/mcollective-rspec-1.0.tgz'")
|
156
|
+
expect{
|
157
|
+
@packager.send(:create_tar)
|
158
|
+
}.to raise_error('error')
|
111
159
|
end
|
160
|
+
end
|
112
161
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
162
|
+
describe '#move_packages' do
|
163
|
+
it 'should copy all the build artifacts to the cwd' do
|
164
|
+
File.stubs(:join).with('rspec_rpm', 'noarch', 'mcollective-rspec-*-1.0-1.noarch.rpm').returns('rspec_rpm/noarch/mcollective-rspec-*-1.0-1.noarch.rpm')
|
165
|
+
File.stubs(:join).with('rspec_srpm', 'mcollective-rspec-1.0-1.src.rpm').returns('1.src.rpm')
|
166
|
+
Dir.stubs(:glob).with('rspec_rpm/noarch/mcollective-rspec-*-1.0-1.noarch.rpm').returns(['1.rpm', '2.rpm'])
|
167
|
+
Dir.stubs(:glob).with('rspec_srpm/mcollective-rspec-1.0-1.src.rpm').returns(['1.src.rpm'])
|
168
|
+
FileUtils.expects(:cp).with(['1.rpm', '2.rpm', '1.src.rpm'], '.')
|
169
|
+
@packager.send(:move_packages)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should write a message and raise an exception if the artifacts cannot be copied' do
|
173
|
+
Dir.stubs(:glob).raises('error')
|
174
|
+
@packager.expects(:puts).with('Could not copy packages to working directory')
|
175
|
+
expect{
|
176
|
+
@packager.send(:move_packages)
|
177
|
+
}.to raise_error('error')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe '#make_spec_file' do
|
182
|
+
it 'should create a specfile from the erb template' do
|
183
|
+
erb = mock
|
184
|
+
file = mock
|
185
|
+
erb.stubs(:result).returns('<% rspec =%>')
|
186
|
+
File.stubs(:dirname).returns('rspec_template')
|
187
|
+
File.expects(:read).with('rspec_template/templates/redhat/rpm_spec.erb').returns(erb)
|
188
|
+
ERB.expects(:new).with(erb, nil, '-').returns(erb)
|
189
|
+
File.expects(:open).with('rspec_tmp/mcollective-rspec-1.0/mcollective-rspec-1.0.spec', 'w').yields(file)
|
190
|
+
file.expects(:puts).with('<% rspec =%>')
|
191
|
+
@packager.send(:make_spec_file)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should write a message and raise an exception if it could not create the specfile' do
|
195
|
+
ERB.stubs(:new).raises('error')
|
196
|
+
@packager.expects(:puts).with("Could not create specfile - 'rspec_tmp/mcollective-rspec-1.0/mcollective-rspec-1.0.spec'")
|
118
197
|
expect{
|
119
|
-
@packager.
|
120
|
-
}.to raise_error(
|
198
|
+
@packager.send(:make_spec_file)
|
199
|
+
}.to raise_error('error')
|
121
200
|
end
|
122
201
|
end
|
123
202
|
|
124
|
-
describe
|
203
|
+
describe '#prepare_tmpdirs' do
|
125
204
|
before :each do
|
126
|
-
|
127
|
-
@packager
|
205
|
+
pluginfiles = ['/agent/rspec.rb', '/agent/rspec.ddl', '/application/rspec.rb']
|
206
|
+
@packager.stubs(:plugin_files).returns(pluginfiles)
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should copy the package content to the tmp build dir' do
|
210
|
+
File.stubs(:directory?).with('rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/agent').returns(false, true)
|
211
|
+
File.stubs(:directory?).with('rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/application').returns(false)
|
212
|
+
FileUtils.expects(:mkdir_p).with('rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/agent')
|
213
|
+
FileUtils.expects(:mkdir_p).with('rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/application')
|
214
|
+
FileUtils.expects(:cp_r).with('/agent/rspec.rb', 'rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/agent')
|
215
|
+
FileUtils.expects(:cp_r).with('/agent/rspec.ddl', 'rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/agent')
|
216
|
+
FileUtils.expects(:cp_r).with('/application/rspec.rb', 'rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/application')
|
217
|
+
@packager.send(:prepare_tmpdirs)
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should fail if we do not have permission to create the directory' do
|
221
|
+
File.stubs(:directory?).with('rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/agent').raises(Errno::EACCES)
|
222
|
+
@packager.expects(:puts)
|
223
|
+
expect{
|
224
|
+
@packager.send(:prepare_tmpdirs)
|
225
|
+
}.to raise_error(Errno::EACCES)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should fail if the files we are trying to copy do not exist' do
|
229
|
+
File.stubs(:directory?).with('rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/agent').raises(Errno::ENOENT)
|
230
|
+
@packager.expects(:puts)
|
231
|
+
expect{
|
232
|
+
@packager.send(:prepare_tmpdirs)
|
233
|
+
}.to raise_error(Errno::ENOENT)
|
234
|
+
|
128
235
|
end
|
129
236
|
|
130
|
-
it
|
131
|
-
File.
|
237
|
+
it 'should write a message an error if the something else goes wrong and raise an exception' do
|
238
|
+
File.stubs(:directory?).with('rspec_tmp/mcollective-rspec-1.0/usr/libexec/mcollective/mcollective/agent').raises('error')
|
239
|
+
@packager.expects(:puts)
|
132
240
|
expect{
|
133
|
-
@packager.
|
134
|
-
}.to raise_error(
|
241
|
+
@packager.send(:prepare_tmpdirs)
|
242
|
+
}.to raise_error('error')
|
135
243
|
end
|
244
|
+
end
|
136
245
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
@packager.
|
142
|
-
|
143
|
-
@packager.make_spec_file
|
144
|
-
File.read(File.join(@packager.tmpdir, "test-2", "test-2.spec")).should == "specfile"
|
246
|
+
describe '#plugin_files' do
|
247
|
+
it 'should return the package files in a single array' do
|
248
|
+
files = ['agent/rspec.rb', 'agent/rspec.ddl', 'application/rspec.rb']
|
249
|
+
plugin.stubs(:packagedata).returns(data)
|
250
|
+
result = @packager.send(:plugin_files)
|
251
|
+
(files | result).should == files
|
145
252
|
end
|
146
253
|
end
|
147
254
|
|
148
|
-
describe
|
149
|
-
it
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
File.
|
154
|
-
|
155
|
-
|
255
|
+
describe '#package_files' do
|
256
|
+
it 'should return the package files and ommit the directories' do
|
257
|
+
files = ['/rspec', '/rspec/1.rb', '/rspec/2.rb']
|
258
|
+
File.expects(:directory?).with('/rspec').returns(true)
|
259
|
+
File.expects(:directory?).with('/rspec/1.rb').returns(false)
|
260
|
+
File.expects(:directory?).with('/rspec/2.rb').returns(false)
|
261
|
+
@packager.send(:package_files, files).should == ['/usr/libexec/mcollective/mcollective/rspec/1.rb',
|
262
|
+
'/usr/libexec/mcollective/mcollective/rspec/2.rb']
|
156
263
|
end
|
157
264
|
end
|
158
265
|
|
159
|
-
describe
|
160
|
-
it
|
161
|
-
|
162
|
-
|
163
|
-
packager.cleanup_tmpdirs
|
164
|
-
|
266
|
+
describe '#cleanup_tmpdirs' do
|
267
|
+
it 'should remove the tmp dirs' do
|
268
|
+
File.stubs(:directory?).with('rspec_tmp').returns(true)
|
269
|
+
FileUtils.expects(:rm_r).with('rspec_tmp')
|
270
|
+
@packager.send(:cleanup_tmpdirs)
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'should write a message and raise an exception if it cannot remove the tmp dirs' do
|
274
|
+
File.stubs(:directory?).raises('error')
|
275
|
+
@packager.expects(:puts).with("Could not remove temporary build directory - 'rspec_tmp'")
|
276
|
+
expect{
|
277
|
+
@packager.send(:cleanup_tmpdirs)
|
278
|
+
}.to raise_error('error')
|
165
279
|
end
|
166
280
|
end
|
167
281
|
end
|