Skip to content

config_drive: remove read-only metadata copies on cleanup - #230

Open
Michaelihc wants to merge 1 commit into
cloudbase:masterfrom
Michaelihc:fix/configdrive-readonly-cleanup
Open

Michaelihc wants to merge 1 commit into
cloudbase:masterfrom
Michaelihc:fix/configdrive-readonly-cleanup

Conversation

@Michaelihc

Copy link
Copy Markdown

Problem

On Windows, the ConfigDrive is copied to a tmp* folder in %TEMP% with shutil.copytree(), which keeps the read-only attribute of the files on the drive. cleanup() then calls shutil.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

  • Clear the read-only attribute of the copied files before deleting the folder.
  • Log a warning if the folder still cannot be deleted, instead of ignoring the error. cleanup() runs in a finally block, so it still does not raise.

Tests

  • Unit tests: test_cleanup_readonly_files deletes a real folder that holds a read-only file. test_cleanup_fails checks that the warning is logged. tox -e py3 and tox -e pep8 pass. Without the fix, the read-only test fails on Windows.
  • Functional tests: functional-tests: verify ConfigDrive metadata copy is removed cloudbase-init-test-resources#22 adds a check that no ConfigDrive copy is left in %TEMP%.
    • Without the fix, the nocloud job fails on that check. CI run
    • With the fix, all jobs pass. CI run
    • Both runs point TEST_RESOURCES at the test-resources branch. That workflow change is not part of this PR.

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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

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.

ConfigDrive cleanup silently leaves read-only metadata copies on Windows

2 participants