Repository navigation
config_drive: remove read-only metadata copies on cleanup - #230
Open
Michaelihc wants to merge 1 commit into
Open
Michaelihc wants to merge 1 commit into
Michaelihc wants to merge 1 commit into
Conversation
On Windows, the ConfigDrive is copied to a temporary folder with shutil.copytree(), which keeps the read-only attribute of the files on the drive. shutil.rmtree(ignore_errors=True) cannot delete those files, so the copy of the metadata was silently left in %TEMP%. Clear the read-only attribute of the copied files before deleting the folder, and log a warning if the folder still cannot be deleted. Fixes: cloudbase#221 Signed-off-by: Michaelihc <michaelihcz@outlook.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the scoped Windows ConfigDrive cleanup changes.
No open issues 🎉
What changed in this PR
This pull request improves ConfigDrive temporary-directory cleanup on Windows by removing read-only attributes from copied metadata files before deletion and logging cleanup failures instead of silently ignoring them.
Changes:
- Clears read-only attributes recursively before removing the metadata directory.
- Logs warnings when cleanup cannot complete while preserving non-raising cleanup behavior.
- Adds coverage for successful cleanup, read-only files, cleanup failures, and updated NoCloud expectations.
| File | Description |
|---|---|
| cloudbaseinit/tests/metadata/services/test_nocloudservice.py | Updates NoCloud cleanup expectations for the revised ConfigDrive cleanup flow. |
| cloudbaseinit/tests/metadata/services/test_baseconfigdrive.py | Adds tests covering successful cleanup, read-only file deletion, and cleanup failure warnings. |
| cloudbaseinit/metadata/services/baseconfigdrive.py | Removes read-only attributes before deleting ConfigDrive copies and reports cleanup failures with warnings. |
Review effort: Lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows, the ConfigDrive is copied to a
tmp*folder in%TEMP%withshutil.copytree(), which keeps the read-only attribute of the files on the drive.cleanup()then callsshutil.rmtree(..., ignore_errors=True), which cannot delete read-only files on Windows, so the copy of the metadata stays on disk and nothing is logged.Fixes #221
Fix
cleanup()runs in afinallyblock, so it still does not raise.Tests
test_cleanup_readonly_filesdeletes a real folder that holds a read-only file.test_cleanup_failschecks that the warning is logged.tox -e py3andtox -e pep8pass. Without the fix, the read-only test fails on Windows.%TEMP%.nocloudjob fails on that check. CI runTEST_RESOURCESat the test-resources branch. That workflow change is not part of this PR.🤖 Generated with Claude Code