simp-beaker-helpers 1.34.3 → 1.35.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/workflows/pr_acceptance.yml +1 -1
- data/.github/workflows/pr_tests.yml +6 -7
- data/.rubocop.yml +652 -495
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -2
- data/lib/simp/beaker_helpers/constants.rb +7 -5
- data/lib/simp/beaker_helpers/inspec.rb +52 -55
- data/lib/simp/beaker_helpers/snapshot.rb +126 -134
- data/lib/simp/beaker_helpers/ssg.rb +33 -34
- data/lib/simp/beaker_helpers/version.rb +2 -1
- data/lib/simp/beaker_helpers/windows.rb +4 -1
- data/lib/simp/beaker_helpers.rb +274 -291
- data/lib/simp/rake/beaker.rb +174 -177
- data/spec/acceptance/suites/default/check_puppet_version_spec.rb +3 -3
- data/spec/acceptance/suites/default/fixture_modules_spec.rb +9 -9
- data/spec/acceptance/suites/default/install_simp_deps_repo_spec.rb +7 -13
- data/spec/acceptance/suites/default/pki_tests_spec.rb +10 -16
- data/spec/acceptance/suites/fips_from_fixtures/00_default_spec.rb +4 -4
- data/spec/acceptance/suites/inspec/00_default_spec.rb +22 -22
- data/spec/acceptance/suites/offline/00_default_spec.rb +43 -12
- data/spec/acceptance/suites/offline/nodesets/default.yml +1 -3
- data/spec/acceptance/suites/puppet_collections/00_default_spec.rb +3 -3
- data/spec/acceptance/suites/snapshot/00_snapshot_test_spec.rb +27 -7
- data/spec/acceptance/suites/snapshot/10_general_usage_spec.rb +3 -3
- data/spec/acceptance/suites/ssg/00_default_spec.rb +20 -18
- data/spec/acceptance/suites/windows/00_default_spec.rb +47 -49
- data/spec/acceptance/suites/windows/nodesets/default.yml +3 -3
- data/spec/acceptance/suites/windows/nodesets/win2012.yml +3 -3
- data/spec/acceptance/suites/windows/nodesets/win2016.yml +3 -3
- data/spec/acceptance/suites/windows/nodesets/win2019.yml +3 -3
- data/spec/lib/simp/beaker_helpers_spec.rb +96 -66
- data/spec/spec_helper.rb +51 -53
- data/spec/spec_helper_acceptance.rb +17 -22
- metadata +5 -5
data/lib/simp/beaker_helpers.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'English'
|
1
2
|
require 'beaker-puppet'
|
2
3
|
require 'bundler'
|
3
4
|
|
5
|
+
# SIMP namespace
|
4
6
|
module Simp; end
|
5
7
|
|
8
|
+
# SIMP Beaker helper methods for testing
|
6
9
|
module Simp::BeakerHelpers
|
7
10
|
include BeakerPuppet
|
8
11
|
|
@@ -17,8 +20,8 @@ module Simp::BeakerHelpers
|
|
17
20
|
|
18
21
|
# Stealing this from the Ruby 2.5 Dir::Tmpname workaround from Rails
|
19
22
|
def self.tmpname
|
20
|
-
t = Time.new.strftime(
|
21
|
-
"simp-beaker-helpers-#{t}-#{
|
23
|
+
t = Time.new.strftime('%Y%m%d')
|
24
|
+
"simp-beaker-helpers-#{t}-#{$PROCESS_ID}-#{rand(0x100000000).to_s(36)}.tmp"
|
22
25
|
end
|
23
26
|
|
24
27
|
# Sets a single YUM option in the form that yum-config-manager/dnf
|
@@ -28,8 +31,8 @@ module Simp::BeakerHelpers
|
|
28
31
|
#
|
29
32
|
# Has no effect if yum or dnf is not present.
|
30
33
|
def set_yum_opt_on(suts, key, value)
|
31
|
-
block_on(suts, :
|
32
|
-
repo,target = key.split('.')
|
34
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
35
|
+
repo, target = key.split('.')
|
33
36
|
|
34
37
|
unless target
|
35
38
|
key = "\\*.#{repo}"
|
@@ -37,13 +40,13 @@ module Simp::BeakerHelpers
|
|
37
40
|
|
38
41
|
command = nil
|
39
42
|
if !sut.which('dnf').empty?
|
40
|
-
install_package_unless_present_on(sut, 'dnf-plugins-core', :
|
43
|
+
install_package_unless_present_on(sut, 'dnf-plugins-core', accept_all_exit_codes: true)
|
41
44
|
command = 'dnf config-manager'
|
42
45
|
elsif !sut.which('yum').empty?
|
43
46
|
command = 'yum-config-manager'
|
44
47
|
end
|
45
48
|
|
46
|
-
on(sut, %
|
49
|
+
on(sut, %(#{command} --save --setopt=#{key}=#{value}), silent: true) if command
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
@@ -57,21 +60,21 @@ module Simp::BeakerHelpers
|
|
57
60
|
# 'skip_if_unavailable' => '1', # Applies globally
|
58
61
|
# 'foo.installonly_limit' => '5' # Applies only to the 'foo' repo
|
59
62
|
# }
|
60
|
-
def set_yum_opts_on(suts, yum_opts={})
|
61
|
-
block_on(suts, :
|
62
|
-
yum_opts.each_pair do |k,v|
|
63
|
+
def set_yum_opts_on(suts, yum_opts = {})
|
64
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
65
|
+
yum_opts.each_pair do |k, v|
|
63
66
|
set_yum_opt_on(sut, k, v)
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
68
|
-
def install_package_unless_present_on(suts, package_name, package_source=nil, opts={})
|
71
|
+
def install_package_unless_present_on(suts, package_name, package_source = nil, opts = {})
|
69
72
|
default_opts = {
|
70
73
|
max_retries: 3,
|
71
74
|
retry_interval: 10
|
72
75
|
}
|
73
76
|
|
74
|
-
block_on(suts, :
|
77
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
75
78
|
package_source = package_name unless package_source
|
76
79
|
|
77
80
|
unless sut.check_for_package(package_name)
|
@@ -79,26 +82,26 @@ module Simp::BeakerHelpers
|
|
79
82
|
package_source,
|
80
83
|
'',
|
81
84
|
nil,
|
82
|
-
default_opts.merge(opts)
|
85
|
+
default_opts.merge(opts),
|
83
86
|
)
|
84
87
|
end
|
85
88
|
end
|
86
89
|
end
|
87
90
|
|
88
|
-
def install_latest_package_on(suts, package_name, package_source=nil, opts={})
|
91
|
+
def install_latest_package_on(suts, package_name, package_source = nil, opts = {})
|
89
92
|
default_opts = {
|
90
93
|
max_retries: 3,
|
91
94
|
retry_interval: 10
|
92
95
|
}
|
93
96
|
|
94
|
-
block_on(suts, :
|
97
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
95
98
|
package_source = package_name unless package_source
|
96
99
|
|
97
100
|
if sut.check_for_package(package_name)
|
98
101
|
sut.upgrade_package(
|
99
102
|
package_source,
|
100
103
|
'',
|
101
|
-
default_opts.merge(opts)
|
104
|
+
default_opts.merge(opts),
|
102
105
|
)
|
103
106
|
else
|
104
107
|
install_package_unless_present_on(sut, package_name, package_source, opts)
|
@@ -107,20 +110,19 @@ module Simp::BeakerHelpers
|
|
107
110
|
end
|
108
111
|
|
109
112
|
def is_windows?(sut)
|
110
|
-
sut[:platform] =~
|
113
|
+
sut[:platform] =~ %r{windows}i
|
111
114
|
end
|
112
115
|
|
113
116
|
# We can't cache this because it may change during a run
|
114
117
|
def fips_enabled(sut)
|
115
|
-
|
118
|
+
on(sut,
|
116
119
|
'cat /proc/sys/crypto/fips_enabled 2>/dev/null',
|
117
|
-
:
|
118
|
-
).output.strip == '1'
|
120
|
+
accept_all_exit_codes: true).output.strip == '1'
|
119
121
|
end
|
120
122
|
|
121
123
|
def rsync_functional_on?(sut)
|
122
124
|
# We have to check if rsync *still* works otherwise
|
123
|
-
return false if
|
125
|
+
return false if @rsync_functional == false
|
124
126
|
|
125
127
|
require 'facter'
|
126
128
|
unless Facter::Util::Resolution.which('rsync')
|
@@ -143,38 +145,38 @@ module Simp::BeakerHelpers
|
|
143
145
|
testfile.unlink
|
144
146
|
end
|
145
147
|
|
146
|
-
|
148
|
+
true
|
147
149
|
end
|
148
150
|
|
149
151
|
# Figure out the best method to copy files to a host and use it
|
150
152
|
#
|
151
153
|
# Will create the directories leading up to the target if they don't exist
|
152
|
-
def copy_to(sut, src, dest, opts={})
|
154
|
+
def copy_to(sut, src, dest, opts = {})
|
153
155
|
sut.mkdir_p(File.dirname(dest))
|
154
156
|
|
155
157
|
if sut[:hypervisor] == 'docker'
|
156
158
|
exclude_list = []
|
157
159
|
opts[:silent] ||= true
|
158
160
|
|
159
|
-
if opts.
|
161
|
+
if opts.key?(:ignore) && !opts[:ignore].empty?
|
160
162
|
opts[:ignore].each do |value|
|
161
163
|
exclude_list << "--exclude '#{value}'"
|
162
164
|
end
|
163
165
|
end
|
164
166
|
|
165
167
|
# Work around for breaking changes in beaker-docker
|
166
|
-
if sut.host_hash[:docker_container]
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
168
|
+
container_id = if sut.host_hash[:docker_container]
|
169
|
+
sut.host_hash[:docker_container].id
|
170
|
+
else
|
171
|
+
sut.host_hash[:docker_container_id]
|
172
|
+
end
|
171
173
|
|
172
174
|
if ENV['BEAKER_docker_cmd']
|
173
175
|
docker_cmd = ENV['BEAKER_docker_cmd']
|
174
176
|
else
|
175
177
|
docker_cmd = 'docker'
|
176
178
|
|
177
|
-
if ::Docker.version['Components'].any?{|x| x['Name'] =~
|
179
|
+
if ::Docker.version['Components'].any? { |x| x['Name'] =~ %r{podman}i }
|
178
180
|
docker_cmd = 'podman'
|
179
181
|
|
180
182
|
if ENV['CONTAINER_HOST']
|
@@ -187,16 +189,16 @@ module Simp::BeakerHelpers
|
|
187
189
|
|
188
190
|
sut.mkdir_p(File.dirname(dest)) unless directory_exists_on(sut, dest)
|
189
191
|
|
190
|
-
if File.file?(src)
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
192
|
+
cmd = if File.file?(src)
|
193
|
+
%(#{docker_cmd} cp "#{src}" "#{container_id}:#{dest}")
|
194
|
+
else
|
195
|
+
[
|
196
|
+
%(tar #{exclude_list.join(' ')} -hcf - -C "#{File.dirname(src)}" "#{File.basename(src)}"),
|
197
|
+
%(#{docker_cmd} exec -i "#{container_id}" tar -C "#{dest}" -xf -),
|
198
|
+
].join(' | ')
|
199
|
+
end
|
198
200
|
|
199
|
-
|
201
|
+
`#{cmd}`
|
200
202
|
elsif rsync_functional_on?(sut)
|
201
203
|
# This makes rsync_to work like beaker and scp usually do
|
202
204
|
exclude_hack = %(__-__' -L --exclude '__-__)
|
@@ -204,9 +206,9 @@ module Simp::BeakerHelpers
|
|
204
206
|
# There appears to be a single copy of 'opts' that gets passed around
|
205
207
|
# through all of the different hosts so we're going to make a local deep
|
206
208
|
# copy so that we don't destroy the world accidentally.
|
207
|
-
|
208
|
-
|
209
|
-
|
209
|
+
local_opts = Marshal.load(Marshal.dump(opts))
|
210
|
+
local_opts[:ignore] ||= []
|
211
|
+
local_opts[:ignore] << exclude_hack
|
210
212
|
|
211
213
|
if File.directory?(src)
|
212
214
|
dest = File.join(dest, File.basename(src)) if File.directory?(src)
|
@@ -216,7 +218,7 @@ module Simp::BeakerHelpers
|
|
216
218
|
# End rsync hackery
|
217
219
|
|
218
220
|
begin
|
219
|
-
rsync_to(sut, src, dest,
|
221
|
+
rsync_to(sut, src, dest, local_opts)
|
220
222
|
rescue
|
221
223
|
# Depending on what is getting tested, a new SSH session might not
|
222
224
|
# work. In this case, we fall back to SSH.
|
@@ -237,21 +239,20 @@ module Simp::BeakerHelpers
|
|
237
239
|
if sut.which('puppet').empty?
|
238
240
|
found_fact = fact_on(sut, fact_name)
|
239
241
|
else
|
240
|
-
facts_json = nil
|
241
242
|
begin
|
242
|
-
cmd_output = on(sut, 'facter -p --json', :
|
243
|
+
cmd_output = on(sut, 'facter -p --json', silent: true)
|
243
244
|
# Facter 4+
|
244
|
-
raise('skip facter -p') if
|
245
|
+
raise('skip facter -p') if cmd_output.stderr.include?('no longer supported')
|
245
246
|
|
246
247
|
facts = JSON.parse(cmd_output.stdout)
|
247
248
|
rescue StandardError
|
248
249
|
# If *anything* fails, we need to fall back to `puppet facts`
|
249
250
|
|
250
|
-
facts_json = retry_on(sut, 'puppet facts find garbage_xxx', :
|
251
|
+
facts_json = retry_on(sut, 'puppet facts find garbage_xxx', silent: true, max_retries: 4).stdout
|
251
252
|
facts = JSON.parse(facts_json)['values']
|
252
253
|
end
|
253
254
|
|
254
|
-
found_fact = facts.dig(*
|
255
|
+
found_fact = facts.dig(*fact_name.split('.'))
|
255
256
|
|
256
257
|
# If we did not find a fact, we should use the upstream function since
|
257
258
|
# puppet may be installed via a gem or through some other means.
|
@@ -264,7 +265,7 @@ module Simp::BeakerHelpers
|
|
264
265
|
end
|
265
266
|
|
266
267
|
# Returns the modulepath on the SUT, as an Array
|
267
|
-
def puppet_modulepath_on(sut,
|
268
|
+
def puppet_modulepath_on(sut, _environment = 'production')
|
268
269
|
splitchar = ':'
|
269
270
|
splitchar = ';' if is_windows?(sut)
|
270
271
|
|
@@ -275,7 +276,7 @@ module Simp::BeakerHelpers
|
|
275
276
|
end
|
276
277
|
|
277
278
|
# Return the default environment path
|
278
|
-
def puppet_environment_path_on(sut,
|
279
|
+
def puppet_environment_path_on(sut, _environment = 'production')
|
279
280
|
File.dirname(sut.puppet_configprint['manifest'])
|
280
281
|
end
|
281
282
|
|
@@ -289,12 +290,9 @@ module Simp::BeakerHelpers
|
|
289
290
|
|
290
291
|
dir = File.join(File.expand_path(dir), 'fixtures')
|
291
292
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
else
|
296
|
-
raise("Could not find fixtures directory at '#{dir}'")
|
297
|
-
end
|
293
|
+
raise("Could not find fixtures directory at '#{dir}'") unless File.directory?(dir)
|
294
|
+
@fixtures_path = dir
|
295
|
+
@fixtures_path
|
298
296
|
end
|
299
297
|
|
300
298
|
# Locates .fixture.yml in or above this directory.
|
@@ -308,8 +306,8 @@ module Simp::BeakerHelpers
|
|
308
306
|
else
|
309
307
|
fixtures_yml = ''
|
310
308
|
dir = '.'
|
311
|
-
while
|
312
|
-
file = File.expand_path(
|
309
|
+
while fixtures_yml.empty? && File.expand_path(dir) != '/'
|
310
|
+
file = File.expand_path('.fixtures.yml', dir)
|
313
311
|
STDERR.puts " ** fixtures_yml_path: #{file}" if ENV['BEAKER_helpers_verbose']
|
314
312
|
if File.exist? file
|
315
313
|
fixtures_yml = file
|
@@ -325,62 +323,59 @@ module Simp::BeakerHelpers
|
|
325
323
|
|
326
324
|
@fixtures_yml_path = fixtures_yml
|
327
325
|
|
328
|
-
|
326
|
+
@fixtures_yml_path
|
329
327
|
end
|
330
328
|
|
331
|
-
|
332
329
|
# returns an Array of puppet modules declared in .fixtures.yml
|
333
330
|
def pupmods_in_fixtures_yml
|
334
331
|
return @pupmods_in_fixtures_yml if @pupmods_in_fixtures_yml
|
335
332
|
|
336
333
|
STDERR.puts ' ** pupmods_in_fixtures_yml' if ENV['BEAKER_helpers_verbose']
|
337
334
|
fixtures_yml = fixtures_yml_path
|
338
|
-
data = YAML.load_file(
|
335
|
+
data = YAML.load_file(fixtures_yml)
|
339
336
|
repos = data.fetch('fixtures').fetch('repositories', {}).keys || []
|
340
337
|
symlinks = data.fetch('fixtures').fetch('symlinks', {}).keys || []
|
341
338
|
STDERR.puts ' ** pupmods_in_fixtures_yml: finished' if ENV['BEAKER_helpers_verbose']
|
342
339
|
|
343
340
|
@pupmods_in_fixtures_yml = (repos + symlinks)
|
344
341
|
|
345
|
-
|
342
|
+
@pupmods_in_fixtures_yml
|
346
343
|
end
|
347
344
|
|
348
|
-
|
349
345
|
# Ensures that the fixture modules (under `spec/fixtures/modules`) exists.
|
350
346
|
# if any fixture modules are missing, run 'rake spec_prep' to populate the
|
351
347
|
# fixtures/modules
|
352
348
|
def ensure_fixture_modules
|
353
|
-
STDERR.puts
|
349
|
+
STDERR.puts ' ** ensure_fixture_modules' if ENV['BEAKER_helpers_verbose']
|
354
350
|
unless ENV['BEAKER_spec_prep'] == 'no'
|
355
|
-
puts
|
356
|
-
puts
|
351
|
+
puts '== checking prepped modules from .fixtures.yml'
|
352
|
+
puts ' -- (use BEAKER_spec_prep=no to disable)'
|
357
353
|
missing_modules = []
|
358
354
|
pupmods_in_fixtures_yml.each do |pupmod|
|
359
355
|
STDERR.puts " ** -- ensure_fixture_modules: '#{pupmod}'" if ENV['BEAKER_helpers_verbose']
|
360
|
-
mod_root = File.expand_path(
|
356
|
+
mod_root = File.expand_path("spec/fixtures/modules/#{pupmod}", File.dirname(fixtures_yml_path))
|
361
357
|
missing_modules << pupmod unless File.directory? mod_root
|
362
358
|
end
|
363
359
|
puts " -- #{missing_modules.size} modules need to be prepped"
|
364
|
-
|
360
|
+
if missing_modules.empty?
|
361
|
+
puts ' == all fixture modules present'
|
362
|
+
else
|
365
363
|
cmd = 'bundle exec rake spec_prep'
|
366
364
|
puts " -- running spec_prep: '#{cmd}'"
|
367
|
-
|
368
|
-
else
|
369
|
-
puts " == all fixture modules present"
|
365
|
+
`#{cmd}`
|
370
366
|
end
|
371
367
|
end
|
372
|
-
STDERR.puts
|
368
|
+
STDERR.puts ' ** -- ensure_fixture_modules: finished' if ENV['BEAKER_helpers_verbose']
|
373
369
|
end
|
374
370
|
|
375
|
-
|
376
371
|
# Copy the local fixture modules (under `spec/fixtures/modules`) onto each SUT
|
377
|
-
def copy_fixture_modules_to(
|
372
|
+
def copy_fixture_modules_to(suts = hosts, opts = {})
|
378
373
|
ensure_fixture_modules
|
379
374
|
|
380
375
|
opts[:pluginsync] = opts.fetch(:pluginsync, true)
|
381
376
|
|
382
377
|
unless ENV['BEAKER_copy_fixtures'] == 'no'
|
383
|
-
block_on(suts, :
|
378
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
384
379
|
STDERR.puts " ** copy_fixture_modules_to: '#{sut}'" if ENV['BEAKER_helpers_verbose']
|
385
380
|
|
386
381
|
# Use spec_prep to provide modules (this supports isolated networks)
|
@@ -392,7 +387,7 @@ module Simp::BeakerHelpers
|
|
392
387
|
# `modulepath` and targets the first one.
|
393
388
|
target_module_path = puppet_modulepath_on(sut).first
|
394
389
|
|
395
|
-
mod_root = File.expand_path(
|
390
|
+
mod_root = File.expand_path('spec/fixtures/modules', File.dirname(fixtures_yml_path))
|
396
391
|
|
397
392
|
Dir.chdir(mod_root) do
|
398
393
|
# Have to do things the slow way on Windows
|
@@ -440,17 +435,14 @@ module Simp::BeakerHelpers
|
|
440
435
|
begin
|
441
436
|
tarfile = "#{Simp::BeakerHelpers.tmpname}.tar"
|
442
437
|
|
443
|
-
excludes = (PUPPET_MODULE_INSTALL_IGNORE + ['spec']).map
|
444
|
-
|
445
|
-
|
438
|
+
excludes = (PUPPET_MODULE_INSTALL_IGNORE + ['spec']).map { |x|
|
439
|
+
"--exclude '*/#{x}'"
|
440
|
+
}.join(' ')
|
446
441
|
|
447
|
-
|
442
|
+
`tar -ch #{excludes} -f #{tarfile} *`
|
448
443
|
|
449
|
-
|
450
|
-
|
451
|
-
else
|
452
|
-
fail("Error: module tar file '#{tarfile}' could not be created at #{mod_root}")
|
453
|
-
end
|
444
|
+
raise("Error: module tar file '#{tarfile}' could not be created at #{mod_root}") unless File.exist?(tarfile)
|
445
|
+
copy_to(sut, tarfile, target_module_path, opts)
|
454
446
|
|
455
447
|
on(sut, "cd #{target_module_path} && tar -xf #{File.basename(tarfile)}")
|
456
448
|
ensure
|
@@ -471,14 +463,20 @@ module Simp::BeakerHelpers
|
|
471
463
|
file_exists_on(sut, '/etc/crypto-policies/config')
|
472
464
|
end
|
473
465
|
|
474
|
-
def munge_ssh_crypto_policies(suts, key_types=['ssh-rsa'])
|
475
|
-
block_on(suts, :
|
466
|
+
def munge_ssh_crypto_policies(suts, key_types = ['ssh-rsa'])
|
467
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
476
468
|
if has_crypto_policies(sut)
|
477
|
-
install_latest_package_on(sut, 'crypto-policies', nil, :
|
469
|
+
install_latest_package_on(sut, 'crypto-policies', nil, accept_all_exit_codes: true)
|
478
470
|
|
479
471
|
# Since we may be doing this prior to having a box flip into FIPS mode, we
|
480
472
|
# need to find and modify *all* of the affected policies
|
481
|
-
on(
|
473
|
+
on(
|
474
|
+
sut,
|
475
|
+
[
|
476
|
+
%{sed --follow-symlinks -i 's/\\(HostKeyAlgorithms\\|PubkeyAcceptedKeyTypes\\)\\(.\\)/\\1\\2#{key_types.join(',')},/g'},
|
477
|
+
"$( grep -L ssh-rsa $( find /etc/crypto-policies /usr/share/crypto-policies -type f -a \\( -name '*.txt' -o -name '*.config' \\) -exec grep -l PubkeyAcceptedKeyTypes {} \\; ) )",
|
478
|
+
].join(' '),
|
479
|
+
)
|
482
480
|
end
|
483
481
|
end
|
484
482
|
end
|
@@ -486,14 +484,14 @@ module Simp::BeakerHelpers
|
|
486
484
|
# Perform the equivalend of an in-place sed without changing the target inode
|
487
485
|
#
|
488
486
|
# Required for many container targets
|
489
|
-
def safe_sed(suts = hosts, pattern, target_file)
|
490
|
-
block_on(suts, :
|
487
|
+
def safe_sed(suts = hosts, pattern, target_file) # rubocop:disable Style/OptionalArguments
|
488
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
491
489
|
tmpfile = sut.tmpfile('safe_sed')
|
492
490
|
|
493
491
|
command = [
|
494
492
|
"cp #{target_file} #{tmpfile}",
|
495
493
|
"sed -i '#{pattern}' #{tmpfile}",
|
496
|
-
"cat #{tmpfile} > #{target_file}"
|
494
|
+
"cat #{tmpfile} > #{target_file}",
|
497
495
|
].join(' && ')
|
498
496
|
|
499
497
|
on(sut, command)
|
@@ -503,11 +501,11 @@ module Simp::BeakerHelpers
|
|
503
501
|
end
|
504
502
|
|
505
503
|
# Configure and reboot SUTs into FIPS mode
|
506
|
-
def enable_fips_mode_on(
|
504
|
+
def enable_fips_mode_on(suts = hosts)
|
507
505
|
puts '== configuring FIPS mode on SUTs'
|
508
506
|
puts ' -- (use BEAKER_fips=no to disable)'
|
509
507
|
|
510
|
-
block_on(suts, :
|
508
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
511
509
|
next if sut[:hypervisor] == 'docker'
|
512
510
|
|
513
511
|
if is_windows?(sut)
|
@@ -527,7 +525,7 @@ module Simp::BeakerHelpers
|
|
527
525
|
# TODO Use simp-ssh Puppet module appropriately (i.e., in a fashion
|
528
526
|
# that doesn't break vagrant access and is appropriate for
|
529
527
|
# typical module tests.)
|
530
|
-
fips_ssh_ciphers = [ 'aes256-ctr','aes192-ctr','aes128-ctr']
|
528
|
+
fips_ssh_ciphers = [ 'aes256-ctr', 'aes192-ctr', 'aes128-ctr']
|
531
529
|
safe_sed(sut, '/Ciphers /d', '/etc/ssh/sshd_config')
|
532
530
|
on(sut, %(echo 'Ciphers #{fips_ssh_ciphers.join(',')}' >> /etc/ssh/sshd_config))
|
533
531
|
|
@@ -579,19 +577,17 @@ module Simp::BeakerHelpers
|
|
579
577
|
# gpgkeys:
|
580
578
|
# - <URL to GPGKEY1>
|
581
579
|
# - <URL to GPGKEY2>
|
582
|
-
def enable_yum_repos_on(
|
583
|
-
block_on(suts, :
|
584
|
-
|
585
|
-
|
586
|
-
repo_manifest = create_yum_resource(repo, metadata)
|
580
|
+
def enable_yum_repos_on(suts = hosts)
|
581
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
582
|
+
sut['yum_repos']&.each_pair do |repo, metadata|
|
583
|
+
repo_manifest = create_yum_resource(repo, metadata)
|
587
584
|
|
588
|
-
|
589
|
-
end
|
585
|
+
apply_manifest_on(sut, repo_manifest, catch_failures: true)
|
590
586
|
end
|
591
587
|
end
|
592
588
|
end
|
593
589
|
|
594
|
-
def create_yum_resource(
|
590
|
+
def create_yum_resource(repo, metadata)
|
595
591
|
repo_attrs = [
|
596
592
|
:assumeyes,
|
597
593
|
:bandwidth,
|
@@ -629,46 +625,46 @@ module Simp::BeakerHelpers
|
|
629
625
|
:sslverify,
|
630
626
|
:target,
|
631
627
|
:throttle,
|
632
|
-
:timeout
|
628
|
+
:timeout,
|
633
629
|
]
|
634
630
|
|
635
|
-
|
631
|
+
repo_manifest = %(yumrepo { #{repo}:)
|
636
632
|
|
637
|
-
|
633
|
+
repo_manifest_opts = []
|
638
634
|
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
635
|
+
# Legacy Support
|
636
|
+
urls = (!metadata[:url].nil?) ? metadata[:url] : metadata[:baseurl]
|
637
|
+
if urls
|
638
|
+
repo_manifest_opts << 'baseurl => ' + '"' + Array(urls).flatten.join('\n ').gsub('$', '\$') + '"'
|
639
|
+
end
|
644
640
|
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
641
|
+
# Legacy Support
|
642
|
+
gpgkeys = (!metadata[:gpgkeys].nil?) ? metadata[:gpgkeys] : metadata[:gpgkey]
|
643
|
+
if gpgkeys
|
644
|
+
repo_manifest_opts << 'gpgkey => ' + '"' + Array(gpgkeys).flatten.join('\n ').gsub('$', '\$') + '"'
|
645
|
+
end
|
650
646
|
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
end
|
647
|
+
repo_attrs.each do |attr|
|
648
|
+
if metadata[attr]
|
649
|
+
repo_manifest_opts << "#{attr} => '#{metadata[attr]}'"
|
655
650
|
end
|
651
|
+
end
|
656
652
|
|
657
|
-
|
653
|
+
repo_manifest + %(\n#{repo_manifest_opts.join(",\n")}) + "\n}\n"
|
658
654
|
end
|
659
655
|
|
660
656
|
# Enable EPEL if appropriate to do so and the system is online
|
661
657
|
#
|
662
658
|
# Can be disabled by setting BEAKER_enable_epel=no
|
663
659
|
def enable_epel_on(suts)
|
664
|
-
block_on(suts, :
|
660
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
665
661
|
if ONLINE
|
666
662
|
os_info = fact_on(sut, 'os')
|
667
663
|
os_maj_rel = os_info['release']['major']
|
668
664
|
|
669
665
|
# This is based on the official EPEL docs https://fedoraproject.org/wiki/EPEL
|
670
666
|
case os_info['name']
|
671
|
-
when 'RedHat','CentOS','AlmaLinux','Rocky'
|
667
|
+
when 'RedHat', 'CentOS', 'AlmaLinux', 'Rocky'
|
672
668
|
install_latest_package_on(
|
673
669
|
sut,
|
674
670
|
'epel-release',
|
@@ -677,42 +673,42 @@ module Simp::BeakerHelpers
|
|
677
673
|
|
678
674
|
if os_info['name'] == 'RedHat' && ENV['BEAKER_RHSM_USER'] && ENV['BEAKER_RHSM_PASS']
|
679
675
|
if os_maj_rel == '7'
|
680
|
-
on sut, %
|
681
|
-
on sut, %
|
676
|
+
on sut, %(subscription-manager repos --enable "rhel-*-extras-rpms")
|
677
|
+
on sut, %(subscription-manager repos --enable "rhel-ha-for-rhel-*-server-rpms")
|
682
678
|
end
|
683
679
|
|
684
680
|
if os_maj_rel == '8'
|
685
|
-
on sut, %
|
681
|
+
on sut, %(subscription-manager repos --enable "codeready-builder-for-rhel-8-#{os_info['architecture']}-rpms")
|
686
682
|
end
|
687
683
|
end
|
688
684
|
|
689
|
-
if ['CentOS','AlmaLinux','Rocky'].include?(os_info['name'])
|
685
|
+
if ['CentOS', 'AlmaLinux', 'Rocky'].include?(os_info['name'])
|
690
686
|
if os_maj_rel == '8'
|
691
687
|
# 8.0 fallback
|
692
688
|
install_latest_package_on(sut, 'dnf-plugins-core')
|
693
|
-
on sut, %
|
689
|
+
on sut, %(dnf config-manager --set-enabled powertools || dnf config-manager --set-enabled PowerTools)
|
694
690
|
end
|
695
691
|
end
|
696
692
|
when 'OracleLinux'
|
697
693
|
package_name = "oracle-epel-release-el#{os_maj_rel}"
|
698
|
-
install_latest_package_on(sut,package_name)
|
694
|
+
install_latest_package_on(sut, package_name)
|
699
695
|
when 'Amazon'
|
700
|
-
on sut, %
|
696
|
+
on sut, %(amazon-linux-extras install epel -y)
|
701
697
|
end
|
702
698
|
end
|
703
699
|
end
|
704
700
|
end
|
705
701
|
|
706
702
|
def update_package_from_centos_stream(suts, package_name)
|
707
|
-
block_on(suts, :
|
703
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
708
704
|
sut.install_package('centos-release-stream') unless sut.check_for_package('centos-release-stream')
|
709
705
|
install_latest_package_on(sut, package_name)
|
710
706
|
sut.uninstall_package('centos-release-stream')
|
711
707
|
end
|
712
708
|
end
|
713
709
|
|
714
|
-
def linux_errata(
|
715
|
-
block_on(suts, :
|
710
|
+
def linux_errata(suts)
|
711
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
716
712
|
# Set the locale if not set
|
717
713
|
sut.set_env_var('LANG', 'en_US.UTF-8') unless sut.get_env_var('LANG')
|
718
714
|
|
@@ -734,8 +730,8 @@ module Simp::BeakerHelpers
|
|
734
730
|
if !sut.which('hostnamectl').empty?
|
735
731
|
on(sut, "hostnamectl set-hostname #{new_fqdn}")
|
736
732
|
else
|
737
|
-
on(sut, "echo '#{new_fqdn}' > /etc/hostname", :
|
738
|
-
on(sut, "hostname #{new_fqdn}", :
|
733
|
+
on(sut, "echo '#{new_fqdn}' > /etc/hostname", accept_all_exit_codes: true)
|
734
|
+
on(sut, "hostname #{new_fqdn}", accept_all_exit_codes: true)
|
739
735
|
end
|
740
736
|
|
741
737
|
if sut.file_exist?('/etc/sysconfig/network')
|
@@ -745,7 +741,7 @@ module Simp::BeakerHelpers
|
|
745
741
|
end
|
746
742
|
|
747
743
|
current_domain = fact_on(sut, 'networking.domain')&.strip
|
748
|
-
|
744
|
+
raise("Error: hosts must have an FQDN, got domain='#{current_domain}'") if current_domain.nil? || current_domain.empty?
|
749
745
|
|
750
746
|
# This may not exist in docker so just skip the whole thing
|
751
747
|
if sut.file_exist?('/etc/ssh')
|
@@ -767,15 +763,15 @@ module Simp::BeakerHelpers
|
|
767
763
|
user_info.map do |u|
|
768
764
|
u.strip!
|
769
765
|
u = u.split(':')
|
770
|
-
|
766
|
+
%r{^(/|/dev/.*|/s?bin/?.*|/proc/?.*)$}.match?(u[5]) ? [nil] : [u[0], u[5]]
|
771
767
|
end
|
772
768
|
]
|
773
769
|
|
774
|
-
user_info.
|
770
|
+
user_info.each_key do |user|
|
775
771
|
src_file = "#{user_info[user]}/.ssh/authorized_keys"
|
776
772
|
tgt_file = "/etc/ssh/local_keys/#{user}"
|
777
773
|
|
778
|
-
on(sut, %
|
774
|
+
on(sut, %(if [ -f "#{src_file}" ]; then cp -a -f "#{src_file}" "#{tgt_file}" && chmod 644 "#{tgt_file}"; fi), silent: true)
|
779
775
|
end
|
780
776
|
end
|
781
777
|
|
@@ -807,22 +803,22 @@ module Simp::BeakerHelpers
|
|
807
803
|
end
|
808
804
|
|
809
805
|
if [
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
806
|
+
'AlmaLinux',
|
807
|
+
'Amazon',
|
808
|
+
'CentOS',
|
809
|
+
'OracleLinux',
|
810
|
+
'RedHat',
|
811
|
+
'Rocky',
|
816
812
|
].include?(os_info['name'])
|
817
813
|
enable_yum_repos_on(sut)
|
818
814
|
enable_epel_on(sut)
|
819
815
|
|
820
816
|
# net-tools required for netstat utility being used by be_listening
|
821
|
-
if (os_info['release']['major'].to_i >= 7) ||((os_info['name'] == 'Amazon') && (os_info['release']['major'].to_i >= 2))
|
817
|
+
if (os_info['release']['major'].to_i >= 7) || ((os_info['name'] == 'Amazon') && (os_info['release']['major'].to_i >= 2))
|
822
818
|
pp = <<-EOS
|
823
819
|
package { 'net-tools': ensure => installed }
|
824
820
|
EOS
|
825
|
-
apply_manifest_on(sut, pp, :
|
821
|
+
apply_manifest_on(sut, pp, catch_failures: false)
|
826
822
|
end
|
827
823
|
|
828
824
|
# Clean up YUM prior to starting our test runs.
|
@@ -839,30 +835,30 @@ module Simp::BeakerHelpers
|
|
839
835
|
def rhel_rhsm_subscribe(suts, *opts)
|
840
836
|
require 'securerandom'
|
841
837
|
|
842
|
-
block_on(suts, :
|
838
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
843
839
|
rhsm_opts = {
|
844
|
-
:
|
845
|
-
:
|
846
|
-
:
|
847
|
-
:
|
840
|
+
username: ENV['BEAKER_RHSM_USER'],
|
841
|
+
password: ENV['BEAKER_RHSM_PASS'],
|
842
|
+
system_name: "#{sut}_beaker_#{Time.now.to_i}_#{SecureRandom.uuid}",
|
843
|
+
repo_list: {
|
848
844
|
'7' => [
|
849
845
|
'rhel-7-server-extras-rpms',
|
850
846
|
'rhel-7-server-rh-common-rpms',
|
851
847
|
'rhel-7-server-rpms',
|
852
|
-
'rhel-7-server-supplementary-rpms'
|
848
|
+
'rhel-7-server-supplementary-rpms',
|
853
849
|
],
|
854
850
|
'8' => [
|
855
851
|
'rhel-8-for-x86_64-baseos-rpms',
|
856
|
-
'rhel-8-for-x86_64-supplementary-rpms'
|
852
|
+
'rhel-8-for-x86_64-supplementary-rpms',
|
857
853
|
],
|
858
854
|
'9' => [
|
859
855
|
'rhel-9-for-x86_64-appstream-rpms',
|
860
|
-
'rhel-9-for-x86_64-baseos-rpms'
|
856
|
+
'rhel-9-for-x86_64-baseos-rpms',
|
861
857
|
]
|
862
858
|
}
|
863
859
|
}
|
864
860
|
|
865
|
-
if opts
|
861
|
+
if opts&.is_a?(Hash)
|
866
862
|
rhsm_opts.merge!(opts)
|
867
863
|
end
|
868
864
|
|
@@ -871,14 +867,14 @@ module Simp::BeakerHelpers
|
|
871
867
|
|
872
868
|
if os == 'RedHat'
|
873
869
|
unless rhsm_opts[:username] && rhsm_opts[:password]
|
874
|
-
warn(
|
870
|
+
warn('BEAKER_RHSM_USER and/or BEAKER_RHSM_PASS not set on RHEL system.', 'Assuming that subscription-manager is not needed. This may prevent packages from installing')
|
875
871
|
return
|
876
872
|
end
|
877
873
|
|
878
|
-
sub_status = on(sut, 'subscription-manager status', :
|
874
|
+
sub_status = on(sut, 'subscription-manager status', accept_all_exit_codes: true)
|
879
875
|
unless sub_status.exit_code == 0
|
880
876
|
logger.info("Registering #{sut} via subscription-manager")
|
881
|
-
on(sut, %
|
877
|
+
on(sut, %(subscription-manager register --auto-attach --name='#{rhsm_opts[:system_name]}' --username='#{rhsm_opts[:username]}' --password='#{rhsm_opts[:password]}'), silent: true)
|
882
878
|
end
|
883
879
|
|
884
880
|
if rhsm_opts[:repo_list][os_release]
|
@@ -889,17 +885,17 @@ module Simp::BeakerHelpers
|
|
889
885
|
|
890
886
|
# Ensure that all users can access the entitlements since we don't know
|
891
887
|
# who we'll be running jobs as (often not root)
|
892
|
-
on(sut, 'chmod -R ugo+rX /etc/pki/entitlement', :
|
888
|
+
on(sut, 'chmod -R ugo+rX /etc/pki/entitlement', accept_all_exit_codes: true)
|
893
889
|
end
|
894
890
|
end
|
895
891
|
end
|
896
892
|
|
897
|
-
def sosreport(suts, dest='sosreports')
|
898
|
-
block_on(suts, :
|
893
|
+
def sosreport(suts, dest = 'sosreports')
|
894
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
899
895
|
install_latest_package_on(sut, 'sos')
|
900
896
|
on(sut, 'sosreport --batch')
|
901
897
|
|
902
|
-
files = on(sut, 'ls /var/tmp/sosreport* /tmp/sosreport* 2>/dev/null', :
|
898
|
+
files = on(sut, 'ls /var/tmp/sosreport* /tmp/sosreport* 2>/dev/null', accept_all_exit_codes: true).output.lines.map(&:strip)
|
903
899
|
|
904
900
|
FileUtils.mkdir_p(dest)
|
905
901
|
|
@@ -910,42 +906,39 @@ module Simp::BeakerHelpers
|
|
910
906
|
end
|
911
907
|
|
912
908
|
def rhel_repo_enable(suts, repos)
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
end
|
909
|
+
return unless ENV['BEAKER_RHSM_USER'] && ENV['BEAKER_RHSM_PASS']
|
910
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
911
|
+
Array(repos).each do |repo|
|
912
|
+
on(sut, %(subscription-manager repos --enable #{repo}))
|
918
913
|
end
|
919
914
|
end
|
920
915
|
end
|
921
916
|
|
922
917
|
def rhel_repo_disable(suts, repos)
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
end
|
918
|
+
return unless ENV['BEAKER_RHSM_USER'] && ENV['BEAKER_RHSM_PASS']
|
919
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
920
|
+
Array(repos).each do |repo|
|
921
|
+
on(sut, %(subscription-manager repos --disable #{repo}), accept_all_exit_codes: true)
|
928
922
|
end
|
929
923
|
end
|
930
924
|
end
|
931
925
|
|
932
926
|
def rhel_rhsm_unsubscribe(suts)
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
end
|
927
|
+
return unless ENV['BEAKER_RHSM_USER'] && ENV['BEAKER_RHSM_PASS']
|
928
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
929
|
+
on(sut, %(subscription-manager unregister), accept_all_exit_codes: true)
|
937
930
|
end
|
938
931
|
end
|
939
932
|
|
940
933
|
# Apply known OS fixes we need to run Beaker on each SUT
|
941
|
-
def fix_errata_on(
|
934
|
+
def fix_errata_on(suts = hosts)
|
942
935
|
windows_suts = suts.select { |sut| is_windows?(sut) }
|
943
936
|
linux_suts = suts - windows_suts
|
944
937
|
|
945
938
|
linux_errata(linux_suts) unless linux_suts.empty?
|
946
939
|
|
947
940
|
unless windows_suts.empty?
|
948
|
-
block_on(windows_suts, :
|
941
|
+
block_on(windows_suts, run_in_parallel: @run_in_parallel) do |sut|
|
949
942
|
# Load the Windows requirements
|
950
943
|
require 'simp/beaker_helpers/windows'
|
951
944
|
|
@@ -980,9 +973,8 @@ module Simp::BeakerHelpers
|
|
980
973
|
end
|
981
974
|
|
982
975
|
# Configure and reboot SUTs into FIPS mode
|
983
|
-
|
984
|
-
|
985
|
-
end
|
976
|
+
return unless ENV['BEAKER_fips'] == 'yes'
|
977
|
+
enable_fips_mode_on(suts)
|
986
978
|
end
|
987
979
|
|
988
980
|
# Generate a fake openssl CA + certs for each host on a given SUT
|
@@ -992,13 +984,13 @@ module Simp::BeakerHelpers
|
|
992
984
|
# NOTE: This generates everything within an SUT and copies it back out.
|
993
985
|
# This is because it is assumed the SUT will have the appropriate
|
994
986
|
# openssl in its environment, which may not be true of the host.
|
995
|
-
def run_fake_pki_ca_on(
|
996
|
-
puts
|
997
|
-
pki_dir = File.expand_path(
|
987
|
+
def run_fake_pki_ca_on(ca_sut = master, _suts = hosts, local_dir = '')
|
988
|
+
puts '== Fake PKI CA'
|
989
|
+
pki_dir = File.expand_path('../../files/pki', File.dirname(__FILE__))
|
998
990
|
host_dir = '/root/pki'
|
999
991
|
|
1000
992
|
ca_sut.mkdir_p(host_dir)
|
1001
|
-
Dir[ File.join(pki_dir, '*') ].each{|f| copy_to(
|
993
|
+
Dir[ File.join(pki_dir, '*') ].each { |f| copy_to(ca_sut, f, host_dir) }
|
1002
994
|
|
1003
995
|
# Collect network information from all SUTs
|
1004
996
|
#
|
@@ -1011,14 +1003,14 @@ module Simp::BeakerHelpers
|
|
1011
1003
|
host_entry = { fqdn => [] }
|
1012
1004
|
|
1013
1005
|
# Add the short name because containers can't change the hostname
|
1014
|
-
host_entry[fqdn] << host.name if
|
1006
|
+
host_entry[fqdn] << host.name if host[:hypervisor] == 'docker'
|
1015
1007
|
|
1016
1008
|
# Ensure that all interfaces are active prior to collecting data
|
1017
1009
|
activate_interfaces(host)
|
1018
1010
|
|
1019
1011
|
networking_fact = pfact_on(host, 'networking')
|
1020
1012
|
if networking_fact && networking_fact['interfaces']
|
1021
|
-
networking_fact['interfaces'].
|
1013
|
+
networking_fact['interfaces'].each_value do |data|
|
1022
1014
|
next unless data['ip']
|
1023
1015
|
next if data['ip'].start_with?('127.')
|
1024
1016
|
|
@@ -1049,10 +1041,10 @@ module Simp::BeakerHelpers
|
|
1049
1041
|
# 3. Pull out an Array of all of the common element keys for future
|
1050
1042
|
# comparison
|
1051
1043
|
common_ip_addresses = suts_network_info
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1044
|
+
.values.flatten
|
1045
|
+
.group_by { |x| x }
|
1046
|
+
.select { |_k, v| v.size > 1 }
|
1047
|
+
.keys
|
1056
1048
|
|
1057
1049
|
# generate PKI certs for each SUT
|
1058
1050
|
Dir.mktmpdir do |dir|
|
@@ -1071,10 +1063,9 @@ module Simp::BeakerHelpers
|
|
1071
1063
|
end
|
1072
1064
|
|
1073
1065
|
# if a local_dir was provided, copy everything down to it
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
end
|
1066
|
+
return if local_dir.empty?
|
1067
|
+
FileUtils.mkdir_p local_dir
|
1068
|
+
scp_from(ca_sut, host_dir, local_dir)
|
1078
1069
|
end
|
1079
1070
|
|
1080
1071
|
# Copy a single SUT's PKI certs (with cacerts) onto an SUT.
|
@@ -1092,26 +1083,26 @@ module Simp::BeakerHelpers
|
|
1092
1083
|
# public/fdqn.pub
|
1093
1084
|
# private/fdqn.pem
|
1094
1085
|
def copy_pki_to(sut, local_pki_dir, sut_base_dir = '/etc/pki/simp-testing')
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1086
|
+
fqdn = fact_on(sut, 'networking.fqdn')
|
1087
|
+
sut_pki_dir = File.join(sut_base_dir, 'pki')
|
1088
|
+
local_host_pki_tree = File.join(local_pki_dir, 'pki', 'keydist', fqdn)
|
1089
|
+
local_cacert = File.join(local_pki_dir, 'pki', 'demoCA', 'cacert.pem')
|
1090
|
+
|
1091
|
+
sut.mkdir_p("#{sut_pki_dir}/public")
|
1092
|
+
sut.mkdir_p("#{sut_pki_dir}/private")
|
1093
|
+
sut.mkdir_p("#{sut_pki_dir}/cacerts")
|
1094
|
+
copy_to(sut, "#{local_host_pki_tree}/#{fqdn}.pem", "#{sut_pki_dir}/private/")
|
1095
|
+
copy_to(sut, "#{local_host_pki_tree}/#{fqdn}.pub", "#{sut_pki_dir}/public/")
|
1096
|
+
|
1097
|
+
copy_to(sut, local_cacert, "#{sut_pki_dir}/cacerts/simp_auto_ca.pem")
|
1098
|
+
|
1099
|
+
# NOTE: to match pki::copy, 'cacert.pem' is copied to 'cacerts.pem'
|
1100
|
+
copy_to(sut, local_cacert, "#{sut_pki_dir}/cacerts/cacerts.pem")
|
1101
|
+
|
1102
|
+
# Need to hash all of the CA certificates so that apps can use them
|
1103
|
+
# properly! This must happen on the host itself since it needs to match
|
1104
|
+
# the native hashing algorithms.
|
1105
|
+
hash_cmd = <<~EOM.strip
|
1115
1106
|
PATH=/opt/puppetlabs/puppet/bin:$PATH; \
|
1116
1107
|
cd #{sut_pki_dir}/cacerts; \
|
1117
1108
|
for x in *; do \
|
@@ -1125,14 +1116,14 @@ module Simp::BeakerHelpers
|
|
1125
1116
|
done
|
1126
1117
|
EOM
|
1127
1118
|
|
1128
|
-
|
1119
|
+
on(sut, hash_cmd)
|
1129
1120
|
end
|
1130
1121
|
|
1131
1122
|
# Copy a CA keydist/ directory of CA+host certs into an SUT
|
1132
1123
|
#
|
1133
1124
|
# This simulates the output of FakeCA's gencerts_nopass.sh to keydist/
|
1134
|
-
def copy_keydist_to(
|
1135
|
-
|
1125
|
+
def copy_keydist_to(ca_sut = master, host_keydist_dir = nil)
|
1126
|
+
unless host_keydist_dir
|
1136
1127
|
modulepath = puppet_modulepath_on(ca_sut)
|
1137
1128
|
|
1138
1129
|
host_keydist_dir = "#{modulepath.first}/pki/files/keydist"
|
@@ -1152,8 +1143,8 @@ module Simp::BeakerHelpers
|
|
1152
1143
|
def activate_interfaces(hosts)
|
1153
1144
|
return if ENV['BEAKER_no_fix_interfaces']
|
1154
1145
|
|
1155
|
-
block_on(hosts, :
|
1156
|
-
if host[:platform]
|
1146
|
+
block_on(hosts, run_in_parallel: @run_in_parallel) do |host|
|
1147
|
+
if host[:platform].include?('windows')
|
1157
1148
|
puts " -- SKIPPING #{host} because it is windows"
|
1158
1149
|
next
|
1159
1150
|
end
|
@@ -1161,18 +1152,18 @@ module Simp::BeakerHelpers
|
|
1161
1152
|
networking_fact = pfact_on(host, 'networking')
|
1162
1153
|
if networking_fact && networking_fact['interfaces']
|
1163
1154
|
networking_fact['interfaces'].each do |iface, data|
|
1164
|
-
next if (
|
1165
|
-
on(host, "ifup #{iface}", :
|
1155
|
+
next if (data['ip'] && !data['ip'].empty?) || (data['ip6'] && !data['ip6'].empty?)
|
1156
|
+
on(host, "ifup #{iface}", accept_all_exit_codes: true)
|
1166
1157
|
end
|
1167
1158
|
else
|
1168
1159
|
interfaces_fact = pfact_on(host, 'interfaces')
|
1169
1160
|
|
1170
1161
|
interfaces = interfaces_fact.strip.split(',')
|
1171
|
-
interfaces.delete_if { |x| x =~
|
1162
|
+
interfaces.delete_if { |x| x =~ %r{^lo} }
|
1172
1163
|
|
1173
1164
|
interfaces.each do |iface|
|
1174
1165
|
if pfact_on(host, "ipaddress_#{iface}")
|
1175
|
-
on(host, "ifup #{iface}", :
|
1166
|
+
on(host, "ifup #{iface}", accept_all_exit_codes: true)
|
1176
1167
|
end
|
1177
1168
|
end
|
1178
1169
|
end
|
@@ -1189,7 +1180,7 @@ module Simp::BeakerHelpers
|
|
1189
1180
|
require 'rspec'
|
1190
1181
|
RSpec.configure do |c|
|
1191
1182
|
c.before(:all) do
|
1192
|
-
@temp_hieradata_dirs
|
1183
|
+
@temp_hieradata_dirs ||= []
|
1193
1184
|
|
1194
1185
|
# We can't guarantee that the upstream vendor isn't disabling interfaces
|
1195
1186
|
activate_interfaces(hosts)
|
@@ -1207,18 +1198,18 @@ module Simp::BeakerHelpers
|
|
1207
1198
|
# @param trim [Boolean] remove leading and trailing whitespace
|
1208
1199
|
#
|
1209
1200
|
# @return [String, nil] the contents of the remote file
|
1210
|
-
def file_content_on(sut, path,
|
1201
|
+
def file_content_on(sut, path, _trim = true)
|
1211
1202
|
file_content = nil
|
1212
1203
|
|
1213
1204
|
if file_exists_on(sut, path)
|
1214
1205
|
Dir.mktmpdir do |dir|
|
1215
1206
|
scp_from(sut, path, dir)
|
1216
1207
|
|
1217
|
-
file_content = File.read(File.join(dir,File.basename(path)))
|
1208
|
+
file_content = File.read(File.join(dir, File.basename(path)))
|
1218
1209
|
end
|
1219
1210
|
end
|
1220
1211
|
|
1221
|
-
|
1212
|
+
file_content
|
1222
1213
|
end
|
1223
1214
|
|
1224
1215
|
# Retrieve the default hiera.yaml path
|
@@ -1270,7 +1261,7 @@ module Simp::BeakerHelpers
|
|
1270
1261
|
# using `#clear_temp_hieradata` in the `after(:all)` hook. It may also be
|
1271
1262
|
# retained for debugging purposes.
|
1272
1263
|
#
|
1273
|
-
def write_hieradata_to(sut, hieradata,
|
1264
|
+
def write_hieradata_to(sut, hieradata, _terminus = 'deprecated')
|
1274
1265
|
@temp_hieradata_dirs ||= []
|
1275
1266
|
data_dir = Dir.mktmpdir('hieradata')
|
1276
1267
|
@temp_hieradata_dirs << data_dir
|
@@ -1308,20 +1299,20 @@ module Simp::BeakerHelpers
|
|
1308
1299
|
sut_environment = sut.puppet_configprint['environment']
|
1309
1300
|
|
1310
1301
|
# This output lets us know where Hiera is configured to look on the system
|
1311
|
-
puppet_lookup_info = on(sut, "puppet lookup --explain --environment #{sut_environment} test__simp__test", :
|
1302
|
+
puppet_lookup_info = on(sut, "puppet lookup --explain --environment #{sut_environment} test__simp__test", silent: true).output.strip.lines
|
1312
1303
|
|
1313
1304
|
if sut.puppet_configprint['manifest'].nil? || sut.puppet_configprint['manifest'].empty?
|
1314
|
-
|
1305
|
+
raise("No output returned from `puppet config print manifest` on #{sut}")
|
1315
1306
|
end
|
1316
1307
|
|
1317
1308
|
puppet_env_path = puppet_environment_path_on(sut)
|
1318
1309
|
|
1319
1310
|
# We'll just take the first match since Hiera will find things there
|
1320
|
-
puppet_lookup_info = puppet_lookup_info.grep(
|
1311
|
+
puppet_lookup_info = puppet_lookup_info.grep(%r{Path "}).grep(Regexp.new(puppet_env_path))
|
1321
1312
|
|
1322
1313
|
# Grep always returns an Array
|
1323
1314
|
if puppet_lookup_info.empty?
|
1324
|
-
|
1315
|
+
raise("Could not determine hiera data directory under #{puppet_env_path} on #{sut}")
|
1325
1316
|
end
|
1326
1317
|
|
1327
1318
|
# Snag the actual path without the extra bits
|
@@ -1343,7 +1334,7 @@ module Simp::BeakerHelpers
|
|
1343
1334
|
datadir_path = puppet_env_path + file_sep + datadir_name
|
1344
1335
|
|
1345
1336
|
# Return the path to the data directory
|
1346
|
-
|
1337
|
+
datadir_path
|
1347
1338
|
end
|
1348
1339
|
|
1349
1340
|
# Write the provided data structure to Hiera's :datadir and configure Hiera to
|
@@ -1363,29 +1354,26 @@ module Simp::BeakerHelpers
|
|
1363
1354
|
#
|
1364
1355
|
# @return [Nil]
|
1365
1356
|
#
|
1366
|
-
def set_hieradata_on(sut, hieradata,
|
1357
|
+
def set_hieradata_on(sut, hieradata, _terminus = 'deprecated')
|
1367
1358
|
write_hieradata_to sut, hieradata
|
1368
1359
|
end
|
1369
1360
|
|
1370
|
-
|
1371
1361
|
# Clean up all temporary hiera data files.
|
1372
1362
|
#
|
1373
1363
|
# Meant to be called from after(:all)
|
1374
1364
|
def clear_temp_hieradata
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
end
|
1365
|
+
return unless @temp_hieradata_dirs && !@temp_hieradata_dirs.empty?
|
1366
|
+
@temp_hieradata_dirs.each do |data_dir|
|
1367
|
+
if File.exist?(data_dir)
|
1368
|
+
FileUtils.rm_r(data_dir)
|
1380
1369
|
end
|
1381
1370
|
end
|
1382
1371
|
end
|
1383
1372
|
|
1384
|
-
|
1385
1373
|
# pluginsync custom facts for all modules
|
1386
|
-
def pluginsync_on(
|
1374
|
+
def pluginsync_on(_suts = hosts)
|
1387
1375
|
puts "== pluginsync_on'" if ENV['BEAKER_helpers_verbose']
|
1388
|
-
pluginsync_manifest
|
1376
|
+
pluginsync_manifest = <<-PLUGINSYNC_MANIFEST
|
1389
1377
|
file { $::settings::libdir:
|
1390
1378
|
ensure => directory,
|
1391
1379
|
source => 'puppet:///plugins',
|
@@ -1395,10 +1383,9 @@ module Simp::BeakerHelpers
|
|
1395
1383
|
noop => false
|
1396
1384
|
}
|
1397
1385
|
PLUGINSYNC_MANIFEST
|
1398
|
-
apply_manifest_on(hosts, pluginsync_manifest, :
|
1386
|
+
apply_manifest_on(hosts, pluginsync_manifest, run_in_parallel: @run_in_parallel)
|
1399
1387
|
end
|
1400
1388
|
|
1401
|
-
|
1402
1389
|
# Looks up latest `puppet-agent` version by the version of its `puppet` gem
|
1403
1390
|
#
|
1404
1391
|
# @param puppet_version [String] target Puppet gem version. Works with
|
@@ -1406,58 +1393,58 @@ module Simp::BeakerHelpers
|
|
1406
1393
|
#
|
1407
1394
|
# @return [String,Nil] the `puppet-agent` version or nil
|
1408
1395
|
#
|
1409
|
-
def latest_puppet_agent_version_for(
|
1396
|
+
def latest_puppet_agent_version_for(puppet_version)
|
1410
1397
|
return nil if puppet_version.nil?
|
1411
1398
|
|
1412
1399
|
require 'rubygems/requirement'
|
1413
1400
|
require 'rubygems/version'
|
1414
1401
|
require 'yaml'
|
1415
1402
|
|
1416
|
-
|
1417
|
-
|
1403
|
+
split_puppet_version = puppet_version.strip.split(',')
|
1418
1404
|
|
1419
1405
|
@agent_version_table ||= YAML.load_file(
|
1420
1406
|
File.expand_path(
|
1421
1407
|
'../../files/puppet-agent-versions.yaml',
|
1422
|
-
File.dirname(__FILE__)
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1408
|
+
File.dirname(__FILE__),
|
1409
|
+
),
|
1410
|
+
).fetch('version_mappings')
|
1411
|
+
pair = @agent_version_table.find do |k, _v|
|
1412
|
+
Gem::Requirement.new(split_puppet_version).satisfied_by?(Gem::Version.new(k))
|
1426
1413
|
end
|
1427
|
-
result =
|
1414
|
+
result = pair&.last
|
1428
1415
|
|
1429
1416
|
# If we didn't get a match, go look for published rubygems
|
1430
1417
|
unless result
|
1431
1418
|
puppet_gems = nil
|
1432
1419
|
|
1433
1420
|
Bundler.with_unbundled_env do
|
1434
|
-
puppet_gems =
|
1421
|
+
puppet_gems = `gem search -ra -e puppet`.match(%r{\((.+)\)})
|
1435
1422
|
end
|
1436
1423
|
|
1437
1424
|
if puppet_gems
|
1438
|
-
puppet_gems = puppet_gems[1].split(
|
1425
|
+
puppet_gems = puppet_gems[1].split(%r{,?\s+}).select { |x| x =~ %r{^\d} }
|
1439
1426
|
|
1440
1427
|
# If we don't have a full version string, we need to massage it for the
|
1441
1428
|
# match.
|
1442
1429
|
begin
|
1443
|
-
if
|
1444
|
-
Gem::Version.new(
|
1445
|
-
if
|
1446
|
-
|
1430
|
+
if split_puppet_version.size == 1
|
1431
|
+
Gem::Version.new(split_puppet_version[0])
|
1432
|
+
if split_puppet_version[0].count('.') < 2
|
1433
|
+
split_puppet_version = "~> #{split_puppet_version[0]}"
|
1447
1434
|
end
|
1448
1435
|
end
|
1449
1436
|
rescue ArgumentError
|
1450
|
-
# this means
|
1437
|
+
# this means split_puppet_version is not just a version, but a version
|
1451
1438
|
# specifier such as "= 5.2.3", "<= 5.1", "> 4", "~> 4.10.7"
|
1452
1439
|
end
|
1453
1440
|
|
1454
1441
|
result = puppet_gems.find do |ver|
|
1455
|
-
Gem::Requirement.new(
|
1442
|
+
Gem::Requirement.new(split_puppet_version).satisfied_by?(Gem::Version.new(ver))
|
1456
1443
|
end
|
1457
1444
|
end
|
1458
1445
|
end
|
1459
1446
|
|
1460
|
-
|
1447
|
+
result
|
1461
1448
|
end
|
1462
1449
|
|
1463
1450
|
# returns hash with :puppet_install_version, :puppet_collection,
|
@@ -1474,18 +1461,16 @@ module Simp::BeakerHelpers
|
|
1474
1461
|
# The first match is internal Beaker and the second is legacy SIMP
|
1475
1462
|
puppet_install_version = ENV['BEAKER_PUPPET_AGENT_VERSION'] || ENV['PUPPET_INSTALL_VERSION'] || ENV['PUPPET_VERSION']
|
1476
1463
|
|
1477
|
-
if puppet_install_version
|
1464
|
+
if puppet_install_version && !puppet_install_version.strip.empty?
|
1478
1465
|
puppet_agent_version = latest_puppet_agent_version_for(puppet_install_version.strip)
|
1479
1466
|
end
|
1480
1467
|
|
1481
1468
|
if puppet_agent_version.nil?
|
1482
|
-
if puppet_collection =
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
raise("Error: Puppet Collection '#{puppet_collection}' must match /puppet(\\d+)/")
|
1488
|
-
end
|
1469
|
+
if (puppet_collection = ENV['BEAKER_PUPPET_COLLECTION'] || host.options['puppet_collection'])
|
1470
|
+
raise("Error: Puppet Collection '#{puppet_collection}' must match /puppet(\\d+)/") unless puppet_collection =~ %r{puppet(\d+)}
|
1471
|
+
puppet_install_version = "~> #{::Regexp.last_match(1)}"
|
1472
|
+
puppet_agent_version = latest_puppet_agent_version_for(puppet_install_version)
|
1473
|
+
|
1489
1474
|
else
|
1490
1475
|
puppet_agent_version = latest_puppet_agent_version_for(DEFAULT_PUPPET_AGENT_VERSION)
|
1491
1476
|
end
|
@@ -1497,13 +1482,12 @@ module Simp::BeakerHelpers
|
|
1497
1482
|
end
|
1498
1483
|
|
1499
1484
|
{
|
1500
|
-
:
|
1501
|
-
:
|
1502
|
-
:
|
1485
|
+
puppet_install_version: puppet_agent_version,
|
1486
|
+
puppet_collection: puppet_collection,
|
1487
|
+
puppet_install_type: ENV.fetch('PUPPET_INSTALL_TYPE', 'agent')
|
1503
1488
|
}
|
1504
1489
|
end
|
1505
1490
|
|
1506
|
-
|
1507
1491
|
# Replacement for `install_puppet` in spec_helper_acceptance.rb
|
1508
1492
|
def install_puppet
|
1509
1493
|
install_info = get_puppet_install_info
|
@@ -1550,27 +1534,27 @@ module Simp::BeakerHelpers
|
|
1550
1534
|
def install_simp_repos(suts, disable = [])
|
1551
1535
|
# NOTE: Do *NOT* use puppet in this method since it may not be available yet
|
1552
1536
|
|
1553
|
-
return if
|
1537
|
+
return if ENV.fetch('SIMP_install_repos', 'yes') == 'no'
|
1554
1538
|
|
1555
|
-
block_on(suts, :
|
1539
|
+
block_on(suts, run_in_parallel: @run_in_parallel) do |sut|
|
1556
1540
|
install_package_unless_present_on(sut, 'yum-utils')
|
1557
1541
|
|
1558
1542
|
os = fact_on(sut, 'os.name')
|
1559
1543
|
release = fact_on(sut, 'os.release.major')
|
1560
1544
|
|
1561
1545
|
# Work around Amazon 2 compatibility
|
1562
|
-
if (
|
1546
|
+
if (os == 'Amazon') && (release.to_s == '2')
|
1563
1547
|
release = '7'
|
1564
1548
|
end
|
1565
1549
|
|
1566
1550
|
install_package_unless_present_on(
|
1567
1551
|
sut,
|
1568
1552
|
'simp-release-community',
|
1569
|
-
"https://download.simp-project.com/simp-release-community.el#{release}.rpm"
|
1553
|
+
"https://download.simp-project.com/simp-release-community.el#{release}.rpm",
|
1570
1554
|
)
|
1571
1555
|
|
1572
1556
|
# TODO: Remove this hack-around when there's a version for AL2
|
1573
|
-
if
|
1557
|
+
if os == 'Amazon'
|
1574
1558
|
on(sut, %(sed -i 's/$releasever/#{release}/g' /etc/yum.repos.d/simp*))
|
1575
1559
|
end
|
1576
1560
|
|
@@ -1603,7 +1587,7 @@ module Simp::BeakerHelpers
|
|
1603
1587
|
to_disable << 'puppet6--simp'
|
1604
1588
|
end
|
1605
1589
|
|
1606
|
-
logger.info(%
|
1590
|
+
logger.info(%(INFO: repos to disable: '#{to_disable.join("', '")}'.))
|
1607
1591
|
|
1608
1592
|
# NOTE: This --enablerepo enables the repos for listing and is inherited
|
1609
1593
|
# from YUM. This does not actually "enable" the repos, that would require
|
@@ -1611,26 +1595,25 @@ module Simp::BeakerHelpers
|
|
1611
1595
|
#
|
1612
1596
|
# Note: Certain versions of EL8 do not dump by default and EL7 does not
|
1613
1597
|
# have the '--dump' option.
|
1614
|
-
x = on(sut, %
|
1615
|
-
y = x.map{|z| z.gsub(%r{/.*\Z},'')}
|
1616
|
-
available_repos = y.grep(
|
1617
|
-
logger.info(%
|
1598
|
+
x = on(sut, %(yum repolist all || dnf repolist --all)).stdout.lines
|
1599
|
+
y = x.map { |z| z.gsub(%r{/.*\Z}, '') }
|
1600
|
+
available_repos = y.grep(%r{\A([a-zA-Z][a-zA-Z0-9:_-]+)\s*}) { |_x| ::Regexp.last_match(1) }
|
1601
|
+
logger.info(%(INFO: available repos: '#{available_repos.join("', '")}'.))
|
1618
1602
|
|
1619
1603
|
invalid_repos = (to_disable - available_repos)
|
1620
1604
|
|
1621
1605
|
# Verify that the repos passed to disable are in the list of valid repos
|
1622
1606
|
unless invalid_repos.empty?
|
1623
|
-
logger.warn(%
|
1607
|
+
logger.warn(%(WARN: install_simp_repo - requested repos to disable do not exist on the target system '#{invalid_repos.join("', '")}'.))
|
1624
1608
|
end
|
1625
1609
|
|
1626
|
-
|
1627
1610
|
(to_disable - invalid_repos).each do |repo|
|
1628
|
-
on(sut, %
|
1611
|
+
on(sut, %(yum-config-manager --disable "#{repo}"))
|
1629
1612
|
end
|
1630
1613
|
end
|
1631
1614
|
end
|
1632
1615
|
|
1633
|
-
set_yum_opts_on(suts, {'simp*.skip_if_unavailable' => '1' })
|
1616
|
+
set_yum_opts_on(suts, { 'simp*.skip_if_unavailable' => '1' })
|
1634
1617
|
end
|
1635
1618
|
|
1636
1619
|
# Set the release and release type of the SIMP yum repos
|
@@ -1638,11 +1621,11 @@ module Simp::BeakerHelpers
|
|
1638
1621
|
# Environment variables may be used to set either one
|
1639
1622
|
# * BEAKER_SIMP_repo_release => The actual release (version number)
|
1640
1623
|
# * BEAKER_SIMP_repo_release_type => The type of release (stable, unstable, rolling, etc...)
|
1641
|
-
def set_simp_repo_release(sut, simp_release_type='stable', simp_release='6')
|
1624
|
+
def set_simp_repo_release(sut, simp_release_type = 'stable', simp_release = '6')
|
1642
1625
|
simp_release = ENV.fetch('BEAKER_SIMP_repo_release', simp_release)
|
1643
1626
|
simp_release_type = ENV.fetch('BEAKER_SIMP_repo_release_type', simp_release_type)
|
1644
1627
|
|
1645
|
-
simp_release_type = 'releases' if
|
1628
|
+
simp_release_type = 'releases' if simp_release_type == 'stable'
|
1646
1629
|
|
1647
1630
|
create_remote_file(sut, '/etc/yum/vars/simprelease', simp_release)
|
1648
1631
|
create_remote_file(sut, '/etc/yum/vars/simpreleasetype', simp_release_type)
|