Skip to content

Commit 2de061f

Browse files
(SIMP-8416) Packagecloud and rsync fixes (#132)
* Fixed: * rsync handling has a better check to see if rsync actually works prior to * using it. The old method had the potential to try and use rsync even if it * no longer worked (FIPS flipped for example). * Changed: * Migrated from PackageCloud to the SIMP download server for updates moving forward. * In ``install_simp_repos()``, warn instead of failing when trying to disable repos that don't exist SIMP-8416 #comment simp-beaker-helpers update
1 parent 48137e4 commit 2de061f

4 files changed

Lines changed: 111 additions & 78 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### 1.19.0 / 2020-09-30
2+
* Fixed:
3+
* rsync handling has a better check to see if rsync actually works prior to
4+
using it. The old method had the potential to try and use rsync even if it
5+
no longer worked (FIPS flipped for example).
6+
* Changed:
7+
* Migrated from PackageCloud to the SIMP download server for updates moving
8+
forward.
9+
110
### 1.18.9 / 2020-08-04
211
* Change windows 2012r2 VM to work around issues where the old image had
312
duplicate ports trying to be opened

lib/simp/beaker_helpers.rb

Lines changed: 87 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,38 @@ def fips_enabled(sut)
3030
).output.strip == '1'
3131
end
3232

33+
def rsync_functional_on?(sut)
34+
# We have to check if rsync *still* works otherwise
35+
return false if (@rsync_functional == false)
36+
37+
require 'facter'
38+
unless Facter::Util::Resolution.which('rsync')
39+
@rsync_functional = false
40+
return @rsync_functional
41+
end
42+
43+
require 'tempfile'
44+
45+
testfile = Tempfile.new('rsync_check')
46+
testfile.puts('test')
47+
testfile.close
48+
49+
begin
50+
rsync_to(sut, testfile.path, sut.system_temp_path)
51+
rescue Beaker::Host::CommandFailure
52+
@rsync_functional = false
53+
return false
54+
ensure
55+
testfile.unlink
56+
end
57+
58+
return true
59+
end
60+
3361
# Figure out the best method to copy files to a host and use it
3462
#
3563
# Will create the directories leading up to the target if they don't exist
3664
def copy_to(sut, src, dest, opts={})
37-
unless fips_enabled(sut) || @has_rsync
38-
%x{which rsync 2>/dev/null}.strip
39-
40-
@has_rsync = !$?.nil? && $?.success?
41-
end
42-
4365
sut.mkdir_p(File.dirname(dest))
4466

4567
if sut[:hypervisor] == 'docker'
@@ -57,7 +79,7 @@ def copy_to(sut, src, dest, opts={})
5779
container_id = sut.host_hash[:docker_container_id]
5880
end
5981
%x(tar #{exclude_list.join(' ')} -hcf - -C "#{File.dirname(src)}" "#{File.basename(src)}" | docker exec -i "#{container_id}" tar -C "#{dest}" -xf -)
60-
elsif @has_rsync && sut.check_for_command('rsync')
82+
elsif rsync_functional_on?(sut)
6183
# This makes rsync_to work like beaker and scp usually do
6284
exclude_hack = %(__-__' -L --exclude '__-__)
6385

@@ -584,7 +606,7 @@ def rhel_rhsm_subscribe(sut, *opts)
584606
end
585607

586608
def sosreport(sut, dest='sosreports')
587-
sut.install_package('sos')
609+
on(sut, 'puppet resource package sos ensure=latest')
588610
on(sut, 'sosreport --batch')
589611

590612
files = on(sut, 'ls /var/tmp/sosreport* /tmp/sosreport* 2>/dev/null', :accept_all_exit_codes => true).output.lines.map(&:strip)
@@ -1170,62 +1192,70 @@ def install_puppet
11701192
run_puppet_install_helper(install_info[:puppet_install_type], install_info[:puppet_install_version])
11711193
end
11721194

1173-
# Configure all SIMP repos on a host and enable all but those listed in the disable list
1195+
# Configure all SIMP repos on a host and disable all repos in the disable Array
11741196
#
1175-
# @param sut Host on which to configure SIMP repos
1176-
# @param disable List of SIMP repos to disable
1177-
# @raise if disable contains an invalid repo name.
1197+
# @param sut [Beaker::Host] Host on which to configure SIMP repos
1198+
# @param disable [Array[String]] List of repos to disable
1199+
# @raise [StandardError] if disable contains an invalid repo name.
11781200
#
11791201
# Examples:
11801202
# install_simp_repos( myhost ) # install all the repos an enable them.
11811203
# install_simp_repos( myhost, ['simp']) # install the repos but disable the simp repo.
11821204
#
1183-
# Current set of valid SIMP repo names:
1184-
# 'simp'
1185-
# 'simp_deps'
1205+
# Valid repo names include any repository available on the system.
11861206
#
1187-
def install_simp_repos(sut, disable = [] )
1188-
repos = {
1189-
'simp' => {
1190-
:baseurl => 'https://packagecloud.io/simp-project/6_X/el/$releasever/$basearch',
1191-
:gpgkey => ['https://raw.githubusercontent.com/NationalSecurityAgency/SIMP/master/GPGKEYS/RPM-GPG-KEY-SIMP',
1192-
'https://download.simp-project.com/simp/GPGKEYS/RPM-GPG-KEY-SIMP-6'
1193-
],
1194-
:gpgcheck => 1,
1195-
:sslverify => 1,
1196-
:sslcacert => '/etc/pki/tls/certs/ca-bundle.crt',
1197-
:metadata_expire => 300
1198-
},
1199-
'simp_deps' => {
1200-
:baseurl => 'https://packagecloud.io/simp-project/6_X_Dependencies/el/$releasever/$basearch',
1201-
:gpgkey => ['https://raw.githubusercontent.com/NationalSecurityAgency/SIMP/master/GPGKEYS/RPM-GPG-KEY-SIMP',
1202-
'https://download.simp-project.com/simp/GPGKEYS/RPM-GPG-KEY-SIMP-6',
1203-
'https://yum.puppet.com/RPM-GPG-KEY-puppetlabs',
1204-
'https://yum.puppet.com/RPM-GPG-KEY-puppet',
1205-
'https://apt.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG-96',
1206-
'https://artifacts.elastic.co/GPG-KEY-elasticsearch',
1207-
'https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana',
1208-
'https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-$releasever'
1209-
],
1210-
:gpgcheck => 1,
1211-
:sslverify => 1,
1212-
:sslcacert => '/etc/pki/tls/certs/ca-bundle.crt',
1213-
:metadata_expire => 300
1214-
}
1215-
}
1216-
# Verify that the repos passed to disable are in the list of valid repos
1217-
disable.each { |d|
1218-
unless repos.has_key?(d)
1219-
raise("ERROR: install_simp_repo - disable contains invalid SIMP repo '#{d}'.")
1207+
# For backwards compatibility purposes, the following translations are
1208+
# automatically performed:
1209+
#
1210+
# * 'simp'
1211+
# * 'simp-community-simp'
1212+
#
1213+
# * 'simp_deps'
1214+
# * 'simp-community-epel'
1215+
# * 'simp-community-postgres'
1216+
# * 'simp-community-puppet'
1217+
#
1218+
def install_simp_repos(sut, disable = [])
1219+
# NOTE: Do *NOT* use puppet in this method since it may not be available yet
1220+
1221+
if on(sut, 'rpm -q yum-utils', :accept_all_exit_codes => true).exit_code != 0
1222+
on(sut, 'yum -y install yum-utils')
1223+
end
1224+
1225+
if on(sut, 'rpm -q simp-release-community', :accept_all_exit_codes => true).exit_code != 0
1226+
on(sut, 'yum -y install "https://download.simp-project.com/simp-release-community.rpm"')
1227+
end
1228+
1229+
to_disable = disable.dup
1230+
1231+
unless to_disable.empty?
1232+
if to_disable.include?('simp')
1233+
to_disable.delete('simp')
1234+
to_disable << 'simp-community-simp'
12201235
end
1221-
}
1222-
repo_manifest = ''
1223-
repos.each { | repo, metadata|
1224-
metadata[:enabled] = disable.include?(repo) ? 0 : 1
1225-
repo_manifest << create_yum_resource(repo, metadata)
1226-
}
1227-
apply_manifest_on(sut, repo_manifest, :catch_failures => true)
1228-
end
1229-
end
12301236

1237+
if to_disable.include?('simp_deps')
1238+
to_disable.delete('simp_deps')
1239+
to_disable << 'simp-community-epel'
1240+
to_disable << 'simp-community-postgres'
1241+
to_disable << 'simp-community-puppet'
1242+
end
12311243

1244+
# NOTE: This --enablerepo enables the repos for listing and is inherited
1245+
# from YUM. This does not actually "enable" the repos, that would require
1246+
# the "--enable" option (from yum-config-manager) :-D.
1247+
available_repos = on(sut, %{yum-config-manager --enablerepo="*"}).stdout.lines.grep(/\A\[(.+)\]\Z/){|x| $1}
1248+
1249+
invalid_repos = (to_disable - available_repos)
1250+
1251+
# Verify that the repos passed to disable are in the list of valid repos
1252+
unless invalid_repos.empty?
1253+
logger.warn(%{WARN: install_simp_repo - requested repos to disable do not exist on the target system '#{invalid_repos.join("', '")}'.})
1254+
end
1255+
1256+
(to_disable - invalid_repos).each do |repo|
1257+
on(sut, %{yum-config-manager --disable "#{repo}"})
1258+
end
1259+
end
1260+
end
1261+
end

lib/simp/beaker_helpers/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Simp; end
22

33
module Simp::BeakerHelpers
4-
VERSION = '1.18.9'
4+
VERSION = '1.19.0'
55
end

spec/acceptance/suites/default/install_simp_deps_repo_spec.rb

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,36 @@
22

33
hosts.each do |host|
44
describe '#write_hieradata_to' do
5+
expect_failures = false
6+
if hosts_with_role(hosts, 'el8').include?(host)
7+
expect_failures = true
8+
end
59

610
it 'should install yum utils' do
711
host.install_package('yum-utils')
812
end
913

10-
context 'defailt settings' do
14+
context 'default settings' do
1115
before(:all) { install_simp_repos(host) }
1216

13-
it 'creates the repo' do
14-
on host, 'test -f /etc/yum.repos.d/simp.repo'
15-
on host, 'test -f /etc/yum.repos.d/simp_deps.repo'
16-
end
17-
1817
it 'enables the correct repos' do
19-
simp6info = on(host, '/usr/bin/yum repolist -v simp | grep ^Repo-status').stdout.strip
20-
expect(simp6info).to match(/.*Repo-status.*enabled.*/)
21-
simp6depsinfo = on(host, 'yum repolist -v simp_deps| grep ^Repo-status').stdout.strip
22-
expect(simp6depsinfo).to match(/.*Repo-status.*enabled.*/)
18+
skip "#{host} is not supported yet" if expect_failures
19+
on(host, 'yum -y list simp')
20+
on(host, 'yum -y list postgresql96')
2321
end
2422
end
2523

2624
context 'when passed a disabled list ' do
27-
before(:all) { install_simp_repos(host, ['simp'] ) }
25+
before(:all) { install_simp_repos(host, ['simp-community-simp'] ) }
2826

29-
it 'creates the repo' do
30-
on host, 'test -f /etc/yum.repos.d/simp.repo'
31-
on host, 'test -f /etc/yum.repos.d/simp_deps.repo'
27+
it 'enables the correct repos' do
28+
skip "#{host} is not supported yet" if expect_failures
29+
on(host, 'yum -y list postgresql96')
3230
end
3331

34-
it 'enables the correct repos' do
35-
simp6info = on(host, 'yum repolist -v simp | grep ^Repo-status').stdout.strip
36-
expect(simp6info).to match(/.*Repo-status.*disabled.*/)
37-
simp6depsinfo = on(host, 'yum repolist -v simp_deps| grep ^Repo-status').stdout.strip
38-
expect(simp6depsinfo).to match(/.*Repo-status.*enabled.*/)
32+
it 'disables the correct repos' do
33+
on(host, 'yum -y list simp', :acceptable_exit_codes => [1])
3934
end
4035
end
41-
4236
end
4337
end

0 commit comments

Comments
 (0)