Skip to content

OCPBUGS-88726: Fix streams in imagemode tests#6195

Open
sergiordlr wants to merge 2 commits into
openshift:mainfrom
sergiordlr:fix_streams_in_imagemode_tests
Open

OCPBUGS-88726: Fix streams in imagemode tests#6195
sergiordlr wants to merge 2 commits into
openshift:mainfrom
sergiordlr:fix_streams_in_imagemode_tests

Conversation

@sergiordlr

@sergiordlr sergiordlr commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

- What I did
I made tests to take into account the osImageStream to select the centos stream when they use it create a containerfile

- How to verify it

Modified tests should pass

Summary by CodeRabbit

  • Tests

    • Enhanced OS image stream test coverage to dynamically support both RHEL 9 and RHEL 10 configurations.
    • Expanded test variants for improved stream compatibility testing and upgrade scenarios.
    • Improved test intelligence to adapt based on cluster's default OS image stream.
  • Chores

    • Removed deprecated default OS image stream constant.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Walkthrough

Removes the static DefaultOSImageStream constant and replaces it with three new exported helpers that derive the default OS image stream and its major version from the live cluster version. Tests in mco_osimagestream.go, mco_metrics.go, and mco_ocb.go are updated to use these helpers, and new disruptive cross-stream test directions (rhel9↔rhel10) are added.

Changes

Dynamic OS Image Stream Detection

Layer / File(s) Summary
Remove static default; add dynamic stream helpers
test/extended-priv/const.go, test/extended-priv/mco_osimagestream.go
Deletes DefaultOSImageStream constant. Adds GetDefaultOSImageStream (derives default from cluster version), GetOSImageStreamMajorVersion (extracts RHEL major version string from a stream name), and SkipIfDefaultOSImageStream. Updates GetEffectiveOsImageStream to call the new dynamic helper instead of the removed constant.
OS image stream tests: dynamic defaults and new cross-stream variants
test/extended-priv/mco_osimagestream.go
Updates the default-stream validation test to call GetDefaultOSImageStream. Adds SkipIfDefaultOSImageStream guards to existing rhel9→rhel10 tests and introduces new disruptive test cases for realtime-kernel (rhel10→rhel9), 64k-pages (rhel10→rhel9), and extensions (both directions) with new Polarion IDs.
Metrics and OCB tests: dynamic EPEL and containerfile generation
test/extended-priv/mco_metrics.go, test/extended-priv/mco_ocb.go
mco_metrics.go derives majorVersion via GetOSImageStreamMajorVersion and constructs EPEL RPM URL/filename dynamically. mco_ocb.go replaces a hardcoded containerfile with getConnectedCustomContainerFileContent(mcp), a new private helper that uses the effective OS image stream to build a per-stream containerfile including ncurses override and EPEL steps.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • openshift/machine-config-operator#6161: Both PRs modify test/extended-priv/mco_ocb.go to conditionally generate custom containerfile content — this PR based on the effective OS image stream for connected clusters, the related PR based on IPv6-only/disconnected behavior.

Suggested labels

jira/valid-bug, jira/valid-reference

Suggested reviewers

  • pablintino
  • yuqi-zhang
🚥 Pre-merge checks | ✅ 13 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Test Structure And Quality ⚠️ Warning GetOSImageStreamMajorVersion lacks input validation; empty/invalid stream values could produce malformed repo URLs and containerfile content without error detection, violating assertion quality and... Add validation to GetOSImageStreamMajorVersion: check stream is not empty and starts with "rhel-", using o.Expect assertions to fail fast with clear error messages on invalid input.
Ipv6 And Disconnected Network Test Compatibility ⚠️ Warning mco_metrics.go test downloads from public repositories (dl.fedoraproject.org, mirrors.rpmfusion.org) without disconnected environment checks and hardcodes version '9' in line 111. Add [Skipped:Disconnected] to test name at line 27, or add IsDisconnectedCluster() check. Replace hardcoded rpmfusion-9 with dynamic majorVersion to match the EPEL download logic.
✅ Passed checks (13 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed All Ginkgo test names in modified files (mco_metrics.go, mco_ocb.go, mco_osimagestream.go) use stable, deterministic string literals with no dynamic information that changes between runs.
Microshift Test Compatibility ✅ Passed The PR modifies existing tests and adds helper functions, but does NOT add new Ginkgo test cases (It/Describe/Context/When blocks). mco_osimagestream.go tests already have [apigroup:machineconfigur...
Single Node Openshift (Sno) Test Compatibility ✅ Passed New Ginkgo tests added to mco_osimagestream.go use SNO-safe helper functions (GetPoolAndNodesForArchitectureOrFail, GetCompactCompatibleOrCustomPool) that internally check IsCompactOrSNOCluster and...
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only test code (test/extended-priv/*.go) with no deployment manifests, operator code, or controllers introducing scheduling constraints that assume HA topology.
Ote Binary Stdout Contract ✅ Passed All logging and stdout writes are contained within test functions (g.It, g.JustBeforeEach, helper functions called from tests). Logger implementation correctly redirects output to GinkgoWriter. No...
No-Weak-Crypto ✅ Passed No weak cryptographic patterns detected. The PR modifies test files to use dynamic OS image stream selection (rhel-9/rhel-10) without introducing MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB, custom cr...
Container-Privileges ✅ Passed PR modifies only Go test files with no container/K8s manifests containing privileged configurations. The custom check for privileged containers is not applicable to this test code.
No-Sensitive-Data-In-Logs ✅ Passed All logging statements in the modified files only log non-sensitive data (stream names, status messages). No passwords, tokens, credentials, PII, or environment variables with sensitive values are...
Title check ✅ Passed The PR title 'OCPBUGS-88726: Fix streams in imagemode tests' directly addresses the main change - fixing stream handling in Image Mode tests by accounting for osImageStream in test selection and containerfile creation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci

openshift-ci Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sergiordlr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 16, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/extended-priv/mco_ocb.go (1)

494-526: 💤 Low value

Containerfile generation silently tolerates ncurses override failures.

Line 523 includes || true after the rpm-ostree override replace command, which silently ignores all errors from the ncurses override step. While this may be intentional to handle version mismatches across streams, it could also hide legitimate failures (e.g., network issues, authentication problems, or repo configuration errors).

Consider logging a warning or verifying the override succeeded when it's expected to work, rather than unconditionally suppressing all errors.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/extended-priv/mco_ocb.go` around lines 494 - 526, The containerfile
content generated by the getConnectedCustomContainerFileContent function uses
`|| true` after the `rpm-ostree override replace` command, which silently
suppresses all errors including legitimate failures like network issues or repo
configuration errors. Modify the Containerfile string to either remove the `||
true` to allow the build to fail on actual errors, or add logging within the
Containerfile itself (using a shell conditional) to document why the override
failure is being tolerated. Ensure the approach clearly distinguishes between
intentional version mismatch handling and actual failures that should not be
hidden.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/extended-priv/mco_osimagestream.go`:
- Around line 308-311: The GetOSImageStreamMajorVersion function lacks input
validation and will return an empty or malformed string if the stream parameter
is empty or doesn't start with "rhel-". Add validation at the beginning of the
function to check that stream is not empty and actually starts with the "rhel-"
prefix before calling strings.TrimPrefix. If the validation fails, return an
empty string or handle the error appropriately to prevent downstream failures in
dependent code.

---

Nitpick comments:
In `@test/extended-priv/mco_ocb.go`:
- Around line 494-526: The containerfile content generated by the
getConnectedCustomContainerFileContent function uses `|| true` after the
`rpm-ostree override replace` command, which silently suppresses all errors
including legitimate failures like network issues or repo configuration errors.
Modify the Containerfile string to either remove the `|| true` to allow the
build to fail on actual errors, or add logging within the Containerfile itself
(using a shell conditional) to document why the override failure is being
tolerated. Ensure the approach clearly distinguishes between intentional version
mismatch handling and actual failures that should not be hidden.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: cda77102-e86f-4d4f-b288-2fa6ee999ccc

📥 Commits

Reviewing files that changed from the base of the PR and between 49eaf75 and ecf9235.

📒 Files selected for processing (4)
  • test/extended-priv/const.go
  • test/extended-priv/mco_metrics.go
  • test/extended-priv/mco_ocb.go
  • test/extended-priv/mco_osimagestream.go
💤 Files with no reviewable changes (1)
  • test/extended-priv/const.go

Comment on lines +308 to +311
// GetOSImageStreamMajorVersion extracts the major version from a stream name (e.g. "rhel-9" -> "9", "rhel-10" -> "10").
func GetOSImageStreamMajorVersion(stream string) string {
return strings.TrimPrefix(stream, "rhel-")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Missing validation in stream major version extraction.

GetOSImageStreamMajorVersion calls strings.TrimPrefix without validating the input format. If stream is empty or doesn't start with "rhel-", it returns an empty or malformed string, causing downstream failures (e.g., invalid CentOS repo URLs in mco_metrics.go line 37, invalid containerfile in mco_ocb.go line 506).

🛡️ Proposed fix with validation
-// GetOSImageStreamMajorVersion extracts the major version from a stream name (e.g. "rhel-9" -> "9", "rhel-10" -> "10").
+// GetOSImageStreamMajorVersion extracts the major version from a stream name (e.g. "rhel-9" -> "9", "rhel-10" -> "10").
+// It validates the stream name format and panics if the input is invalid.
 func GetOSImageStreamMajorVersion(stream string) string {
+	o.Expect(stream).NotTo(o.BeEmpty(), "Stream name cannot be empty")
+	o.Expect(stream).To(o.HavePrefix("rhel-"), "Stream name must start with 'rhel-', got: %s", stream)
 	return strings.TrimPrefix(stream, "rhel-")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// GetOSImageStreamMajorVersion extracts the major version from a stream name (e.g. "rhel-9" -> "9", "rhel-10" -> "10").
func GetOSImageStreamMajorVersion(stream string) string {
return strings.TrimPrefix(stream, "rhel-")
}
// GetOSImageStreamMajorVersion extracts the major version from a stream name (e.g. "rhel-9" -> "9", "rhel-10" -> "10").
// Returns an error if the stream name format is invalid.
func GetOSImageStreamMajorVersion(stream string) (string, error) {
if stream == "" {
return "", fmt.Errorf("stream name cannot be empty")
}
if !strings.HasPrefix(stream, "rhel-") {
return "", fmt.Errorf("stream name must start with 'rhel-', got: %s", stream)
}
return strings.TrimPrefix(stream, "rhel-"), nil
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/extended-priv/mco_osimagestream.go` around lines 308 - 311, The
GetOSImageStreamMajorVersion function lacks input validation and will return an
empty or malformed string if the stream parameter is empty or doesn't start with
"rhel-". Add validation at the beginning of the function to check that stream is
not empty and actually starts with the "rhel-" prefix before calling
strings.TrimPrefix. If the validation fails, return an empty string or handle
the error appropriately to prevent downstream failures in dependent code.

@openshift-ci

openshift-ci Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@sergiordlr: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@sergiordlr sergiordlr changed the title Fix streams in imagemode tests OCPBUGS-88726: Fix streams in imagemode tests Jun 16, 2026
@openshift-ci-robot openshift-ci-robot added jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Jun 16, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@sergiordlr: This pull request references Jira Issue OCPBUGS-88726, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

- What I did
I made tests to take into account the osImageStream to select the centos stream when they use it create a containerfile

- How to verify it

Modified tests should pass

Summary by CodeRabbit

  • Tests

  • Enhanced OS image stream test coverage to dynamically support both RHEL 9 and RHEL 10 configurations.

  • Expanded test variants for improved stream compatibility testing and upgrade scenarios.

  • Improved test intelligence to adapt based on cluster's default OS image stream.

  • Chores

  • Removed deprecated default OS image stream constant.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants