← Back to issue list

build providers: idempotent destroy for LXD

View original Github issue

Metadata

Project
snapcraft
Number
#2529
Type
pull request
State
merged
Author
sergiusens
Labels
—
Created
Updated
Closed

Current evaluation

Merged PR #2529 made LXD cleanup idempotent, preventing missing-container errors from masking launch failures; landed as commit 1b2905885.

Resolution: closed resolved

Reason: PR #2529 was merged into master as commit 1b2905885. It tolerates a missing LXD container during cleanup, preserving the original storage-pool launch error instead of raising an AttributeError.

Evaluated by: mr-cal-bot

No scores available.

Issue body

Fixes SNAPCRAFT-MB Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com> - [ ] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)? - [ ] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)? - [ ] Have you successfully run `./runtests.sh static`? - [ ] Have you successfully run `./runtests.sh tests/unit`? ----- Before ``` (snapcraft) multipass@lxd-snapcraft:~/t$ snapcraft --use-lxd Using 'snap/snapcraft.yaml': Project assets will be searched for from the 'snap' directory. The LXD provider is offered as a technology preview for early adopters. The command line interface, container names or lifecycle handling may change in upcoming releases. Launching a container. Sorry, an error occurred in Snapcraft: Traceback (most recent call last): File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_base_provider.py", line 249, in launch_instance self._start() File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 166, in _start raise errors.ProviderInstanceNotFoundError(instance_name=self.instance_name) snapcraft.internal.build_providers.errors.ProviderInstanceNotFoundError: Cannot find an instance named 'snapcraft-test'. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 151, in _launch container = self._lxd_client.containers.create(config, wait=True) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/pylxd/models/container.py", line 276, in create response = client.api.containers.post(json=config, target=target) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/pylxd/client.py", line 168, in post self._assert_response(response, allowed_status_codes=(200, 201, 202)) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/pylxd/client.py", line 108, in _assert_response raise exceptions.LXDAPIException(response) pylxd.exceptions.LXDAPIException: No storage pool found. Please create a new storage pool The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_base_provider.py", line 117, in __enter__ self.create() File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 246, in create self.launch_instance() File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_base_provider.py", line 257, in launch_instance self._launch() File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 155, in _launch ) from lxd_api_error snapcraft.internal.build_providers.errors.ProviderLaunchError: An error occurred with the instance when trying to launch with 'LXD': No storage pool found. Please create a new storage pool. Ensure that 'LXD' is setup correctly and try again. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/multipass/venv/snapcraft/bin/snapcraft", line 11, in <module> load_entry_point('snapcraft', 'console_scripts', 'snapcraft')() File "/home/multipass/snapcraft/snapcraft/cli/__main__.py", line 81, in run run_snapcraft(prog_name="snapcraft") File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 1043, in invoke return Command.invoke(self, ctx) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func return f(get_current_context(), *args, **kwargs) File "/home/multipass/snapcraft/snapcraft/cli/_runner.py", line 93, in run ctx.forward(lifecyclecli.commands["snap"]) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 553, in forward return self.invoke(cmd, **kwargs) File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/home/multipass/snapcraft/snapcraft/cli/lifecycle.py", line 272, in snap _execute(steps.PRIME, parts=[], pack_project=True, output=output, **kwargs) File "/home/multipass/snapcraft/snapcraft/cli/lifecycle.py", line 98, in _execute with build_provider_class(project=project, echoer=echo) as instance: File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_base_provider.py", line 120, in __enter__ self.destroy() File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 250, in destroy self._stop() File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 196, in _stop self._container.sync() AttributeError: 'NoneType' object has no attribute 'sync' We would appreciate it if you created a bug report at https://launchpad.net/snapcraft/+filebug with the above text included. ``` and after ``` (snapcraft) multipass@lxd-snapcraft:~/t$ snapcraft --use-lxd Using 'snap/snapcraft.yaml': Project assets will be searched for from the 'snap' directory. The LXD provider is offered as a technology preview for early adopters. The command line interface, container names or lifecycle handling may change in upcoming releases. Launching a container. An error occurred with the instance when trying to launch with 'LXD': No storage pool found. Please create a new storage pool. Ensure that 'LXD' is setup correctly and try again. ```

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Merged PR #2529 made LXD cleanup idempotent, preventing missing-container errors from masking launch failures; landed as commit 1b2905885.
stealth/space-bunny-alpha — closed resolved Merged PR #2529 as commit 1b2905885, making LXD provider cleanup idempotent so failed launches no longer crash on a missing container and report the original LXD error.
stealth/space-bunny-alpha — closed resolved Merged PR #2529 (commit 1b2905885) making LXD provider cleanup idempotent: destroy() no longer crashes with AttributeError on a missing container, so failed launches surface the original LXD error instead.
stealth/space-bunny-alpha — closed resolved Merged #2529 (commit 1b2905885), making LXD provider cleanup idempotent so failed launches no longer crash on a missing container and report the original LXD error.
qwen/qwen3.6-35b-a3b — — Merged fix making LXD provider destroy idempotent. Resolves AttributeError crash during cleanup when container launch fails. Prevents NoneType sync errors and displays a clean error message instead.
qwen3.6-35b-a3b-mtp-q6 — — Merged into master. Fixes SNAPCRAFT-MB by making LXD container destruction idempotent. Prevents AttributeError crashes during failed launches or missing instances, ensuring graceful error reporting and cleanup.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#578 Make lxd containers ephemeral snapcraft merged Merged via commit 038bf3f05, making LXD build containers ephemeral and fixing Launchpad bug #1577548. Integration coverage was deferred to bug #1593529.
74%
#459 Remove LXD container once we've finished a build snapcraft closed Closed unmerged: testing showed cleanbuild already destroyed its LXD containers; the startup failure was fixed separately by merged PR #458 (f78b1e3a3).
73%
#1762 lxd: delete container only if parts is empty snapcraft merged Merged PR #1762 (dbce9a058), changing LXD cleanup to delete a build container only after all parts are removed, preserving it for targeted cleans and making repeated cleans safe.
71%
#3115 build providers: ignore missing LXD instance when cleaning project snapcraft merged Merged PR #3115 (commit 8ce59011a) makes project cleanup ignore missing LXD instances deleted manually.
71%
#2374 build providers: destroy on create failures snapcraft merged Merged PR #2374 (commit ec0fbe2be, LP #1792242) adds cleanup so build providers are destroyed when creation/launch fails, preventing VMs from being left running.
71%
#1644 lxd: fix the push in container builds snapcraft merged Merged PR #1644 fixed LXD container-build artifact pushes; the change landed as commit d4a34e07d.
70%