cloud-init
cloud-init copied to clipboard
fix: cloud-init clean --logs should not remove non-files
Proposed Commit Message
Add test coverage for the fix that prevents cloud-init clean --logs
from attempting to remove non-file paths (e.g., character devices,
directories) that may appear in the log file configuration.
The test verifies that when /dev/null is configured as a log path,
it is safely skipped while actual log files are still removed.
Additional Context
Test Steps
tox -e py3 -- tests/unittests/cmd/test_clean.py::TestClean::test_remove_artifacts_skips_non_file_logs
Merge type
- [x] Squash merge using "Proposed Commit Message"
- [ ] Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)
Thanks for this @blackboxsw. I left a couple of comments. Also, can you share the error you saw?
@holmanb here is the error which could be caused be custom /etc/cloud/cloud.cfg.d/05_logging.cfg changing log files to character devices or symlinks.
root@dd:~# cloud-init clean --logs
Traceback (most recent call last):
File "/usr/bin/cloud-init", line 9, in <module>
sys.exit(main.main())
~~~~~~~~~^^
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 1308, in main
return sub_main(args, parser)
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 1438, in sub_main
retval = functor(name, args)
File "/usr/lib/python3/dist-packages/cloudinit/cmd/clean.py", line 189, in handle_clean_args
exit_code = remove_artifacts(
init, args.remove_logs, args.remove_seed, args.remove_config
)
File "/usr/lib/python3/dist-packages/cloudinit/cmd/clean.py", line 129, in remove_artifacts
del_file(log_file)
~~~~~~~~^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2072, in del_file
os.unlink(path)
~~~~~~~~~^^^^^^
OSError: [Errno 16] Device or resource busy: '/dev/console'