lxd: delete container only if parts is empty
Metadata
Current evaluation
Merged fix resolving bug 1734145 by updating LXD container cleanup logic to only delete containers when parts are empty. Approved by one reviewer, passed CI checks, and modified two files.
Suggested action: —
No scores available.
Issue body
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on [bug reports](https://bugs.launchpad.net/snapcraft)?
- [x] If this is a new feature. Have you discussed the design on the [forum](https://forum.snapcraft.io)?
- [x] Have you successfully run `./runtests.sh static`?
- [x] Have you successfully run `./runtests.sh unit`?
-----
Steps to manually test this:
* export SNAPCRAFT_CONTAINER_BUILDS=helga
* cd snapcraft/tests/integration/snaps/go-hello/
* lxc list helga: | grep go-hello
* Observe no container exists
* snapcraft pull
* lxc list helga: | grep go-hello
* Observe container exists
* snapcraft clean -s pull go-hello
* lxc list helga: | grep go-hello
* Observe container exists
* snapcraft clean go-hello
* Observe container still exists, artifacts were cleaned
* snapcraft clean
* lxc list helga: | grep go-hello
* Observe container was deleted, message "Deleting helga:snapcraft-go-hello"
* Repeat "snapcraft clean", "snapcraft clean go-hello", "snapcraft clean -s pull go-hello"
* Observe no error occurred with already deleted container
Fixes [bug 1734145](https://bugs.launchpad.net/snapcraft/+bug/1734145)
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | — | Merged fix resolving bug 1734145 by updating LXD container cleanup logic to only delete containers when parts are empty. Approved by one reviewer, passed CI checks, and modified two files. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged to fix bug 1734145. Updates LXD container cleanup to only delete containers when the parts list is empty, preventing errors during repeated clean operations. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix for bug 1734145 modifies LXD container cleanup to only delete containers when parts are empty, preventing errors during repeated clean commands. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1403 lxd: Only remove container if one exists | snapcraft | merged | Merged following two reviewer approvals and passing CI. The update resolves duplicate exceptions during failed LXD container creation by adding a conditional check before attempting container removal. | |
| #1434 lxd: clean with no parts should only delete | snapcraft | merged | Merged. Updates snapcraft LXD handling so running clean without arguments only deletes container resources instead of executing commands inside them. Approved by one reviewer and merged. | |
| #1627 lxd: split container classes into different files | snapcraft | merged | Merged refactoring splitting LXD container classes from lxd.py into separate modules. Improves organization, moves Cleanbuilder methods, de-duplicates env vars, and fixes mocking imports. No functional changes. Approved by two reviewers and passed CI. | |
| #1644 lxd: fix the push in container builds | snapcraft | merged | Merged pull request fixing LXD container push builds. Approved by one reviewer, the change refactored test cases for better coverage and updated build logic. Review comments highlighted the need for Travis integration and broader testing beyond unit tests. | |
| #1230 lxd: refactor Cleanbuilder into Containerbuild and add Project. | snapcraft | merged | Merged. Refactored Cleanbuilder into a Containerbuild base class and introduced a Project class to manage persistent LXD containers for snap builds. Approved after code review and test fixes. | |
| #1488 lxd: always remove existing device for project folder | snapcraft | merged | Merged as a follow-up to #1483, ensuring existing devices are always removed for the LXD project folder. Approved by two reviewers with zero unresolved comments. The change modifies three files, adds 64 lines, removes one, and passed all CI checks. | |
| #2095 lxd: proper error classes for container errors | snapcraft | merged | Merged after approval. Refactored LXD container errors into dedicated classes, relocated them to the LXD module, and fixed architecture retrieval error handling. Added corresponding unit tests. Resolves Launchpad bugs #1734233 and #1734235. | |
| #1742 lxd: always remove tmp_dir after execution | snapcraft | merged | Merged fix ensuring the temporary directory is always removed after LXD container builds, preventing disk space waste on errors. Approved and passed CI. | |
| #1978 ci: switch to stable lxd and unconfined containers | snapcraft | merged | Merged CI configuration update switching to stable LXD and unconfined containers. Approved by two reviewers with a two-file, five-line change. | |
| #1516 lxd: LXD not installed when using remote | snapcraft | merged | Merged fix for a bug where lxc installation was not correctly verified when using a LXD remote. Also corrected incomplete test scenario usage. Approved by two reviewers, modified two files. |