simp-beaker-helpers 1.19.4 → 1.21.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a44635bd8cc4cc1a091769b42837b03e7711e280ce4e81a261614ff95ca0241
4
- data.tar.gz: afbf39be4623d4abb203efcf4215d931cba9366ee1252658918d382d5e6191fd
3
+ metadata.gz: 843c00fb877d83ee9cd76a342b122923764e67452b3e8974de7232193d31d387
4
+ data.tar.gz: 195e83133f422f09bf168870c7acafbea8c59ed22c0bae7aea87126c4248349a
5
5
  SHA512:
6
- metadata.gz: e2e6e7bf750cb1b75240583efa6ae766981fe82be3fcfa59e498198285c97901569fd4a17857328497b54c55fbc098504883b1be9b5239db2809ba8a3c80ed90
7
- data.tar.gz: 20ad194cabcf61d8489efb238ff5d9590c76c3d6e2ea850431d2a51b7295720bf75a8deb48b752c942e0fe0ca8322e5591cf5b2718d69c6a88d923165661c65c
6
+ metadata.gz: 3ba248b4786e0950a8f6df44e6f697e7d4f83603334e101dc49c3096403d5ded68aaf3c98845cd6b1046706021c2957556b80d792f6588e9f6a6eee9184ba4f9
7
+ data.tar.gz: 40d7e4f4a8ea7ab2b6d3d841be12b95a85006093f290030c91958dd6215ac8f5cabd064af1773e94a5b2cb4c9beb86c47958b09a17fd56d4017372d4297d6cdd
@@ -1,3 +1,51 @@
1
+ ### 1.21.4 / 2021-01-21
2
+ * Fixed:
3
+ * Reverted the use of OpenStruct due to issues with seralization
4
+ * Hash objects have a 'dig' method as of Ruby 2.3 so pinned this gem to a
5
+ minimum version of Ruby 2.3
6
+
7
+ ### 1.21.3 / 2021-01-20
8
+ * Fixed:
9
+ * Allow all methods that can safely take SUT arrays to do so
10
+ * Ensure that pfact_on returns a Hash if appropriate
11
+ * Fix container support in copy_to
12
+ * Added:
13
+ * Explicitly support podman local and remote in copy_to
14
+
15
+ ### 1.21.2 / 2021-01-15
16
+ * Fixed version mismatch. 1.21.1 was tagged with an incorrect version
17
+ in version.rb.
18
+
19
+ ### 1.21.1 / 2021-01-13
20
+ * Added:
21
+ * update_package_from_centos_stream method
22
+ * install_latest_package_on method
23
+ * Fixed:
24
+ * Removed some of the extraneous calls to facter
25
+ * Automatically pull the CentOS 8 kernel to the latest version in
26
+ CentOS-Stream to work around issues on FIPS systems
27
+
28
+ ### 1.20.1 / 2021-01-08
29
+ * Fixed:
30
+ * Ensure that yum calls commands appropriately depending on whether or not
31
+ packages are already installed.
32
+ * Also change all HostKeyAlgorithms settings for SSH connections
33
+
34
+ ### 1.20.0 / 2021-01-05
35
+ * Added:
36
+ * A `enable_epel_on` function that follows the instructions on the EPEL
37
+ website to properly enable EPEL on hosts. May be disabled using
38
+ `BEAKER_enable_epel=no`.
39
+ * An Ubuntu nodeset to make sure our default settings don't destroy other
40
+ Linux systems.
41
+ * Added has_crypto_policies method for determining if crypto policies are
42
+ present on the SUT
43
+ * Added munge_ssh_crypto_policies to allow vagrant to SSH back into systems
44
+ with restrictive crypto policies (usually FIPS)
45
+ * Fixed:
46
+ * Modify all crypto-policy backend files to support ssh-rsa keys
47
+ * Try harder when doing yum installations
48
+
1
49
  ### 1.19.4 / 2021-01-05
2
50
  * Fixed:
3
51
  * Only return a default empty string when `pfact_on` finds a `nil` value
@@ -18,6 +18,33 @@ module Simp::BeakerHelpers
18
18
  "simp-beaker-helpers-#{t}-#{$$}-#{rand(0x100000000).to_s(36)}.tmp"
19
19
  end
20
20
 
21
+ def install_latest_package_on(suts, package_name, package_source=nil, opts={})
22
+ default_opts = {
23
+ max_retries: 3,
24
+ retry_interval: 10
25
+ }
26
+
27
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
28
+ block_on(suts, :run_in_parallel => parallel) do |sut|
29
+ package_source = package_name unless package_source
30
+
31
+ if sut.check_for_package(package_name)
32
+ sut.upgrade_package(
33
+ package_source,
34
+ '',
35
+ default_opts.merge(opts)
36
+ )
37
+ else
38
+ sut.install_package(
39
+ package_source,
40
+ '',
41
+ nil,
42
+ default_opts.merge(opts)
43
+ )
44
+ end
45
+ end
46
+ end
47
+
21
48
  def is_windows?(sut)
22
49
  sut[:platform] =~ /windows/i
23
50
  end
@@ -80,7 +107,30 @@ module Simp::BeakerHelpers
80
107
  else
81
108
  container_id = sut.host_hash[:docker_container_id]
82
109
  end
83
- %x(tar #{exclude_list.join(' ')} -hcf - -C "#{File.dirname(src)}" "#{File.basename(src)}" | docker exec -i "#{container_id}" tar -C "#{dest}" -xf -)
110
+
111
+ if ENV['BEAKER_docker_cmd']
112
+ docker_cmd = ENV['BEAKER_docker_cmd']
113
+ else
114
+ docker_cmd = 'docker'
115
+
116
+ if ::Docker.version['Components'].any?{|x| x['Name'] =~ /podman/i}
117
+ docker_cmd = 'podman'
118
+
119
+ if ENV['CONTAINER_HOST']
120
+ docker_cmd = 'podman --remote'
121
+ elsif ENV['DOCKER_HOST']
122
+ docker_cmd = "podman --remote --url=#{ENV['DOCKER_HOST']}"
123
+ end
124
+ end
125
+ end
126
+
127
+ unless directory_exists_on(sut, dest)
128
+ dest = File.dirname(dest)
129
+ sut.mkdir_p(dest)
130
+ end
131
+
132
+ %x(tar #{exclude_list.join(' ')} -hcf - -C "#{File.dirname(src)}" "#{File.basename(src)}" | #{docker_cmd} exec -i "#{container_id}" tar -C "#{dest}" -xf -)
133
+
84
134
  elsif rsync_functional_on?(sut)
85
135
  # This makes rsync_to work like beaker and scp usually do
86
136
  exclude_hack = %(__-__' -L --exclude '__-__)
@@ -116,34 +166,34 @@ module Simp::BeakerHelpers
116
166
 
117
167
  # use the `puppet fact` face to look up facts on an SUT
118
168
  def pfact_on(sut, fact_name)
119
- require 'ostruct'
120
-
169
+ found_fact = nil
121
170
  # If puppet is not installed, there are no puppet facts to fetch
122
171
  if sut.which('puppet').empty?
123
- fact_on(sut, fact_name, :silent => true)
172
+ found_fact = fact_on(sut, fact_name)
124
173
  else
125
174
  facts_json = nil
126
175
  begin
127
176
  cmd_output = on(sut, 'facter -p --json', :silent => true)
128
-
129
177
  # Facter 4+
130
178
  raise('skip facter -p') if (cmd_output.stderr =~ /no longer supported/)
131
179
 
132
- facts = JSON.parse(cmd_output.stdout, object_class: OpenStruct)
180
+ facts = JSON.parse(cmd_output.stdout)
133
181
  rescue StandardError
134
182
  # If *anything* fails, we need to fall back to `puppet facts`
135
183
 
136
184
  facts_json = on(sut, 'puppet facts find garbage_xxx', :silent => true).stdout
137
- facts = JSON.parse(facts_json, object_class: OpenStruct).values
185
+ facts = JSON.parse(facts_json)['values']
138
186
  end
139
187
 
140
188
  found_fact = facts.dig(*(fact_name.split('.')))
141
189
 
142
- # Fall back to the behavior in fact_on
143
- found_fact = '' if found_fact.nil?
144
-
145
- return found_fact
190
+ # If we did not find a fact, we should use the upstream function since
191
+ # puppet may be installed via a gem or through some other means.
192
+ found_fact = fact_on(sut, fact_name) if found_fact.nil?
146
193
  end
194
+
195
+ # Ensure that Hashes return as Hash objects
196
+ found_fact.is_a?(OpenStruct) ? found_fact.marshal_dump : found_fact
147
197
  end
148
198
 
149
199
  # Returns the modulepath on the SUT, as an Array
@@ -321,6 +371,22 @@ module Simp::BeakerHelpers
321
371
  pluginsync_on(suts) if opts[:pluginsync]
322
372
  end
323
373
 
374
+ def has_crypto_policies(sut)
375
+ file_exists_on(sut, '/etc/crypto-policies/config')
376
+ end
377
+
378
+ def munge_ssh_crypto_policies(suts, key_types=['ssh-rsa'])
379
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
380
+ block_on(suts, :run_in_parallel => parallel) do |sut|
381
+ if has_crypto_policies(sut)
382
+ install_latest_package_on(sut, 'crypto-policies', nil, :accept_all_exit_codes => true)
383
+
384
+ # Since we may be doing this prior to having a box flip into FIPS mode, we
385
+ # need to find and modify *all* of the affected policies
386
+ on( sut, %{sed --follow-symlinks -i 's/\\(HostKeyAlgorithms\\|PubkeyAcceptedKeyTypes\\)\\(.\\)/\\1\\2#{key_types.join(',')},/g' $( grep -L ssh-rsa $( find /etc/crypto-policies /usr/share/crypto-policies -type f -a \\( -name '*.txt' -o -name '*.config' \\) -exec grep -l PubkeyAcceptedKeyTypes {} \\; ) ) })
387
+ end
388
+ end
389
+ end
324
390
 
325
391
  # Configure and reboot SUTs into FIPS mode
326
392
  def enable_fips_mode_on( suts = hosts )
@@ -328,7 +394,10 @@ module Simp::BeakerHelpers
328
394
  puts ' -- (use BEAKER_fips=no to disable)'
329
395
  parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
330
396
 
397
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
331
398
  block_on(suts, :run_in_parallel => parallel) do |sut|
399
+ next if sut[:hypervisor] == 'docker'
400
+
332
401
  if is_windows?(sut)
333
402
  puts " -- SKIPPING #{sut} because it is windows"
334
403
  next
@@ -374,17 +443,14 @@ module Simp::BeakerHelpers
374
443
  on(sut, module_install_cmd)
375
444
  end
376
445
 
377
- # Enable FIPS and then reboot to finish.
378
- on(sut, %(puppet apply --verbose #{fips_enable_modulepath} -e "class { 'fips': enabled => true }"))
379
-
380
446
  # Work around Vagrant and cipher restrictions in EL8+
381
447
  #
382
448
  # Hopefully, Vagrant will update the used ciphers at some point but who
383
449
  # knows when that will be
384
- opensshserver_config = '/etc/crypto-policies/back-ends/opensshserver.config'
385
- if file_exists_on(sut, opensshserver_config)
386
- on(sut, "sed --follow-symlinks -i 's/PubkeyAcceptedKeyTypes=/PubkeyAcceptedKeyTypes=ssh-rsa,/' #{opensshserver_config}")
387
- end
450
+ munge_ssh_crypto_policies(sut)
451
+
452
+ # Enable FIPS and then reboot to finish.
453
+ on(sut, %(puppet apply --verbose #{fips_enable_modulepath} -e "class { 'fips': enabled => true }"))
388
454
 
389
455
  sut.reboot
390
456
  end
@@ -477,102 +543,171 @@ module Simp::BeakerHelpers
477
543
  repo_manifest = repo_manifest + %(\n#{repo_manifest_opts.join(",\n")}) + "\n}\n"
478
544
  end
479
545
 
480
- def linux_errata( sut )
481
- # We need to be able to flip between server and client without issue
482
- on sut, 'puppet resource group puppet gid=52'
483
- on sut, 'puppet resource user puppet comment="Puppet" gid="52" uid="52" home="/var/lib/puppet" managehome=true'
484
-
485
- # Make sure we have a domain on our host
486
- current_domain = fact_on(sut, 'domain').strip
487
- hostname = fact_on(sut, 'hostname').strip
488
-
489
- if current_domain.empty?
490
- new_fqdn = hostname + '.beaker.test'
546
+ # Enable EPEL if appropriate to do so and the system is online
547
+ #
548
+ # Can be disabled by setting BEAKER_enable_epel=no
549
+ def enable_epel_on(suts)
550
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
551
+ block_on(suts, :run_in_parallel => parallel) do |sut|
552
+ if ONLINE && (ENV['BEAKER_stringify_facts'] != 'no')
553
+ os_info = fact_on(sut, 'os')
554
+ os_maj_rel = os_info['release']['major']
555
+
556
+ # This is based on the official EPEL docs https://fedoraproject.org/wiki/EPEL
557
+ if ['RedHat', 'CentOS'].include?(os_info['name'])
558
+ install_latest_package_on(
559
+ sut,
560
+ 'epel-release',
561
+ "https://dl.fedoraproject.org/pub/epel/epel-release-latest-#{os_maj_rel}.noarch.rpm",
562
+ )
563
+
564
+ if os_info['name'] == 'RedHat'
565
+ if os_maj_rel == '7'
566
+ on sut, %{subscription-manager repos --enable "rhel-*-optional-rpms"}
567
+ on sut, %{subscription-manager repos --enable "rhel-*-extras-rpms"}
568
+ on sut, %{subscription-manager repos --enable "rhel-ha-for-rhel-*-server-rpms"}
569
+ end
491
570
 
492
- on(sut, "sed -i 's/#{hostname}.*/#{new_fqdn} #{hostname}/' /etc/hosts")
493
- on(sut, "echo '#{new_fqdn}' > /etc/hostname", :accept_all_exit_codes => true)
494
- on(sut, "hostname #{new_fqdn}", :accept_all_exit_codes => true)
571
+ if os_maj_rel == '8'
572
+ on sut, %{subscription-manager repos --enable "codeready-builder-for-rhel-8-#{os_info['architecture']}-rpms"}
573
+ end
574
+ end
495
575
 
496
- if sut.file_exist?('/etc/sysconfig/network')
497
- on(sut, "sed -s '/HOSTNAME=/d' /etc/sysconfig/network")
498
- on(sut, "echo 'HOSTNAME=#{new_fqdn}' >> /etc/sysconfig/network")
576
+ if os_info['name'] == 'CentOS'
577
+ if os_maj_rel == '8'
578
+ # 8.0 fallback
579
+ install_latest_package_on(sut, 'dnf-plugins-core')
580
+ on sut, %{dnf config-manager --set-enabled powertools || dnf config-manager --set-enabled PowerTools}
581
+ end
582
+ end
583
+ end
499
584
  end
500
585
  end
586
+ end
501
587
 
502
- if fact_on(sut, 'domain').strip.empty?
503
- fail("Error: hosts must have an FQDN, got domain='#{current_domain}'")
588
+ def update_package_from_centos_stream(suts, package_name)
589
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
590
+ block_on(suts, :run_in_parallel => parallel) do |sut|
591
+ sut.install_package('centos-release-stream') unless sut.check_for_package('centos-release-stream')
592
+ install_latest_package_on(sut, package_name)
593
+ sut.uninstall_package('centos-release-stream')
504
594
  end
595
+ end
505
596
 
506
- # This may not exist in docker so just skip the whole thing
507
- if sut.file_exist?('/etc/ssh')
508
- # SIMP uses a central ssh key location so we prep that spot in case we
509
- # flip to the SIMP SSH module.
510
- on(sut, 'mkdir -p /etc/ssh/local_keys')
511
- on(sut, 'chown -R root:root /etc/ssh/local_keys')
512
- on(sut, 'chmod 755 /etc/ssh/local_keys')
513
-
514
- user_info = on(sut, 'getent passwd').stdout.lines
515
-
516
- # Hash of user => home_dir
517
- # Exclude silly directories
518
- # * /
519
- # * /dev/*
520
- # * /s?bin
521
- # * /proc
522
- user_info = Hash[
523
- user_info.map do |u|
524
- u.strip!
525
- u = u.split(':')
526
- u[5] =~ %r{^(/|/dev/.*|/s?bin/?.*|/proc/?.*)$} ? [nil] : [u[0], u[5]]
527
- end
528
- ]
597
+ def linux_errata( suts )
598
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
599
+ block_on(suts, :run_in_parallel => parallel) do |sut|
600
+ # We need to be able to flip between server and client without issue
601
+ on sut, 'puppet resource group puppet gid=52'
602
+ on sut, 'puppet resource user puppet comment="Puppet" gid="52" uid="52" home="/var/lib/puppet" managehome=true'
529
603
 
530
- user_info.keys.each do |user|
531
- src_file = "#{user_info[user]}/.ssh/authorized_keys"
532
- tgt_file = "/etc/ssh/local_keys/#{user}"
604
+ os_info = fact_on(sut, 'os')
533
605
 
534
- on(sut, %{if [ -f "#{src_file}" ]; then cp -a -f "#{src_file}" "#{tgt_file}" && chmod 644 "#{tgt_file}"; fi}, :silent => true)
535
- end
536
- end
606
+ # Make sure we have a domain on our host
607
+ current_domain = fact_on(sut, 'domain').strip
608
+ hostname = fact_on(sut, 'hostname').strip
537
609
 
538
- # SIMP uses structured facts, therefore stringify_facts must be disabled
539
- unless ENV['BEAKER_stringify_facts'] == 'yes'
540
- on sut, 'puppet config set stringify_facts false'
541
- end
610
+ if current_domain.empty?
611
+ new_fqdn = hostname + '.beaker.test'
542
612
 
543
- # Occasionally we run across something similar to BKR-561, so to ensure we
544
- # at least have the host defaults:
545
- #
546
- # :hieradatadir is used as a canary here; it isn't the only missing key
547
- unless sut.host_hash.key? :hieradatadir
548
- configure_type_defaults_on(sut)
549
- end
613
+ on(sut, "sed -i 's/#{hostname}.*/#{new_fqdn} #{hostname}/' /etc/hosts")
614
+ on(sut, "echo '#{new_fqdn}' > /etc/hostname", :accept_all_exit_codes => true)
615
+ on(sut, "hostname #{new_fqdn}", :accept_all_exit_codes => true)
550
616
 
551
- if fact_on(sut, 'osfamily') == 'RedHat'
552
- if fact_on(sut, 'operatingsystem') == 'RedHat'
553
- RSpec.configure do |c|
554
- c.before(:all) do
555
- rhel_rhsm_subscribe(sut)
556
- end
617
+ if sut.file_exist?('/etc/sysconfig/network')
618
+ on(sut, "sed -s '/HOSTNAME=/d' /etc/sysconfig/network")
619
+ on(sut, "echo 'HOSTNAME=#{new_fqdn}' >> /etc/sysconfig/network")
620
+ end
621
+ end
622
+
623
+ if fact_on(sut, 'domain').strip.empty?
624
+ fail("Error: hosts must have an FQDN, got domain='#{current_domain}'")
625
+ end
557
626
 
558
- c.after(:all) do
559
- rhel_rhsm_unsubscribe(sut)
627
+ # This may not exist in docker so just skip the whole thing
628
+ if sut.file_exist?('/etc/ssh')
629
+ # SIMP uses a central ssh key location so we prep that spot in case we
630
+ # flip to the SIMP SSH module.
631
+ on(sut, 'mkdir -p /etc/ssh/local_keys')
632
+ on(sut, 'chown -R root:root /etc/ssh/local_keys')
633
+ on(sut, 'chmod 755 /etc/ssh/local_keys')
634
+
635
+ user_info = on(sut, 'getent passwd').stdout.lines
636
+
637
+ # Hash of user => home_dir
638
+ # Exclude silly directories
639
+ # * /
640
+ # * /dev/*
641
+ # * /s?bin
642
+ # * /proc
643
+ user_info = Hash[
644
+ user_info.map do |u|
645
+ u.strip!
646
+ u = u.split(':')
647
+ u[5] =~ %r{^(/|/dev/.*|/s?bin/?.*|/proc/?.*)$} ? [nil] : [u[0], u[5]]
560
648
  end
649
+ ]
650
+
651
+ user_info.keys.each do |user|
652
+ src_file = "#{user_info[user]}/.ssh/authorized_keys"
653
+ tgt_file = "/etc/ssh/local_keys/#{user}"
654
+
655
+ on(sut, %{if [ -f "#{src_file}" ]; then cp -a -f "#{src_file}" "#{tgt_file}" && chmod 644 "#{tgt_file}"; fi}, :silent => true)
561
656
  end
562
657
  end
563
658
 
564
- enable_yum_repos_on(sut)
659
+ # SIMP uses structured facts, therefore stringify_facts must be disabled
660
+ unless ENV['BEAKER_stringify_facts'] == 'yes'
661
+ on sut, 'puppet config set stringify_facts false'
662
+ end
565
663
 
566
- # net-tools required for netstat utility being used by be_listening
567
- if fact_on(sut, 'operatingsystemmajrelease') == '7'
568
- pp = <<-EOS
569
- package { 'net-tools': ensure => installed }
570
- EOS
571
- apply_manifest_on(sut, pp, :catch_failures => false)
664
+ # Occasionally we run across something similar to BKR-561, so to ensure we
665
+ # at least have the host defaults:
666
+ #
667
+ # :hieradatadir is used as a canary here; it isn't the only missing key
668
+ unless sut.host_hash.key? :hieradatadir
669
+ configure_type_defaults_on(sut)
572
670
  end
573
671
 
574
- # Clean up YUM prior to starting our test runs.
575
- on(sut, 'yum clean all')
672
+ if os_info['family'] == 'RedHat'
673
+ # OS-specific items
674
+ if os_info['name'] == 'RedHat'
675
+ RSpec.configure do |c|
676
+ c.before(:all) do
677
+ rhel_rhsm_subscribe(sut)
678
+ end
679
+
680
+ c.after(:all) do
681
+ rhel_rhsm_unsubscribe(sut)
682
+ end
683
+ end
684
+ end
685
+
686
+ if ['CentOS','RedHat','OracleLinux'].include?(os_info['name'])
687
+ enable_yum_repos_on(sut)
688
+ enable_epel_on(sut)
689
+
690
+ # net-tools required for netstat utility being used by be_listening
691
+ if os_info['release']['major'].to_i >= 7
692
+ pp = <<-EOS
693
+ package { 'net-tools': ensure => installed }
694
+ EOS
695
+ apply_manifest_on(sut, pp, :catch_failures => false)
696
+ end
697
+
698
+ unless sut[:hypervisor] == 'docker'
699
+ if (os_info['name'] == 'CentOS') && (os_info['release']['major'].to_i >= 8)
700
+ if os_info['release']['minor'].to_i == 3
701
+ update_package_from_centos_stream(sut, 'kernel')
702
+ sut.reboot
703
+ end
704
+ end
705
+ end
706
+
707
+ # Clean up YUM prior to starting our test runs.
708
+ on(sut, 'yum clean all')
709
+ end
710
+ end
576
711
  end
577
712
  end
578
713
 
@@ -580,85 +715,100 @@ module Simp::BeakerHelpers
580
715
  #
581
716
  # Must set BEAKER_RHSM_USER and BEAKER_RHSM_PASS environment variables or pass them in as
582
717
  # parameters
583
- def rhel_rhsm_subscribe(sut, *opts)
718
+ def rhel_rhsm_subscribe(suts, *opts)
584
719
  require 'securerandom'
585
720
 
586
- rhsm_opts = {
587
- :username => ENV['BEAKER_RHSM_USER'],
588
- :password => ENV['BEAKER_RHSM_PASS'],
589
- :system_name => "#{sut}_beaker_#{Time.now.to_i}_#{SecureRandom.uuid}",
590
- :repo_list => {
591
- '7' => [
592
- 'rhel-7-server-extras-rpms',
593
- 'rhel-7-server-optional-rpms',
594
- 'rhel-7-server-rh-common-rpms',
595
- 'rhel-7-server-rpms',
596
- 'rhel-7-server-supplementary-rpms'
597
- ],
598
- '8' => [
599
- 'rhel-8-for-x86_64-baseos-rpms',
600
- 'rhel-8-for-x86_64-supplementary-rpms'
601
- ]
721
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
722
+ block_on(suts, :run_in_parallel => parallel) do |sut|
723
+ rhsm_opts = {
724
+ :username => ENV['BEAKER_RHSM_USER'],
725
+ :password => ENV['BEAKER_RHSM_PASS'],
726
+ :system_name => "#{sut}_beaker_#{Time.now.to_i}_#{SecureRandom.uuid}",
727
+ :repo_list => {
728
+ '7' => [
729
+ 'rhel-7-server-extras-rpms',
730
+ 'rhel-7-server-optional-rpms',
731
+ 'rhel-7-server-rh-common-rpms',
732
+ 'rhel-7-server-rpms',
733
+ 'rhel-7-server-supplementary-rpms'
734
+ ],
735
+ '8' => [
736
+ 'rhel-8-for-x86_64-baseos-rpms',
737
+ 'rhel-8-for-x86_64-supplementary-rpms'
738
+ ]
739
+ }
602
740
  }
603
- }
604
741
 
605
- if opts && opts.is_a?(Hash)
606
- rhsm_opts.merge!(opts)
607
- end
742
+ if opts && opts.is_a?(Hash)
743
+ rhsm_opts.merge!(opts)
744
+ end
608
745
 
609
- os = fact_on(sut, 'operatingsystem').strip
610
- os_release = fact_on(sut, 'operatingsystemmajrelease').strip
746
+ os = fact_on(sut, 'operatingsystem').strip
747
+ os_release = fact_on(sut, 'operatingsystemmajrelease').strip
611
748
 
612
- if os == 'RedHat'
613
- unless rhsm_opts[:username] && rhsm_opts[:password]
614
- fail("You must set BEAKER_RHSM_USER and BEAKER_RHSM_PASS environment variables to register RHEL systems")
615
- end
749
+ if os == 'RedHat'
750
+ unless rhsm_opts[:username] && rhsm_opts[:password]
751
+ fail("You must set BEAKER_RHSM_USER and BEAKER_RHSM_PASS environment variables to register RHEL systems")
752
+ end
616
753
 
617
- sub_status = on(sut, 'subscription-manager status', :accept_all_exit_codes => true)
618
- unless sub_status.exit_code == 0
619
- logger.info("Registering #{sut} via subscription-manager")
620
- on(sut, %{subscription-manager register --auto-attach --name='#{rhsm_opts[:system_name]}' --username='#{rhsm_opts[:username]}' --password='#{rhsm_opts[:password]}'}, :silent => true)
621
- end
754
+ sub_status = on(sut, 'subscription-manager status', :accept_all_exit_codes => true)
755
+ unless sub_status.exit_code == 0
756
+ logger.info("Registering #{sut} via subscription-manager")
757
+ on(sut, %{subscription-manager register --auto-attach --name='#{rhsm_opts[:system_name]}' --username='#{rhsm_opts[:username]}' --password='#{rhsm_opts[:password]}'}, :silent => true)
758
+ end
622
759
 
623
- if rhsm_opts[:repo_list][os_release]
624
- rhel_repo_enable(sut, rhsm_opts[:repo_list][os_release])
625
- else
626
- logger.warn("simp-beaker-helpers:#{__method__} => Default repos for RHEL '#{os_release}' not found")
627
- end
760
+ if rhsm_opts[:repo_list][os_release]
761
+ rhel_repo_enable(sut, rhsm_opts[:repo_list][os_release])
762
+ else
763
+ logger.warn("simp-beaker-helpers:#{__method__} => Default repos for RHEL '#{os_release}' not found")
764
+ end
628
765
 
629
- # Ensure that all users can access the entitlements since we don't know
630
- # who we'll be running jobs as (often not root)
631
- on(sut, 'chmod -R ugo+rX /etc/pki/entitlement', :accept_all_exit_codes => true)
766
+ # Ensure that all users can access the entitlements since we don't know
767
+ # who we'll be running jobs as (often not root)
768
+ on(sut, 'chmod -R ugo+rX /etc/pki/entitlement', :accept_all_exit_codes => true)
769
+ end
632
770
  end
633
771
  end
634
772
 
635
- def sosreport(sut, dest='sosreports')
636
- on(sut, 'puppet resource package sos ensure=latest')
637
- on(sut, 'sosreport --batch')
773
+ def sosreport(suts, dest='sosreports')
774
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
775
+ block_on(suts, :run_in_parallel => parallel) do |sut|
776
+ install_latest_package_on(sut, 'sos')
777
+ on(sut, 'sosreport --batch')
638
778
 
639
- files = on(sut, 'ls /var/tmp/sosreport* /tmp/sosreport* 2>/dev/null', :accept_all_exit_codes => true).output.lines.map(&:strip)
779
+ files = on(sut, 'ls /var/tmp/sosreport* /tmp/sosreport* 2>/dev/null', :accept_all_exit_codes => true).output.lines.map(&:strip)
640
780
 
641
- FileUtils.mkdir_p(dest)
781
+ FileUtils.mkdir_p(dest)
642
782
 
643
- files.each do |file|
644
- scp_from(sut, file, File.absolute_path(dest))
783
+ files.each do |file|
784
+ scp_from(sut, file, File.absolute_path(dest))
785
+ end
645
786
  end
646
787
  end
647
788
 
648
- def rhel_repo_enable(sut, repos)
649
- Array(repos).each do |repo|
650
- on(sut, %{subscription-manager repos --enable #{repo}})
789
+ def rhel_repo_enable(suts, repos)
790
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
791
+ block_on(suts, :run_in_parallel => parallel) do |sut|
792
+ Array(repos).each do |repo|
793
+ on(sut, %{subscription-manager repos --enable #{repo}})
794
+ end
651
795
  end
652
796
  end
653
797
 
654
- def rhel_repo_disable(sut, repos)
655
- Array(repos).each do |repo|
656
- on(sut, %{subscription-manager repos --disable #{repo}}, :accept_all_exit_codes => true)
798
+ def rhel_repo_disable(suts, repos)
799
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
800
+ block_on(suts, :run_in_parallel => parallel) do |sut|
801
+ Array(repos).each do |repo|
802
+ on(sut, %{subscription-manager repos --disable #{repo}}, :accept_all_exit_codes => true)
803
+ end
657
804
  end
658
805
  end
659
806
 
660
- def rhel_rhsm_unsubscribe(sut)
661
- on(sut, %{subscription-manager unregister}, :accept_all_exit_codes => true)
807
+ def rhel_rhsm_unsubscribe(suts)
808
+ parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
809
+ block_on(suts, :run_in_parallel => parallel) do |sut|
810
+ on(sut, %{subscription-manager unregister}, :accept_all_exit_codes => true)
811
+ end
662
812
  end
663
813
 
664
814
  # Apply known OS fixes we need to run Beaker on each SUT
@@ -732,6 +882,9 @@ module Simp::BeakerHelpers
732
882
 
733
883
  host_entry = { fqdn => [] }
734
884
 
885
+ # Add the short name because containers can't change the hostname
886
+ host_entry[fqdn] << host.name if (host[:hypervisor] == 'docker')
887
+
735
888
  # Ensure that all interfaces are active prior to collecting data
736
889
  activate_interfaces(host) unless ENV['BEAKER_no_fix_interfaces']
737
890
 
@@ -745,7 +898,7 @@ module Simp::BeakerHelpers
745
898
  host_entry[fqdn] << ipaddress.strip
746
899
 
747
900
  unless host_entry[fqdn].empty?
748
- suts_network_info[fqdn] = host_entry[fqdn]
901
+ suts_network_info[fqdn] = host_entry[fqdn].sort.uniq
749
902
  end
750
903
  end
751
904
  end
@@ -774,6 +927,7 @@ module Simp::BeakerHelpers
774
927
  end
775
928
 
776
929
  copy_to(ca_sut, pki_hosts_file, host_dir)
930
+
777
931
  # generate certs
778
932
  on(ca_sut, "cd #{host_dir}; cat #{host_dir}/pki.hosts | xargs bash make.sh")
779
933
  end
@@ -808,8 +962,8 @@ module Simp::BeakerHelpers
808
962
  sut.mkdir_p("#{sut_pki_dir}/public")
809
963
  sut.mkdir_p("#{sut_pki_dir}/private")
810
964
  sut.mkdir_p("#{sut_pki_dir}/cacerts")
811
- copy_to(sut, "#{local_host_pki_tree}/#{fqdn}.pem", "#{sut_pki_dir}/private/")
812
- copy_to(sut, "#{local_host_pki_tree}/#{fqdn}.pub", "#{sut_pki_dir}/public/")
965
+ copy_to(sut, "#{local_host_pki_tree}/#{fqdn}.pem", "#{sut_pki_dir}/private/")
966
+ copy_to(sut, "#{local_host_pki_tree}/#{fqdn}.pub", "#{sut_pki_dir}/public/")
813
967
 
814
968
  copy_to(sut, local_cacert, "#{sut_pki_dir}/cacerts/simp_auto_ca.pem")
815
969
 
@@ -819,18 +973,19 @@ module Simp::BeakerHelpers
819
973
  # Need to hash all of the CA certificates so that apps can use them
820
974
  # properly! This must happen on the host itself since it needs to match
821
975
  # the native hashing algorithms.
822
- hash_cmd = <<-EOM.strip
823
- cd #{sut_pki_dir}/cacerts; \
824
- for x in *; do \
825
- if [ ! -h "$x" ]; then \
826
- `openssl x509 -in $x >/dev/null 2>&1`; \
827
- if [ $? -eq 0 ]; then \
828
- hash=`openssl x509 -in $x -hash | head -1`; \
829
- ln -sf $x $hash.0; \
830
- fi; \
831
- fi; \
832
- done
833
- EOM
976
+ hash_cmd = <<~EOM.strip
977
+ PATH=/opt/puppetlabs/puppet/bin:$PATH; \
978
+ cd #{sut_pki_dir}/cacerts; \
979
+ for x in *; do \
980
+ if [ ! -h "$x" ]; then \
981
+ `openssl x509 -in $x >/dev/null 2>&1`; \
982
+ if [ $? -eq 0 ]; then \
983
+ hash=`openssl x509 -in $x -hash | head -1`; \
984
+ ln -sf $x $hash.0; \
985
+ fi; \
986
+ fi; \
987
+ done
988
+ EOM
834
989
 
835
990
  on(sut, hash_cmd)
836
991
  end
@@ -1245,13 +1400,12 @@ done
1245
1400
  def install_simp_repos(sut, disable = [])
1246
1401
  # NOTE: Do *NOT* use puppet in this method since it may not be available yet
1247
1402
 
1248
- if on(sut, 'rpm -q yum-utils', :accept_all_exit_codes => true).exit_code != 0
1249
- on(sut, 'yum -y install yum-utils')
1250
- end
1251
-
1252
- if on(sut, 'rpm -q simp-release-community', :accept_all_exit_codes => true).exit_code != 0
1253
- on(sut, 'yum -y install "https://download.simp-project.com/simp-release-community.rpm"')
1254
- end
1403
+ install_latest_package_on(sut, 'yum-utils')
1404
+ install_latest_package_on(
1405
+ sut,
1406
+ 'simp-release-community',
1407
+ "https://download.simp-project.com/simp-release-community.rpm",
1408
+ )
1255
1409
 
1256
1410
  to_disable = disable.dup
1257
1411
 
@@ -17,7 +17,11 @@ module Simp::BeakerHelpers
17
17
  require 'open-uri'
18
18
 
19
19
  begin
20
- ONLINE = true if open('http://google.com')
20
+ if URI.respond_to?(:open)
21
+ ONLINE = true if URI.open('http://google.com')
22
+ else
23
+ ONLINE = true if open('http://google.com')
24
+ end
21
25
  rescue
22
26
  ONLINE = false
23
27
  end
@@ -1,5 +1,5 @@
1
1
  module Simp; end
2
2
 
3
3
  module Simp::BeakerHelpers
4
- VERSION = '1.19.4'
4
+ VERSION = '1.21.4'
5
5
  end
@@ -18,6 +18,9 @@ Gem::Specification.new do |s|
18
18
  s.metadata = {
19
19
  'issue_tracker' => 'https://simp-project.atlassian.net'
20
20
  }
21
+
22
+ s.required_ruby_version = '>= 2.3.0'
23
+
21
24
  s.add_runtime_dependency 'beaker' , ['>= 4.17.0', '< 5.0.0']
22
25
  s.add_runtime_dependency 'beaker-rspec' , '~> 6.2'
23
26
  s.add_runtime_dependency 'beaker-puppet' , ['>= 1.18.14', '< 2.0.0']
@@ -6,21 +6,27 @@
6
6
  end
7
7
  -%>
8
8
  HOSTS:
9
- server-el7:
9
+ el7:
10
10
  roles:
11
- - server
12
- - master
13
- - default
14
11
  - el7
12
+ - master
15
13
  platform: el-7-x86_64
16
14
  box: centos/7
17
15
  hypervisor: <%= hypervisor %>
18
16
 
19
- server-el8:
17
+ el8:
18
+ roles:
19
+ - el8
20
+ platform: el-8-x86_64
21
+ box: centos/8
22
+ hypervisor: <%= hypervisor %>
23
+
24
+ el8-0:
20
25
  roles:
21
26
  - el8
22
27
  platform: el-8-x86_64
23
28
  box: centos/8
29
+ box_version: "1905.1"
24
30
  hypervisor: <%= hypervisor %>
25
31
 
26
32
  CONFIG:
@@ -30,3 +36,14 @@ CONFIG:
30
36
  <% if ENV['BEAKER_PUPPET_COLLECTION'] -%>
31
37
  puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %>
32
38
  <% end -%>
39
+ ssh:
40
+ keepalive: true
41
+ keepalive_interval: 10
42
+ host_key:
43
+ - <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:host_key].join("\n#{' '*6}- ") %>
44
+ kex:
45
+ - <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:kex].join("\n#{' '*6}- ") %>
46
+ encryption:
47
+ - <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:encryption].join("\n#{' '*6}- ") %>
48
+ hmac:
49
+ - <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:hmac].join("\n#{' '*6}- ") %>
@@ -0,0 +1,36 @@
1
+ HOSTS:
2
+ el7:
3
+ roles:
4
+ - el7
5
+ - master
6
+ platform: el-7-x86_64
7
+ hypervisor: docker
8
+ image: simpproject/simp_build_centos7
9
+ docker_cmd: '/usr/sbin/sshd -D -E /var/log/sshd.log'
10
+
11
+ el8:
12
+ roles:
13
+ - el8
14
+ platform: el-8-x86_64
15
+ hypervisor: docker
16
+ image: simpproject/simp_build_centos8
17
+ docker_cmd: '["/sbin/init"]'
18
+
19
+ CONFIG:
20
+ docker_preserve_image: true
21
+ log_level: verbose
22
+ type: aio
23
+ <% if ENV['BEAKER_PUPPET_COLLECTION'] -%>
24
+ puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %>
25
+ <% end -%>
26
+ ssh:
27
+ keepalive: true
28
+ keepalive_interval: 10
29
+ host_key:
30
+ - <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:host_key].join("\n#{' '*6}- ") %>
31
+ kex:
32
+ - <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:kex].join("\n#{' '*6}- ") %>
33
+ encryption:
34
+ - <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:encryption].join("\n#{' '*6}- ") %>
35
+ hmac:
36
+ - <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:hmac].join("\n#{' '*6}- ") %>
@@ -0,0 +1,20 @@
1
+ <%
2
+ if ENV['BEAKER_HYPERVISOR']
3
+ hypervisor = ENV['BEAKER_HYPERVISOR']
4
+ else
5
+ hypervisor = 'vagrant'
6
+ end
7
+ -%>
8
+ HOSTS:
9
+ focal:
10
+ platform: ubuntu-20.04-x86_64
11
+ box: ubuntu/focal64
12
+ hypervisor: <%= hypervisor %>
13
+
14
+ CONFIG:
15
+ log_level: verbose
16
+ type: aio
17
+ vagrant_memsize: 256
18
+ <% if ENV['BEAKER_PUPPET_COLLECTION'] -%>
19
+ puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %>
20
+ <% end -%>
@@ -5,7 +5,7 @@ hosts.each do |host|
5
5
  context "on #{host}" do
6
6
  puppet_collection = host.options[:puppet_collection]
7
7
 
8
- client_puppet_version = on(host, 'puppet --version').output.strip
8
+ client_puppet_version = on(host, 'puppet --version').stdout.strip
9
9
 
10
10
  if puppet_collection =~ /puppet(\d+)/
11
11
  puppet_collection_version = $1
@@ -37,4 +37,10 @@ context 'after copy_fixture_modules_to( hosts )' do
37
37
  expect(pfact_on(master, 'fips_enabled')).to eq expected
38
38
  end
39
39
  end
40
+
41
+ describe "pfact_on returns a hash" do
42
+ it 'should return a Hash' do
43
+ expect(pfact_on(master, 'os')).to be_a(Hash)
44
+ end
45
+ end
40
46
  end
@@ -1 +1 @@
1
- ../../nodesets
1
+ spec/acceptance/suites/default/../../nodesets
@@ -1 +1 @@
1
- ../../nodesets
1
+ spec/acceptance/suites/fips_from_fixtures/../../nodesets
@@ -1 +1 @@
1
- ../../nodesets
1
+ spec/acceptance/suites/snapshot/../../nodesets
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simp-beaker-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.4
4
+ version: 1.21.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tessmer
8
8
  - Trevor Vaughan
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-05 00:00:00.000000000 Z
12
+ date: 2021-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beaker
@@ -188,6 +188,8 @@ files:
188
188
  - lib/simp/rake/beaker.rb
189
189
  - simp-beaker-helpers.gemspec
190
190
  - spec/acceptance/nodesets/default.yml
191
+ - spec/acceptance/nodesets/docker.yml
192
+ - spec/acceptance/nodesets/ubuntu.yml
191
193
  - spec/acceptance/suites/default/check_puppet_version_spec.rb
192
194
  - spec/acceptance/suites/default/enable_fips_spec.rb
193
195
  - spec/acceptance/suites/default/fixture_modules_spec.rb
@@ -220,7 +222,7 @@ licenses:
220
222
  - Apache-2.0
221
223
  metadata:
222
224
  issue_tracker: https://simp-project.atlassian.net
223
- post_install_message:
225
+ post_install_message:
224
226
  rdoc_options: []
225
227
  require_paths:
226
228
  - lib
@@ -228,19 +230,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
230
  requirements:
229
231
  - - ">="
230
232
  - !ruby/object:Gem::Version
231
- version: '0'
233
+ version: 2.3.0
232
234
  required_rubygems_version: !ruby/object:Gem::Requirement
233
235
  requirements:
234
236
  - - ">="
235
237
  - !ruby/object:Gem::Version
236
238
  version: '0'
237
239
  requirements: []
238
- rubygems_version: 3.0.9
239
- signing_key:
240
+ rubyforge_project:
241
+ rubygems_version: 2.7.10
242
+ signing_key:
240
243
  specification_version: 4
241
244
  summary: beaker helper methods for SIMP
242
245
  test_files:
243
246
  - spec/acceptance/nodesets/default.yml
247
+ - spec/acceptance/nodesets/docker.yml
248
+ - spec/acceptance/nodesets/ubuntu.yml
244
249
  - spec/acceptance/suites/default/check_puppet_version_spec.rb
245
250
  - spec/acceptance/suites/default/enable_fips_spec.rb
246
251
  - spec/acceptance/suites/default/fixture_modules_spec.rb