Skip to content

Improve chroot guessing on EL#586

Open
ekohl wants to merge 5 commits intorpm-software-management:masterfrom
ekohl:copr-guess-el
Open

Improve chroot guessing on EL#586
ekohl wants to merge 5 commits intorpm-software-management:masterfrom
ekohl:copr-guess-el

Conversation

@ekohl
Copy link
Copy Markdown

@ekohl ekohl commented Jun 21, 2025

When a project is not built in the epel buildroot but instead in centos-stream or rhel the command copr enable $copr will fail.

Copr can provide available chroots when a repository is not found and this information is already shown to the user. we can improve our guessing with this information when a user hasn't provided the chroot.

The result is that it'll always prefer epel, but can also use the centos-stream or the rhel buildroot when available. This makes it easier for projects that build without EPEL.

The PR is organized into some refactoring commits that shouldn't affect anything. The result is that the final commit actually making the change is relatively small. I've chosen to first attempt the primary guess instead of probing for available repos first. This should result in lower server load for copr because in the majority of cases the guess is still valid.

This is an alternative take on #525.

Fixes #524

ekohl added 5 commits June 21, 2025 15:55
The DNF repository download accepts the full chroot name and doesn't
need the arch to be passed in via a separate parameter. Non-existing
chroots will be reported as well.

There's no need to have the chroot parts as an instance variable if it's
only used once so this also passes it in as a parameter.
Copr can provide available chroots when a repository is not found. When
a user hasn't provided the chroot, we can improve our guessing.

The result is that it'll always prefer epel, but can also use the
centos-stream or rhel buildroot when available. This makes it easier for
projects that build without EPEL.

This is an alternative take on 313470b.
@ekohl
Copy link
Copy Markdown
Author

ekohl commented Jun 21, 2025

Verified on a plain CentOS Stream 9. Reproducer of the problem:

# dnf install -y -q dnf-plugins-core
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <[email protected]>"
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

Installed:
  dbus-libs-1:1.12.20-8.el9.x86_64     dnf-plugins-core-4.3.0-21.el9.noarch            python3-dateutil-1:2.8.1-7.el9.noarch   
  python3-dbus-1.2.18-2.el9.x86_64     python3-dnf-plugins-core-4.3.0-21.el9.noarch    python3-six-1.15.0-9.el9.noarch         
  python3-systemd-234-19.el9.x86_64    systemd-libs-252-53.el9.x86_64                 

# dnf copr enable -y @theforeman/foremanctl
Enabling a Copr repository. Please note that this repository is not part
of the main distribution, and quality may vary.

The Fedora Project does not exercise any power over the contents of
this repository beyond the rules outlined in the Copr FAQ at
<https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr>,
and packages are not held to any quality or security level.

Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.
Error: It wasn't possible to enable this project.
Repository 'epel-9-x86_64' does not exist in project '@theforeman/foremanctl'.
Available repositories: 'fedora-rawhide-x86_64', 'centos-stream-9-x86_64', 'fedora-42-x86_64', 'rhel-9-x86_64', 'fedora-41-x86_64'

If you want to enable a non-default repository, use the following command:
  'dnf copr enable @theforeman/foremanctl <repository>'
But note that the installed repo file will likely need a manual modification.

Now with the patch applied:

# dnf install -y -q patch

Installed:
  ed-1.14.2-12.el9.x86_64                  info-6.7-15.el9.x86_64                  patch-2.7.6-16.el9.x86_64                 

# cd /usr/lib/python3.9/site-packages/dnf-plugins
# curl -L https://github.com/rpm-software-management/dnf-plugins-core/pull/586.patch | patch -p2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 13162  100 13162    0     0  27709      0 --:--:-- --:--:-- --:--:-- 55535
patching file copr.py
Hunk #1 succeeded at 244 (offset -19 lines).
Hunk #2 succeeded at 292 (offset -19 lines).
Hunk #3 succeeded at 472 (offset -21 lines).
Hunk #4 succeeded at 489 (offset -21 lines).
Hunk #5 succeeded at 684 (offset -21 lines).
patching file copr.py
Hunk #1 succeeded at 477 (offset -21 lines).
Hunk #2 succeeded at 503 (offset -21 lines).
patching file copr.py
Hunk #1 succeeded at 472 (offset -21 lines).
Hunk #2 succeeded at 503 (offset -21 lines).
patching file copr.py
Hunk #1 succeeded at 249 (offset -19 lines).
Hunk #2 succeeded at 505 (offset -21 lines).
patching file copr.py
Hunk #1 succeeded at 77 (offset -1 lines).
Hunk #2 succeeded at 442 (offset -19 lines).
Hunk #3 succeeded at 476 with fuzz 2 (offset -21 lines).
Hunk #4 succeeded at 508 (offset -21 lines).
Hunk #5 succeeded at 529 (offset -21 lines).
# dnf copr enable -y @theforeman/foremanctl
Enabling a Copr repository. Please note that this repository is not part
of the main distribution, and quality may vary.

The Fedora Project does not exercise any power over the contents of
this repository beyond the rules outlined in the Copr FAQ at
<https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr>,
and packages are not held to any quality or security level.

Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.
Repository successfully enabled.
# cat /etc/yum.repos.d/
_copr:copr.fedorainfracloud.org:group_theforeman:foremanctl.repo
centos-addons.repo
centos.repo
# cat /etc/yum.repos.d/_copr\:copr.fedorainfracloud.org\:group_theforeman\:foremanctl.repo 
[copr:copr.fedorainfracloud.org:group_theforeman:foremanctl]
name=Copr repo for foremanctl owned by @theforeman
baseurl=https://download.copr.fedorainfracloud.org/results/@theforeman/foremanctl/centos-stream-$releasever-$basearch/
type=rpm-md
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://download.copr.fedorainfracloud.org/results/@theforeman/foremanctl/pubkey.gpg
repo_gpgcheck=0
enabled=1
enabled_metadata=1

Then on AlmaLinux 9 with the patch applied:

# dnf copr enable -y @theforeman/foremanctl
Enabling a Copr repository. Please note that this repository is not part
of the main distribution, and quality may vary.

The Fedora Project does not exercise any power over the contents of
this repository beyond the rules outlined in the Copr FAQ at
<https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr>,
and packages are not held to any quality or security level.

Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.
Repository successfully enabled.
# cat /etc/yum.repos.d/_copr\:copr.fedorainfracloud.org\:group_theforeman\:foremanctl.repo
[copr:copr.fedorainfracloud.org:group_theforeman:foremanctl]
name=Copr repo for foremanctl owned by @theforeman
baseurl=https://download.copr.fedorainfracloud.org/results/@theforeman/foremanctl/rhel-9-$basearch/
type=rpm-md
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://download.copr.fedorainfracloud.org/results/@theforeman/foremanctl/pubkey.gpg
repo_gpgcheck=0
enabled=1
enabled_metadata=1

Note how it chose the correct buildroot: centos-stream on CentOS Stream and rhel on AlmaLinux.

@ekohl ekohl marked this pull request as ready for review June 21, 2025 14:14
@ekohl ekohl requested a review from a team as a code owner June 21, 2025 14:14
@ekohl ekohl requested review from pkratoch and removed request for a team June 21, 2025 14:14
Comment on lines +504 to +506
guesses = ['epel', 'rhel']
if "CentOS Stream" in dist:
guesses.insert(1, 'centos-stream')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#525 (comment) showed me there's also the centos-stream+epel-next chroot. Should we support that too?

Suggested change
guesses = ['epel', 'rhel']
if "CentOS Stream" in dist:
guesses.insert(1, 'centos-stream')
if "CentOS Stream" in dist:
guesses = ['centos-stream+epel-next', 'epel', 'centos-stream', 'rhel']
else:
guesses = ['epel', 'rhel']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The centos-stream+epel-next chroots are tricky. For versions 8 and 9 (the only ones we have EPEL Next), real systems should be one of:

  • RHEL + EPEL
  • CentOS Stream + EPEL + EPEL Next

But in mock-core-configs we have all of these:

  • rhel+epel
  • centos-stream+epel
  • centos-stream+epel-next

For versions 8 and 9, EPEL on CentOS Stream means both EPEL and EPEL Next. Using only EPEL without EPEL Next on CentOS Stream is not valid and will result in uninstallable packages (albeit rarely). I think the centos-stream+epel-next chroots should be retired and centos-stream+epel chroots should be updated to also include the epel-next template (matching what centos-stream+epel-next is now). If we do that, there won't be any need to include logic in the copr plugin for centos-stream+epel-next.

Also, EPEL 8 Next is already EOL, EPEL 9 Next goes EOL in about two years, and EPEL 10 uses a totally different structure that obsoletes EPEL Next.

@carlwgeorge
Copy link
Copy Markdown
Contributor

Thanks for working on this! I'd definitely like to see something like this implemented. The current logic makes sense for EPEL 8/9, but I think it's not quite right for EPEL 10. The epel-10 chroot is actually centos-stream+epel-10. This chroot will often (but not always) work fine on RHEL 10, but rhel+epel-10 is the better first choice. Because of this I don't think we should make the initial assumption of the epel chroot being the best one. If we ignore the "make an initial assumption to usually avoid fetching the available chroots" idea for a moment, this is how I envision the priority order for each distro.

  • RHEL 9 (same logic for RHEL 8)
    • epel-9 (rhel+epel-9)
    • rhel-9
    • centos-stream+epel-next-9
    • centos-stream-9
  • CentOS Stream 9 (same logic for CentOS Stream 8, although it's already EOL)
    • centos-stream+epel-next-9
    • centos-stream-9
    • epel-9 (rhel+epel-9)
    • rhel-9
  • RHEL 10
    • rhel+epel-10
    • rhel-10
    • epel-10 (centos-stream+epel-10)
    • centos-stream-10
  • CentOS Stream 10
    • epel-10 (centos-stream+epel-10)
    • centos-stream-10
    • rhel+epel-10
    • rhel-10

I don't know if it's worth the effort to assume the first option for each distro and then check for alternatives, or if we should just fetch the available chroots first and then pick the best one.

@ekohl
Copy link
Copy Markdown
Author

ekohl commented Jul 14, 2025

@carlwgeorge thanks for the vision piece. I think you clearly identified I was still firmly in the EPEL 8/9 mindset.

I don't know if it's worth the effort to assume the first option for each distro and then check for alternatives, or if we should just fetch the available chroots first and then pick the best one.

There could be some COPR service load impact, though it's probably quite cheap. Still, perhaps worth checking with the COPR maintainers?

I would still like to see this implemented, but am currently busy. If anyone wants to pick this up and address @carlwgeorge's concerns then please.

@praiskup praiskup moved this to Needs triage in CPT Kanban Aug 1, 2025
@praiskup
Copy link
Copy Markdown
Member

praiskup commented Aug 1, 2025

perhaps worth checking with the COPR maintainers?

I added this PR on team's kanban, we should get to the review soon.

@praiskup
Copy link
Copy Markdown
Member

praiskup commented Aug 1, 2025

Not a review, just a note. Have you looked at the api for DNF5?

Example call: https://copr.fedorainfracloud.org/api_3/rpmrepo/@copr/copr-pull-requests/fedora-rawhide-x86_64

That gives you a full introspection into given Copr repository via a single API query. The problem is that the query isn't actually generating repofile (that is a task for the client).

My assumption was that it's too late to implement the same thing in dnf-plugins-core, because Fedora has already moved to DNF5 and getting such a huge change into Enterprise Linux packages would be complicated.

@praiskup praiskup moved this from Needs triage to In 3 months in CPT Kanban Aug 6, 2025
@praiskup praiskup moved this from In 3 months to Needs triage in CPT Kanban Aug 6, 2025
@nikromen nikromen moved this from Needs triage to In Progress in CPT Kanban Aug 11, 2025
@praiskup praiskup removed this from CPT Kanban Aug 13, 2025
@nikromen
Copy link
Copy Markdown

Hi @ ekohl thanks for working on this. The main logic change in 9caeff1 looks good to me. If it increase user friendliness for folks using the plugin on centos +1.

I also afree with what @ carlwgeorge mentioned about epel next, that would be good for e.g. follow-up PR.

But one thing from my side as a Copr maintainer: I don't like the refactoring commits. The current code might not be perfect, but it works, and from a perspective of someone who should maintain this code, but doesn't actively participate in this repo: if it works, no touchy! :D But if something will go wrong with it and it would be fixed by someone else (I doubt that) , then I don't mind, so I'd lean towards keeping the changes minimal.

There could be some COPR service load impact, though it's probably quite cheap.

I don't think that's an issue, copr can handle it, the impact will be minimal I think.

Example call: https://copr.fedorainfracloud.org/api_3/rpmrepo/@copr/copr-pull-requests/fedora-rawhide-x86_64

That gives you a full introspection into given Copr repository via a single API query. The problem is that the query isn't actually generating repofile (that is a task for the client).

I agree with Pavel here, all the info can be found via one API call here if it is necesarry for implementing the more complex part with the epel next.

So overall from me, +1 to the 9caeff1 and small -1 to the refactoring unless it won't backfire on us :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

copr plugin: _guess_chroot does not handle centos stream properly

4 participants