How to change syncing policy for Repositories on Satellite 6 from "Immediate" to "On-Demand".

Solution Verified - Updated -

Environment

Satellite 6.2
Satellite 6.3

Issue

Need to change syncing policy from "Immediate" to "On-Demand" in order to free disk space.

Resolution

WARNING: This will remove all RPMs that were uploaded via hammer or the UI for repositories that are not synchronized from a remote source. These packages will need to be re-uploaded after running the below steps.

WARNING: This action is irreversible and data-loss may occur as you are forcibly removing all previously downloaded and uploaded RPMs. Creating a VM snapshot or backing up your Satellite before performing this operation is highly recommended

1) Backup your Satellite 6 Server using katello-backup. (including pulp content)

2) Delete all the files on the file system which are stored at:

2.a) If Satellite was upgraded from Satellite 6.1
/var/lib/pulp/content/rpm

# rm -rf /var/lib/pulp/content/rpm

2.b) Satellite 6.2
/var/lib/pulp/content/units/{rpm,srpm,drpm,distribution}

# rm -rf /var/lib/pulp/content/units/{rpm,srpm,drpm,distribution}

3) Change policy for each repository to "On-Demand" using the rake command below:
Note: This will also change the kickstart repositories to on demand which might be something you do not want

3.a) For Satellite 6.2

# for id in `hammer repository list --organization-id 1 | awk '{print $1}' | grep -v "-" | grep -v "ID" `; do  hammer repository update --id=$id --download-policy=on_demand ; done   

3.b) For Satellite 6.3

# foreman-rake katello:change_download_policy DOWNLOAD_POLICY=on_demand

4) Update the database with the following script:

#!/usr/bin/env python
try:
    from pymongo import MongoClient
except ImportError:
    print 'Error: PyMongo module is not installed'
    exit()

client = MongoClient()
db = client.pulp_database

collections_list = [db.units_rpm, db.units_srpm, db.units_drpm, db.units_distribution]



def mongoupdate(collection):

    print "Updating collection " + collection.name
    results = collection.update_many(
        {"downloaded": True},
        {"$set": {"downloaded": False}}
    )
    print 'Done, updated ' + str(results.modified_count) + " records \n"


for i in collections_list:
    mongoupdate(i)


count = 0
for i in collections_list:
    print '\nChecking if there are any downloaded packages left at ' + i.name + '\n'
    cur = i.find({"downloaded": True})
    for k in cur:
        count += 1
    print '  Amount of downloaded packages  ' + str(count) + '\n'
    count = 0

5) Reload pulp:

# for i in pulp_resource_manager pulp_workers pulp_celerybeat pulp_streamer; do service $i restart; done

6) Resync all the repos with hammer using the --skip-metadata-check true flag.

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.

5 Comments

Just to confirm, I've tested this procedure on Satellite 6.3.0 and seems to work fine, too.

Two comments:

Step 2 can be triggered with a single command via :

DOWNLOAD_POLICY=on_demand foreman-rake  katello:change_download_policy

Step 5 depends on the number of enabled repos, and can be parallelized according to the number of CPU cores your Satellite server has by substituting "-P 4" below with the number of cores:

hammer repository list | grep -P '^\d' | cut -f 1 -d '|' |xargs -n 1 -P 4 hammer repository synchronize --skip-metadata-check true --id 

In my 4-core Satellite system the metadata synchronization took about 3h for ~70 repos with -P4, YMMV.

I tried to run this on a Satellite 6.2.13, but got an error in step 3:

[root@salcto-sat01 ~]# foreman-rake katello:change_download_policy DOWNLOAD_POLICY=on_demand
rake aborted!
Don't know how to build task 'katello:change_download_policy'

(See full trace by running task with --trace)
[root@salcto-sat01 ~]# rpm -q satellite
satellite-6.2.13-4.0.el7sat.noarch
[root@salcto-sat01 ~]# 

Any pointers are appreciated.

Thanks!

foreman-rake katello:change_download_policy DOWNLOAD_POLICY=on_demand

Is available only from Sat 6.3, so for 6.2 you should rely on

# for id in `hammer repository list --organization-id 1 | awk '{print $1}' | grep -v "-" | grep -v "ID" `; do  hammer repository update --id=$id --download-policy=on_demand ; done   

For more references see the article Satellite 6.2 Feature Overview: Lazy Sync

Tried it on Sat 6.2.15, it worked, but the repository update should only be done on RPMs repositories, not Kickstart ones.
Having a Kickstart repo in on-demand mode gives me problems with PXE provisioning until I revert it to Immediate and fully sync the repo.

Just had an issue with pulp_streamer service being down while doing yum-install(s) on client machines.
Better be sure to restart it along with the other pulp services, like

# for i in pulp_resource_manager pulp_workers pulp_celerybeat pulp_streamer; do service $i restart; done