@@ -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
0 commit comments