Skip to content

Conversation

@blackboxsw
Copy link
Collaborator

  • I have added unit tests to cover the new behavior under ``tests/unit_tests/```
  • I have run tox -e format locally to automatically format my code before submitting
  • I have run tox locally ensuring that it passes before submitting
  • (if applicable) I have added a reference to issues that this PR relates to in the PR message (Refs GH-1234, Fixes GH-1234)
  • My commits are atomic and follow the convetional commit message format (https://www.conventionalcommits.org/en/v1.0.0/)

Description

Add functionality to use new cloud-init clean params to remove stale cloud-init artifacts from previous boots.
Retain fallback for older versions of cloud-init which may not yet support the -c all param.

cloud-init version 23.1 introduced new commandline options to cloud-init clean:

  1. --machine-id to uninitialize /etc/machine-id
  2. -c all which remove previous boot artifacts such as /etc/netplan/50-cloud-init.yaml and and cloud artifacts (generated by azure)

Additional Context and Relevant Issues

Test Steps

@blackboxsw blackboxsw requested a review from Copilot January 10, 2026 00:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the clean() method to leverage newer cloud-init clean options (--machine-id and -c all) introduced in cloud-init version 23.1, with a fallback mechanism for older cloud-init versions that don't support these parameters.

Changes:

  • Updated BaseInstance.clean() to use cloud-init clean --logs --machine-id -c all by default
  • Added fallback logic to retry with cloud-init clean --logs if the -c all option is unrecognized
  • Added comprehensive unit tests covering success, fallback, and edge cases
  • Version bumped to 1!10.17.0

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pycloudlib/instance.py Updated clean method to use new cloud-init options with fallback for older versions
tests/unit_tests/test_instance.py Added TestClean class with unit tests covering various scenarios for the updated clean method
VERSION Bumped version from 1!10.16.0 to 1!10.17.0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@blackboxsw blackboxsw force-pushed the cloud-init-clean-all branch from bb81156 to fff8d87 Compare January 10, 2026 00:21
@blackboxsw blackboxsw marked this pull request as draft January 10, 2026 00:24
@blackboxsw blackboxsw force-pushed the cloud-init-clean-all branch from fff8d87 to a47f483 Compare January 13, 2026 15:03
@blackboxsw blackboxsw force-pushed the cloud-init-clean-all branch from 9fe8fd7 to cdd8b05 Compare January 13, 2026 15:09
@blackboxsw blackboxsw marked this pull request as ready for review January 13, 2026 15:20
# [1] https://github.com/canonical/cloud-init/commit/abfdf1d83995cc20e
self.execute("sudo cloud-init clean --logs")
self.execute("sudo echo 'uninitialized' > /etc/machine-id")
result = self.execute("sudo cloud-init clean --logs --machine-id -c all")
Copy link
Collaborator Author

@blackboxsw blackboxsw Jan 13, 2026

Choose a reason for hiding this comment

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

CC: @hammerstefan @uhryniuk. Hello CPC folks, just wanted to raise awareness that this move represents moving toward image support for images with cloud-init > 23.4. This shouldn't break anything CPC side for testing because it falls back to original behavior, but it raises a question or two:

  • Does CPC test infra run any tests actively against images earlier than focal with updates?
  • Is there any CPC image build operation that invokes cloud-init clean which could benefit from additional --machine-id -c all params?

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