Skip to content

Commit

Permalink
Remove outdated deps and fix sed (#186)
Browse files Browse the repository at this point in the history
* Fixed:
  * Replaced calls to `sed -c` with something POSIX compliant that should work
    on non-RHEL systems
  * fix windows test
* Added:
  * Updated all dependencies to their latest versions where possible and removed
    dependencies on deprecated libraries.

Fixes #165
Fixes #185
  • Loading branch information
trevor-vaughan authored Jun 17, 2022
1 parent fa5b6b9 commit 1ff15d7
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 69 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion files/pki/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
100 changes: 52 additions & 48 deletions lib/simp/beaker_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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 = ''
Expand Down Expand Up @@ -535,8 +548,7 @@ def enable_fips_mode_on( suts = hosts )
# - <URL to GPGKEY1>
# - <URL to GPGKEY2>
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)
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -661,17 +672,15 @@ 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')
end
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')

Expand All @@ -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")
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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')

Expand All @@ -854,34 +866,30 @@ 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
end
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
end
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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
6 changes: 5 additions & 1 deletion lib/simp/beaker_helpers/ssg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/simp/rake/beaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions simp-beaker-helpers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion spec/acceptance/nodesets/amzn2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
3 changes: 1 addition & 2 deletions spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'] %>
Expand Down
1 change: 0 additions & 1 deletion spec/acceptance/nodesets/oel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'] %>
Expand Down
1 change: 0 additions & 1 deletion spec/acceptance/nodesets/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
2 changes: 0 additions & 2 deletions spec/acceptance/suites/windows/00_default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading

0 comments on commit 1ff15d7

Please sign in to comment.