beaker-puppet 1.29.0 → 3.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 +3 -3
- data/.github/workflows/test.yml +28 -7
- data/.github_changelog_generator +3 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +887 -0
- data/CHANGELOG.md +50 -0
- data/CODEOWNERS +1 -0
- data/Gemfile +5 -20
- data/README.md +4 -13
- 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 +17 -24
- 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 +145 -229
- 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 +269 -480
- 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 +53 -80
- 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/release-prep.sh +11 -0
- data/setup/aio/010_Install_Puppet_Agent.rb +22 -9
- 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 +9 -18
- data/setup/common/045_EnsureMasterStarted.rb +2 -2
- data/setup/gem/010_GemInstall.rb +6 -5
- 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 +463 -724
- 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 +471 -863
- 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 +89 -97
- 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 +188 -188
- metadata +38 -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,508 @@ 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(
|
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)
|
494
489
|
|
495
|
-
expect(
|
496
|
-
expect(
|
497
|
-
|
498
|
-
subject.stub_hosts( 'ipspec' )
|
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(
|
518
|
-
|
519
|
-
expect( subject ).to receive( :default ).and_return( master )
|
520
|
-
expect( subject ).to receive( :stub_forge_on ).with( master, nil ).once
|
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)
|
521
513
|
|
522
|
-
subject.
|
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(
|
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 })
|
538
532
|
|
539
|
-
expect(
|
540
|
-
expect(
|
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)
|
541
535
|
|
542
|
-
expect(
|
543
|
-
expect(
|
544
|
-
expect(
|
545
|
-
expect(
|
546
|
-
|
547
|
-
subject.stop_agent_on( deb_agent )
|
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(
|
630
|
-
|
631
|
-
expect( subject ).to receive( :default ).and_return( master )
|
632
|
-
expect( subject ).to receive( :stop_agent_on ).with( master ).once
|
621
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
633
622
|
|
634
|
-
subject.
|
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
|
-
it 'signs certs with `puppetserver ca`
|
652
|
-
allow(
|
641
|
+
it 'signs certs with `puppetserver ca`' do
|
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
|
-
|
661
|
-
expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
|
662
|
-
expect(subject).to receive(:version_is_less).and_return(false)
|
663
|
-
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all', :acceptable_exit_codes => [0, 24]).once
|
650
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all', acceptable_exit_codes: [0, 24]).once
|
664
651
|
expect(subject).to receive(:on).with(master, 'puppetserver ca list --all').once.and_return(result)
|
665
652
|
|
666
|
-
subject.sign_certificate_for(
|
667
|
-
end
|
668
|
-
|
669
|
-
it 'signs certs with `puppet cert` in Puppet 5' do
|
670
|
-
allow( subject ).to receive( :sleep ).and_return( true )
|
671
|
-
|
672
|
-
result.stdout = "+ \"#{agent}\""
|
673
|
-
|
674
|
-
allow( subject ).to receive( :puppet ) do |arg|
|
675
|
-
arg
|
676
|
-
end
|
677
|
-
|
678
|
-
version_result = double("version", :stdout => "5.0.0")
|
679
|
-
expect(subject).to receive(:on).with(master, '--version').and_return(version_result)
|
680
|
-
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', :acceptable_exit_codes => [0, 24]).once
|
682
|
-
expect(subject).to receive(:on).with(master, 'cert --list --all').once.and_return( result )
|
683
|
-
|
684
|
-
subject.sign_certificate_for( agent )
|
653
|
+
subject.sign_certificate_for(agent)
|
685
654
|
end
|
686
655
|
|
687
656
|
it 'retries 11 times before quitting' do
|
688
|
-
allow(
|
657
|
+
allow(subject).to receive(:sleep).and_return(true)
|
689
658
|
|
690
659
|
result.stdout = "Requested Certificates: \"#{agent}\""
|
691
|
-
allow(
|
660
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
692
661
|
|
693
|
-
allow(
|
662
|
+
allow(subject).to receive(:puppet) do |arg|
|
694
663
|
arg
|
695
664
|
end
|
696
665
|
|
697
|
-
|
698
|
-
|
699
|
-
expect(
|
700
|
-
|
701
|
-
expect(
|
666
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all',
|
667
|
+
acceptable_exit_codes: [0, 24]).exactly(11).times
|
668
|
+
expect(subject).to receive(:on).with(master,
|
669
|
+
'puppetserver ca list --all').exactly(11).times.and_return(result)
|
670
|
+
expect(subject).to receive(:fail_test).once
|
702
671
|
|
703
|
-
subject.sign_certificate_for(
|
672
|
+
subject.sign_certificate_for(agent)
|
704
673
|
end
|
705
674
|
|
706
675
|
it 'accepts an array of hosts to validate' do
|
707
|
-
allow(
|
676
|
+
allow(subject).to receive(:sleep).and_return(true)
|
708
677
|
|
709
678
|
result.stdout = "+ \"#{agent}\" + \"#{custom}\""
|
710
|
-
allow(
|
679
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
711
680
|
|
712
|
-
allow(
|
681
|
+
allow(subject).to receive(:puppet) do |arg|
|
713
682
|
arg
|
714
683
|
end
|
715
|
-
expect(
|
716
|
-
|
717
|
-
expect(subject).to receive(:on).with(master, '--
|
718
|
-
|
719
|
-
expect(
|
720
|
-
expect( subject ).to receive( :on ).with( master, "puppetserver ca list --all").once.and_return( result )
|
684
|
+
expect(subject).to receive(:on).with(master, 'agent -t', acceptable_exit_codes: [0, 1, 2]).once
|
685
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --certname master').once
|
686
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca sign --all',
|
687
|
+
acceptable_exit_codes: [0, 24]).once
|
688
|
+
expect(subject).to receive(:on).with(master, 'puppetserver ca list --all').once.and_return(result)
|
721
689
|
|
722
|
-
subject.sign_certificate_for(
|
690
|
+
subject.sign_certificate_for([master, agent, custom])
|
723
691
|
end
|
724
692
|
end
|
725
693
|
|
726
|
-
describe
|
694
|
+
describe '#sign_certificate' do
|
727
695
|
it 'delegates to #sign_certificate_for with the default host' do
|
728
|
-
allow(
|
729
|
-
expect(
|
696
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
697
|
+
expect(subject).to receive(:default).and_return(master)
|
730
698
|
|
731
|
-
expect(
|
699
|
+
expect(subject).to receive(:sign_certificate_for).with(master).once
|
732
700
|
|
733
|
-
subject.sign_certificate
|
701
|
+
subject.sign_certificate
|
734
702
|
end
|
735
703
|
end
|
736
704
|
|
@@ -740,136 +708,136 @@ describe ClassMixedWithDSLHelpers do
|
|
740
708
|
let(:is_pe) { false }
|
741
709
|
let(:use_service) { false }
|
742
710
|
let(:platform) { 'redhat' }
|
743
|
-
let(:host)
|
711
|
+
let(:host) do
|
744
712
|
FakeHost.create('fakevm', "#{platform}-version-arch",
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
}
|
713
|
+
'type' => is_pe ? 'pe' : 'git',
|
714
|
+
'use-service' => use_service)
|
715
|
+
end
|
749
716
|
|
750
717
|
def stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created
|
751
718
|
subject.instance_variable_set(:@path, test_case_path)
|
752
|
-
allow(
|
753
|
-
allow(
|
754
|
-
allow(
|
719
|
+
allow(host).to receive(:tmpdir).and_return(tmpdir_path)
|
720
|
+
allow(host).to receive(:file_exist?).and_return(true)
|
721
|
+
allow(subject).to receive(:options).and_return({})
|
755
722
|
end
|
756
723
|
|
757
724
|
before do
|
758
725
|
stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created
|
759
|
-
allow(
|
726
|
+
allow(subject).to receive(:curl_with_retries)
|
760
727
|
end
|
761
728
|
|
762
|
-
it
|
763
|
-
expect
|
729
|
+
it 'raises an ArgumentError if you try to submit a String instead of a Hash of options' do
|
730
|
+
expect do
|
731
|
+
subject.with_puppet_running_on(host,
|
732
|
+
'--foo --bar')
|
733
|
+
end.to raise_error(ArgumentError, /conf_opts must be a Hash. You provided a String: '--foo --bar'/)
|
764
734
|
end
|
765
735
|
|
766
736
|
it 'raises the early_exception if backup_the_file fails' do
|
767
|
-
allow(
|
768
|
-
|
769
|
-
expect
|
770
|
-
expect {
|
737
|
+
allow(subject).to receive(:restore_puppet_conf_from_backup)
|
738
|
+
expect(subject).to receive(:backup_the_file).and_raise(RuntimeError.new('puppet conf backup failed'))
|
739
|
+
expect do
|
771
740
|
subject.with_puppet_running_on(host, {})
|
772
|
-
|
741
|
+
end.to raise_error(RuntimeError, /puppet conf backup failed/)
|
773
742
|
end
|
774
743
|
|
775
744
|
it 'receives a Minitest::Assertion and fails the test correctly' do
|
776
|
-
allow(
|
777
|
-
allow(
|
778
|
-
allow(
|
779
|
-
|
780
|
-
expect( subject ).to receive( :fail_test )
|
745
|
+
allow(subject).to receive(:backup_the_file).and_raise(Minitest::Assertion.new('assertion failed!'))
|
746
|
+
allow(host).to receive(:puppet).and_return({})
|
747
|
+
allow(subject).to receive(:restore_puppet_conf_from_backup)
|
748
|
+
expect(subject).to receive(:fail_test)
|
781
749
|
subject.with_puppet_running_on(host, {})
|
782
750
|
end
|
783
751
|
|
784
752
|
context 'with test flow exceptions' do
|
785
753
|
it 'can pass_test' do
|
786
|
-
expect(
|
787
|
-
expect
|
754
|
+
expect(subject).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::PassTest)
|
755
|
+
expect do
|
788
756
|
subject.with_puppet_running_on(host, {}).to receive(:pass_test)
|
789
|
-
|
757
|
+
end.to raise_error(Beaker::DSL::Outcomes::PassTest)
|
790
758
|
end
|
791
759
|
it 'can fail_test' do
|
792
|
-
expect(
|
793
|
-
expect
|
760
|
+
expect(subject).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::FailTest)
|
761
|
+
expect do
|
794
762
|
subject.with_puppet_running_on(host, {}).to receive(:fail_test)
|
795
|
-
|
763
|
+
end.to raise_error(Beaker::DSL::Outcomes::FailTest)
|
796
764
|
end
|
797
765
|
it 'can skip_test' do
|
798
|
-
expect(
|
799
|
-
expect
|
766
|
+
expect(subject).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::SkipTest)
|
767
|
+
expect do
|
800
768
|
subject.with_puppet_running_on(host, {}).to receive(:skip_test)
|
801
|
-
|
769
|
+
end.to raise_error(Beaker::DSL::Outcomes::SkipTest)
|
802
770
|
end
|
803
771
|
it 'can pending_test' do
|
804
|
-
expect(
|
805
|
-
expect
|
772
|
+
expect(subject).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::PendingTest)
|
773
|
+
expect do
|
806
774
|
subject.with_puppet_running_on(host, {}).to receive(:pending_test)
|
807
|
-
|
775
|
+
end.to raise_error(Beaker::DSL::Outcomes::PendingTest)
|
808
776
|
end
|
809
777
|
end
|
810
778
|
|
811
779
|
describe 'with puppet-server' do
|
812
|
-
let(:default_confdir) {
|
813
|
-
let(:default_vardir) {
|
780
|
+
let(:default_confdir) { '/etc/puppet' }
|
781
|
+
let(:default_vardir) { '/var/lib/puppet' }
|
814
782
|
|
815
|
-
let(:custom_confdir) {
|
816
|
-
let(:custom_vardir) {
|
783
|
+
let(:custom_confdir) { '/tmp/etc/puppet' }
|
784
|
+
let(:custom_vardir) { '/tmp/var/lib/puppet' }
|
817
785
|
|
818
|
-
let(:command_line_args) {"--vardir=#{custom_vardir} --confdir=#{custom_confdir}"}
|
819
|
-
let(:conf_opts)
|
820
|
-
|
786
|
+
let(:command_line_args) { "--vardir=#{custom_vardir} --confdir=#{custom_confdir}" }
|
787
|
+
let(:conf_opts) do
|
788
|
+
{ __commandline_args__: command_line_args,
|
789
|
+
is_puppetserver: true, }
|
790
|
+
end
|
821
791
|
|
822
|
-
let(:default_puppetserver_opts)
|
823
|
-
{
|
824
|
-
|
825
|
-
|
792
|
+
let(:default_puppetserver_opts) do
|
793
|
+
{ 'jruby-puppet' => {
|
794
|
+
'master-conf-dir' => default_confdir,
|
795
|
+
'master-var-dir' => default_vardir,
|
826
796
|
},
|
827
|
-
|
828
|
-
|
829
|
-
}
|
830
|
-
|
831
|
-
}
|
797
|
+
'certificate-authority' => {
|
798
|
+
'allow-subject-alt-names' => true,
|
799
|
+
}, }
|
800
|
+
end
|
832
801
|
|
833
|
-
let(:custom_puppetserver_opts)
|
834
|
-
{
|
835
|
-
|
836
|
-
|
802
|
+
let(:custom_puppetserver_opts) do
|
803
|
+
{ 'jruby-puppet' => {
|
804
|
+
'master-conf-dir' => custom_confdir,
|
805
|
+
'master-var-dir' => custom_vardir,
|
837
806
|
},
|
838
|
-
|
839
|
-
|
840
|
-
}
|
841
|
-
|
842
|
-
}
|
807
|
+
'certificate-authority' => {
|
808
|
+
'allow-subject-alt-names' => true,
|
809
|
+
}, }
|
810
|
+
end
|
843
811
|
|
844
|
-
let(:puppetserver_conf) {
|
812
|
+
let(:puppetserver_conf) { '/etc/puppetserver/conf.d/puppetserver.conf' }
|
845
813
|
let(:logger) { double }
|
846
814
|
|
847
815
|
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( logger ).to receive( :debug)
|
816
|
+
allow(subject).to receive(:restore_puppet_conf_from_backup)
|
817
|
+
allow(subject).to receive(:bounce_service)
|
818
|
+
allow(subject).to receive(:stop_puppet_from_source_on)
|
819
|
+
allow(subject).to receive(:dump_puppet_log)
|
820
|
+
allow(subject).to receive(:restore_puppet_conf_from_backup)
|
821
|
+
allow(subject).to receive(:puppet_master_started)
|
822
|
+
allow(subject).to receive(:lay_down_new_puppet_conf)
|
823
|
+
allow(subject).to receive(:logger).and_return(logger)
|
824
|
+
allow(logger).to receive(:error)
|
825
|
+
allow(logger).to receive(:debug)
|
859
826
|
end
|
860
827
|
|
861
828
|
before do
|
862
829
|
stub_post_setup
|
863
|
-
allow(
|
864
|
-
allow(
|
865
|
-
allow(
|
866
|
-
allow(
|
867
|
-
allow(
|
830
|
+
allow(subject).to receive(:options).and_return({ is_puppetserver: true })
|
831
|
+
allow(subject).to receive(:modify_tk_config)
|
832
|
+
allow(subject).to receive(:puppet_config).with(host, 'confdir', anything).and_return(default_confdir)
|
833
|
+
allow(subject).to receive(:puppet_config).with(host, 'vardir', anything).and_return(default_vardir)
|
834
|
+
allow(subject).to receive(:puppet_config).with(host, 'config',
|
835
|
+
anything).and_return("#{default_confdir}/puppet.conf")
|
868
836
|
end
|
869
837
|
|
870
838
|
describe 'when the global option for :is_puppetserver is false' do
|
871
839
|
it 'checks the option for the host object' do
|
872
|
-
allow(
|
840
|
+
allow(subject).to receive(:options).and_return({ is_puppetserver: false })
|
873
841
|
host[:is_puppetserver] = true
|
874
842
|
expect(subject).to receive(:modify_tk_config)
|
875
843
|
subject.with_puppet_running_on(host, conf_opts)
|
@@ -879,8 +847,8 @@ describe ClassMixedWithDSLHelpers do
|
|
879
847
|
describe 'and command line args passed' do
|
880
848
|
it 'modifies SUT trapperkeeper configuration w/ command line args' do
|
881
849
|
host['puppetserver-confdir'] = '/etc/puppetserver/conf.d'
|
882
|
-
expect(
|
883
|
-
|
850
|
+
expect(subject).to receive(:modify_tk_config).with(host, puppetserver_conf,
|
851
|
+
custom_puppetserver_opts)
|
884
852
|
subject.with_puppet_running_on(host, conf_opts)
|
885
853
|
end
|
886
854
|
end
|
@@ -889,16 +857,16 @@ describe ClassMixedWithDSLHelpers do
|
|
889
857
|
let(:command_line_args) { nil }
|
890
858
|
it 'modifies SUT trapperkeeper configuration w/ puppet defaults' do
|
891
859
|
host['puppetserver-confdir'] = '/etc/puppetserver/conf.d'
|
892
|
-
expect(
|
893
|
-
|
860
|
+
expect(subject).to receive(:modify_tk_config).with(host, puppetserver_conf,
|
861
|
+
default_puppetserver_opts)
|
894
862
|
subject.with_puppet_running_on(host, conf_opts)
|
895
863
|
end
|
896
864
|
end
|
897
865
|
end
|
898
866
|
|
899
|
-
describe
|
867
|
+
describe 'with valid arguments' do
|
900
868
|
before do
|
901
|
-
expect(
|
869
|
+
expect(Tempfile).to receive(:open).with('beaker')
|
902
870
|
end
|
903
871
|
|
904
872
|
context 'for pe hosts' do
|
@@ -913,7 +881,7 @@ describe ClassMixedWithDSLHelpers do
|
|
913
881
|
|
914
882
|
it 'yields to a block in between bouncing service calls' do
|
915
883
|
execution = 0
|
916
|
-
allow(
|
884
|
+
allow(subject).to receive(:curl_with_retries)
|
917
885
|
expect do
|
918
886
|
subject.with_puppet_running_on(host, {}) do
|
919
887
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(1).times
|
@@ -927,7 +895,7 @@ describe ClassMixedWithDSLHelpers do
|
|
927
895
|
|
928
896
|
context ':restart_when_done flag set false' do
|
929
897
|
it 'starts puppet once, stops it twice' do
|
930
|
-
subject.with_puppet_running_on(host, { :
|
898
|
+
subject.with_puppet_running_on(host, { restart_when_done: false })
|
931
899
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
|
932
900
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
|
933
901
|
end
|
@@ -943,9 +911,9 @@ describe ClassMixedWithDSLHelpers do
|
|
943
911
|
|
944
912
|
it 'yields to a block after bouncing service' do
|
945
913
|
execution = 0
|
946
|
-
allow(
|
914
|
+
allow(subject).to receive(:curl_with_retries)
|
947
915
|
expect do
|
948
|
-
subject.with_puppet_running_on(host, { :
|
916
|
+
subject.with_puppet_running_on(host, { restart_when_done: false }) do
|
949
917
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(1).times
|
950
918
|
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(1).times
|
951
919
|
execution += 1
|
@@ -956,162 +924,6 @@ describe ClassMixedWithDSLHelpers do
|
|
956
924
|
end
|
957
925
|
end
|
958
926
|
|
959
|
-
context 'for foss packaged hosts using passenger' do
|
960
|
-
before(:each) do
|
961
|
-
host.uses_passenger!
|
962
|
-
end
|
963
|
-
it 'bounces puppet twice' do
|
964
|
-
allow( subject ).to receive(:curl_with_retries)
|
965
|
-
subject.with_puppet_running_on(host, {})
|
966
|
-
expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
|
967
|
-
end
|
968
|
-
|
969
|
-
it 'gracefully restarts using apache2ctl' do
|
970
|
-
allow(host).to receive( :check_for_command ).and_return( true )
|
971
|
-
allow( subject ).to receive(:curl_with_retries)
|
972
|
-
subject.with_puppet_running_on(host, {})
|
973
|
-
expect(host).to execute_commands_matching(/apache2ctl graceful/).exactly(2).times
|
974
|
-
end
|
975
|
-
|
976
|
-
it 'gracefully restarts using apachectl' do
|
977
|
-
allow(host).to receive( :check_for_command ).and_return( false )
|
978
|
-
allow( subject ).to receive(:curl_with_retries)
|
979
|
-
subject.with_puppet_running_on(host, {})
|
980
|
-
expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
|
981
|
-
end
|
982
|
-
|
983
|
-
it 'yields to a block after bouncing service' do
|
984
|
-
execution = 0
|
985
|
-
allow( subject ).to receive(:curl_with_retries)
|
986
|
-
expect do
|
987
|
-
subject.with_puppet_running_on(host, {}) do
|
988
|
-
expect(host).to execute_commands_matching(/apachectl graceful/).once
|
989
|
-
execution += 1
|
990
|
-
end
|
991
|
-
end.to change { execution }.by(1)
|
992
|
-
expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
|
993
|
-
end
|
994
|
-
|
995
|
-
context ':restart_when_done flag set false' do
|
996
|
-
it 'bounces puppet once' do
|
997
|
-
allow( subject ).to receive(:curl_with_retries)
|
998
|
-
subject.with_puppet_running_on(host, { :restart_when_done => false })
|
999
|
-
expect(host).to execute_commands_matching(/apachectl graceful/).once
|
1000
|
-
end
|
1001
|
-
|
1002
|
-
it 'yields to a block after bouncing service' do
|
1003
|
-
execution = 0
|
1004
|
-
allow( subject ).to receive(:curl_with_retries)
|
1005
|
-
expect do
|
1006
|
-
subject.with_puppet_running_on(host, { :restart_when_done => false }) do
|
1007
|
-
expect(host).to execute_commands_matching(/apachectl graceful/).once
|
1008
|
-
execution += 1
|
1009
|
-
end
|
1010
|
-
end.to change { execution }.by(1)
|
1011
|
-
end
|
1012
|
-
end
|
1013
|
-
end
|
1014
|
-
|
1015
|
-
context 'for foss packaged hosts using webrick' do
|
1016
|
-
let(:use_service) { true }
|
1017
|
-
|
1018
|
-
it 'stops and starts master using service scripts twice' do
|
1019
|
-
allow( subject ).to receive(:curl_with_retries)
|
1020
|
-
subject.with_puppet_running_on(host, {})
|
1021
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times
|
1022
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
|
1023
|
-
end
|
1024
|
-
|
1025
|
-
it 'yields to a block in between bounce calls for the service' do
|
1026
|
-
execution = 0
|
1027
|
-
expect do
|
1028
|
-
subject.with_puppet_running_on(host, {}) do
|
1029
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
|
1030
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).once
|
1031
|
-
execution += 1
|
1032
|
-
end
|
1033
|
-
end.to change { execution }.by(1)
|
1034
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times
|
1035
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
|
1036
|
-
end
|
1037
|
-
|
1038
|
-
context ':restart_when_done flag set false' do
|
1039
|
-
it 'stops (twice) and starts (once) master using service scripts' do
|
1040
|
-
allow( subject ).to receive(:curl_with_retries)
|
1041
|
-
subject.with_puppet_running_on(host, { :restart_when_done => false })
|
1042
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
|
1043
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
|
1044
|
-
end
|
1045
|
-
|
1046
|
-
it 'yields to a block after stopping and starting service' do
|
1047
|
-
execution = 0
|
1048
|
-
expect do
|
1049
|
-
subject.with_puppet_running_on(host, { :restart_when_done => false }) do
|
1050
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
|
1051
|
-
expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).once
|
1052
|
-
execution += 1
|
1053
|
-
end
|
1054
|
-
end.to change { execution }.by(1)
|
1055
|
-
end
|
1056
|
-
end
|
1057
|
-
end
|
1058
|
-
|
1059
|
-
context 'running from source' do
|
1060
|
-
let('use-service') { false }
|
1061
|
-
|
1062
|
-
it 'does not try to stop if not started' do
|
1063
|
-
expect( subject ).to receive(:start_puppet_from_source_on!).and_return false
|
1064
|
-
expect( subject ).to_not receive(:stop_puppet_from_source_on)
|
1065
|
-
|
1066
|
-
subject.with_puppet_running_on(host, {})
|
1067
|
-
end
|
1068
|
-
|
1069
|
-
context 'successfully' do
|
1070
|
-
before do
|
1071
|
-
expect( host ).to receive(:port_open?).with(8140).and_return(true)
|
1072
|
-
end
|
1073
|
-
|
1074
|
-
it 'starts puppet from source' do
|
1075
|
-
subject.with_puppet_running_on(host, {})
|
1076
|
-
end
|
1077
|
-
|
1078
|
-
it 'stops puppet from source' do
|
1079
|
-
subject.with_puppet_running_on(host, {})
|
1080
|
-
expect(host).to execute_commands_matching(/^kill [^-]/).once
|
1081
|
-
expect(host).to execute_commands_matching(/^kill -0/).once
|
1082
|
-
end
|
1083
|
-
|
1084
|
-
it 'yields between starting and stopping' do
|
1085
|
-
execution = 0
|
1086
|
-
expect do
|
1087
|
-
subject.with_puppet_running_on(host, {}) do
|
1088
|
-
expect(host).to execute_commands_matching(/^puppet master/).once
|
1089
|
-
execution += 1
|
1090
|
-
end
|
1091
|
-
end.to change { execution }.by(1)
|
1092
|
-
expect(host).to execute_commands_matching(/^kill [^-]/).once
|
1093
|
-
expect(host).to execute_commands_matching(/^kill -0/).once
|
1094
|
-
end
|
1095
|
-
|
1096
|
-
it 'passes on commandline args' do
|
1097
|
-
subject.with_puppet_running_on(host, {:__commandline_args__ => '--with arg'})
|
1098
|
-
expect(host).to execute_commands_matching(/^puppet master --with arg/).once
|
1099
|
-
end
|
1100
|
-
|
1101
|
-
it 'is not affected by the :restart_when_done flag' do
|
1102
|
-
execution = 0
|
1103
|
-
expect do
|
1104
|
-
subject.with_puppet_running_on(host, { :restart_when_done => true }) do
|
1105
|
-
expect(host).to execute_commands_matching(/^puppet master/).once
|
1106
|
-
execution += 1
|
1107
|
-
end
|
1108
|
-
end.to change { execution }.by(1)
|
1109
|
-
expect(host).to execute_commands_matching(/^kill [^-]/).once
|
1110
|
-
expect(host).to execute_commands_matching(/^kill -0/).once
|
1111
|
-
end
|
1112
|
-
end
|
1113
|
-
end
|
1114
|
-
|
1115
927
|
describe 'backup and restore of puppet.conf' do
|
1116
928
|
before :each do
|
1117
929
|
allow(subject).to receive(:puppet_config).with(host, 'confdir', anything).and_return('/root/mock')
|
@@ -1119,14 +931,14 @@ describe ClassMixedWithDSLHelpers do
|
|
1119
931
|
end
|
1120
932
|
|
1121
933
|
let(:original_location) { '/root/mock/puppet.conf' }
|
1122
|
-
let(:backup_location)
|
934
|
+
let(:backup_location) do
|
1123
935
|
filename = File.basename(original_location)
|
1124
936
|
File.join(tmpdir_path, "#{filename}.bak")
|
1125
|
-
|
1126
|
-
let(:new_location)
|
937
|
+
end
|
938
|
+
let(:new_location) do
|
1127
939
|
filename = File.basename(original_location)
|
1128
940
|
File.join(tmpdir_path, filename)
|
1129
|
-
|
941
|
+
end
|
1130
942
|
|
1131
943
|
context 'when a puppetservice is used' do
|
1132
944
|
let(:use_service) { true }
|
@@ -1138,194 +950,122 @@ describe ClassMixedWithDSLHelpers do
|
|
1138
950
|
end
|
1139
951
|
|
1140
952
|
it 'restores puppet.conf before restarting' do
|
1141
|
-
subject.with_puppet_running_on(host, { :
|
953
|
+
subject.with_puppet_running_on(host, { restart_when_done: true })
|
1142
954
|
expect(host).to execute_commands_matching_in_order(/cat '#{backup_location}' > '#{original_location}'/,
|
1143
955
|
/ensure=stopped/,
|
1144
956
|
/ensure=running/)
|
1145
957
|
end
|
1146
958
|
end
|
1147
|
-
|
1148
|
-
context 'when a puppetservice is not used' do
|
1149
|
-
before do
|
1150
|
-
expect( host ).to receive(:port_open?).with(8140).and_return(true)
|
1151
|
-
end
|
1152
|
-
|
1153
|
-
it 'backs up puppet.conf' do
|
1154
|
-
subject.with_puppet_running_on(host, {})
|
1155
|
-
expect(host).to execute_commands_matching(/cp #{original_location} #{backup_location}/).once
|
1156
|
-
expect(host).to execute_commands_matching(/cat #{new_location} > #{original_location}/).once
|
1157
|
-
end
|
1158
|
-
|
1159
|
-
it 'restores puppet.conf after restarting when a puppetservice is not used' do
|
1160
|
-
subject.with_puppet_running_on(host, {})
|
1161
|
-
expect(host).to execute_commands_matching_in_order(/kill [^-]/,
|
1162
|
-
/cat '#{backup_location}' > '#{original_location}'/m)
|
1163
|
-
end
|
1164
|
-
|
1165
|
-
it "doesn't restore a non-existent file" do
|
1166
|
-
allow( subject ).to receive(:backup_the_file)
|
1167
|
-
subject.with_puppet_running_on(host, {})
|
1168
|
-
expect(host).to execute_commands_matching(/rm -f '#{original_location}'/)
|
1169
|
-
end
|
1170
|
-
end
|
1171
|
-
end
|
1172
|
-
|
1173
|
-
let(:logger) { double.as_null_object }
|
1174
|
-
describe 'handling failures' do
|
1175
|
-
|
1176
|
-
before do
|
1177
|
-
allow( subject ).to receive( :logger ).and_return( logger )
|
1178
|
-
expect( subject ).to receive(:stop_puppet_from_source_on).and_raise(RuntimeError.new('Also failed in teardown.'))
|
1179
|
-
expect( host ).to receive(:port_open?).with(8140).and_return(true)
|
1180
|
-
end
|
1181
|
-
|
1182
|
-
it 'does not swallow an exception raised from within test block if ensure block also fails' do
|
1183
|
-
expect( subject.logger ).to receive(:error).with(/Raised during attempt to teardown.*Also failed in teardown/)
|
1184
|
-
|
1185
|
-
expect do
|
1186
|
-
subject.with_puppet_running_on(host, {}) { raise 'Failed while yielding.' }
|
1187
|
-
end.to raise_error(RuntimeError, /failed.*because.*Failed while yielding./)
|
1188
|
-
end
|
1189
|
-
|
1190
|
-
it 'dumps the puppet logs if there is an error in the teardown' do
|
1191
|
-
expect( subject.logger ).to receive(:notify).with(/Dumping master log/)
|
1192
|
-
|
1193
|
-
expect do
|
1194
|
-
subject.with_puppet_running_on(host, {})
|
1195
|
-
end.to raise_error(RuntimeError, /Also failed in teardown/)
|
1196
|
-
end
|
1197
|
-
|
1198
|
-
it 'does not mask the teardown error with an error from dumping the logs' do
|
1199
|
-
expect( subject.logger ).to receive(:notify).with(/Dumping master log/).and_raise("Error from dumping logs")
|
1200
|
-
|
1201
|
-
expect do
|
1202
|
-
subject.with_puppet_running_on(host, {})
|
1203
|
-
end.to raise_error(RuntimeError, /Also failed in teardown/)
|
1204
|
-
end
|
1205
|
-
|
1206
|
-
it 'does not swallow a teardown exception if no earlier exception was raised' do
|
1207
|
-
expect( subject.logger).to_not receive(:error)
|
1208
|
-
expect do
|
1209
|
-
subject.with_puppet_running_on(host, {})
|
1210
|
-
end.to raise_error(RuntimeError, 'Also failed in teardown.')
|
1211
|
-
end
|
1212
|
-
|
1213
959
|
end
|
1214
|
-
|
1215
960
|
end
|
1216
961
|
end
|
1217
962
|
|
1218
963
|
describe '#with_puppet_running' do
|
1219
964
|
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' )
|
965
|
+
allow(subject).to receive(:hosts).and_return(hosts)
|
966
|
+
expect(subject).to receive(:default).and_return(master)
|
1226
967
|
|
968
|
+
expect(subject).to receive(:with_puppet_running_on).with(master, { opt: 'value' }, '/dir').once
|
1227
969
|
|
970
|
+
subject.with_puppet_running({ opt: 'value' }, '/dir')
|
1228
971
|
end
|
1229
972
|
end
|
1230
973
|
|
1231
974
|
describe '#bounce_service' do
|
1232
|
-
let(
|
1233
|
-
let(
|
975
|
+
let(:options) { Beaker::Options::Presets.new.presets }
|
976
|
+
let(:result) { double.as_null_object }
|
1234
977
|
before :each do
|
1235
|
-
allow(
|
978
|
+
allow(subject).to receive(:options) { options }
|
1236
979
|
end
|
1237
980
|
|
1238
981
|
it 'requests a reload but not a restart if the reload is successful' do
|
1239
982
|
host = FakeHost.create
|
1240
|
-
allow(
|
1241
|
-
allow(
|
1242
|
-
allow( host ).to receive( :graceful_restarts? ).and_return( false )
|
983
|
+
allow(result).to receive(:exit_code).and_return(0)
|
984
|
+
allow(host).to receive(:any_exec_result).and_return(result)
|
1243
985
|
|
1244
|
-
expect(
|
1245
|
-
/service not_real_service reload
|
986
|
+
expect(Beaker::Command).to receive(:new).with(
|
987
|
+
/service not_real_service reload/,
|
1246
988
|
).once
|
1247
|
-
expect(
|
1248
|
-
subject.bounce_service(
|
989
|
+
expect(subject).to receive(:puppet_resource).never
|
990
|
+
subject.bounce_service(host, 'not_real_service')
|
1249
991
|
end
|
1250
992
|
|
1251
993
|
it 'requests a restart if the reload fails' do
|
1252
994
|
host = FakeHost.create
|
1253
|
-
allow(
|
1254
|
-
allow(
|
1255
|
-
expect(
|
1256
|
-
expect(
|
995
|
+
allow(result).to receive(:exit_code).and_return(1)
|
996
|
+
allow(host).to receive(:exec).and_return(result)
|
997
|
+
expect(subject).to receive(:curl_with_retries)
|
998
|
+
expect(subject).to receive(:puppet_resource).with(
|
1257
999
|
anything, 'not_real_service', anything
|
1258
|
-
).exactly(
|
1259
|
-
subject.bounce_service(
|
1000
|
+
).exactly(2).times
|
1001
|
+
subject.bounce_service(host, 'not_real_service')
|
1260
1002
|
end
|
1261
1003
|
|
1262
1004
|
it 'uses the default port argument if none given' do
|
1263
1005
|
host = FakeHost.create
|
1264
|
-
|
1265
|
-
|
1266
|
-
expect( subject ).to receive( :curl_with_retries ).with(
|
1006
|
+
allow(result).to receive(:exit_code).and_return(1)
|
1007
|
+
expect(subject).to receive(:curl_with_retries).with(
|
1267
1008
|
anything, anything, /8140/, anything, anything
|
1268
1009
|
)
|
1269
|
-
subject.bounce_service(
|
1010
|
+
subject.bounce_service(host, 'not_real_service')
|
1270
1011
|
end
|
1271
1012
|
|
1272
1013
|
it 'takes the port argument' do
|
1273
1014
|
host = FakeHost.create
|
1274
|
-
|
1275
|
-
|
1276
|
-
expect( subject ).to receive( :curl_with_retries ).with(
|
1015
|
+
allow(result).to receive(:exit_code).and_return(1)
|
1016
|
+
expect(subject).to receive(:curl_with_retries).with(
|
1277
1017
|
anything, anything, /8000/, anything, anything
|
1278
1018
|
)
|
1279
|
-
subject.bounce_service(
|
1019
|
+
subject.bounce_service(host, 'not_real_service', nil, 8000)
|
1280
1020
|
end
|
1281
1021
|
end
|
1282
1022
|
|
1283
1023
|
describe '#sleep_until_puppetdb_started' do
|
1284
|
-
let(
|
1024
|
+
let(:options) do # defaults from presets.rb
|
1285
1025
|
{
|
1286
|
-
:
|
1287
|
-
:
|
1026
|
+
puppetdb_port_nonssl: 8080,
|
1027
|
+
puppetdb_port_ssl: 8081,
|
1288
1028
|
}
|
1289
1029
|
end
|
1290
1030
|
|
1291
1031
|
before :each do
|
1292
|
-
allow(
|
1293
|
-
allow(
|
1294
|
-
allow(
|
1032
|
+
allow(subject).to receive(:options) { options }
|
1033
|
+
allow(hosts[0]).to receive(:node_name).and_return('')
|
1034
|
+
allow(subject).to receive(:version_is_less).and_return(true)
|
1295
1035
|
end
|
1296
1036
|
|
1297
1037
|
it 'uses the default ports if none given' do
|
1298
1038
|
host = hosts[0]
|
1299
|
-
expect(
|
1300
|
-
expect(
|
1301
|
-
subject.sleep_until_puppetdb_started(
|
1039
|
+
expect(subject).to receive(:retry_on).with(anything, /8080/, anything).once.ordered
|
1040
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8081/, anything).once.ordered
|
1041
|
+
subject.sleep_until_puppetdb_started(host)
|
1302
1042
|
end
|
1303
1043
|
|
1304
1044
|
it 'allows setting the nonssl_port' do
|
1305
1045
|
host = hosts[0]
|
1306
|
-
expect(
|
1307
|
-
expect(
|
1046
|
+
expect(subject).to receive(:retry_on).with(anything, /8084/, anything).once.ordered
|
1047
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8081/, anything).once.ordered
|
1308
1048
|
|
1309
|
-
subject.sleep_until_puppetdb_started(
|
1049
|
+
subject.sleep_until_puppetdb_started(host, 8084)
|
1310
1050
|
end
|
1311
1051
|
|
1312
1052
|
it 'allows setting the ssl_port' do
|
1313
1053
|
host = hosts[0]
|
1314
|
-
expect(
|
1315
|
-
expect(
|
1054
|
+
expect(subject).to receive(:retry_on).with(anything, /8080/, anything).once.ordered
|
1055
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8085/, anything).once.ordered
|
1316
1056
|
|
1317
|
-
subject.sleep_until_puppetdb_started(
|
1057
|
+
subject.sleep_until_puppetdb_started(host, nil, 8085)
|
1318
1058
|
end
|
1319
1059
|
|
1320
1060
|
context 'when pe_ver is less than 2016.1.0' do
|
1321
1061
|
it 'uses the version endpoint' do
|
1322
1062
|
host = hosts[0]
|
1323
1063
|
host['pe_ver'] = '2015.3.3'
|
1324
|
-
expect(
|
1325
|
-
expect(
|
1064
|
+
expect(subject).to receive(:retry_on).with(anything, %r{pdb/meta/v1/version}, anything).once.ordered
|
1065
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8081/, anything).once.ordered
|
1326
1066
|
|
1327
|
-
expect(
|
1328
|
-
subject.sleep_until_puppetdb_started(
|
1067
|
+
expect(subject).to receive(:version_is_less).with(host['pe_ver'], '2016.1.0').and_return(true)
|
1068
|
+
subject.sleep_until_puppetdb_started(host)
|
1329
1069
|
end
|
1330
1070
|
end
|
1331
1071
|
|
@@ -1333,60 +1073,59 @@ describe ClassMixedWithDSLHelpers do
|
|
1333
1073
|
it 'uses the status endpoint' do
|
1334
1074
|
host = hosts[0]
|
1335
1075
|
host['pe_ver'] = '2016.1.0'
|
1336
|
-
expect(
|
1337
|
-
|
1076
|
+
expect(subject).to receive(:retry_on).with(anything, %r{status/v1/services/puppetdb-status},
|
1077
|
+
anything).once.ordered
|
1078
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8081/, anything).once.ordered
|
1338
1079
|
|
1339
|
-
expect(
|
1340
|
-
subject.sleep_until_puppetdb_started(
|
1080
|
+
expect(subject).to receive(:version_is_less).with(host['pe_ver'], '2016.1.0').and_return(false)
|
1081
|
+
subject.sleep_until_puppetdb_started(host)
|
1341
1082
|
end
|
1342
1083
|
end
|
1343
|
-
|
1344
1084
|
end
|
1345
1085
|
|
1346
1086
|
describe '#sleep_until_puppetserver_started' do
|
1347
|
-
let(
|
1348
|
-
{ :
|
1087
|
+
let(:options) do
|
1088
|
+
{ puppetserver_port: 8140 }
|
1349
1089
|
end
|
1350
1090
|
|
1351
1091
|
before :each do
|
1352
|
-
allow(
|
1353
|
-
allow(
|
1092
|
+
allow(subject).to receive(:options) { options }
|
1093
|
+
allow(hosts[0]).to receive(:node_name)
|
1354
1094
|
end
|
1355
1095
|
|
1356
1096
|
it 'uses the default port if none given' do
|
1357
1097
|
host = hosts[0]
|
1358
|
-
expect(
|
1359
|
-
subject.sleep_until_puppetserver_started(
|
1098
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8140/, anything).once.ordered
|
1099
|
+
subject.sleep_until_puppetserver_started(host)
|
1360
1100
|
end
|
1361
1101
|
|
1362
1102
|
it 'allows setting the port' do
|
1363
1103
|
host = hosts[0]
|
1364
|
-
expect(
|
1365
|
-
subject.sleep_until_puppetserver_started(
|
1104
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /8147/, anything).once.ordered
|
1105
|
+
subject.sleep_until_puppetserver_started(host, 8147)
|
1366
1106
|
end
|
1367
1107
|
end
|
1368
1108
|
|
1369
1109
|
describe '#sleep_until_nc_started' do
|
1370
|
-
let(
|
1371
|
-
{ :
|
1110
|
+
let(:options) do # defaults from presets.rb
|
1111
|
+
{ nodeclassifier_port: 4433 }
|
1372
1112
|
end
|
1373
1113
|
|
1374
1114
|
before :each do
|
1375
|
-
allow(
|
1376
|
-
allow(
|
1115
|
+
allow(subject).to receive(:options) { options }
|
1116
|
+
allow(hosts[0]).to receive(:node_name)
|
1377
1117
|
end
|
1378
1118
|
|
1379
1119
|
it 'uses the default port if none given' do
|
1380
1120
|
host = hosts[0]
|
1381
|
-
expect(
|
1382
|
-
subject.sleep_until_nc_started(
|
1121
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /4433/, anything).once.ordered
|
1122
|
+
subject.sleep_until_nc_started(host)
|
1383
1123
|
end
|
1384
1124
|
|
1385
1125
|
it 'allows setting the port' do
|
1386
1126
|
host = hosts[0]
|
1387
|
-
expect(
|
1388
|
-
subject.sleep_until_nc_started(
|
1127
|
+
expect(subject).to receive(:curl_with_retries).with(anything, anything, /4435/, anything).once.ordered
|
1128
|
+
subject.sleep_until_nc_started(host, 4435)
|
1389
1129
|
end
|
1390
1130
|
end
|
1391
|
-
|
1392
1131
|
end
|