diff --git a/CHANGELOG.md b/CHANGELOG.md index 7466ac7..05c8d12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +### 1.25.0 / 2022-06-11 +* Fixed: + * Replaced calls to `sed -c` with something POSIX compliant that should work + on non-RHEL systems +* Added: + * Updated all dependencies to their latest versions where possible and removed + depdendencies on deprecated libraries. + ### 1.24.5 / 2022-05-06 * Fixed: * Added a workaround for Amazon Linux 2 testing diff --git a/Gemfile b/Gemfile index cd4fe38..5f3a941 100644 --- a/Gemfile +++ b/Gemfile @@ -44,8 +44,8 @@ group :system_tests do gem 'beaker-rspec' gem 'beaker-windows' gem 'net-ssh' - gem 'puppet', ENV.fetch('PUPPET_VERSION', '~> 6.0') - gem 'puppetlabs_spec_helper', '~> 3.0' + gem 'puppet', ENV.fetch('PUPPET_VERSION', '~> 7.0') gem 'rubocop' gem 'rubocop-rspec' + gem 'puppetlabs_spec_helper', '~> 4.0' end diff --git a/files/pki/make.sh b/files/pki/make.sh index 258050e..73cb6a1 100755 --- a/files/pki/make.sh +++ b/files/pki/make.sh @@ -73,7 +73,8 @@ for hosts in $*; do done done - sed -ci "s/# subjectAltName = #ALTNAMES#/subjectAltName = ${altnames}/" "working/${hname}.cnf" + tgt_file="working/${hname}.cnf" + sed -e "s/# subjectAltName = #ALTNAMES#/subjectAltName = ${altnames}/" "$tgt_file" 1<> "$tgt_file" fi echo "-- running openssl req" diff --git a/lib/simp/beaker_helpers.rb b/lib/simp/beaker_helpers.rb index 84dd874..5d09ffe 100644 --- a/lib/simp/beaker_helpers.rb +++ b/lib/simp/beaker_helpers.rb @@ -12,6 +12,8 @@ module Simp::BeakerHelpers require 'simp/beaker_helpers/ssg' require 'simp/beaker_helpers/version' + @run_in_parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') + # Stealing this from the Ruby 2.5 Dir::Tmpname workaround from Rails def self.tmpname t = Time.new.strftime("%Y%m%d") @@ -25,8 +27,7 @@ def self.tmpname # # Has no effect if yum or dnf is not present. def set_yum_opt_on(suts, key, value) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| repo,target = key.split('.') unless target @@ -56,8 +57,7 @@ def set_yum_opt_on(suts, key, value) # 'foo.installonly_limit' => '5' # Applies only to the 'foo' repo # } def set_yum_opts_on(suts, yum_opts={}) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| yum_opts.each_pair do |k,v| set_yum_opt_on(sut, k, v) end @@ -70,8 +70,7 @@ def install_package_unless_present_on(suts, package_name, package_source=nil, op retry_interval: 10 } - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| package_source = package_name unless package_source unless sut.check_for_package(package_name) @@ -91,8 +90,7 @@ def install_latest_package_on(suts, package_name, package_source=nil, opts={}) retry_interval: 10 } - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| package_source = package_name unless package_source if sut.check_for_package(package_name) @@ -380,8 +378,7 @@ def copy_fixture_modules_to( suts = hosts, opts = {}) opts[:pluginsync] = opts.fetch(:pluginsync, true) unless ENV['BEAKER_copy_fixtures'] == 'no' - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| STDERR.puts " ** copy_fixture_modules_to: '#{sut}'" if ENV['BEAKER_helpers_verbose'] # Use spec_prep to provide modules (this supports isolated networks) @@ -443,8 +440,7 @@ def has_crypto_policies(sut) end def munge_ssh_crypto_policies(suts, key_types=['ssh-rsa']) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| if has_crypto_policies(sut) install_latest_package_on(sut, 'crypto-policies', nil, :accept_all_exit_codes => true) @@ -455,14 +451,31 @@ def munge_ssh_crypto_policies(suts, key_types=['ssh-rsa']) end end + # Perform the equivalend of an in-place sed without changing the target inode + # + # Required for many container targets + def safe_sed(suts = hosts, pattern, target_file) + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| + tmpfile = sut.tmpfile('safe_sed') + + command = [ + "cp #{target_file} #{tmpfile}", + "sed -i '#{pattern}' #{tmpfile}", + "cat #{tmpfile} > #{target_file}" + ].join(' && ') + + on(sut, command) + + sut.rm_rf(tmpfile) + end + end + # Configure and reboot SUTs into FIPS mode def enable_fips_mode_on( suts = hosts ) puts '== configuring FIPS mode on SUTs' puts ' -- (use BEAKER_fips=no to disable)' - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| next if sut[:hypervisor] == 'docker' if is_windows?(sut) @@ -483,7 +496,7 @@ def enable_fips_mode_on( suts = hosts ) # that doesn't break vagrant access and is appropriate for # typical module tests.) fips_ssh_ciphers = [ 'aes256-ctr','aes192-ctr','aes128-ctr'] - on(sut, %(sed -ci '/Ciphers /d' /etc/ssh/sshd_config)) + safe_sed(sut, '/Ciphers /d', '/etc/ssh/sshd_config') on(sut, %(echo 'Ciphers #{fips_ssh_ciphers.join(',')}' >> /etc/ssh/sshd_config)) fips_enable_modulepath = '' @@ -535,8 +548,7 @@ def enable_fips_mode_on( suts = hosts ) # - # - def enable_yum_repos_on( suts = hosts ) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| if sut['yum_repos'] sut['yum_repos'].each_pair do |repo, metadata| repo_manifest = create_yum_resource(repo, metadata) @@ -617,8 +629,7 @@ def create_yum_resource( repo, metadata ) # # Can be disabled by setting BEAKER_enable_epel=no def enable_epel_on(suts) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| if ONLINE os_info = fact_on(sut, 'os') os_maj_rel = os_info['release']['major'] @@ -661,8 +672,7 @@ def enable_epel_on(suts) end def update_package_from_centos_stream(suts, package_name) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| sut.install_package('centos-release-stream') unless sut.check_for_package('centos-release-stream') install_latest_package_on(sut, package_name) sut.uninstall_package('centos-release-stream') @@ -670,8 +680,7 @@ def update_package_from_centos_stream(suts, package_name) end def linux_errata( suts ) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| # Set the locale if not set sut.set_env_var('LANG', 'en_US.UTF-8') unless sut.get_env_var('LANG') @@ -688,9 +697,14 @@ def linux_errata( suts ) if current_domain.empty? new_fqdn = hostname + '.beaker.test' - on(sut, "sed -ci 's/#{hostname}.*/#{new_fqdn} #{hostname}/' /etc/hosts") - on(sut, "echo '#{new_fqdn}' > /etc/hostname", :accept_all_exit_codes => true) - on(sut, "hostname #{new_fqdn}", :accept_all_exit_codes => true) + safe_sed(sut, 's/#{hostname}.*/#{new_fqdn} #{hostname}/', '/etc/hosts') + + if !sut.which('hostnamectl').empty? + on(sut, "hostnamectl set-hostname #{new_fqdn}") + else + on(sut, "echo '#{new_fqdn}' > /etc/hostname", :accept_all_exit_codes => true) + on(sut, "hostname #{new_fqdn}", :accept_all_exit_codes => true) + end if sut.file_exist?('/etc/sysconfig/network') on(sut, "sed -s '/HOSTNAME=/d' /etc/sysconfig/network") @@ -785,8 +799,7 @@ def linux_errata( suts ) def rhel_rhsm_subscribe(suts, *opts) require 'securerandom' - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| rhsm_opts = { :username => ENV['BEAKER_RHSM_USER'], :password => ENV['BEAKER_RHSM_PASS'], @@ -838,8 +851,7 @@ def rhel_rhsm_subscribe(suts, *opts) end def sosreport(suts, dest='sosreports') - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| install_latest_package_on(sut, 'sos') on(sut, 'sosreport --batch') @@ -854,8 +866,7 @@ def sosreport(suts, dest='sosreports') end def rhel_repo_enable(suts, repos) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| Array(repos).each do |repo| on(sut, %{subscription-manager repos --enable #{repo}}) end @@ -863,8 +874,7 @@ def rhel_repo_enable(suts, repos) end def rhel_repo_disable(suts, repos) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| Array(repos).each do |repo| on(sut, %{subscription-manager repos --disable #{repo}}, :accept_all_exit_codes => true) end @@ -872,16 +882,14 @@ def rhel_repo_disable(suts, repos) end def rhel_rhsm_unsubscribe(suts) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| on(sut, %{subscription-manager unregister}, :accept_all_exit_codes => true) end end # Apply known OS fixes we need to run Beaker on each SUT def fix_errata_on( suts = hosts ) - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| if is_windows?(sut) # Load the Windows requirements require 'simp/beaker_helpers/windows' @@ -1091,8 +1099,7 @@ def copy_keydist_to( ca_sut = master, host_keydist_dir = nil ) def activate_interfaces(hosts) return if ENV['BEAKER_no_fix_interfaces'] - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(hosts, :run_in_parallel => parallel) do |host| + block_on(hosts, :run_in_parallel => @run_in_parallel) do |host| if host[:platform] =~ /windows/ puts " -- SKIPPING #{host} because it is windows" next @@ -1335,8 +1342,7 @@ def pluginsync_on( suts = hosts ) noop => false } PLUGINSYNC_MANIFEST - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - apply_manifest_on(hosts, pluginsync_manifest, :run_in_parallel => parallel) + apply_manifest_on(hosts, pluginsync_manifest, :run_in_parallel => @run_in_parallel) end @@ -1455,9 +1461,8 @@ def install_puppet ENV['BEAKER_PUPPET_COLLECTION'] = install_info[:puppet_collection] end - require 'beaker/puppet_install_helper' - - run_puppet_install_helper(install_info[:puppet_install_type], install_info[:puppet_install_version]) + require 'beaker-puppet' + install_puppet_on(hosts, version: install_info[:puppet_install_version]) end # Configure all SIMP repos on a host and disable all repos in the disable Array @@ -1494,8 +1499,7 @@ def install_simp_repos(suts, disable = []) return if (ENV.fetch('SIMP_install_repos', 'yes') == 'no') - parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes') - block_on(suts, :run_in_parallel => parallel) do |sut| + block_on(suts, :run_in_parallel => @run_in_parallel) do |sut| install_package_unless_present_on(sut, 'yum-utils') os = fact_on(sut, 'os.name') diff --git a/lib/simp/beaker_helpers/ssg.rb b/lib/simp/beaker_helpers/ssg.rb index 2dd7624..c1fac46 100644 --- a/lib/simp/beaker_helpers/ssg.rb +++ b/lib/simp/beaker_helpers/ssg.rb @@ -420,7 +420,11 @@ def get_ssg_datastream # # This isn't 100% correct but it's "good enough" for an automated CI # environment to tell us if something is critically out of alignment. - on(@sut, %(cd scap-content/build-scripts; sed -ci 's/ssg.build_derivatives.profile_handling/__simp_dontcare__ = None #ssg.build_derivatives.profile_handling/g' enable_derivatives.py)) + safe_sed( + @sut, + 's/ssg.build_derivatives.profile_handling/__simp_dontcare__ = None #ssg.build_derivatives.profile_handling/g', + 'scap-content/build-scripts/enable_derivatives.py' + ) on(@sut, %(cd scap-content/build; cmake ../; make -j4 #{OS_INFO[@os][@os_rel]['ssg']['build_target']}-content && cp *ds.xml #{@scap_working_dir})) end diff --git a/lib/simp/rake/beaker.rb b/lib/simp/rake/beaker.rb index 89d5823..3f7096b 100644 --- a/lib/simp/rake/beaker.rb +++ b/lib/simp/rake/beaker.rb @@ -2,7 +2,8 @@ require 'rake/clean' require 'rake/tasklib' require 'fileutils' -require 'puppetlabs_spec_helper/tasks/beaker' +require 'beaker/tasks/rake_task' +require 'beaker-rspec/rake_task' require 'puppetlabs_spec_helper/tasks/fixtures' module Simp; end diff --git a/simp-beaker-helpers.gemspec b/simp-beaker-helpers.gemspec index 8447eec..0e2e3a2 100644 --- a/simp-beaker-helpers.gemspec +++ b/simp-beaker-helpers.gemspec @@ -22,19 +22,14 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.3.0' s.add_runtime_dependency 'beaker' , ['>= 4.17.0', '< 5.0.0'] - s.add_runtime_dependency 'beaker-rspec' , '~> 6.2' + s.add_runtime_dependency 'beaker-rspec' , '~> 7.1' s.add_runtime_dependency 'beaker-puppet' , ['>= 1.18.14', '< 2.0.0'] s.add_runtime_dependency 'beaker-docker' , ['>= 0.8.3', '< 2.0.0'] s.add_runtime_dependency 'docker-api' , ['>= 2.1.0', '< 3.0.0'] s.add_runtime_dependency 'beaker-vagrant' , ['>= 0.6.4', '< 2.0.0'] - s.add_runtime_dependency 'beaker-puppet_install_helper', '~> 0.9' s.add_runtime_dependency 'highline' , '~> 2.0' s.add_runtime_dependency 'nokogiri' , '~> 1.8' - # Because net-telnet dropped support for Ruby < 2.3.0 - # TODO: Update this when we no longer support Ruby 2.1.9 (should be October 2018) - s.add_runtime_dependency 'net-telnet', '~> 0.1.1' - ### s.files = Dir['Rakefile', '{bin,lib,spec}/**/*', 'README*', 'LICENSE*'] & `git ls-files -z .`.split("\0") s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") diff --git a/spec/acceptance/nodesets/amzn2.yml b/spec/acceptance/nodesets/amzn2.yml index 8c87b71..490a732 100644 --- a/spec/acceptance/nodesets/amzn2.yml +++ b/spec/acceptance/nodesets/amzn2.yml @@ -18,7 +18,6 @@ CONFIG: log_level: verbose synced_folder : disabled type: aio - vagrant_memsize: 512 <% if ENV['BEAKER_PUPPET_COLLECTION'] -%> puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %> <% end -%> diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml index 0aa267c..a55a979 100644 --- a/spec/acceptance/nodesets/default.yml +++ b/spec/acceptance/nodesets/default.yml @@ -18,13 +18,12 @@ HOSTS: roles: - el8 platform: el-8-x86_64 - box: generic/centos8 + box: centos/stream8 hypervisor: <%= hypervisor %> CONFIG: log_level: verbose type: aio - vagrant_memsize: 512 vagrant_cpus: 2 <% if ENV['BEAKER_PUPPET_COLLECTION'] -%> puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %> diff --git a/spec/acceptance/nodesets/oel.yml b/spec/acceptance/nodesets/oel.yml index 3e4050f..f4d4044 100644 --- a/spec/acceptance/nodesets/oel.yml +++ b/spec/acceptance/nodesets/oel.yml @@ -24,7 +24,6 @@ HOSTS: CONFIG: log_level: verbose type: aio - vagrant_memsize: 1024 vagrant_cpus: 2 <% if ENV['BEAKER_PUPPET_COLLECTION'] -%> puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %> diff --git a/spec/acceptance/nodesets/ubuntu.yml b/spec/acceptance/nodesets/ubuntu.yml index df36b75..86cc4b6 100644 --- a/spec/acceptance/nodesets/ubuntu.yml +++ b/spec/acceptance/nodesets/ubuntu.yml @@ -14,7 +14,6 @@ HOSTS: CONFIG: log_level: verbose type: aio - vagrant_memsize: 512 <% if ENV['BEAKER_PUPPET_COLLECTION'] -%> puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %> <% end -%> diff --git a/spec/acceptance/suites/windows/00_default_spec.rb b/spec/acceptance/suites/windows/00_default_spec.rb index 1099086..3e25684 100644 --- a/spec/acceptance/suites/windows/00_default_spec.rb +++ b/spec/acceptance/suites/windows/00_default_spec.rb @@ -5,8 +5,6 @@ require 'simp/beaker_helpers' include Simp::BeakerHelpers -require 'beaker/puppet_install_helper' - unless ENV['BEAKER_provision'] == 'no' hosts.each do |host| unless Simp::BeakerHelpers::Snapshot.exist?(host, 'puppet_installed') diff --git a/spec/acceptance/suites/windows/nodesets/default.yml b/spec/acceptance/suites/windows/nodesets/default.yml index 600e5d4..cfcf8c7 100644 --- a/spec/acceptance/suites/windows/nodesets/default.yml +++ b/spec/acceptance/suites/windows/nodesets/default.yml @@ -29,7 +29,6 @@ HOSTS: CONFIG: log_level: verbose type: aio - vagrant_memsize: 256 <% if ENV['BEAKER_PUPPET_ENVIRONMENT'] -%> puppet_environment: <%= ENV['BEAKER_PUPPET_ENVIRONMENT'] %> <% end -%> diff --git a/spec/acceptance/suites/windows/nodesets/win2016.yml b/spec/acceptance/suites/windows/nodesets/win2016.yml index 52b4719..2a03452 100644 --- a/spec/acceptance/suites/windows/nodesets/win2016.yml +++ b/spec/acceptance/suites/windows/nodesets/win2016.yml @@ -29,7 +29,6 @@ HOSTS: CONFIG: log_level: verbose type: aio - vagrant_memsize: 256 <% if ENV['BEAKER_PUPPET_ENVIRONMENT'] -%> puppet_environment: <%= ENV['BEAKER_PUPPET_ENVIRONMENT'] %> <% end -%> diff --git a/spec/acceptance/suites/windows/nodesets/win2019.yml b/spec/acceptance/suites/windows/nodesets/win2019.yml index 7607f80..94939cf 100644 --- a/spec/acceptance/suites/windows/nodesets/win2019.yml +++ b/spec/acceptance/suites/windows/nodesets/win2019.yml @@ -28,7 +28,6 @@ HOSTS: CONFIG: log_level: verbose type: aio - vagrant_memsize: 256 <% if ENV['BEAKER_PUPPET_ENVIRONMENT'] -%> puppet_environment: <%= ENV['BEAKER_PUPPET_ENVIRONMENT'] %> <% end -%>