diff --git a/testsuite/features/step_definitions/command_steps.rb b/testsuite/features/step_definitions/command_steps.rb index 99f0a8c17b18..f82ac9520b0d 100644 --- a/testsuite/features/step_definitions/command_steps.rb +++ b/testsuite/features/step_definitions/command_steps.rb @@ -168,7 +168,7 @@ raise ScriptError, "Synchronization error, channel #{channel} or #{channel}-#{architecture} in #{product} product not found" if channels_to_synchronize.nil? || channels_to_synchronize.empty? channels_to_synchronize.each do |os_product_version_channel| - command = "spacewalk-common-channels -u admin -p admin -a #{architecture} #{os_product_version_channel}" + command = "spacewalk-common-channels -u admin -p admin -a #{architecture} #{os_product_version_channel.gsub("-#{architecture}", '')}" get_target('server').run(command, verbose: true) log "Channel #{os_product_version_channel} added" end @@ -350,7 +350,7 @@ # Remove from the list to kill those channels that are already synced channels_to_kill.each do |remaining_channel| - if channel_is_synced(remaining_channel) + if channel_sync_completed?(remaining_channel) log "Channel '#{remaining_channel}' is already synced, so there is no need to kill repo-sync process." channels_to_kill.delete(remaining_channel) end @@ -419,7 +419,7 @@ end begin repeat_until_timeout(timeout: timeout, message: 'Channel not fully synced') do - break if channel_is_synced(channel) + break if channel_sync_completed?(channel) log "#{time_spent / 60.to_i} minutes out of #{timeout / 60.to_i} waiting for '#{channel}' channel to be synchronized" if ((time_spent += checking_rate) % 60).zero? sleep checking_rate @@ -441,7 +441,7 @@ time_spent = 0 checking_rate = 10 # Let's start with a timeout margin aside from the sum of the timeouts for each channel - timeout = 600 + timeout = 900 channels_to_wait.each do |channel| if TIMEOUT_BY_CHANNEL_NAME[channel].nil? log "Unknown timeout for channel #{channel}, assuming one minute" @@ -453,9 +453,11 @@ begin repeat_until_timeout(timeout: timeout, message: 'Product not fully synced') do channels_to_wait.each do |channel| - if channel_is_synced(channel) + if channel_sync_completed?(channel) channels_to_wait.delete(channel) log "Channel #{channel} finished syncing" + else + log "Channel #{channel} still syncing" end end break if channels_to_wait.empty? diff --git a/testsuite/features/support/commonlib.rb b/testsuite/features/support/commonlib.rb index c7a2e65def91..80e0e355cb8b 100644 --- a/testsuite/features/support/commonlib.rb +++ b/testsuite/features/support/commonlib.rb @@ -584,11 +584,36 @@ def update_controller_ca certutil -d sql:/root/.pki/nssdb -A -t TC -n "susemanager" -i /etc/pki/trust/anchors/#{server_name}.cert` end +# This method checks if the synchronization for the given channel is completed +# +# @param channel_name [String] the channel to check +# @return [Boolean] true if the synchronization is completed, false otherwise +def channel_sync_completed?(channel_name) + log_tmp_file = '/tmp/reposync.log' + get_target('server').extract('/var/log/rhn/reposync.log', log_tmp_file) + raise ScriptError, 'The file with repository synchronization logs doesn\'t exist or is empty' if !File.exist?(log_tmp_file) || File.empty?(log_tmp_file) + + log_content = File.readlines(log_tmp_file) + channel_found = false + log_content.each do |line| + if line.include?('Channel: ') && line.include?(channel_name) + log "Channel #{channel_name} found in the reposync log" + channel_found = true + elsif line.include?('Channel: ') && !line.include?(channel_name) + channel_found = false + elsif line.include?('Sync of channel completed.') && channel_found + return true + end + end + + false +end + # Determines whether a channel is synchronized on the server. # # @param channel [String] The name of the channel to check. # @return [Boolean] Returns true if the channel is synchronized, false otherwise. -def channel_is_synced(channel) +def channel_is_synced?(channel) sync_status = false # solv is the last file to be written when the server synchronizes a channel, therefore we wait until it exist result, code = get_target('server').run("dumpsolv /var/cache/rhn/repodata/#{channel}/solv", verbose: false, check_errors: false) @@ -736,9 +761,13 @@ def wait_action_complete(actionid, timeout: DEFAULT_TIMEOUT) # @param channels [Array] The list of channels to filter. # @param filters [Array] The list of filters to apply. def filter_channels(channels, filters = []) - filtered_channels = channels.clone - filters.each do |filter| - filtered_channels.delete_if { |channel| channel.include? filter } + if channels.nil? || channels.empty? + puts 'Warning: No channels to filter' + else + filtered_channels = channels.clone + filters.each do |filter| + filtered_channels.delete_if { |channel| channel.include? filter } + end end filtered_channels end