Skip to content

feat: add reserve_resources method for CRN capacity pre-check#286

Merged
aliel merged 2 commits into
mainfrom
aliel-add-reserve-resources-method
Apr 20, 2026
Merged

feat: add reserve_resources method for CRN capacity pre-check#286
aliel merged 2 commits into
mainfrom
aliel-add-reserve-resources-method

Conversation

@aliel
Copy link
Copy Markdown
Member

@aliel aliel commented Apr 20, 2026

No description provided.

@github-actions
Copy link
Copy Markdown

Failed to retrieve llama text: POST 502: Bad Gateway

Copy link
Copy Markdown

@foxpatch-aleph foxpatch-aleph left a comment

Choose a reason for hiding this comment

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

The PR adds a useful reserve_resources method for CRN capacity pre-check and refactors create_vm_control_payload to use a new create_control_payload helper. However, there are two issues: (1) the original create_vm_control_payload function had a bug where it created a payload dict but returned a different dict entirely - this was silently broken before and the PR correctly fixes it; (2) there's no test coverage for the new functionality. The code quality is good and follows existing patterns.

src/aleph/sdk/utils.py (line 240): The original create_vm_control_payload function had a subtle bug: it created a payload dict but then returned a completely new dict literal (the return payload at the end was unreachable). The PR correctly fixes this by extracting the common logic into create_control_payload. This is a good refactor that fixes a latent bug.

src/aleph/sdk/client/vm_client.py (line 337): The new reserve_resources method is missing test coverage. Please add tests following the existing pattern in test_vm_client.py (e.g., test_perform_operation, test_notify_allocation). Test both success (200) and failure (503) cases.

src/aleph/sdk/client/vm_client.py (line 368): Minor: The logger format string uses %s which works but could be more explicit. Consider using str(e) for consistency with the return statement, or use .format() or f-string: logger.error("HTTP error during reserve_resources: %s", str(e))

src/aleph/sdk/client/vm_client.py (line 327): Note: The notify_allocation method doesn't have error handling for aiohttp.ClientError while reserve_resources does. Consider adding similar error handling to notify_allocation for consistency, or document why it's different.

Copy link
Copy Markdown

@foxpatch-aleph foxpatch-aleph left a comment

Choose a reason for hiding this comment

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

This PR adds a well-implemented reserve_resources method for CRN capacity pre-checks. The implementation follows existing authentication patterns, the refactoring of create_vm_control_payload to use a generic helper reduces duplication, and tests cover the main success and failure scenarios. The code is clean and consistent with the codebase.

src/aleph/sdk/client/vm_client.py (line 368): Minor: The %s format specifier will call str() automatically, so str(e) is redundant. Consider simplifying to logger.error("HTTP error during reserve_resources: %s", e) for consistency with typical logging patterns.

tests/unit/test_vm_client.py (line 270): Consider adding a test for the aiohttp.ClientError exception path that returns (None, str(e)). While this mirrors the pattern in other methods like perform_operation, adding coverage would improve test completeness.

@aliel aliel merged commit 696b2aa into main Apr 20, 2026
37 checks passed
@aliel aliel deleted the aliel-add-reserve-resources-method branch April 20, 2026 17:15
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