Foreman 2.3 and Katello 3.18 how to Republish Repository Metadata on CommandLine

Problem:

We are looking to automate a workaround for our Smart Proxy Sync Issues. The workaround we found was to republish the repo’s metadata, the Content View’s metadata and to do a full sync to the smart proxy having the issue.

If you could do this via a cronjob and a script it would be much better than through the GUI.

Expected outcome:

We found something on RedHat’s support site that said we should be able to do this:

https://satellite.example.com/products/89/repositories/68
    where in the above url :  `68` is the `repo_id` and `89` is the product_id.
  • Open up the rake console and execute the following set of commands to re-generate the metadata for the specific repository.
  • Replace 68 in the below command with with correct numeric repository id that you got from the URL.

Raw

# foreman-rake console
> User.current = User.first
> repo =  Katello::Repository.find(68)
> ForemanTasks.async_task(Actions::Pulp::Repository::DistributorPublish, :pulp_id => repo.pulp_id, :distributor_type_id => Runcible::Models::YumDistributor.type_id, :override_config => {:force_full => true})
> quit

This is from: How to forcefully regenerate metadata for a particular repository on Red Hat Satellite 6? - Red Hat Customer Portal

However, when I run it we get this error:

root@katello02-> foreman-rake console
Loading production environment (Rails 6.0.3.4)
irb(main):001:0> User.current = User.first
=> #<User id: 4, login: “superuser”, firstname: “Admin”, lastname: “User”, mail: “root@XXXXXX.net”, admin: true, last_login_on: “2021-10-29 18:03:30”, auth_source_id: 1, created_at: “2021-06-02 22:59:11”, updated_at: “2021-06-02 22:59:11”, password_hash: [FILTERED], password_salt: [FILTERED], locale: nil, avatar_hash: nil, default_organization_id: 1, default_location_id: 2, lower_login: “superuser”, mail_enabled: true, timezone: nil, description: nil, disabled: false, password: nil>
irb(main):002:0> repo = Katello::Repository.find(99)
=> #<Katello::Repository id: 99, pulp_id: “091097fc-ea7a-44e1-9ece-c01a443f3078”, library_instance_id: nil, content_view_version_id: 2, relative_path: “XXXXX/Library/custom/CentOS_7/foreman_client_c…”, environment_id: 2, saved_checksum_type: nil, distribution_version: nil, distribution_arch: nil, distribution_bootable: nil, distribution_family: nil, distribution_variant: nil, container_repository_name: nil, root_id: 20, remote_href: “/pulp/api/v3/remotes/rpm/rpm/9e1a98db-fd3b-43b8-97…”, publication_href: “/pulp/api/v3/publications/rpm/rpm/88404e0e-7ae3-44…”, version_href: “/pulp/api/v3/repositories/rpm/rpm/2027fbd0-f9f8-49…”>
irb(main):003:0> ForemanTasks.async_task(Actions::Pulp::Repository::DistributorPublish, :pulp_id => repo.pulp_id, :distributor_type_id => Runcible::Models::YumDistributor.type_id)
Traceback (most recent call last):
16: from foreman-tasks (3.0.5) lib/foreman_tasks.rb:23:in trigger' 15: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_taxonomies.rb:9:in plan’
14: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_taxonomies.rb:30:in with_current_taxonomies' 13: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_taxonomies.rb:10:in block in plan’
12: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_user.rb:9:in plan' 11: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_user.rb:31:in with_current_user’
10: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_user.rb:10:in block in plan' 9: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_timezone.rb:9:in plan’
8: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_timezone.rb:31:in with_current_timezone' 7: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_timezone.rb:10:in block in plan’
6: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_request_id.rb:9:in plan' 5: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_request_id.rb:31:in with_current_request_id’
4: from foreman-tasks (3.0.5) app/lib/actions/middleware/keep_current_request_id.rb:10:in block in plan' 3: from katello (3.18.2.1) app/lib/actions/middleware/remote_action.rb:9:in plan’
2: from katello (3.18.2.1) app/lib/actions/middleware/backend_services_check.rb:23:in plan' 1: from katello (3.18.2.1) app/lib/actions/pulp/repository/distributor_publish.rb:7:in plan’
ArgumentError (wrong number of arguments (given 1, expected 3))
irb(main):004:0>

So we can do the Content View metadata regeneration and proxy sync using hammer but hammer doesn’t seem to have an option to republish the metadata for a Product’s Repository. Therefore, we are trying to use the rake command. It is expecting some arguments but I am not sure what or how to pass those.

Foreman and Proxy versions:

Main Server:

root@katello02-> rpm -qa | egrep -i “foreman|katello”
katello-common-3.18.2-1.el7.noarch
foreman-installer-katello-2.3.4-1.el7.noarch
foreman-installer-2.3.4-1.el7.noarch
foreman-release-2.3.4-1.el7.noarch
tfm-rubygem-hammer_cli_foreman_bootdisk-0.3.0-1.el7.noarch
foreman-dynflow-sidekiq-2.3.4-1.el7.noarch
katello-client-bootstrap-1.7.5-1.el7.noarch
rubygem-foreman_maintain-0.7.9-1.el7.noarch
tfm-rubygem-foreman-tasks-core-0.3.4-1.fm2_1.el7.noarch
tfm-rubygem-katello-3.18.2.1-1.el7.noarch
pulp-katello-1.0.3-1.el7.noarch
katello-3.18.2-1.el7.noarch
katello-selinux-3.5.0-1.el7.noarch
foreman-2.3.4-1.el7.noarch
katello-server-ca-1.0-1.noarch
tfm-rubygem-hammer_cli_foreman_tasks-0.0.15-1.fm2_2.el7.noarch
foreman-debug-2.3.4-1.el7.noarch
katello-repos-3.18.2-1.el7.noarch
tfm-rubygem-foreman_remote_execution_core-1.4.0-1.el7.noarch
tfm-rubygem-foreman-tasks-3.0.5-1.fm2_3.el7.noarch
tfm-rubygem-hammer_cli_foreman-2.3.2-1.el7.noarch
foreman-postgresql-2.3.4-1.el7.noarch
foreman-selinux-2.3.4-1.el7.noarch
foreman-service-2.3.4-1.el7.noarch
foreman-proxy-2.3.4-1.el7.noarch
katello-default-ca-1.0-1.noarch
tfm-rubygem-hammer_cli_katello-0.24.3-1.el7.noarch
foreman-cli-2.3.4-1.el7.noarch
tfm-rubygem-foreman_remote_execution-4.2.2-1.fm2_3.el7.noarch
katello-debug-3.18.2-1.el7.noarch
katello-certs-tools-2.7.3-1.el7.noarch
tfm-rubygem-hammer_cli_foreman_docker-0.0.7-1.el7.noarch
[~]

Proxy:

rpm -qa | egrep -i ‘foreman|katello’ | grep -i -v aws

katello-default-ca-1.0-1.noarch

katello-repos-3.18.4-1.el7.noarch

katello-certs-tools-2.7.3-1.el7.noarch

foreman-installer-2.3.5-1.el7.noarch

katello-debug-3.18.4-1.el7.noarch

katello-server-ca-1.0-1.noarch

foreman-release-2.3.5-1.el7.noarch

rubygem-foreman_maintain-0.7.10-1.el7.noarch

foreman-proxy-content-3.18.4-1.el7.noarch

katello-client-bootstrap-1.7.5-1.el7.noarch

foreman-debug-2.3.5-1.el7.noarch

foreman-installer-katello-2.3.5-1.el7.noarch

katello-common-3.18.4-1.el7.noarch

foreman-proxy-2.3.5-1.el7.noarch

Distribution and version:

CentOS Linux release 7.9.2009 (Core)

Thank you very much,

Eledor

Hi @eledor,

According to this method signature, could you try modify

ForemanTasks.async_task(Actions::Pulp::Repository::DistributorPublish, :pulp_id => repo.pulp_id, :distributor_type_id => Runcible::Models::YumDistributor.type_id, :override_config => {:force_full => true})

to something like:

ForemanTasks.async_task(Actions::Pulp::Repository::DistributorPublish, repo, repo.pulp, :pulp_id => repo.pulp_id, :distributor_type_id => Runcible::Models::YumDistributor.type_id, :override_config => {:force_full => true})

Let me know how it works.
Thanks.

Hi there,

Thank you so much for your reply.

I issued the command you suggested and I think we are closer but it errors out with:

irb(main):003:0> ForemanTasks.async_task(Actions::Pulp::Repository::DistributorPublish, repo, repo.pulp, :pulp_id => repo.pulp_id, :distributor_type_id => Runcible::Models::YumDistributor.type_id, :override_config => {:force_full => true})
Traceback (most recent call last):
2: from lib/tasks/console.rake:5:in block in <top (required)>' 1: from (irb):3 NoMethodError (undefined method pulp’ for #Katello::Repository:0x000000000e3a5d00)
Did you mean? pulp_id
irb(main):004:0>

Cheers,

Eledor

Sorry, the command should be:

ForemanTasks.async_task(Actions::Pulp::Repository::DistributorPublish, repo, smart_proxy, :pulp_id => repo.pulp_id, :distributor_type_id => Runcible::Models::YumDistributor.type_id, :override_config => {:force_full => true})

The second argument is the smart_proxy in your system.

Hi @lfu

No worries, you are the one helping me… So i think I just don’t know ruby is part of my problem here.

I think we are creating an object with:

repo = Katello::Repository.find(99)

right?

And then this is a method:

ForemanTasks.async_task(Actions::Pulp::Repository::DistributorPublish, repo, smart_proxy, :pulp_id => repo.pulp_id, :distributor_type_id => Runcible::Models::YumDistributor.type_id, :override_config => {:force_full => true})

To which we pass arguments to, right?

I am not sure what it wants for smart_proxy… I have tried various iterations of things but it errors out every time.

Would you please be able to provide an example using a Smart Proxy with an ID of 4?

here is an example of what i tried:

irb(main):023:0> ForemanTasks.async_task(Actions::Pulp::Repository::DistributorPublish, repo, smart_proxy, :pulp_id => repo.pulp_id, :smart_proxy_id => 4, :distributor_type_id => Runcible::Models::YumDistributor.type_id, :override_config => {:force_full => true})
Traceback (most recent call last):
2: from lib/tasks/console.rake:5:in block in <top (required)>' 1: from (irb):23 NameError (undefined local variable or method smart_proxy’ for main:Object)
irb(main):024:0>

repo is the repository you want to publish.

Use smart_proxy = SmartProxy.pulp_primary if there is only one smart proxy.
Or SmartProxy.all to find out the id of the proxy you want to use then smart_proxy = SmartProxy.find(<id>) to get the object.

Then call ForemanTasks.async_task with all the parameters.

Good luck!

Hi @lfu

Cool, that worked!

Thanks a lot!!!