beaker-puppet 1.29.0 → 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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/release.yml +2 -2
- data/.github/workflows/test.yml +28 -7
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +842 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +5 -20
- data/Rakefile +64 -169
- data/acceptance/config/acceptance-options.rb +3 -3
- data/acceptance/config/gem/acceptance-options.rb +8 -8
- data/acceptance/config/git/acceptance-options.rb +8 -8
- data/acceptance/config/pkg/acceptance-options.rb +7 -7
- data/acceptance/pre_suite/gem/install.rb +6 -6
- data/acceptance/pre_suite/git/install.rb +22 -22
- data/acceptance/pre_suite/pkg/install.rb +3 -3
- data/acceptance/tests/backwards_compatible.rb +6 -7
- data/acceptance/tests/clone_git_repo_on_test.rb +12 -13
- data/acceptance/tests/create_tmpdir_on_test.rb +13 -9
- data/acceptance/tests/install_smoke_test.rb +5 -4
- data/acceptance/tests/stub_host.rb +11 -10
- data/acceptance/tests/web_helpers_test.rb +11 -10
- data/beaker-puppet.gemspec +16 -23
- data/bin/beaker-puppet +2 -4
- data/lib/beaker-puppet/helpers/facter_helpers.rb +9 -7
- data/lib/beaker-puppet/helpers/host_helpers.rb +10 -7
- data/lib/beaker-puppet/helpers/puppet_helpers.rb +151 -160
- data/lib/beaker-puppet/helpers/rake_helpers.rb +1 -1
- data/lib/beaker-puppet/helpers/tk_helpers.rb +22 -28
- data/lib/beaker-puppet/install_utils/aio_defaults.rb +39 -43
- data/lib/beaker-puppet/install_utils/ezbake_utils.rb +34 -42
- data/lib/beaker-puppet/install_utils/foss_defaults.rb +134 -138
- data/lib/beaker-puppet/install_utils/foss_utils.rb +293 -320
- data/lib/beaker-puppet/install_utils/module_utils.rb +58 -70
- data/lib/beaker-puppet/install_utils/puppet5.rb +30 -35
- data/lib/beaker-puppet/install_utils/puppet_utils.rb +58 -68
- data/lib/beaker-puppet/install_utils/windows_utils.rb +34 -36
- data/lib/beaker-puppet/version.rb +1 -1
- data/lib/beaker-puppet/wrappers.rb +13 -14
- data/lib/beaker-puppet.rb +4 -5
- data/setup/aio/010_Install_Puppet_Agent.rb +5 -6
- data/setup/common/000-delete-puppet-when-none.rb +2 -4
- data/setup/common/003_solaris_cert_fix.rb +74 -70
- data/setup/common/005_redhat_subscription_fix.rb +3 -2
- data/setup/common/011_Install_Puppet_Server.rb +7 -9
- data/setup/common/012_Finalize_Installs.rb +5 -5
- data/setup/common/025_StopFirewall.rb +1 -1
- data/setup/common/030_StopSssd.rb +2 -2
- data/setup/common/040_ValidateSignCert.rb +10 -12
- data/setup/common/045_EnsureMasterStarted.rb +2 -2
- data/setup/gem/010_GemInstall.rb +5 -4
- data/setup/git/000_EnvSetup.rb +48 -48
- data/setup/git/010_TestSetup.rb +13 -12
- data/setup/git/020_PuppetUserAndGroup.rb +3 -2
- data/setup/git/060_InstallModules.rb +14 -14
- data/setup/git/070_InstallCACerts.rb +82 -82
- data/spec/beaker-puppet/helpers/facter_helpers_spec.rb +22 -24
- data/spec/beaker-puppet/helpers/host_helpers_spec.rb +10 -6
- data/spec/beaker-puppet/helpers/puppet_helpers_spec.rb +506 -517
- data/spec/beaker-puppet/helpers/tk_helpers_spec.rb +20 -24
- data/spec/beaker-puppet/install_utils/ezbake_utils_spec.rb +86 -90
- data/spec/beaker-puppet/install_utils/foss_utils_spec.rb +636 -599
- data/spec/beaker-puppet/install_utils/module_utils_spec.rb +125 -116
- data/spec/beaker-puppet/install_utils/puppet5_spec.rb +159 -165
- data/spec/beaker-puppet/install_utils/puppet_utils_spec.rb +92 -77
- data/spec/beaker-puppet/install_utils/windows_utils_spec.rb +101 -89
- data/spec/beaker-puppet/wrappers_spec.rb +10 -10
- data/spec/helpers.rb +85 -91
- data/tasks/ci.rake +171 -179
- metadata +33 -62
- data/setup/common/020_InstallCumulusModules.rb +0 -13
- data/setup/common/021_InstallAristaModuleMasters.rb +0 -12
- data/setup/common/022_InstallAristaModuleAgents.rb +0 -13
@@ -11,88 +11,87 @@ class ClassMixedWithDSLHelpers
|
|
11
11
|
def logger
|
12
12
|
RSpec::Mocks::Double.new('logger').as_null_object
|
13
13
|
end
|
14
|
-
|
15
14
|
end
|
16
15
|
|
17
16
|
describe ClassMixedWithDSLHelpers do
|
18
|
-
let(
|
19
|
-
let(
|
20
|
-
let(
|
21
|
-
let(
|
22
|
-
|
23
|
-
let(
|
24
|
-
let(
|
25
|
-
let(
|
26
|
-
let(
|
27
|
-
let(
|
28
|
-
let(
|
17
|
+
let(:opts) { Beaker::Options::Presets.env_vars }
|
18
|
+
let(:command) { 'ls' }
|
19
|
+
let(:host) { double.as_null_object }
|
20
|
+
let(:result) { Beaker::Result.new(host, command) }
|
21
|
+
|
22
|
+
let(:master) { make_host('master', roles: %w[master agent default]) }
|
23
|
+
let(:agent) { make_host('agent', roles: %w[agent]) }
|
24
|
+
let(:custom) { make_host('custom', roles: %w[custom agent]) }
|
25
|
+
let(:dash) { make_host('console', roles: %w[dashboard agent]) }
|
26
|
+
let(:db) { make_host('db', roles: %w[database agent]) }
|
27
|
+
let(:hosts) { [master, agent, dash, db, custom] }
|
29
28
|
|
30
29
|
describe '#create_tmpdir_on' do
|
31
|
-
let(:host) { {'user' => 'puppet', 'group' => 'muppets'} }
|
30
|
+
let(:host) { { 'user' => 'puppet', 'group' => 'muppets' } }
|
32
31
|
let(:result_success) { double.as_null_object }
|
33
32
|
let(:result_failure) { double.as_null_object }
|
34
33
|
let(:tmpdir) { '/tmp/beaker.XXXXXX/' }
|
35
34
|
|
36
35
|
before :each do
|
37
|
-
allow(
|
38
|
-
allow(
|
39
|
-
allow(
|
40
|
-
allow(
|
41
|
-
allow(
|
36
|
+
allow(host).to receive(:tmpdir).and_return(tmpdir)
|
37
|
+
allow(host).to receive(:result).and_return(result_success)
|
38
|
+
allow(result_success).to receive(:success?).and_return(true)
|
39
|
+
allow(result_success).to receive(:stdout).and_return('puppet')
|
40
|
+
allow(result_failure).to receive(:success?).and_return(false)
|
42
41
|
end
|
43
42
|
|
44
43
|
context 'with the path_prefix argument' do
|
45
44
|
it 'passes path_prefix to host.tmpdir' do
|
46
|
-
expect(
|
47
|
-
subject.create_tmpdir_on(
|
45
|
+
expect(host).to receive(:tmpdir).with('beaker')
|
46
|
+
subject.create_tmpdir_on(host, 'beaker')
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
50
|
context 'with the user argument' do
|
52
51
|
it 'calls chown when a user is specified' do
|
53
|
-
expect(
|
54
|
-
expect(
|
52
|
+
expect(host).to receive(:user_get).and_return(result_success)
|
53
|
+
expect(host).to receive(:chown).with(host['user'], tmpdir)
|
55
54
|
|
56
|
-
subject.create_tmpdir_on(
|
55
|
+
subject.create_tmpdir_on(host, 'beaker', host['user'])
|
57
56
|
end
|
58
57
|
|
59
58
|
it 'does not call chown when a user is not specified' do
|
60
|
-
expect(
|
59
|
+
expect(host).to_not receive(:chown)
|
61
60
|
|
62
|
-
subject.create_tmpdir_on(
|
61
|
+
subject.create_tmpdir_on(host, 'beaker')
|
63
62
|
end
|
64
63
|
|
65
64
|
it 'does not call chown and cleans up when the user does not exist on the host' do
|
66
|
-
expect(
|
67
|
-
expect(
|
65
|
+
expect(host).to receive(:user_get).and_return(result_failure)
|
66
|
+
expect(host).to receive(:rm_rf).with(tmpdir)
|
68
67
|
|
69
|
-
expect
|
70
|
-
subject.create_tmpdir_on(
|
71
|
-
|
68
|
+
expect do
|
69
|
+
subject.create_tmpdir_on(host, 'beaker', 'invalid.user')
|
70
|
+
end.to raise_error(RuntimeError, /User invalid.user does not exist on /)
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
75
74
|
context 'with the group argument' do
|
76
75
|
it 'calls chgrp when a group is specified' do
|
77
|
-
expect(
|
78
|
-
expect(
|
76
|
+
expect(host).to receive(:group_get).and_return(result_success)
|
77
|
+
expect(host).to receive(:chgrp).with(host['group'], tmpdir)
|
79
78
|
|
80
|
-
subject.create_tmpdir_on(
|
79
|
+
subject.create_tmpdir_on(host, 'beaker', nil, host['group'])
|
81
80
|
end
|
82
81
|
|
83
82
|
it 'does not call chgrp when a group is not specified' do
|
84
|
-
expect(
|
83
|
+
expect(subject).to_not receive(:chgrp)
|
85
84
|
|
86
|
-
subject.create_tmpdir_on(
|
85
|
+
subject.create_tmpdir_on(host, 'beaker')
|
87
86
|
end
|
88
87
|
|
89
88
|
it 'does not call chgrp and cleans up when the group does not exist on the host' do
|
90
|
-
expect(
|
91
|
-
expect(
|
89
|
+
expect(host).to receive(:group_get).and_return(result_failure)
|
90
|
+
expect(host).to receive(:rm_rf).with(tmpdir)
|
92
91
|
|
93
|
-
expect
|
94
|
-
subject.create_tmpdir_on(
|
95
|
-
|
92
|
+
expect do
|
93
|
+
subject.create_tmpdir_on(host, 'beaker', nil, 'invalid.group')
|
94
|
+
end.to raise_error(RuntimeError, /Group invalid.group does not exist on /)
|
96
95
|
end
|
97
96
|
end
|
98
97
|
|
@@ -100,22 +99,22 @@ describe ClassMixedWithDSLHelpers do
|
|
100
99
|
# don't coalesce the group into chown, i.e. `chown user:group`
|
101
100
|
# this keeps execution paths simple, clean, and discrete
|
102
101
|
it 'calls chown and chgrp separately' do
|
103
|
-
expect(
|
104
|
-
expect(
|
105
|
-
expect(
|
106
|
-
expect(
|
102
|
+
expect(host).to receive(:user_get).and_return(result_success)
|
103
|
+
expect(host).to receive(:group_get).and_return(result_success)
|
104
|
+
expect(host).to receive(:chown).with(host['user'], tmpdir)
|
105
|
+
expect(host).to receive(:chgrp).with(host['group'], tmpdir)
|
107
106
|
|
108
|
-
subject.create_tmpdir_on(
|
107
|
+
subject.create_tmpdir_on(host, 'beaker', host['user'], host['group'])
|
109
108
|
end
|
110
109
|
|
111
110
|
it 'does not pass group to chown' do
|
112
|
-
allow(
|
113
|
-
allow(
|
111
|
+
allow(host).to receive(:user_get).and_return(result_success)
|
112
|
+
allow(host).to receive(:chgrp).with(host['group'], tmpdir)
|
114
113
|
|
115
|
-
expect(
|
116
|
-
expect(
|
114
|
+
expect(host).to receive(:group_get).and_return(result_success)
|
115
|
+
expect(host).to receive(:chown).with(host['user'], tmpdir)
|
117
116
|
|
118
|
-
subject.create_tmpdir_on(
|
117
|
+
subject.create_tmpdir_on(host, 'beaker', host['user'], host['group'])
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
@@ -131,68 +130,65 @@ describe ClassMixedWithDSLHelpers do
|
|
131
130
|
end
|
132
131
|
|
133
132
|
context 'with no user argument' do
|
134
|
-
|
135
133
|
context 'with no path name argument' do
|
136
134
|
it 'executes chown once' do
|
137
|
-
cmd =
|
138
|
-
expect(Beaker::Command).to receive(:new).with(/puppet config print user --section master/, [],
|
135
|
+
cmd = 'the command'
|
136
|
+
expect(Beaker::Command).to receive(:new).with(/puppet config print user --section master/, [],
|
137
|
+
{ 'ENV' => {}, :cmdexe => true }).and_return(cmd)
|
139
138
|
expect(subject).to receive(:on).with(host, cmd).and_return(result)
|
140
|
-
expect(subject).to receive(:create_tmpdir_on).with(host,
|
139
|
+
expect(subject).to receive(:create_tmpdir_on).with(host, %r{/tmp/beaker}, /puppet/)
|
141
140
|
subject.create_tmpdir_for_user(host)
|
142
141
|
end
|
143
142
|
end
|
144
143
|
|
145
144
|
context 'with path name argument' do
|
146
145
|
it 'executes chown once' do
|
147
|
-
cmd =
|
148
|
-
expect(Beaker::Command).to receive(:new).with(/puppet config print user --section master/, [],
|
146
|
+
cmd = 'the command'
|
147
|
+
expect(Beaker::Command).to receive(:new).with(/puppet config print user --section master/, [],
|
148
|
+
{ 'ENV' => {}, :cmdexe => true }).and_return(cmd)
|
149
149
|
expect(subject).to receive(:on).with(host, cmd).and_return(result)
|
150
|
-
expect(subject).to receive(:create_tmpdir_on).with(host,
|
151
|
-
subject.create_tmpdir_for_user(host,
|
150
|
+
expect(subject).to receive(:create_tmpdir_on).with(host, %r{/tmp/bogus}, /puppet/)
|
151
|
+
subject.create_tmpdir_for_user(host, '/tmp/bogus')
|
152
152
|
end
|
153
153
|
end
|
154
|
-
|
155
154
|
end
|
156
|
-
|
157
155
|
end
|
158
156
|
|
159
|
-
|
160
157
|
describe '#apply_manifest_on' do
|
161
|
-
|
162
158
|
before :each do
|
163
159
|
hosts.each do |host|
|
164
|
-
allow(
|
160
|
+
allow(host).to receive(:tmpfile)
|
165
161
|
end
|
166
162
|
end
|
167
163
|
|
168
164
|
it 'calls puppet' do
|
169
|
-
allow(
|
170
|
-
expect(
|
171
|
-
expect(
|
172
|
-
|
173
|
-
and_return(
|
165
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
166
|
+
expect(subject).to receive(:create_remote_file).and_return(true)
|
167
|
+
expect(subject).to receive(:puppet).
|
168
|
+
# with( 'apply', '--verbose', 'agent' ).
|
169
|
+
and_return('puppet_command')
|
174
170
|
|
175
|
-
expect(
|
176
|
-
with(
|
177
|
-
{:
|
171
|
+
expect(subject).to receive(:on)
|
172
|
+
.with(agent, 'puppet_command',
|
173
|
+
{ acceptable_exit_codes: [0] })
|
178
174
|
|
179
|
-
subject.apply_manifest_on(
|
175
|
+
subject.apply_manifest_on(agent, 'class { "boo": }')
|
180
176
|
end
|
181
177
|
|
182
178
|
it 'operates on an array of hosts' do
|
183
|
-
allow(
|
179
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
184
180
|
the_hosts = [master, agent]
|
185
181
|
|
186
|
-
expect(
|
182
|
+
expect(subject).to receive(:create_remote_file).twice.and_return(true)
|
187
183
|
the_hosts.each do |host|
|
188
|
-
expect(
|
189
|
-
and_return(
|
184
|
+
expect(subject).to receive(:puppet)
|
185
|
+
.and_return('puppet_command')
|
190
186
|
|
191
|
-
expect(
|
192
|
-
with(
|
187
|
+
expect(subject).to receive(:on)
|
188
|
+
.with(host, 'puppet_command', { acceptable_exit_codes: [0] })
|
193
189
|
end
|
194
190
|
|
195
|
-
result = subject.apply_manifest_on(
|
191
|
+
result = subject.apply_manifest_on(the_hosts, 'include foobar')
|
196
192
|
expect(result).to be_an(Array)
|
197
193
|
end
|
198
194
|
|
@@ -201,536 +197,534 @@ describe ClassMixedWithDSLHelpers do
|
|
201
197
|
FakeFS.deactivate!
|
202
198
|
# This will only get hit if forking processes is supported and at least 2 items are being submitted to run in parallel
|
203
199
|
# expect( InParallel::InParallelExecutor ).to receive(:_execute_in_parallel).with(any_args).and_call_original.exactly(2).times
|
204
|
-
allow(
|
200
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
205
201
|
the_hosts = [master, agent]
|
206
202
|
|
207
|
-
allow(
|
208
|
-
allow(
|
209
|
-
and_return(
|
203
|
+
allow(subject).to receive(:create_remote_file).and_return(true)
|
204
|
+
allow(subject).to receive(:puppet)
|
205
|
+
.and_return('puppet_command')
|
210
206
|
the_hosts.each do |host|
|
211
|
-
allow(
|
212
|
-
with(
|
207
|
+
allow(subject).to receive(:on)
|
208
|
+
.with(host, 'puppet_command', { acceptable_exit_codes: [0] })
|
213
209
|
end
|
214
210
|
|
215
211
|
result = nil
|
216
|
-
result = subject.apply_manifest_on(
|
212
|
+
result = subject.apply_manifest_on(the_hosts, 'include foobar')
|
217
213
|
expect(result).to be_an(Array)
|
218
214
|
end
|
219
215
|
|
220
216
|
it 'runs block_on in parallel if set' do
|
221
217
|
InParallel::InParallelExecutor.logger = logger
|
222
218
|
FakeFS.deactivate!
|
223
|
-
allow(
|
219
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
224
220
|
the_hosts = [master, agent]
|
225
221
|
|
226
|
-
allow(
|
227
|
-
allow(
|
228
|
-
and_return(
|
222
|
+
allow(subject).to receive(:create_remote_file).and_return(true)
|
223
|
+
allow(subject).to receive(:puppet)
|
224
|
+
.and_return('puppet_command')
|
229
225
|
the_hosts.each do |host|
|
230
|
-
allow(
|
231
|
-
with(
|
226
|
+
allow(subject).to receive(:on)
|
227
|
+
.with(host, 'puppet_command', { acceptable_exit_codes: [0] })
|
232
228
|
end
|
233
|
-
expect(
|
229
|
+
expect(subject).to receive(:block_on).with(
|
234
230
|
anything,
|
235
|
-
{:
|
231
|
+
{ run_in_parallel: true },
|
236
232
|
)
|
237
233
|
|
238
|
-
subject.apply_manifest_on(
|
234
|
+
subject.apply_manifest_on(the_hosts, 'include foobar', { run_in_parallel: true })
|
239
235
|
end
|
240
236
|
|
241
237
|
it 'adds acceptable exit codes with :catch_failures' do
|
242
|
-
allow(
|
243
|
-
expect(
|
244
|
-
expect(
|
245
|
-
and_return(
|
238
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
239
|
+
expect(subject).to receive(:create_remote_file).and_return(true)
|
240
|
+
expect(subject).to receive(:puppet)
|
241
|
+
.and_return('puppet_command')
|
246
242
|
|
247
|
-
expect(
|
248
|
-
with(
|
249
|
-
{:
|
243
|
+
expect(subject).to receive(:on)
|
244
|
+
.with(agent, 'puppet_command',
|
245
|
+
{ acceptable_exit_codes: [0, 2] })
|
250
246
|
|
251
|
-
subject.apply_manifest_on(
|
247
|
+
subject.apply_manifest_on(agent,
|
252
248
|
'class { "boo": }',
|
253
|
-
{:
|
249
|
+
{ catch_failures: true })
|
254
250
|
end
|
255
251
|
it 'allows acceptable exit codes through :catch_failures' do
|
256
|
-
allow(
|
257
|
-
expect(
|
258
|
-
expect(
|
259
|
-
and_return(
|
252
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
253
|
+
expect(subject).to receive(:create_remote_file).and_return(true)
|
254
|
+
expect(subject).to receive(:puppet)
|
255
|
+
.and_return('puppet_command')
|
260
256
|
|
261
|
-
expect(
|
262
|
-
with(
|
263
|
-
|
257
|
+
expect(subject).to receive(:on)
|
258
|
+
.with(agent, 'puppet_command',
|
259
|
+
{ acceptable_exit_codes: [4, 0, 2] })
|
264
260
|
|
265
|
-
subject.apply_manifest_on(
|
261
|
+
subject.apply_manifest_on(agent,
|
266
262
|
'class { "boo": }',
|
267
|
-
{:
|
268
|
-
|
263
|
+
{ acceptable_exit_codes: [4],
|
264
|
+
catch_failures: true, })
|
269
265
|
end
|
270
266
|
it 'enforces a 0 exit code through :catch_changes' do
|
271
|
-
allow(
|
272
|
-
expect(
|
273
|
-
expect(
|
274
|
-
and_return(
|
267
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
268
|
+
expect(subject).to receive(:create_remote_file).and_return(true)
|
269
|
+
expect(subject).to receive(:puppet)
|
270
|
+
.and_return('puppet_command')
|
275
271
|
|
276
|
-
expect(
|
272
|
+
expect(subject).to receive(:on).with(
|
277
273
|
agent,
|
278
274
|
'puppet_command',
|
279
|
-
{:
|
275
|
+
{ acceptable_exit_codes: [0] },
|
280
276
|
)
|
281
277
|
|
282
278
|
subject.apply_manifest_on(
|
283
279
|
agent,
|
284
280
|
'class { "boo": }',
|
285
|
-
{:
|
281
|
+
{ catch_changes: true },
|
286
282
|
)
|
287
283
|
end
|
288
284
|
it 'enforces a 2 exit code through :expect_changes' do
|
289
|
-
allow(
|
290
|
-
expect(
|
291
|
-
expect(
|
292
|
-
and_return(
|
285
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
286
|
+
expect(subject).to receive(:create_remote_file).and_return(true)
|
287
|
+
expect(subject).to receive(:puppet)
|
288
|
+
.and_return('puppet_command')
|
293
289
|
|
294
|
-
expect(
|
290
|
+
expect(subject).to receive(:on).with(
|
295
291
|
agent,
|
296
292
|
'puppet_command',
|
297
|
-
{:
|
293
|
+
{ acceptable_exit_codes: [2] },
|
298
294
|
)
|
299
295
|
|
300
296
|
subject.apply_manifest_on(
|
301
297
|
agent,
|
302
298
|
'class { "boo": }',
|
303
|
-
{:
|
299
|
+
{ expect_changes: true },
|
304
300
|
)
|
305
301
|
end
|
306
302
|
it 'enforces exit codes through :expect_failures' do
|
307
|
-
allow(
|
308
|
-
expect(
|
309
|
-
expect(
|
310
|
-
and_return(
|
303
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
304
|
+
expect(subject).to receive(:create_remote_file).and_return(true)
|
305
|
+
expect(subject).to receive(:puppet)
|
306
|
+
.and_return('puppet_command')
|
311
307
|
|
312
|
-
expect(
|
308
|
+
expect(subject).to receive(:on).with(
|
313
309
|
agent,
|
314
310
|
'puppet_command',
|
315
|
-
{:
|
311
|
+
{ acceptable_exit_codes: [1, 4, 6] },
|
316
312
|
)
|
317
313
|
|
318
314
|
subject.apply_manifest_on(
|
319
315
|
agent,
|
320
316
|
'class { "boo": }',
|
321
|
-
{:
|
317
|
+
{ expect_failures: true },
|
322
318
|
)
|
323
319
|
end
|
324
320
|
it 'enforces exit codes through :expect_failures' do
|
325
|
-
allow(
|
326
|
-
expect
|
321
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
322
|
+
expect do
|
327
323
|
subject.apply_manifest_on(
|
328
324
|
agent,
|
329
325
|
'class { "boo": }',
|
330
|
-
:
|
331
|
-
:
|
326
|
+
expect_failures: true,
|
327
|
+
catch_failures: true,
|
332
328
|
)
|
333
|
-
|
329
|
+
end.to raise_error ArgumentError, /catch_failures.+expect_failures/
|
334
330
|
end
|
335
331
|
it 'enforces added exit codes through :expect_failures' do
|
336
|
-
allow(
|
337
|
-
expect(
|
338
|
-
expect(
|
339
|
-
and_return(
|
332
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
333
|
+
expect(subject).to receive(:create_remote_file).and_return(true)
|
334
|
+
expect(subject).to receive(:puppet)
|
335
|
+
.and_return('puppet_command')
|
340
336
|
|
341
|
-
expect(
|
337
|
+
expect(subject).to receive(:on).with(
|
342
338
|
agent,
|
343
339
|
'puppet_command',
|
344
|
-
{:
|
340
|
+
{ acceptable_exit_codes: [1, 2, 3, 4, 5, 6] },
|
345
341
|
)
|
346
342
|
|
347
343
|
subject.apply_manifest_on(
|
348
344
|
agent,
|
349
345
|
'class { "boo": }',
|
350
|
-
{:
|
351
|
-
|
346
|
+
{ acceptable_exit_codes: (1..5),
|
347
|
+
expect_failures: true, },
|
352
348
|
)
|
353
349
|
end
|
354
350
|
|
355
351
|
it 'can set the --parser future flag' do
|
356
|
-
allow(
|
357
|
-
expect(
|
352
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
353
|
+
expect(subject).to receive(:create_remote_file).and_return(true)
|
358
354
|
|
359
|
-
expect(
|
355
|
+
expect(subject).to receive(:puppet).with(
|
360
356
|
'apply',
|
361
357
|
anything,
|
362
358
|
include(
|
363
359
|
:parser => 'future',
|
364
360
|
'detailed-exitcodes' => nil,
|
365
|
-
:verbose => nil
|
366
|
-
)
|
361
|
+
:verbose => nil,
|
362
|
+
),
|
367
363
|
)
|
368
364
|
|
369
|
-
allow(
|
365
|
+
allow(subject).to receive(:on)
|
370
366
|
hosts.each do |host|
|
371
|
-
allow(
|
367
|
+
allow(host).to receive(:tmpfile).and_return('pants')
|
372
368
|
end
|
373
369
|
|
374
370
|
subject.apply_manifest_on(
|
375
371
|
agent,
|
376
372
|
'class { "boo": }',
|
377
|
-
:
|
378
|
-
:
|
379
|
-
:
|
373
|
+
acceptable_exit_codes: (1..5),
|
374
|
+
future_parser: true,
|
375
|
+
expect_failures: true,
|
380
376
|
)
|
381
377
|
end
|
382
378
|
|
383
379
|
it 'can set the --noops flag' do
|
384
|
-
allow(
|
385
|
-
expect(
|
380
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
381
|
+
expect(subject).to receive(:create_remote_file).and_return(true)
|
386
382
|
|
387
|
-
expect(
|
383
|
+
expect(subject).to receive(:puppet).with(
|
388
384
|
'apply',
|
389
385
|
anything,
|
390
386
|
include(
|
391
387
|
:noop => nil,
|
392
388
|
'detailed-exitcodes' => nil,
|
393
|
-
:verbose => nil
|
394
|
-
)
|
389
|
+
:verbose => nil,
|
390
|
+
),
|
395
391
|
)
|
396
392
|
|
397
|
-
allow(
|
393
|
+
allow(subject).to receive(:on)
|
398
394
|
hosts.each do |host|
|
399
|
-
allow(
|
395
|
+
allow(host).to receive(:tmpfile).and_return('pants')
|
400
396
|
end
|
401
397
|
|
402
398
|
subject.apply_manifest_on(
|
403
399
|
agent,
|
404
400
|
'class { "boo": }',
|
405
|
-
:
|
406
|
-
:
|
407
|
-
:
|
401
|
+
acceptable_exit_codes: (1..5),
|
402
|
+
noop: true,
|
403
|
+
expect_failures: true,
|
408
404
|
)
|
409
405
|
end
|
410
406
|
end
|
411
407
|
|
412
408
|
it 'can set the --debug flag' do
|
413
|
-
allow(
|
414
|
-
allow(
|
415
|
-
allow(
|
416
|
-
allow(
|
409
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
410
|
+
allow(subject).to receive(:create_remote_file).and_return(true)
|
411
|
+
allow(agent).to receive(:tmpfile)
|
412
|
+
allow(subject).to receive(:on)
|
417
413
|
|
418
|
-
expect(
|
414
|
+
expect(subject).to receive(:puppet).with(
|
419
415
|
'apply',
|
420
416
|
anything,
|
421
|
-
include(
|
417
|
+
include(debug: nil),
|
422
418
|
)
|
423
419
|
|
424
420
|
subject.apply_manifest_on(
|
425
421
|
agent,
|
426
422
|
'class { "boo": }',
|
427
|
-
:
|
423
|
+
debug: true,
|
428
424
|
)
|
429
425
|
end
|
430
426
|
|
431
|
-
describe
|
432
|
-
it
|
433
|
-
allow(
|
427
|
+
describe '#apply_manifest' do
|
428
|
+
it 'delegates to #apply_manifest_on with the default host' do
|
429
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
434
430
|
# allow( subject ).to receive( :default ).and_return( master )
|
435
431
|
|
436
|
-
expect(
|
437
|
-
expect(
|
438
|
-
|
439
|
-
subject.apply_manifest( 'manifest', {:opt => 'value'} )
|
432
|
+
expect(subject).to receive(:default).and_return(master)
|
433
|
+
expect(subject).to receive(:apply_manifest_on).with(master, 'manifest', { opt: 'value' }).once
|
440
434
|
|
435
|
+
subject.apply_manifest('manifest', { opt: 'value' })
|
441
436
|
end
|
442
437
|
end
|
443
438
|
|
444
439
|
describe '#stub_hosts_on' do
|
445
440
|
it 'executes puppet on the host passed and ensures it is reverted' do
|
446
441
|
test_host = make_host('my_host', {})
|
447
|
-
allow(
|
442
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
448
443
|
logger = double.as_null_object
|
449
444
|
|
450
|
-
expect(
|
451
|
-
allow(
|
452
|
-
expect(
|
453
|
-
manifest
|
445
|
+
expect(subject).to receive(:on).once
|
446
|
+
allow(subject).to receive(:logger).and_return(logger)
|
447
|
+
expect(subject).to receive(:teardown).and_yield
|
448
|
+
manifest = <<-EOS.gsub /^\s+/, ''
|
454
449
|
host { 'puppetlabs.com':
|
455
450
|
\tensure => present,
|
456
451
|
\tip => '127.0.0.1',
|
457
452
|
\thost_aliases => [],
|
458
453
|
}
|
459
454
|
EOS
|
460
|
-
expect(
|
461
|
-
|
462
|
-
expect(
|
463
|
-
|
464
|
-
|
465
|
-
|
455
|
+
expect(subject).to receive(:apply_manifest_on).once
|
456
|
+
.with(test_host, manifest)
|
457
|
+
expect(subject).to receive(:puppet).once
|
458
|
+
.with('resource', 'host',
|
459
|
+
'puppetlabs.com',
|
460
|
+
'ensure=absent')
|
466
461
|
|
467
|
-
subject.stub_hosts_on(
|
462
|
+
subject.stub_hosts_on(test_host, { 'puppetlabs.com' => '127.0.0.1' })
|
468
463
|
end
|
469
464
|
it 'adds aliases to defined hostname' do
|
470
465
|
test_host = make_host('my_host', {})
|
471
|
-
allow(
|
466
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
472
467
|
logger = double.as_null_object
|
473
468
|
|
474
|
-
expect(
|
475
|
-
allow(
|
476
|
-
expect(
|
477
|
-
manifest
|
469
|
+
expect(subject).to receive(:on).once
|
470
|
+
allow(subject).to receive(:logger).and_return(logger)
|
471
|
+
expect(subject).to receive(:teardown).and_yield
|
472
|
+
manifest = <<-EOS.gsub /^\s+/, ''
|
478
473
|
host { 'puppetlabs.com':
|
479
474
|
\tensure => present,
|
480
475
|
\tip => '127.0.0.1',
|
481
|
-
\thost_aliases => [
|
476
|
+
\thost_aliases => ["foo", "bar"],
|
482
477
|
}
|
483
478
|
EOS
|
484
|
-
expect(
|
485
|
-
|
479
|
+
expect(subject).to receive(:apply_manifest_on).once
|
480
|
+
.with(test_host, manifest)
|
486
481
|
|
487
|
-
subject.stub_hosts_on(
|
482
|
+
subject.stub_hosts_on(test_host, { 'puppetlabs.com' => '127.0.0.1' }, { 'puppetlabs.com' => %w[foo bar] })
|
488
483
|
end
|
489
484
|
end
|
490
485
|
|
491
|
-
describe
|
492
|
-
it
|
493
|
-
allow(
|
494
|
-
|
495
|
-
expect( subject ).to receive( :default ).and_return( master )
|
496
|
-
expect( subject ).to receive( :stub_hosts_on ).with( master, 'ipspec' ).once
|
486
|
+
describe '#stub_hosts' do
|
487
|
+
it 'delegates to stub_hosts_on with the default host' do
|
488
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
497
489
|
|
498
|
-
subject.
|
490
|
+
expect(subject).to receive(:default).and_return(master)
|
491
|
+
expect(subject).to receive(:stub_hosts_on).with(master, 'ipspec').once
|
499
492
|
|
493
|
+
subject.stub_hosts('ipspec')
|
500
494
|
end
|
501
495
|
end
|
502
496
|
|
503
497
|
describe '#stub_forge_on' do
|
504
498
|
it 'stubs forge.puppetlabs.com with the value of `forge`' do
|
505
|
-
allow(
|
499
|
+
allow(subject).to receive(:resolve_hostname_on).and_return ( '127.0.0.1')
|
506
500
|
host = make_host('my_host', {})
|
507
|
-
expect(
|
508
|
-
with(
|
501
|
+
expect(subject).to receive(:stub_hosts_on)
|
502
|
+
.with(host, { 'forge.puppetlabs.com' => '127.0.0.1' }, { 'forge.puppetlabs.com' => ['forge.puppet.com',
|
503
|
+
'forgeapi.puppetlabs.com', 'forgeapi.puppet.com',] })
|
509
504
|
|
510
|
-
subject.stub_forge_on(
|
505
|
+
subject.stub_forge_on(host, 'my_forge.example.com')
|
511
506
|
end
|
512
507
|
end
|
513
508
|
|
514
|
-
describe
|
515
|
-
it
|
516
|
-
allow(
|
517
|
-
allow(
|
509
|
+
describe '#stub_forge' do
|
510
|
+
it 'delegates to stub_forge_on with the default host' do
|
511
|
+
allow(subject).to receive(:options).and_return({})
|
512
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
518
513
|
|
519
|
-
expect(
|
520
|
-
expect(
|
521
|
-
|
522
|
-
subject.stub_forge( )
|
514
|
+
expect(subject).to receive(:default).and_return(master)
|
515
|
+
expect(subject).to receive(:stub_forge_on).with(master, nil).once
|
523
516
|
|
517
|
+
subject.stub_forge
|
524
518
|
end
|
525
519
|
end
|
526
520
|
|
527
|
-
describe
|
528
|
-
let(
|
529
|
-
let(
|
521
|
+
describe '#stop_agent_on' do
|
522
|
+
let(:result_fail) { Beaker::Result.new([], '') }
|
523
|
+
let(:result_pass) { Beaker::Result.new([], '') }
|
530
524
|
before :each do
|
531
|
-
allow(
|
525
|
+
allow(subject).to receive(:sleep).and_return(true)
|
532
526
|
end
|
533
527
|
|
534
528
|
it 'runs the pe-puppet on a system without pe-puppet-agent' do
|
535
529
|
vardir = '/var'
|
536
|
-
deb_agent = make_host(
|
537
|
-
allow(
|
538
|
-
|
539
|
-
expect( deb_agent ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
|
540
|
-
expect( deb_agent ).to receive( :file_exist? ).with("/etc/init.d/pe-puppet-agent").and_return(false)
|
530
|
+
deb_agent = make_host('deb', platform: 'debian-7-amd64', pe_ver: '3.7')
|
531
|
+
allow(deb_agent).to receive(:puppet_configprint).and_return({ 'vardir' => vardir })
|
541
532
|
|
542
|
-
expect(
|
543
|
-
expect(
|
544
|
-
expect( subject ).to receive( :puppet_resource ).with( "service", "pe-puppet", "ensure=stopped").once
|
545
|
-
expect( subject ).to receive( :on ).once
|
533
|
+
expect(deb_agent).to receive(:file_exist?).with('/var/state/agent_catalog_run.lock').and_return(false)
|
534
|
+
expect(deb_agent).to receive(:file_exist?).with('/etc/init.d/pe-puppet-agent').and_return(false)
|
546
535
|
|
547
|
-
subject.
|
536
|
+
expect(subject).to receive(:aio_version?).with(deb_agent).and_return(false)
|
537
|
+
expect(subject).to receive(:version_is_less).with(deb_agent[:pe_ver], '3.2').and_return(false)
|
538
|
+
expect(subject).to receive(:puppet_resource).with('service', 'pe-puppet', 'ensure=stopped').once
|
539
|
+
expect(subject).to receive(:on).once
|
548
540
|
|
541
|
+
subject.stop_agent_on(deb_agent)
|
549
542
|
end
|
550
543
|
|
551
544
|
it 'runs the pe-puppet-agent on a unix system with pe-puppet-agent' do
|
552
545
|
vardir = '/var'
|
553
|
-
el_agent = make_host(
|
554
|
-
allow(
|
546
|
+
el_agent = make_host('el', platform: 'el-5-x86_64', pe_ver: '3.7')
|
547
|
+
allow(el_agent).to receive(:puppet_configprint).and_return({ 'vardir' => vardir })
|
555
548
|
|
556
|
-
expect(
|
557
|
-
expect(
|
549
|
+
expect(el_agent).to receive(:file_exist?).with('/var/state/agent_catalog_run.lock').and_return(false)
|
550
|
+
expect(el_agent).to receive(:file_exist?).with('/etc/init.d/pe-puppet-agent').and_return(true)
|
558
551
|
|
559
|
-
expect(
|
560
|
-
expect(
|
561
|
-
expect(
|
562
|
-
expect(
|
552
|
+
expect(subject).to receive(:aio_version?).with(el_agent).and_return(false)
|
553
|
+
expect(subject).to receive(:version_is_less).with(el_agent[:pe_ver], '3.2').and_return(false)
|
554
|
+
expect(subject).to receive(:puppet_resource).with('service', 'pe-puppet-agent', 'ensure=stopped').once
|
555
|
+
expect(subject).to receive(:on).once
|
563
556
|
|
564
|
-
subject.stop_agent_on(
|
557
|
+
subject.stop_agent_on(el_agent)
|
565
558
|
end
|
566
559
|
|
567
560
|
it 'runs puppet on a unix system 4.0 or newer' do
|
568
561
|
vardir = '/var'
|
569
|
-
el_agent = make_host(
|
570
|
-
allow(
|
562
|
+
el_agent = make_host('el', platform: 'el-5-x86_64', pe_ver: '4.0')
|
563
|
+
allow(el_agent).to receive(:puppet_configprint).and_return({ 'vardir' => vardir })
|
571
564
|
|
572
|
-
expect(
|
565
|
+
expect(el_agent).to receive(:file_exist?).with('/var/state/agent_catalog_run.lock').and_return(false)
|
573
566
|
|
574
|
-
expect(
|
575
|
-
expect(
|
576
|
-
expect(
|
577
|
-
expect(
|
567
|
+
expect(subject).to receive(:aio_version?).with(el_agent).and_return(true)
|
568
|
+
expect(subject).to receive(:version_is_less).with(el_agent[:pe_ver], '3.2').and_return(false)
|
569
|
+
expect(subject).to receive(:puppet_resource).with('service', 'puppet', 'ensure=stopped').once
|
570
|
+
expect(subject).to receive(:on).once
|
578
571
|
|
579
|
-
subject.stop_agent_on(
|
572
|
+
subject.stop_agent_on(el_agent)
|
580
573
|
end
|
581
574
|
|
582
575
|
it 'can run on an array of hosts' do
|
583
576
|
vardir = '/var'
|
584
|
-
el_agent = make_host(
|
585
|
-
el_agent2 = make_host(
|
577
|
+
el_agent = make_host('el', platform: 'el-5-x86_64', pe_ver: '4.0')
|
578
|
+
el_agent2 = make_host('el', platform: 'el-5-x86_64', pe_ver: '4.0')
|
586
579
|
|
587
|
-
allow(
|
588
|
-
expect(
|
589
|
-
expect(
|
590
|
-
expect(
|
580
|
+
allow(el_agent).to receive(:puppet_configprint).and_return({ 'vardir' => vardir })
|
581
|
+
expect(el_agent).to receive(:file_exist?).with('/var/state/agent_catalog_run.lock').and_return(false)
|
582
|
+
expect(subject).to receive(:aio_version?).with(el_agent).and_return(true)
|
583
|
+
expect(subject).to receive(:version_is_less).with(el_agent[:pe_ver], '3.2').and_return(false)
|
591
584
|
|
592
|
-
allow(
|
593
|
-
expect(
|
594
|
-
expect(
|
595
|
-
expect(
|
585
|
+
allow(el_agent2).to receive(:puppet_configprint).and_return({ 'vardir' => vardir })
|
586
|
+
expect(el_agent2).to receive(:file_exist?).with('/var/state/agent_catalog_run.lock').and_return(false)
|
587
|
+
expect(subject).to receive(:aio_version?).with(el_agent2).and_return(true)
|
588
|
+
expect(subject).to receive(:version_is_less).with(el_agent2[:pe_ver], '3.2').and_return(false)
|
596
589
|
|
597
|
-
expect(
|
598
|
-
expect(
|
590
|
+
expect(subject).to receive(:puppet_resource).with('service', 'puppet', 'ensure=stopped').twice
|
591
|
+
expect(subject).to receive(:on).twice
|
599
592
|
|
600
|
-
subject.stop_agent_on(
|
593
|
+
subject.stop_agent_on([el_agent, el_agent2])
|
601
594
|
end
|
602
595
|
|
603
596
|
it 'runs in parallel with run_in_parallel=true' do
|
604
597
|
InParallel::InParallelExecutor.logger = logger
|
605
598
|
FakeFS.deactivate!
|
606
599
|
vardir = '/var'
|
607
|
-
el_agent = make_host(
|
608
|
-
el_agent2 = make_host(
|
600
|
+
el_agent = make_host('el', platform: 'el-5-x86_64', pe_ver: '4.0')
|
601
|
+
el_agent2 = make_host('el', platform: 'el-5-x86_64', pe_ver: '4.0')
|
609
602
|
|
610
|
-
allow(
|
611
|
-
allow(
|
603
|
+
allow(el_agent).to receive(:puppet_configprint).and_return({ 'vardir' => vardir })
|
604
|
+
allow(el_agent).to receive(:file_exist?).with('/var/state/agent_catalog_run.lock').and_return(false)
|
612
605
|
|
613
|
-
allow(
|
614
|
-
allow(
|
606
|
+
allow(el_agent2).to receive(:puppet_configprint).and_return({ 'vardir' => vardir })
|
607
|
+
allow(el_agent2).to receive(:file_exist?).with('/var/state/agent_catalog_run.lock').and_return(false)
|
615
608
|
|
616
609
|
# This will only get hit if forking processes is supported and at least 2 items are being submitted to run in parallel
|
617
|
-
expect(
|
610
|
+
expect(subject).to receive(:block_on).with(
|
618
611
|
anything,
|
619
|
-
include(
|
612
|
+
include(run_in_parallel: true),
|
620
613
|
)
|
621
614
|
|
622
|
-
subject.stop_agent_on(
|
615
|
+
subject.stop_agent_on([el_agent, el_agent2], { run_in_parallel: true })
|
623
616
|
end
|
624
|
-
|
625
617
|
end
|
626
618
|
|
627
|
-
describe
|
619
|
+
describe '#stop_agent' do
|
628
620
|
it 'delegates to #stop_agent_on with default host' do
|
629
|
-
allow(
|
621
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
630
622
|
|
631
|
-
expect(
|
632
|
-
expect(
|
633
|
-
|
634
|
-
subject.stop_agent( )
|
623
|
+
expect(subject).to receive(:default).and_return(master)
|
624
|
+
expect(subject).to receive(:stop_agent_on).with(master).once
|
635
625
|
|
626
|
+
subject.stop_agent
|
636
627
|
end
|
637
628
|
end
|
638
629
|
|
639
|
-
describe
|
640
|
-
|
630
|
+
describe '#sign_certificate_for' do
|
641
631
|
before :each do
|
642
|
-
allow(
|
643
|
-
allow(
|
644
|
-
allow(
|
645
|
-
allow(
|
632
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
633
|
+
allow(subject).to receive(:master).and_return(master)
|
634
|
+
allow(subject).to receive(:dashboard).and_return(dash)
|
635
|
+
allow(subject).to receive(:database).and_return(db)
|
646
636
|
hosts.each do |host|
|
647
|
-
allow(
|
637
|
+
allow(host).to receive(:node_name).and_return('')
|
648
638
|
end
|
649
639
|
end
|
650
640
|
|
651
641
|
it 'signs certs with `puppetserver ca` in Puppet 6' do
|
652
|
-
allow(
|
642
|
+
allow(subject).to receive(:sleep).and_return(true)
|
653
643
|
|
654
644
|
result.stdout = "+ \"#{agent}\""
|
655
645
|
|
656
|
-
allow(
|
646
|
+
allow(subject).to receive(:puppet) do |arg|
|
657
647
|
arg
|
658
648
|
end
|
659
649
|
|
660
|
-
version_result = double(
|
650
|
+
version_result = double('version', stdout: '6.0.0')
|
661
651
|
expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
|
662
652
|
expect(subject).to receive(:version_is_less).and_return(false)
|
663
|
-
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all', :
|
653
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24]).once
|
664
654
|
expect(subject).to receive(:on).with(master, 'puppetserver ca list --all').once.and_return(result)
|
665
655
|
|
666
|
-
subject.sign_certificate_for(
|
656
|
+
subject.sign_certificate_for(agent)
|
667
657
|
end
|
668
658
|
|
669
659
|
it 'signs certs with `puppet cert` in Puppet 5' do
|
670
|
-
allow(
|
660
|
+
allow(subject).to receive(:sleep).and_return(true)
|
671
661
|
|
672
662
|
result.stdout = "+ \"#{agent}\""
|
673
663
|
|
674
|
-
allow(
|
664
|
+
allow(subject).to receive(:puppet) do |arg|
|
675
665
|
arg
|
676
666
|
end
|
677
667
|
|
678
|
-
version_result = double(
|
668
|
+
version_result = double('version', stdout: '5.0.0')
|
679
669
|
expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
|
680
670
|
expect(subject).to receive(:version_is_less).and_return(true)
|
681
|
-
expect(subject).to receive(:on).with(master, 'cert --sign --all --allow-dns-alt-names',
|
682
|
-
|
671
|
+
expect(subject).to receive(:on).with(master, 'cert --sign --all --allow-dns-alt-names',
|
672
|
+
acceptable_exit_codes: [0, 24]).once
|
673
|
+
expect(subject).to receive(:on).with(master, 'cert --list --all').once.and_return(result)
|
683
674
|
|
684
|
-
subject.sign_certificate_for(
|
675
|
+
subject.sign_certificate_for(agent)
|
685
676
|
end
|
686
677
|
|
687
678
|
it 'retries 11 times before quitting' do
|
688
|
-
allow(
|
679
|
+
allow(subject).to receive(:sleep).and_return(true)
|
689
680
|
|
690
681
|
result.stdout = "Requested Certificates: \"#{agent}\""
|
691
|
-
allow(
|
682
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
692
683
|
|
693
|
-
allow(
|
684
|
+
allow(subject).to receive(:puppet) do |arg|
|
694
685
|
arg
|
695
686
|
end
|
696
687
|
|
697
|
-
version_result = double(
|
688
|
+
version_result = double('version', stdout: '6.0.0')
|
698
689
|
expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
|
699
|
-
expect(
|
700
|
-
|
701
|
-
expect(
|
690
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all',
|
691
|
+
acceptable_exit_codes: [0, 24]).exactly(11).times
|
692
|
+
expect(subject).to receive(:on).with(master,
|
693
|
+
'puppetserver ca list --all').exactly(11).times.and_return(result)
|
694
|
+
expect(subject).to receive(:fail_test).once
|
702
695
|
|
703
|
-
subject.sign_certificate_for(
|
696
|
+
subject.sign_certificate_for(agent)
|
704
697
|
end
|
705
698
|
|
706
699
|
it 'accepts an array of hosts to validate' do
|
707
|
-
allow(
|
700
|
+
allow(subject).to receive(:sleep).and_return(true)
|
708
701
|
|
709
702
|
result.stdout = "+ \"#{agent}\" + \"#{custom}\""
|
710
|
-
allow(
|
703
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
711
704
|
|
712
|
-
allow(
|
705
|
+
allow(subject).to receive(:puppet) do |arg|
|
713
706
|
arg
|
714
707
|
end
|
715
|
-
expect(
|
716
|
-
version_result = double(
|
708
|
+
expect(subject).to receive(:on).with(master, 'agent -t', acceptable_exit_codes: [0, 1, 2]).once
|
709
|
+
version_result = double('version', stdout: '6.0.0')
|
717
710
|
expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
|
718
|
-
expect(
|
719
|
-
expect(
|
720
|
-
|
711
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --certname master').once
|
712
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all',
|
713
|
+
acceptable_exit_codes: [0, 24]).once
|
714
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca list --all').once.and_return(result)
|
721
715
|
|
722
|
-
subject.sign_certificate_for(
|
716
|
+
subject.sign_certificate_for([master, agent, custom])
|
723
717
|
end
|
724
718
|
end
|
725
719
|
|
726
|
-
describe
|
720
|
+
describe '#sign_certificate' do
|
727
721
|
it 'delegates to #sign_certificate_for with the default host' do
|
728
|
-
allow(
|
729
|
-
expect(
|
722
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
723
|
+
expect(subject).to receive(:default).and_return(master)
|
730
724
|
|
731
|
-
expect(
|
725
|
+
expect(subject).to receive(:sign_certificate_for).with(master).once
|
732
726
|
|
733
|
-
subject.sign_certificate
|
727
|
+
subject.sign_certificate
|
734
728
|
end
|
735
729
|
end
|
736
730
|
|
@@ -740,136 +734,139 @@ describe ClassMixedWithDSLHelpers do
|
|
740
734
|
let(:is_pe) { false }
|
741
735
|
let(:use_service) { false }
|
742
736
|
let(:platform) { 'redhat' }
|
743
|
-
let(:host)
|
737
|
+
let(:host) do
|
744
738
|
FakeHost.create('fakevm', "#{platform}-version-arch",
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
}
|
739
|
+
'type' => is_pe ? 'pe' : 'git',
|
740
|
+
'use-service' => use_service)
|
741
|
+
end
|
749
742
|
|
750
743
|
def stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created
|
751
744
|
subject.instance_variable_set(:@path, test_case_path)
|
752
|
-
allow(
|
753
|
-
allow(
|
754
|
-
allow(
|
745
|
+
allow(host).to receive(:tmpdir).and_return(tmpdir_path)
|
746
|
+
allow(host).to receive(:file_exist?).and_return(true)
|
747
|
+
allow(subject).to receive(:options).and_return({})
|
755
748
|
end
|
756
749
|
|
757
750
|
before do
|
758
751
|
stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created
|
759
|
-
allow(
|
752
|
+
allow(subject).to receive(:curl_with_retries)
|
760
753
|
end
|
761
754
|
|
762
|
-
it
|
763
|
-
expect
|
755
|
+
it 'raises an ArgumentError if you try to submit a String instead of a Hash of options' do
|
756
|
+
expect do
|
757
|
+
subject.with_puppet_running_on(host,
|
758
|
+
'--foo --bar')
|
759
|
+
end.to raise_error(ArgumentError, /conf_opts must be a Hash. You provided a String: '--foo --bar'/)
|
764
760
|
end
|
765
761
|
|
766
762
|
it 'raises the early_exception if backup_the_file fails' do
|
767
|
-
allow(
|
768
|
-
allow(
|
769
|
-
expect(
|
770
|
-
expect
|
763
|
+
allow(host).to receive(:use_service_scripts?)
|
764
|
+
allow(subject).to receive(:restore_puppet_conf_from_backup)
|
765
|
+
expect(subject).to receive(:backup_the_file).and_raise(RuntimeError.new('puppet conf backup failed'))
|
766
|
+
expect do
|
771
767
|
subject.with_puppet_running_on(host, {})
|
772
|
-
|
768
|
+
end.to raise_error(RuntimeError, /puppet conf backup failed/)
|
773
769
|
end
|
774
770
|
|
775
771
|
it 'receives a Minitest::Assertion and fails the test correctly' do
|
776
|
-
allow(
|
777
|
-
allow(
|
778
|
-
allow(
|
779
|
-
allow(
|
780
|
-
expect(
|
772
|
+
allow(subject).to receive(:backup_the_file).and_raise(Minitest::Assertion.new('assertion failed!'))
|
773
|
+
allow(host).to receive(:puppet).and_return({})
|
774
|
+
allow(subject).to receive(:restore_puppet_conf_from_backup)
|
775
|
+
allow(host).to receive(:use_service_scripts?)
|
776
|
+
expect(subject).to receive(:fail_test)
|
781
777
|
subject.with_puppet_running_on(host, {})
|
782
778
|
end
|
783
779
|
|
784
780
|
context 'with test flow exceptions' do
|
785
781
|
it 'can pass_test' do
|
786
|
-
expect(
|
787
|
-
expect
|
782
|
+
expect(subject).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::PassTest)
|
783
|
+
expect do
|
788
784
|
subject.with_puppet_running_on(host, {}).to receive(:pass_test)
|
789
|
-
|
785
|
+
end.to raise_error(Beaker::DSL::Outcomes::PassTest)
|
790
786
|
end
|
791
787
|
it 'can fail_test' do
|
792
|
-
expect(
|
793
|
-
expect
|
788
|
+
expect(subject).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::FailTest)
|
789
|
+
expect do
|
794
790
|
subject.with_puppet_running_on(host, {}).to receive(:fail_test)
|
795
|
-
|
791
|
+
end.to raise_error(Beaker::DSL::Outcomes::FailTest)
|
796
792
|
end
|
797
793
|
it 'can skip_test' do
|
798
|
-
expect(
|
799
|
-
expect
|
794
|
+
expect(subject).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::SkipTest)
|
795
|
+
expect do
|
800
796
|
subject.with_puppet_running_on(host, {}).to receive(:skip_test)
|
801
|
-
|
797
|
+
end.to raise_error(Beaker::DSL::Outcomes::SkipTest)
|
802
798
|
end
|
803
799
|
it 'can pending_test' do
|
804
|
-
expect(
|
805
|
-
expect
|
800
|
+
expect(subject).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::PendingTest)
|
801
|
+
expect do
|
806
802
|
subject.with_puppet_running_on(host, {}).to receive(:pending_test)
|
807
|
-
|
803
|
+
end.to raise_error(Beaker::DSL::Outcomes::PendingTest)
|
808
804
|
end
|
809
805
|
end
|
810
806
|
|
811
807
|
describe 'with puppet-server' do
|
812
|
-
let(:default_confdir) {
|
813
|
-
let(:default_vardir) {
|
808
|
+
let(:default_confdir) { '/etc/puppet' }
|
809
|
+
let(:default_vardir) { '/var/lib/puppet' }
|
814
810
|
|
815
|
-
let(:custom_confdir) {
|
816
|
-
let(:custom_vardir) {
|
811
|
+
let(:custom_confdir) { '/tmp/etc/puppet' }
|
812
|
+
let(:custom_vardir) { '/tmp/var/lib/puppet' }
|
817
813
|
|
818
|
-
let(:command_line_args) {"--vardir=#{custom_vardir} --confdir=#{custom_confdir}"}
|
819
|
-
let(:conf_opts)
|
820
|
-
|
814
|
+
let(:command_line_args) { "--vardir=#{custom_vardir} --confdir=#{custom_confdir}" }
|
815
|
+
let(:conf_opts) do
|
816
|
+
{ __commandline_args__: command_line_args,
|
817
|
+
is_puppetserver: true, }
|
818
|
+
end
|
821
819
|
|
822
|
-
let(:default_puppetserver_opts)
|
823
|
-
{
|
824
|
-
|
825
|
-
|
820
|
+
let(:default_puppetserver_opts) do
|
821
|
+
{ 'jruby-puppet' => {
|
822
|
+
'master-conf-dir' => default_confdir,
|
823
|
+
'master-var-dir' => default_vardir,
|
826
824
|
},
|
827
|
-
|
828
|
-
|
829
|
-
}
|
830
|
-
|
831
|
-
}
|
825
|
+
'certificate-authority' => {
|
826
|
+
'allow-subject-alt-names' => true,
|
827
|
+
}, }
|
828
|
+
end
|
832
829
|
|
833
|
-
let(:custom_puppetserver_opts)
|
834
|
-
{
|
835
|
-
|
836
|
-
|
830
|
+
let(:custom_puppetserver_opts) do
|
831
|
+
{ 'jruby-puppet' => {
|
832
|
+
'master-conf-dir' => custom_confdir,
|
833
|
+
'master-var-dir' => custom_vardir,
|
837
834
|
},
|
838
|
-
|
839
|
-
|
840
|
-
}
|
841
|
-
|
842
|
-
}
|
835
|
+
'certificate-authority' => {
|
836
|
+
'allow-subject-alt-names' => true,
|
837
|
+
}, }
|
838
|
+
end
|
843
839
|
|
844
|
-
let(:puppetserver_conf) {
|
840
|
+
let(:puppetserver_conf) { '/etc/puppetserver/conf.d/puppetserver.conf' }
|
845
841
|
let(:logger) { double }
|
846
842
|
|
847
843
|
def stub_post_setup
|
848
|
-
allow(
|
849
|
-
allow(
|
850
|
-
allow(
|
851
|
-
allow(
|
852
|
-
allow(
|
853
|
-
allow(
|
854
|
-
allow(
|
855
|
-
allow(
|
856
|
-
allow(
|
857
|
-
allow(
|
858
|
-
allow(
|
844
|
+
allow(subject).to receive(:restore_puppet_conf_from_backup)
|
845
|
+
allow(subject).to receive(:bounce_service)
|
846
|
+
allow(subject).to receive(:stop_puppet_from_source_on)
|
847
|
+
allow(subject).to receive(:dump_puppet_log)
|
848
|
+
allow(subject).to receive(:restore_puppet_conf_from_backup)
|
849
|
+
allow(subject).to receive(:puppet_master_started)
|
850
|
+
allow(subject).to receive(:start_puppet_from_source_on!)
|
851
|
+
allow(subject).to receive(:lay_down_new_puppet_conf)
|
852
|
+
allow(subject).to receive(:logger).and_return(logger)
|
853
|
+
allow(logger).to receive(:error)
|
854
|
+
allow(logger).to receive(:debug)
|
859
855
|
end
|
860
856
|
|
861
857
|
before do
|
862
858
|
stub_post_setup
|
863
|
-
allow(
|
864
|
-
allow(
|
865
|
-
allow(
|
866
|
-
allow(
|
867
|
-
allow(
|
859
|
+
allow(subject).to receive(:options).and_return({ is_puppetserver: true })
|
860
|
+
allow(subject).to receive(:modify_tk_config)
|
861
|
+
allow(subject).to receive(:puppet_config).with(host, 'confdir', anything).and_return(default_confdir)
|
862
|
+
allow(subject).to receive(:puppet_config).with(host, 'vardir', anything).and_return(default_vardir)
|
863
|
+
allow(subject).to receive(:puppet_config).with(host, 'config',
|
864
|
+
anything).and_return("#{default_confdir}/puppet.conf")
|
868
865
|
end
|
869
866
|
|
870
867
|
describe 'when the global option for :is_puppetserver is false' do
|
871
868
|
it 'checks the option for the host object' do
|
872
|
-
allow(
|
869
|
+
allow(subject).to receive(:options).and_return({ is_puppetserver: false })
|
873
870
|
host[:is_puppetserver] = true
|
874
871
|
expect(subject).to receive(:modify_tk_config)
|
875
872
|
subject.with_puppet_running_on(host, conf_opts)
|
@@ -879,8 +876,8 @@ describe ClassMixedWithDSLHelpers do
|
|
879
876
|
describe 'and command line args passed' do
|
880
877
|
it 'modifies SUT trapperkeeper configuration w/ command line args' do
|
881
878
|
host['puppetserver-confdir'] = '/etc/puppetserver/conf.d'
|
882
|
-
expect(
|
883
|
-
|
879
|
+
expect(subject).to receive(:modify_tk_config).with(host, puppetserver_conf,
|
880
|
+
custom_puppetserver_opts)
|
884
881
|
subject.with_puppet_running_on(host, conf_opts)
|
885
882
|
end
|
886
883
|
end
|
@@ -889,16 +886,16 @@ describe ClassMixedWithDSLHelpers do
|
|
889
886
|
let(:command_line_args) { nil }
|
890
887
|
it 'modifies SUT trapperkeeper configuration w/ puppet defaults' do
|
891
888
|
host['puppetserver-confdir'] = '/etc/puppetserver/conf.d'
|
892
|
-
expect(
|
893
|
-
|
889
|
+
expect(subject).to receive(:modify_tk_config).with(host, puppetserver_conf,
|
890
|
+
default_puppetserver_opts)
|
894
891
|
subject.with_puppet_running_on(host, conf_opts)
|
895
892
|
end
|
896
893
|
end
|
897
894
|
end
|
898
895
|
|
899
|
-
describe
|
896
|
+
describe 'with valid arguments' do
|
900
897
|
before do
|
901
|
-
expect(
|
898
|
+
expect(Tempfile).to receive(:open).with('beaker')
|
902
899
|
end
|
903
900
|
|
904
901
|
context 'for pe hosts' do
|
@@ -913,7 +910,7 @@ describe ClassMixedWithDSLHelpers do
|
|
913
910
|
|
914
911
|
it 'yields to a block in between bouncing service calls' do
|
915
912
|
execution = 0
|
916
|
-
allow(
|
913
|
+
allow(subject).to receive(:curl_with_retries)
|
917
914
|
expect do
|
918
915
|
subject.with_puppet_running_on(host, {}) do
|
919
916
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(1).times
|
@@ -927,7 +924,7 @@ describe ClassMixedWithDSLHelpers do
|
|
927
924
|
|
928
925
|
context ':restart_when_done flag set false' do
|
929
926
|
it 'starts puppet once, stops it twice' do
|
930
|
-
subject.with_puppet_running_on(host, { :
|
927
|
+
subject.with_puppet_running_on(host, { restart_when_done: false })
|
931
928
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
|
932
929
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
|
933
930
|
end
|
@@ -943,9 +940,9 @@ describe ClassMixedWithDSLHelpers do
|
|
943
940
|
|
944
941
|
it 'yields to a block after bouncing service' do
|
945
942
|
execution = 0
|
946
|
-
allow(
|
943
|
+
allow(subject).to receive(:curl_with_retries)
|
947
944
|
expect do
|
948
|
-
subject.with_puppet_running_on(host, { :
|
945
|
+
subject.with_puppet_running_on(host, { restart_when_done: false }) do
|
949
946
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(1).times
|
950
947
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(1).times
|
951
948
|
execution += 1
|
@@ -961,28 +958,28 @@ describe ClassMixedWithDSLHelpers do
|
|
961
958
|
host.uses_passenger!
|
962
959
|
end
|
963
960
|
it 'bounces puppet twice' do
|
964
|
-
allow(
|
961
|
+
allow(subject).to receive(:curl_with_retries)
|
965
962
|
subject.with_puppet_running_on(host, {})
|
966
963
|
expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
|
967
964
|
end
|
968
965
|
|
969
966
|
it 'gracefully restarts using apache2ctl' do
|
970
|
-
allow(host).to receive(
|
971
|
-
allow(
|
967
|
+
allow(host).to receive(:check_for_command).and_return(true)
|
968
|
+
allow(subject).to receive(:curl_with_retries)
|
972
969
|
subject.with_puppet_running_on(host, {})
|
973
970
|
expect(host).to execute_commands_matching(/apache2ctl graceful/).exactly(2).times
|
974
971
|
end
|
975
972
|
|
976
973
|
it 'gracefully restarts using apachectl' do
|
977
|
-
allow(host).to receive(
|
978
|
-
allow(
|
974
|
+
allow(host).to receive(:check_for_command).and_return(false)
|
975
|
+
allow(subject).to receive(:curl_with_retries)
|
979
976
|
subject.with_puppet_running_on(host, {})
|
980
977
|
expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
|
981
978
|
end
|
982
979
|
|
983
980
|
it 'yields to a block after bouncing service' do
|
984
981
|
execution = 0
|
985
|
-
allow(
|
982
|
+
allow(subject).to receive(:curl_with_retries)
|
986
983
|
expect do
|
987
984
|
subject.with_puppet_running_on(host, {}) do
|
988
985
|
expect(host).to execute_commands_matching(/apachectl graceful/).once
|
@@ -994,16 +991,16 @@ describe ClassMixedWithDSLHelpers do
|
|
994
991
|
|
995
992
|
context ':restart_when_done flag set false' do
|
996
993
|
it 'bounces puppet once' do
|
997
|
-
allow(
|
998
|
-
subject.with_puppet_running_on(host, { :
|
994
|
+
allow(subject).to receive(:curl_with_retries)
|
995
|
+
subject.with_puppet_running_on(host, { restart_when_done: false })
|
999
996
|
expect(host).to execute_commands_matching(/apachectl graceful/).once
|
1000
997
|
end
|
1001
998
|
|
1002
999
|
it 'yields to a block after bouncing service' do
|
1003
1000
|
execution = 0
|
1004
|
-
allow(
|
1001
|
+
allow(subject).to receive(:curl_with_retries)
|
1005
1002
|
expect do
|
1006
|
-
subject.with_puppet_running_on(host, { :
|
1003
|
+
subject.with_puppet_running_on(host, { restart_when_done: false }) do
|
1007
1004
|
expect(host).to execute_commands_matching(/apachectl graceful/).once
|
1008
1005
|
execution += 1
|
1009
1006
|
end
|
@@ -1016,7 +1013,7 @@ describe ClassMixedWithDSLHelpers do
|
|
1016
1013
|
let(:use_service) { true }
|
1017
1014
|
|
1018
1015
|
it 'stops and starts master using service scripts twice' do
|
1019
|
-
allow(
|
1016
|
+
allow(subject).to receive(:curl_with_retries)
|
1020
1017
|
subject.with_puppet_running_on(host, {})
|
1021
1018
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times
|
1022
1019
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
|
@@ -1037,8 +1034,8 @@ describe ClassMixedWithDSLHelpers do
|
|
1037
1034
|
|
1038
1035
|
context ':restart_when_done flag set false' do
|
1039
1036
|
it 'stops (twice) and starts (once) master using service scripts' do
|
1040
|
-
allow(
|
1041
|
-
subject.with_puppet_running_on(host, { :
|
1037
|
+
allow(subject).to receive(:curl_with_retries)
|
1038
|
+
subject.with_puppet_running_on(host, { restart_when_done: false })
|
1042
1039
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
|
1043
1040
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
|
1044
1041
|
end
|
@@ -1046,7 +1043,7 @@ describe ClassMixedWithDSLHelpers do
|
|
1046
1043
|
it 'yields to a block after stopping and starting service' do
|
1047
1044
|
execution = 0
|
1048
1045
|
expect do
|
1049
|
-
subject.with_puppet_running_on(host, { :
|
1046
|
+
subject.with_puppet_running_on(host, { restart_when_done: false }) do
|
1050
1047
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
|
1051
1048
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).once
|
1052
1049
|
execution += 1
|
@@ -1057,18 +1054,16 @@ describe ClassMixedWithDSLHelpers do
|
|
1057
1054
|
end
|
1058
1055
|
|
1059
1056
|
context 'running from source' do
|
1060
|
-
let('use-service') { false }
|
1061
|
-
|
1062
1057
|
it 'does not try to stop if not started' do
|
1063
|
-
expect(
|
1064
|
-
expect(
|
1058
|
+
expect(subject).to receive(:start_puppet_from_source_on!).and_return false
|
1059
|
+
expect(subject).to_not receive(:stop_puppet_from_source_on)
|
1065
1060
|
|
1066
1061
|
subject.with_puppet_running_on(host, {})
|
1067
1062
|
end
|
1068
1063
|
|
1069
1064
|
context 'successfully' do
|
1070
1065
|
before do
|
1071
|
-
expect(
|
1066
|
+
expect(host).to receive(:port_open?).with(8140).and_return(true)
|
1072
1067
|
end
|
1073
1068
|
|
1074
1069
|
it 'starts puppet from source' do
|
@@ -1094,14 +1089,14 @@ describe ClassMixedWithDSLHelpers do
|
|
1094
1089
|
end
|
1095
1090
|
|
1096
1091
|
it 'passes on commandline args' do
|
1097
|
-
subject.with_puppet_running_on(host, {:
|
1092
|
+
subject.with_puppet_running_on(host, { __commandline_args__: '--with arg' })
|
1098
1093
|
expect(host).to execute_commands_matching(/^puppet master --with arg/).once
|
1099
1094
|
end
|
1100
1095
|
|
1101
1096
|
it 'is not affected by the :restart_when_done flag' do
|
1102
1097
|
execution = 0
|
1103
1098
|
expect do
|
1104
|
-
subject.with_puppet_running_on(host, { :
|
1099
|
+
subject.with_puppet_running_on(host, { restart_when_done: true }) do
|
1105
1100
|
expect(host).to execute_commands_matching(/^puppet master/).once
|
1106
1101
|
execution += 1
|
1107
1102
|
end
|
@@ -1119,14 +1114,14 @@ describe ClassMixedWithDSLHelpers do
|
|
1119
1114
|
end
|
1120
1115
|
|
1121
1116
|
let(:original_location) { '/root/mock/puppet.conf' }
|
1122
|
-
let(:backup_location)
|
1117
|
+
let(:backup_location) do
|
1123
1118
|
filename = File.basename(original_location)
|
1124
1119
|
File.join(tmpdir_path, "#{filename}.bak")
|
1125
|
-
|
1126
|
-
let(:new_location)
|
1120
|
+
end
|
1121
|
+
let(:new_location) do
|
1127
1122
|
filename = File.basename(original_location)
|
1128
1123
|
File.join(tmpdir_path, filename)
|
1129
|
-
|
1124
|
+
end
|
1130
1125
|
|
1131
1126
|
context 'when a puppetservice is used' do
|
1132
1127
|
let(:use_service) { true }
|
@@ -1138,7 +1133,7 @@ describe ClassMixedWithDSLHelpers do
|
|
1138
1133
|
end
|
1139
1134
|
|
1140
1135
|
it 'restores puppet.conf before restarting' do
|
1141
|
-
subject.with_puppet_running_on(host, { :
|
1136
|
+
subject.with_puppet_running_on(host, { restart_when_done: true })
|
1142
1137
|
expect(host).to execute_commands_matching_in_order(/cat '#{backup_location}' > '#{original_location}'/,
|
1143
1138
|
/ensure=stopped/,
|
1144
1139
|
/ensure=running/)
|
@@ -1147,7 +1142,7 @@ describe ClassMixedWithDSLHelpers do
|
|
1147
1142
|
|
1148
1143
|
context 'when a puppetservice is not used' do
|
1149
1144
|
before do
|
1150
|
-
expect(
|
1145
|
+
expect(host).to receive(:port_open?).with(8140).and_return(true)
|
1151
1146
|
end
|
1152
1147
|
|
1153
1148
|
it 'backs up puppet.conf' do
|
@@ -1163,7 +1158,7 @@ describe ClassMixedWithDSLHelpers do
|
|
1163
1158
|
end
|
1164
1159
|
|
1165
1160
|
it "doesn't restore a non-existent file" do
|
1166
|
-
allow(
|
1161
|
+
allow(subject).to receive(:backup_the_file)
|
1167
1162
|
subject.with_puppet_running_on(host, {})
|
1168
1163
|
expect(host).to execute_commands_matching(/rm -f '#{original_location}'/)
|
1169
1164
|
end
|
@@ -1172,15 +1167,14 @@ describe ClassMixedWithDSLHelpers do
|
|
1172
1167
|
|
1173
1168
|
let(:logger) { double.as_null_object }
|
1174
1169
|
describe 'handling failures' do
|
1175
|
-
|
1176
1170
|
before do
|
1177
|
-
allow(
|
1178
|
-
expect(
|
1179
|
-
expect(
|
1171
|
+
allow(subject).to receive(:logger).and_return(logger)
|
1172
|
+
expect(subject).to receive(:stop_puppet_from_source_on).and_raise(RuntimeError.new('Also failed in teardown.'))
|
1173
|
+
expect(host).to receive(:port_open?).with(8140).and_return(true)
|
1180
1174
|
end
|
1181
1175
|
|
1182
1176
|
it 'does not swallow an exception raised from within test block if ensure block also fails' do
|
1183
|
-
expect(
|
1177
|
+
expect(subject.logger).to receive(:error).with(/Raised during attempt to teardown.*Also failed in teardown/)
|
1184
1178
|
|
1185
1179
|
expect do
|
1186
1180
|
subject.with_puppet_running_on(host, {}) { raise 'Failed while yielding.' }
|
@@ -1188,7 +1182,7 @@ describe ClassMixedWithDSLHelpers do
|
|
1188
1182
|
end
|
1189
1183
|
|
1190
1184
|
it 'dumps the puppet logs if there is an error in the teardown' do
|
1191
|
-
expect(
|
1185
|
+
expect(subject.logger).to receive(:notify).with(/Dumping master log/)
|
1192
1186
|
|
1193
1187
|
expect do
|
1194
1188
|
subject.with_puppet_running_on(host, {})
|
@@ -1196,7 +1190,7 @@ describe ClassMixedWithDSLHelpers do
|
|
1196
1190
|
end
|
1197
1191
|
|
1198
1192
|
it 'does not mask the teardown error with an error from dumping the logs' do
|
1199
|
-
expect(
|
1193
|
+
expect(subject.logger).to receive(:notify).with(/Dumping master log/).and_raise('Error from dumping logs')
|
1200
1194
|
|
1201
1195
|
expect do
|
1202
1196
|
subject.with_puppet_running_on(host, {})
|
@@ -1204,128 +1198,124 @@ describe ClassMixedWithDSLHelpers do
|
|
1204
1198
|
end
|
1205
1199
|
|
1206
1200
|
it 'does not swallow a teardown exception if no earlier exception was raised' do
|
1207
|
-
expect(
|
1201
|
+
expect(subject.logger).to_not receive(:error)
|
1208
1202
|
expect do
|
1209
1203
|
subject.with_puppet_running_on(host, {})
|
1210
1204
|
end.to raise_error(RuntimeError, 'Also failed in teardown.')
|
1211
1205
|
end
|
1212
|
-
|
1213
1206
|
end
|
1214
|
-
|
1215
1207
|
end
|
1216
1208
|
end
|
1217
1209
|
|
1218
1210
|
describe '#with_puppet_running' do
|
1219
1211
|
it 'delegates to #with_puppet_running_on with the default host' do
|
1220
|
-
allow(
|
1221
|
-
expect(
|
1222
|
-
|
1223
|
-
expect( subject ).to receive( :with_puppet_running_on ).with( master, {:opt => 'value'}, '/dir' ).once
|
1224
|
-
|
1225
|
-
subject.with_puppet_running( {:opt => 'value'}, '/dir' )
|
1212
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
1213
|
+
expect(subject).to receive(:default).and_return(master)
|
1226
1214
|
|
1215
|
+
expect(subject).to receive(:with_puppet_running_on).with(master, { opt: 'value' }, '/dir').once
|
1227
1216
|
|
1217
|
+
subject.with_puppet_running({ opt: 'value' }, '/dir')
|
1228
1218
|
end
|
1229
1219
|
end
|
1230
1220
|
|
1231
1221
|
describe '#bounce_service' do
|
1232
|
-
let(
|
1233
|
-
let(
|
1222
|
+
let(:options) { Beaker::Options::Presets.new.presets }
|
1223
|
+
let(:result) { double.as_null_object }
|
1234
1224
|
before :each do
|
1235
|
-
allow(
|
1225
|
+
allow(subject).to receive(:options) { options }
|
1236
1226
|
end
|
1237
1227
|
|
1238
1228
|
it 'requests a reload but not a restart if the reload is successful' do
|
1239
1229
|
host = FakeHost.create
|
1240
|
-
allow(
|
1241
|
-
allow(
|
1242
|
-
allow(
|
1230
|
+
allow(result).to receive(:exit_code).and_return(0)
|
1231
|
+
allow(host).to receive(:any_exec_result).and_return(result)
|
1232
|
+
allow(host).to receive(:graceful_restarts?).and_return(false)
|
1243
1233
|
|
1244
|
-
expect(
|
1245
|
-
/service not_real_service reload
|
1234
|
+
expect(Beaker::Command).to receive(:new).with(
|
1235
|
+
/service not_real_service reload/,
|
1246
1236
|
).once
|
1247
|
-
expect(
|
1248
|
-
subject.bounce_service(
|
1237
|
+
expect(subject).to receive(:puppet_resource).never
|
1238
|
+
subject.bounce_service(host, 'not_real_service')
|
1249
1239
|
end
|
1250
1240
|
|
1251
1241
|
it 'requests a restart if the reload fails' do
|
1252
1242
|
host = FakeHost.create
|
1253
|
-
allow(
|
1254
|
-
allow(
|
1255
|
-
expect(
|
1256
|
-
expect(
|
1243
|
+
allow(result).to receive(:exit_code).and_return(1)
|
1244
|
+
allow(host).to receive(:exec).and_return(result)
|
1245
|
+
expect(subject).to receive(:curl_with_retries)
|
1246
|
+
expect(subject).to receive(:puppet_resource).with(
|
1257
1247
|
anything, 'not_real_service', anything
|
1258
|
-
).exactly(
|
1259
|
-
subject.bounce_service(
|
1248
|
+
).exactly(2).times
|
1249
|
+
subject.bounce_service(host, 'not_real_service')
|
1260
1250
|
end
|
1261
1251
|
|
1262
1252
|
it 'uses the default port argument if none given' do
|
1263
1253
|
host = FakeHost.create
|
1264
|
-
expect(
|
1265
|
-
allow(
|
1266
|
-
expect(
|
1254
|
+
expect(host).to receive(:graceful_restarts?).and_return(false)
|
1255
|
+
allow(result).to receive(:exit_code).and_return(1)
|
1256
|
+
expect(subject).to receive(:curl_with_retries).with(
|
1267
1257
|
anything, anything, /8140/, anything, anything
|
1268
1258
|
)
|
1269
|
-
subject.bounce_service(
|
1259
|
+
subject.bounce_service(host, 'not_real_service')
|
1270
1260
|
end
|
1271
1261
|
|
1272
1262
|
it 'takes the port argument' do
|
1273
1263
|
host = FakeHost.create
|
1274
|
-
expect(
|
1275
|
-
allow(
|
1276
|
-
expect(
|
1264
|
+
expect(host).to receive(:graceful_restarts?).and_return(false)
|
1265
|
+
allow(result).to receive(:exit_code).and_return(1)
|
1266
|
+
expect(subject).to receive(:curl_with_retries).with(
|
1277
1267
|
anything, anything, /8000/, anything, anything
|
1278
1268
|
)
|
1279
|
-
subject.bounce_service(
|
1269
|
+
subject.bounce_service(host, 'not_real_service', nil, 8000)
|
1280
1270
|
end
|
1281
1271
|
end
|
1282
1272
|
|
1283
1273
|
describe '#sleep_until_puppetdb_started' do
|
1284
|
-
let(
|
1274
|
+
let(:options) do # defaults from presets.rb
|
1285
1275
|
{
|
1286
|
-
:
|
1287
|
-
:
|
1276
|
+
puppetdb_port_nonssl: 8080,
|
1277
|
+
puppetdb_port_ssl: 8081,
|
1288
1278
|
}
|
1289
1279
|
end
|
1290
1280
|
|
1291
1281
|
before :each do
|
1292
|
-
allow(
|
1293
|
-
allow(
|
1294
|
-
allow(
|
1282
|
+
allow(subject).to receive(:options) { options }
|
1283
|
+
allow(hosts[0]).to receive(:node_name).and_return('')
|
1284
|
+
allow(subject).to receive(:version_is_less).and_return(true)
|
1295
1285
|
end
|
1296
1286
|
|
1297
1287
|
it 'uses the default ports if none given' do
|
1298
1288
|
host = hosts[0]
|
1299
|
-
expect(
|
1300
|
-
expect(
|
1301
|
-
subject.sleep_until_puppetdb_started(
|
1289
|
+
expect(subject).to receive(:retry_on).with(anything, /8080/, anything).once.ordered
|
1290
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8081/, anything).once.ordered
|
1291
|
+
subject.sleep_until_puppetdb_started(host)
|
1302
1292
|
end
|
1303
1293
|
|
1304
1294
|
it 'allows setting the nonssl_port' do
|
1305
1295
|
host = hosts[0]
|
1306
|
-
expect(
|
1307
|
-
expect(
|
1296
|
+
expect(subject).to receive(:retry_on).with(anything, /8084/, anything).once.ordered
|
1297
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8081/, anything).once.ordered
|
1308
1298
|
|
1309
|
-
subject.sleep_until_puppetdb_started(
|
1299
|
+
subject.sleep_until_puppetdb_started(host, 8084)
|
1310
1300
|
end
|
1311
1301
|
|
1312
1302
|
it 'allows setting the ssl_port' do
|
1313
1303
|
host = hosts[0]
|
1314
|
-
expect(
|
1315
|
-
expect(
|
1304
|
+
expect(subject).to receive(:retry_on).with(anything, /8080/, anything).once.ordered
|
1305
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8085/, anything).once.ordered
|
1316
1306
|
|
1317
|
-
subject.sleep_until_puppetdb_started(
|
1307
|
+
subject.sleep_until_puppetdb_started(host, nil, 8085)
|
1318
1308
|
end
|
1319
1309
|
|
1320
1310
|
context 'when pe_ver is less than 2016.1.0' do
|
1321
1311
|
it 'uses the version endpoint' do
|
1322
1312
|
host = hosts[0]
|
1323
1313
|
host['pe_ver'] = '2015.3.3'
|
1324
|
-
expect(
|
1325
|
-
expect(
|
1314
|
+
expect(subject).to receive(:retry_on).with(anything, %r{pdb/meta/v1/version}, anything).once.ordered
|
1315
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8081/, anything).once.ordered
|
1326
1316
|
|
1327
|
-
expect(
|
1328
|
-
subject.sleep_until_puppetdb_started(
|
1317
|
+
expect(subject).to receive(:version_is_less).with(host['pe_ver'], '2016.1.0').and_return(true)
|
1318
|
+
subject.sleep_until_puppetdb_started(host)
|
1329
1319
|
end
|
1330
1320
|
end
|
1331
1321
|
|
@@ -1333,60 +1323,59 @@ describe ClassMixedWithDSLHelpers do
|
|
1333
1323
|
it 'uses the status endpoint' do
|
1334
1324
|
host = hosts[0]
|
1335
1325
|
host['pe_ver'] = '2016.1.0'
|
1336
|
-
expect(
|
1337
|
-
|
1326
|
+
expect(subject).to receive(:retry_on).with(anything, %r{status/v1/services/puppetdb-status},
|
1327
|
+
anything).once.ordered
|
1328
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8081/, anything).once.ordered
|
1338
1329
|
|
1339
|
-
expect(
|
1340
|
-
subject.sleep_until_puppetdb_started(
|
1330
|
+
expect(subject).to receive(:version_is_less).with(host['pe_ver'], '2016.1.0').and_return(false)
|
1331
|
+
subject.sleep_until_puppetdb_started(host)
|
1341
1332
|
end
|
1342
1333
|
end
|
1343
|
-
|
1344
1334
|
end
|
1345
1335
|
|
1346
1336
|
describe '#sleep_until_puppetserver_started' do
|
1347
|
-
let(
|
1348
|
-
{ :
|
1337
|
+
let(:options) do
|
1338
|
+
{ puppetserver_port: 8140 }
|
1349
1339
|
end
|
1350
1340
|
|
1351
1341
|
before :each do
|
1352
|
-
allow(
|
1353
|
-
allow(
|
1342
|
+
allow(subject).to receive(:options) { options }
|
1343
|
+
allow(hosts[0]).to receive(:node_name)
|
1354
1344
|
end
|
1355
1345
|
|
1356
1346
|
it 'uses the default port if none given' do
|
1357
1347
|
host = hosts[0]
|
1358
|
-
expect(
|
1359
|
-
subject.sleep_until_puppetserver_started(
|
1348
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8140/, anything).once.ordered
|
1349
|
+
subject.sleep_until_puppetserver_started(host)
|
1360
1350
|
end
|
1361
1351
|
|
1362
1352
|
it 'allows setting the port' do
|
1363
1353
|
host = hosts[0]
|
1364
|
-
expect(
|
1365
|
-
subject.sleep_until_puppetserver_started(
|
1354
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8147/, anything).once.ordered
|
1355
|
+
subject.sleep_until_puppetserver_started(host, 8147)
|
1366
1356
|
end
|
1367
1357
|
end
|
1368
1358
|
|
1369
1359
|
describe '#sleep_until_nc_started' do
|
1370
|
-
let(
|
1371
|
-
{ :
|
1360
|
+
let(:options) do # defaults from presets.rb
|
1361
|
+
{ nodeclassifier_port: 4433 }
|
1372
1362
|
end
|
1373
1363
|
|
1374
1364
|
before :each do
|
1375
|
-
allow(
|
1376
|
-
allow(
|
1365
|
+
allow(subject).to receive(:options) { options }
|
1366
|
+
allow(hosts[0]).to receive(:node_name)
|
1377
1367
|
end
|
1378
1368
|
|
1379
1369
|
it 'uses the default port if none given' do
|
1380
1370
|
host = hosts[0]
|
1381
|
-
expect(
|
1382
|
-
subject.sleep_until_nc_started(
|
1371
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /4433/, anything).once.ordered
|
1372
|
+
subject.sleep_until_nc_started(host)
|
1383
1373
|
end
|
1384
1374
|
|
1385
1375
|
it 'allows setting the port' do
|
1386
1376
|
host = hosts[0]
|
1387
|
-
expect(
|
1388
|
-
subject.sleep_until_nc_started(
|
1377
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /4435/, anything).once.ordered
|
1378
|
+
subject.sleep_until_nc_started(host, 4435)
|
1389
1379
|
end
|
1390
1380
|
end
|
1391
|
-
|
1392
1381
|
end
|