Skip to content

Conversation

@vamsikrishna-siddu
Copy link
Contributor

@vamsikrishna-siddu vamsikrishna-siddu commented Sep 23, 2025

Short description:

The Current implementation of valid_cdi_certificate assumes the local time on the server where we run the tests is utc. But the timezone can be different in machine we are running the tests. So I have changed the function to use utc timezone as the certificate before and after times are in utc.

More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
jira-ticket:

Summary by CodeRabbit

  • Bug Fixes

    • Corrected certificate validity checks to use timezone-aware UTC comparisons, avoiding incorrect expired/not-yet-valid results across time zones.
  • Tests

    • Updated tests to use UTC-aware datetime parsing and comparisons for consistent, reliable validation behavior.

@coderabbitai
Copy link

coderabbitai bot commented Sep 23, 2025

Walkthrough

Replaced time-based parsing and naive timestamps in a test with timezone-aware UTC datetime parsing and comparisons; removed the time import and now obtains current time via datetime.datetime.now(datetime.timezone.utc) for certificate validity assertions.

Changes

Cohort / File(s) Summary
Tests: timezone-aware datetime parsing
tests/storage/test_cdi_certificate.py
Replaced time.mktime/time.strptime and naive timestamp handling with datetime.strptime(...).replace(tzinfo=datetime.timezone.utc) and datetime.datetime.now(datetime.timezone.utc); updated assertion to compare UTC-aware datetimes; removed time import.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description follows the template headings but only the Short description is filled in, leaving critical sections such as More details, What this PR does / why we need it, Which issue(s) this PR fixes, Special notes for reviewer, and the jira-ticket field empty or unassigned. Please populate all template sections with relevant information by adding detailed context under More details, explaining the purpose and impact in What this PR does / why we need it, listing any related issues or fixes under Which issue(s) this PR fixes, providing any special reviewer notes, and specifying a Jira ticket URL or “NONE” in the jira-ticket field.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely identifies the specific function being changed and the nature of the update by indicating that valid_cdi_certificate now fetches UTC time instead of local time, which accurately reflects the main change in the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 96ef815 and e7f15c8.

📒 Files selected for processing (1)
  • tests/storage/test_cdi_certificate.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/storage/test_cdi_certificate.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: build-container
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: tox
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged

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-virtualization-qe-bot-2

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: A tracking issue is created for this PR and will be closed when the PR is merged or closed
  • Pre-commit Checks: pre-commit runs automatically if .pre-commit-config.yaml exists
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest build-container - Rebuild and test container image
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 2 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No WIP, hold, or conflict labels
  5. Verified: PR must be marked as verified (if verification is enabled)

📊 Review Process

Approvers and Reviewers

Approvers:

  • jpeimer

Reviewers:

  • Ahmad-Hafe
  • dalia-frank
  • duyanyan
  • josemacassan
  • jpeimer
  • kgoldbla
  • kshvaika
  • stesrn
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
tests/storage/test_cdi_certificate.py (3)

85-87: Prefer datetime.timezone.utc over datetime.UTC for broader compatibility

datetime.UTC exists only in Python 3.11+. Use datetime.timezone.utc to avoid AttributeError on 3.10 and earlier.

-                start_timestamp = start_date.replace(tzinfo=datetime.UTC).timestamp()
+                start_timestamp = start_date.replace(tzinfo=datetime.timezone.utc).timestamp()

Please confirm the CI runtime Python version; if it's <3.11 this change is required.


89-91: Same UTC constant issue here

Align with datetime.timezone.utc for compatibility.

-                end_timestamp = end_date.replace(tzinfo=datetime.UTC).timestamp()
+                end_timestamp = end_date.replace(tzinfo=datetime.timezone.utc).timestamp()

92-95: Simplify UTC “now” computation; avoid stringify/parse round‑trip

No need to strftime/strptime; compute the aware UTC timestamp directly. Also avoid datetime.UTC for compatibility.

-                current_time = datetime.datetime.now(datetime.timezone.utc).strftime(RFC3339_FORMAT)
-                current_date = datetime.datetime.strptime(current_time, RFC3339_FORMAT)
-                current_timestamp = current_date.replace(tzinfo=datetime.UTC).timestamp()
+                current_timestamp = datetime.datetime.now(datetime.timezone.utc).timestamp()

Optional (cleaner): compare aware datetimes instead of floats (fewer conversions):

-                start_date = datetime.datetime.strptime(start, RFC3339_FORMAT)
-                start_timestamp = start_date.replace(tzinfo=datetime.timezone.utc).timestamp()
-                end_date = datetime.datetime.strptime(end, RFC3339_FORMAT)
-                end_timestamp = end_date.replace(tzinfo=datetime.timezone.utc).timestamp()
-                current_timestamp = datetime.datetime.now(datetime.timezone.utc).timestamp()
-                assert start_timestamp <= current_timestamp <= end_timestamp, f"Certificate of {cdi_secret} expired"
+                start_dt = datetime.datetime.strptime(start, RFC3339_FORMAT).replace(tzinfo=datetime.timezone.utc)
+                end_dt = datetime.datetime.strptime(end, RFC3339_FORMAT).replace(tzinfo=datetime.timezone.utc)
+                now_dt = datetime.datetime.now(datetime.timezone.utc)
+                assert start_dt <= now_dt <= end_dt, f"Certificate of {cdi_secret} not valid at current time"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c33dfd2 and 96ef815.

📒 Files selected for processing (1)
  • tests/storage/test_cdi_certificate.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build-container
  • GitHub Check: tox
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged

@jpeimer
Copy link
Contributor

jpeimer commented Sep 25, 2025

/approve
/lgtm

rnetser
rnetser previously approved these changes Sep 25, 2025
Copy link
Collaborator

@rnetser rnetser left a comment

Choose a reason for hiding this comment

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

nit:
see CodeRabbit's suggestion

+                start_dt = datetime.datetime.strptime(start, RFC3339_FORMAT).replace(tzinfo=datetime.timezone.utc)
+                end_dt = datetime.datetime.strptime(end, RFC3339_FORMAT).replace(tzinfo=datetime.timezone.utc)
+                now_dt = datetime.datetime.now(datetime.timezone.utc)
+                assert start_dt <= now_dt <= end_dt, f"Certificate of {cdi_secret} not valid at current time"

@rnetser
Copy link
Collaborator

rnetser commented Sep 25, 2025

/lgtm
/approve

@vamsikrishna-siddu
Copy link
Contributor Author

/verified

@vamsikrishna-siddu
Copy link
Contributor Author

@jpeimer @rnetser After adding the new changes as suggested by coderabbit . The reviews got lost. Can you please review it again . Thanks

@jpeimer
Copy link
Contributor

jpeimer commented Sep 28, 2025

/approve
/lgtm

@rnetser
Copy link
Collaborator

rnetser commented Sep 28, 2025

/approve
/lgtm

@openshift-virtualization-qe-bot

New container for quay.io/openshift-cnv/openshift-virtualization-tests:latest published

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants