Skip to content

Refresh the ISO URL when returning it#31

Merged
carbonin merged 2 commits intoopenshift-assisted:masterfrom
carbonin:refresh-iso-url
Jul 15, 2025
Merged

Refresh the ISO URL when returning it#31
carbonin merged 2 commits intoopenshift-assisted:masterfrom
carbonin:refresh-iso-url

Conversation

@carbonin
Copy link
Copy Markdown
Collaborator

@carbonin carbonin commented Jul 15, 2025

The download URL in the infraenv will be valid for a few hours after the cluster is created, but once the URL expires the dedicated URL API is required to refresh it. This commit updates the cluster_iso_download_url tool to just use that API all the time instead of pulling the url and expiration out of the infraenv.

Summary by CodeRabbit

  • New Features

    • Added support for retrieving infrastructure environment download URLs using a standardized method that returns presigned URLs with optional expiration details.
  • Refactor

    • Improved and unified the formatting of presigned URLs for download links, ensuring consistent output across tools.
  • Tests

    • Introduced new and updated test cases to cover the new download URL retrieval method and its error handling.

carbonin added 2 commits July 15, 2025 10:58
The download URL in the infraenv will be valid for a few hours after the
cluster is created, but once the URL expires the dedicated URL API is
required to refresh it. This commit updates the cluster_iso_download_url
tool to just use that API all the time instead of pulling the url and
expiration out of the infraenv.
@carbonin carbonin requested a review from eranco74 July 15, 2025 14:59
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jul 15, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: carbonin

The full list of commands accepted by this bot can be found 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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 15, 2025

Walkthrough

The changes introduce a helper function for formatting presigned URLs and refactor related tools to use this function and a new client method that returns a typed PresignedUrl object. Additional asynchronous tests are added to cover the new client method, and existing tests are updated to mock and verify the new approach.

Changes

File(s) Change Summary
server.py Added format_presigned_url helper; refactored tools to use new client method and formatting for presigned URLs.
service_client/assisted_service_api.py Added async method get_infra_env_download_url to InventoryClient for retrieving presigned URLs.
tests/test_assisted_service_api.py Added async test cases for get_infra_env_download_url, covering success and error scenarios.
tests/test_server.py Updated tests to mock and assert new client method for presigned URL retrieval; adjusted assertions accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Server
    participant InventoryClient
    participant AssistedServiceAPI

    User->>Server: Request ISO download URL
    Server->>InventoryClient: get_infra_env_download_url(infra_env_id)
    InventoryClient->>AssistedServiceAPI: get_infra_env_download_url(infra_env_id)
    AssistedServiceAPI-->>InventoryClient: PresignedUrl object
    InventoryClient-->>Server: PresignedUrl object
    Server->>Server: format_presigned_url(PresignedUrl)
    Server-->>User: Formatted URL string
Loading

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • eranco74

Poem

The presigned URLs now shine so bright,
With helper functions, they're just right!
Tests are added, mocks in tow,
Consistent formats steal the show.
The cluster’s links are neat and true—
A bunny’s work, for all of you! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 15, 2025
Copy link
Copy Markdown

@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 (4)
service_client/assisted_service_api.py (1)

688-716: Instantiate InstallerApi only once per call chain

asyncio.to_thread() is passed self._installer_api().get_infra_env_download_url, which recreates an ApiClient/InstallerApi every time this helper is invoked.
Because many higher-level flows iterate over several infra-envs (see cluster_iso_download_url in server.py), this can result in a noticeable amount of unnecessary client construction and TLS handshakes.

-            result = await asyncio.to_thread(
-                self._installer_api().get_infra_env_download_url,
-                infra_env_id=infra_env_id,
-            )
+            api_client = self._installer_api()
+            result = await asyncio.to_thread(
+                api_client.get_infra_env_download_url,
+                infra_env_id=infra_env_id,
+            )

Caching the InstallerApi (or the underlying ApiClient) for the lifetime of InventoryClient, or at least re-using it within the same coroutine, would cut the overhead without changing observable behaviour.

server.py (2)

21-40: Edge-case: missing or blank URL

format_presigned_url blindly interpolates presigned_url.url, which is allowed to be None/empty by the OpenAPI model.
If the API ever returns an object with no URL (e.g. quota exceeded), the string will contain “URL: None”, which is misleading.

-    response_parts = [f"URL: {presigned_url.url}"]
+    if not presigned_url.url:
+        return "No URL returned by the service."
+    response_parts = [f"URL: {presigned_url.url}"]

Consider short-circuiting or raising to make the failure explicit.


253-263: Sequential I/O could be parallelised

For clusters with many infra-envs the loop performs one API call at a time:

for infra_env in infra_envs:
    presigned_url = await client.get_infra_env_download_url(infra_env_id)

Those calls are network-bound and independent, so gathering them concurrently can cut total latency:

tasks = [
    client.get_infra_env_download_url(env["id"])
    for env in infra_envs
]
for presigned_url in await asyncio.gather(*tasks):
    ...

Not critical for small clusters but worth considering.

tests/test_server.py (1)

362-376: Minor: keep test data consistent

The mocked infra-env id is "test-infraenv-id" but the URL embedded in the expectation uses "test-id". Tests pass because the function just echoes the mocked URL, yet inconsistent fixtures make debugging harder. Align the id in the URL (or derive it from the fixture) to avoid confusion.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58d84de and 3b68859.

📒 Files selected for processing (4)
  • server.py (3 hunks)
  • service_client/assisted_service_api.py (1 hunks)
  • tests/test_assisted_service_api.py (1 hunks)
  • tests/test_server.py (9 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
server.py (1)
service_client/assisted_service_api.py (1)
  • get_infra_env_download_url (675-716)
tests/test_server.py (2)
service_client/assisted_service_api.py (1)
  • get_infra_env_download_url (675-716)
tests/test_utils.py (1)
  • create_test_presigned_url (82-90)
tests/test_assisted_service_api.py (2)
service_client/assisted_service_api.py (1)
  • get_infra_env_download_url (675-716)
tests/test_utils.py (1)
  • create_test_presigned_url (82-90)
🔇 Additional comments (1)
tests/test_assisted_service_api.py (1)

690-771: Solid coverage

👍 Comprehensive positive / negative cases for the new API; mocks are isolated and assertions are precise.

Copy link
Copy Markdown
Collaborator

@eranco74 eranco74 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2025
@carbonin
Copy link
Copy Markdown
Collaborator Author

/retest

@carbonin carbonin merged commit 55443bb into openshift-assisted:master Jul 15, 2025
12 checks passed
@carbonin carbonin deleted the refresh-iso-url branch July 15, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants