-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add env on core restart due to restore #5548
Conversation
📝 WalkthroughWalkthroughThe pull request introduces modifications to the backup and restore functionality in the Home Assistant Supervisor. The changes focus on enhancing the control and flexibility of the Home Assistant container management during restore operations. Key modifications include adding a new parameter to control container removal, updating job stage handling, and introducing a mechanism to pass restore job IDs to the Home Assistant container. The changes span multiple files in the supervisor and test directories, affecting core system components like backup management, job handling, and Docker container interactions. Changes
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
cad497e
to
60c9b81
Compare
There was a problem hiding this 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 (1)
tests/api/test_backups.py (1)
864-916
: LGTM! Well-structured test implementation.The test effectively verifies the addition of the
SUPERVISOR_RESTORE_JOB_ID
environment variable during Home Assistant restore operations. Good use of parametrization to cover both partial and full backup scenarios.Consider adding the following test cases to improve coverage:
- Negative test case: Verify the environment variable is not added when Home Assistant is not being restored
- Validation test case: Ensure the job UUID format in the environment variable matches the expected pattern
Example negative test case:
@pytest.mark.parametrize( ("backup_type", "postbody"), [("partial", {"folders": ["share"]}), ("full", {"homeassistant": False})] ) async def test_restore_without_homeassistant_no_env( api_client: TestClient, coresys: CoreSys, docker: DockerAPI, backup_type: str, postbody: dict[str, Any], ): """Test restoring without home assistant does not add env to container.""" # Test implementation... assert "SUPERVISOR_RESTORE_JOB_ID" not in docker.containers.create.call_args.kwargs["environment"]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
supervisor/backups/backup.py
(1 hunks)supervisor/backups/const.py
(0 hunks)supervisor/backups/manager.py
(2 hunks)supervisor/core.py
(2 hunks)supervisor/docker/homeassistant.py
(3 hunks)supervisor/homeassistant/core.py
(3 hunks)supervisor/jobs/__init__.py
(5 hunks)tests/api/test_backups.py
(2 hunks)tests/backups/test_manager.py
(1 hunks)
💤 Files with no reviewable changes (1)
- supervisor/backups/const.py
🚧 Files skipped from review as they are similar to previous changes (6)
- supervisor/backups/backup.py
- tests/backups/test_manager.py
- supervisor/homeassistant/core.py
- supervisor/docker/homeassistant.py
- supervisor/jobs/init.py
- supervisor/backups/manager.py
🧰 Additional context used
📓 Path-based instructions (1)
supervisor/core.py (6)
Pattern */**(html|markdown|md)
: - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.
- Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
- In step-by-step instructions, front the location phrase in the instructional sentence.
- In step-by-step instructions, front the 'goal' in the instructional sentence.
- In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
- do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'
Pattern */**(html|markdown|md)
: - Use bold to mark UI strings.
- If "" are used to mark UI strings, replace them by bold.
Pattern */**(html|markdown|md)
: - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"
Pattern */**(html|markdown|md)
: - Use sentence-style capitalization also in headings.
Pattern */**(html|markdown|md)
: do not comment on HTML used for icons
Pattern */**(html|markdown|md)
: Avoid flagging inline HTML for embedding videos in future reviews for this repository.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run the Supervisor
- GitHub Check: Run tests Python 3.12.8
🔇 Additional comments (3)
tests/api/test_backups.py (1)
18-22
: LGTM!The new imports are correctly placed and necessary for the new test functionality.
supervisor/core.py (2)
336-336
: LGTM! Well-designed parameter addition.The new keyword-only parameter with a descriptive name and safe default value maintains backward compatibility while enabling the new functionality.
347-349
: Verify error handling in Home Assistant core stop method.The implementation correctly forwards the container removal parameter. Since errors are suppressed here, ensure the
core.stop()
method properly handles container removal failures.✅ Verification successful
Error handling for container removal is properly implemented
The
stop()
method implementations across the codebase show appropriate error handling:
- Base implementation suppresses DockerNotFound errors
- Container manager handles NotFound exceptions
- Errors are handled at both caller and implementation levels
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check error handling in Home Assistant core stop method # Look for error handling around container removal in the Home Assistant core implementation # Search for the core.stop() method implementation ast-grep --pattern 'async def stop($$$) { $$$ }' | grep -A 10 'async def stop' # Look for error handling around container removal rg -A 5 'remove_container.*=.*True'Length of output: 2583
60c9b81
to
34ecd4d
Compare
There was a problem hiding this 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 (1)
tests/api/test_backups.py (1)
864-916
: Well-structured test with comprehensive coverage!The test effectively verifies that the Home Assistant container receives the correct restore job ID during both partial and full restores. The implementation includes proper mocking, event handling, and assertions.
Consider renaming the test to be more specific about what it's testing, e.g.,
test_restore_adds_job_id_to_ha_container_env
.-async def test_restore_homeassistant_adds_env( +async def test_restore_adds_job_id_to_ha_container_env(
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
supervisor/backups/backup.py
(1 hunks)supervisor/backups/const.py
(0 hunks)supervisor/backups/manager.py
(6 hunks)supervisor/core.py
(2 hunks)supervisor/docker/homeassistant.py
(3 hunks)supervisor/homeassistant/core.py
(2 hunks)supervisor/jobs/__init__.py
(6 hunks)tests/api/test_backups.py
(2 hunks)tests/backups/test_manager.py
(1 hunks)
💤 Files with no reviewable changes (1)
- supervisor/backups/const.py
🚧 Files skipped from review as they are similar to previous changes (7)
- supervisor/backups/backup.py
- supervisor/core.py
- supervisor/docker/homeassistant.py
- supervisor/homeassistant/core.py
- supervisor/jobs/init.py
- tests/backups/test_manager.py
- supervisor/backups/manager.py
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Build armv7 supervisor
- GitHub Check: Build armhf supervisor
- GitHub Check: Build aarch64 supervisor
- GitHub Check: Run tests Python 3.12.8
🔇 Additional comments (1)
tests/api/test_backups.py (1)
18-18
: LGTM!The new imports are correctly placed and necessary for the test functionality.
Also applies to: 22-22
Proposed change
Add
SUPERVISOR_RESTORE_JOB_ID
env to home assistant container when it restarts due to a restore. This will be there even if the restore failed as long as Home Assistant was actually stopped as part of the restore.Type of change
Additional information
Checklist
ruff format supervisor tests
)If API endpoints or add-on configuration are added/changed:
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests