How to change download policy of repositories in Red Hat Satellite 6?

Solution Verified - Updated -

Environment

  • Red Hat Satellite 6.10 and above

Issue

  • How to change download policy of all enabled repositories in Red Hat Satellite 6?
  • How to change repository download policy to immediate in Red Hat Satellite 6?

Resolution

  • To change default download policy, follow below steps on Red Hat Satellite WebUI.

    Administer > Settings > Content > Select "Default Repository download policy" > set "immediate"
    
  • Change download policy of already enabled repository through WebUI.

    Content > products > select "Product" > select "repository" > select "Download Policy" > choose the policy
    
  • Use the following commands to set download policies for all enabled repositories in Red Hat Satellite 6.

    - Changing download policy to 'immediate'.
    # foreman-rake katello:change_download_policy DOWNLOAD_POLICY=immediate
    
    - Changing download policy to 'on-demand'.
    # foreman-rake katello:change_download_policy DOWNLOAD_POLICY=on_demand
    

For more KB articles/solutions related to Red Hat Satellite 6.x Repository Issues, please refer to the Red Hat Satellite Consolidated Troubleshooting Article for Red Hat Satellite 6.x Repository Issues.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

10 Comments

Tried to update the download policy for all repos to "on demand" but got this error on a lot of repos:

Failed to update repository Red Hat Enterprise Linux 7 Server RPMs x86_64 7.5 (856): Validation failed: Checksum type Checksum type cannot be set for yum repositories with on demand download policy.

How to solve this?

This is tricky: you had to (most probably automatically) set a checksum type to the (katello) repos, which prevents them in changing the policy to On Demand (that newly requires no checksum type, dunno why). I think the below rake script can clean the checksum types. It works on 6.9, for older releases, you need to replace pulp_primary by pulp_master:

Katello::RootRepository.yum_type.find_each do |root_repo|
  root_repo.transaction do
    begin
      if [::Runcible::Models::YumImporter::DOWNLOAD_ON_DEMAND, ::Runcible::Models::YumImporter::DOWNLOAD_BACKGROUND].include?(root_repo.download_policy) && root_repo.url.present? && URI(root_repo.url).scheme == 'file'
        root_repo.update_attribute(:download_policy, ::Runcible::Models::YumImporter::DOWNLOAD_IMMEDIATE)
        root_repo.repositories.each do |repo|
          importer = repo.importers[0]
          config = {
            :download_policy => ::Runcible::Models::YumImporter::DOWNLOAD_IMMEDIATE
          }

          SmartProxy.pulp_primary.pulp_api.resources.repository.update_importer(repo.pulp_id, importer[:id], config) if (importer && importer[:id])
        end
      end

      if !root_repo.on_demand? && root_repo.url.present?
        root_repo.update_attribute(:checksum_type, nil)

        root_repo.repositories.each do |repo|
          begin
            repo.update_attribute(:saved_checksum_type, nil)

            if repo.find_distributor[:config]&.delete(:checksum_type)
              SmartProxy.pulp_primary.pulp_api.resources.repository.update_distributor(
                repo.pulp_id, repo.find_distributor[:id], repo.find_distributor[:config])
            end
          # rubocop:disable HandleExceptions
          rescue RestClient::ResourceNotFound
          end
        end
      end
    end
  end
end

Save that as a checksum.rake file, and run: cat checksum.rake | foreman-rake console. THEN re-run the katello:change_download_policy rake script again.

I will ask katello engineering to verify if my script is correct (it quite truly mimics one upgrade script), so please hold on until I confirm it correctness.

Thanks for the help Pavel, I took a snapshot of the Satellite server, and run your script. It seems to work correctly. After your script, I could change the download policy of all the repos to "on_demand". Now, the /var/lib/pulp volume is still full: how can I delete the unneeded RPM files from there? I tried running:

# foreman-rake katello:delete_orphaned_content RAILS_ENV=production
# /etc/cron.weekly/pulp-maintenance

But they did not free any disk space. Thanks!!

Thanks

Anyone running into the same issue for Satellite 6.10 or above, please look into bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=2159776 .

We are in a process of improving the repo update task which will nil the checksum_type automatically if it is set for repo and we are trying to change its download policy to on_demand.

I attempted to change my download policies with your command, but all failed with this error. I am running SAT build: 6.8.4.

foreman-rake katello:change_download_policy DOWNLOAD_POLICY=immediate

Processing Repository 1/67: Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server (2) Failed to update repository Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server (2): The Dynflow world was not initialized yet. If your plugin uses it, make sure to call Rails.application.dynflow.require! in some initializer

Processing Repository 2/67: Red Hat Enterprise Virtualization Agents for RHEL 6 Server RPMs x86_64 6Server (6) Failed to update repository Red Hat Enterprise Virtualization Agents for RHEL 6 Server RPMs x86_64 6Server (6): The Dynflow world was not initialized yet. If your plugin uses it, make sure to call Rails.application.dynflow.require! in so me initializer

I was hoping someone would answer this, I'm having the same problem. Did you solve it?

Hello, that is a known issue. Please follow this KCS.

Pavel, this didn't help me. Still the same error message. I tried to change both: task :correct_repositories and task :correct_puppet_environments I took Katello version from RPM installed.

Hello, sad to read that. Apart of the workaround in the KCS https://access.redhat.com/solutions/5655281, I realized we have released a hotfix for 6.8.6 in https://bugzilla.redhat.com/show_bug.cgi?id=1908101#c15 . Which should be imho based on the codechange in the KCS, either way..

If the HF is not applicable or the codechange from KCS does not work, please raise a support case to troubleshoot further.