Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override releasever_{major,minor} with system-release provides #2198

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

evan-goode
Copy link
Member

@evan-goode evan-goode commented Jan 21, 2025

The releasever_major and releasever_minor substitution variables are usually derived by splitting releasever on the first .. However, to support EPEL 10 [1], we would like a way for distributions to override these values. Specifically, we would like RHEL 10 to have a releasever of 10 with a releasever_major of 10 and a releasever_minor of 0 (later incrementing to 1, 2, to correspond with the RHEL minor version).

This commit adds a new API function, detect_releasevers, which derives releasever, releasever_major, and releasever_minor from virtual provides on the system-release package (any of DISTROVERPKG). The detection of releasever is unchanged. releasever_major and releasever_minor are specified by the versions of the system-release-major and system-release-minor provides, respectively.

If the user specifies a --releasever=X.Y on the command line, the distribution settings for releasever, releasever_major, and releasever_minor will all be overridden: releasever will be set to X.Y, releasever_major will be set to X, and releasever_minor will be set to Y, same as before.

If a user wants to specify a custom releasever_{major,minor}, they have to set all three with --setopt=releasever=X --setopt=releasever_major=Y --setopt=releasever_minor=z, taking care to put releasever_major and releasever_minor after releasever so they are not overridden. This is admittedly not ideal, but I can't think of another solution to this problem that preserves the following properties:

  1. If they are not overridden, releasever_{major,minor} are derived by splitting releasever. This behavior was added in Split $releasever to $releasever_major and $releasever_minor #1989.
  2. If --releasever is specified on the command line, releasever_{major,minor} should be set accordingly, even if releasever{major_minor} are specified by provides in the distribution system-release package.
  3. The user should somehow be able to specify their own custom releasever, releasever_major, and releasever_minor.

Maybe we could add --releasever_major= and --releasever_minor options that take priority over --releasever to improve point (3).

Another caveat to allowing overriding releasever_{major,minor} is existing API users using detect_releasever. Take this snippet from our doc/examples/install_extension.py:

    with dnf.Base() as base:
        # Substitutions are needed for correct interpretation of repo files.
        RELEASEVER = dnf.rpm.detect_releasever(base.conf.installroot)
        base.conf.substitutions['releasever'] = RELEASEVER

Now, in order to detect the correct releasever_{major,minor}, the correct code would be

    with dnf.Base() as base:
        # Substitutions are needed for correct interpretation of repo files.
        RELEASEVER, MAJOR, MINOR = dnf.rpm.detect_releasevers(base.conf.installroot)
        base.conf.substitutions['releasever'] = RELEASEVER
        if MAJOR is not None:
            base.conf.substitutions['releasever_major']
        if MINOR is not None:
            base.conf.substitutions['releasever_minor']

Requires rpm-software-management/libdnf#1689.

[1] https://issues.redhat.com/browse/RHEL-68034

This allows setting a releasever_major or releasever_minor
independent of releasever, which is needed by EPEL.

Related: https://issues.redhat.com/browse/RHEL-68034
dnf/const.py.in Outdated
@@ -25,6 +25,8 @@ CONF_AUTOMATIC_FILENAME='/etc/dnf/automatic.conf'
DISTROVERPKG=('system-release(releasever)', 'system-release',
'distribution-release(releasever)', 'distribution-release',
'redhat-release', 'suse-release')
DISTROVER_MAJOR_PKG='system-release-major'
DISTROVER_MINOR_PKG='system-release-minor'
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make more sense to use system-release(releasever_major) and system-release(releasever_minor) for the provides for consistency with the existing system-release(releasever)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes, those are better, I changed it. DNF respects either system-release or system-release(releasever) but looks like libdnf's dnf_context_set_os_release only looks at system-release(releasever) and not system-release.

The releasever_major and releasever_minor substitution variables are
usually derived by splitting releasever on the first `.`. However, to
support EPEL 10 [1], we would like a way for distributions to override these
values. Specifically, we would like RHEL 10 to have a releasever of `10`
with a releasever_major of `10` and a releasever_minor of `0` (later
incrementing to `1`, `2`, to correspond with the RHEL minor version).

This commit adds a new API function, `detect_releasevers`, which derives
releasever, releasever_major, and releasever_minor from virtual provides
on the system-release package (any of `DISTROVERPKG`). The detection of
releasever is unchanged. releasever_major and releasever_minor are
specified by the versions of the `system-release-major` and
`system-release-minor` provides, respectively.

If the user specifies a `--releasever=X.Y` on the command line, the
distribution settings for releasever, releasever_major, and releasever_minor
will all be overridden: releasever will be set to X.Y, releasever_major will be
set to X, and releasever_minor will be set to Y, same as before.  If a user
wants to specify a custom releasever_major and releasever_minor, they have to
set all three with `--setopt=releasever=X --setopt=releasever_major=Y
--setopt=releasever_minor=z`, taking care to put `releasever_major` and
`releasever_minor` after `releasever` so they are not overridden.

[1] https://issues.redhat.com/browse/RHEL-68034
@evan-goode evan-goode force-pushed the evan-goode/provide-releasever-major-minor branch from 1a54f5b to 4872d0a Compare January 22, 2025 18:55
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.

2 participants