Skip to content

Introduce special handling of distro context#4895

Draft
LecrisUT wants to merge 5 commits into
teemtee:mainfrom
LecrisUT:feat/distro-context
Draft

Introduce special handling of distro context#4895
LecrisUT wants to merge 5 commits into
teemtee:mainfrom
LecrisUT:feat/distro-context

Conversation

@LecrisUT
Copy link
Copy Markdown
Member

A special handling for distro is needed because there are cross-distro validations that should be true like fedora-eln == centos or centos-stream-10 == rhel-10.

Depends-on #4894


Pull Request Checklist

  • implement the feature
  • write the documentation
  • extend the test coverage
  • update the specification
  • mention the version
  • include a release note

LecrisUT added 5 commits May 13, 2026 15:39
Signed-off-by: Cristian Le <git@lecris.dev>
Signed-off-by: Cristian Le <git@lecris.dev>
Signed-off-by: Cristian Le <git@lecris.dev>
Signed-off-by: Cristian Le <git@lecris.dev>
Signed-off-by: Cristian Le <git@lecris.dev>
@LecrisUT LecrisUT added status | blocked The merging of PR is blocked on some other issue area | context The context adjust implementation ci | full test Pull request is ready for the full test execution labels May 18, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a custom TmtContext and a plugin-based distro context system to support advanced distribution comparisons for CentOS, Fedora, and RHEL. It migrates existing context usage to TmtContext, which now handles case-insensitivity by default. Feedback identifies a regex typo in the CentOS pattern and logic errors in CentOS and RHEL comparison methods that prevent correct cross-distro equality matching and cause asymmetric results.

@provides_distro_context("centos")
@container
class CentosDistro(RhelLikeDistro):
_DISTRO_PATTERN = re.compile(r"^centos-?(?P<stream>stream)?-?(?P<version>[\d.]*])$")
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.

high

The regular expression for CentOS distros contains a typo: a literal ] is included at the end of the version named group. This will cause the pattern to fail for standard CentOS names like centos-9, causing them to fall back to UnknownDistro and lose specific comparison logic.

Suggested change
_DISTRO_PATTERN = re.compile(r"^centos-?(?P<stream>stream)?-?(?P<version>[\d.]*])$")
_DISTRO_PATTERN = re.compile(r"^centos-?(?P<stream>stream)?-?(?P<version>[\d.]*)$")

Comment on lines +60 to +64
# centos < rhel with higher version
if version_comp == -1:
return -1
# centos > rhel with same version or lower
return 1
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.

high

The comparison logic returns 1 when versions are equal (version_comp == 0), which means centos-stream-10 == rhel-10 will evaluate to False. This contradicts the PR description which explicitly states that such cross-distro validations should be true.

Suggested change
# centos < rhel with higher version
if version_comp == -1:
return -1
# centos > rhel with same version or lower
return 1
# centos < rhel with higher version
if version_comp == -1:
return -1
# centos == rhel with same version
if version_comp == 0:
return 0
# centos > rhel with lower version
return 1

Comment on lines +42 to +47
# rhel > centos with lower version
if version_comp == 1:
return 1

# rhel < centos with same version or higher
return -1
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.

high

This logic returns -1 when versions are equal, meaning rhel-10 == centos-10 will be False. To align with the PR's goal of supporting cross-distro equality, it should return 0 when the versions match.

Suggested change
# rhel > centos with lower version
if version_comp == 1:
return 1
# rhel < centos with same version or higher
return -1
# rhel > centos with lower version
if version_comp == 1:
return 1
# rhel == centos with same version
if version_comp == 0:
return 0
# rhel < centos with higher version
return -1

assert other.version is None # narrow type

# rhel is only rhel
return other.family == "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.

medium

The unversioned equality check is asymmetric: CentosDistro considers itself equal to rhel, but RhelDistro does not consider itself equal to centos. While this might reflect a one-way compatibility (CentOS as a superset of RHEL), it can lead to confusing results in context matching where == is expected to be symmetric.

Suggested change
return other.family == "rhel"
return other.family in ("rhel", "centos")

@happz happz added this to planning May 20, 2026
@github-project-automation github-project-automation Bot moved this to backlog in planning May 20, 2026
@happz happz moved this from backlog to implement in planning May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area | context The context adjust implementation ci | full test Pull request is ready for the full test execution status | blocked The merging of PR is blocked on some other issue

Projects

Status: implement

Development

Successfully merging this pull request may close these issues.

2 participants