LXDInstance.exists() can error if project doesn't exist in LXD 6.6
Metadata
Current evaluation
Fixed by merged PR canonical/craft-providers#874 (commit 48bd685), which changed LXDInstance.exists() to use pylxd and avoid lxc list failures for nonexistent LXD projects.
Resolution: closed resolved
Reason: PR canonical/craft-providers#874 was merged as commit 48bd685. It refactored LXDInstance.exists() to query instance existence through pylxd rather than lxc list.
Evaluated by: mr-cal-bot
No scores available.
Issue body
### Bug Description
When a project doesn't exist, `lxc --project <project> list` now fails instead of succeeding with no output. This causes downstream commands like `*craft clean` to fail sometimes in our CI.
### To Reproduce
```console
$ sudo snap remove --purge lxd
lxd removed
$ sudo snap install --revision 36020 lxd
lxd 6.5-ccdfb39 from Canonical✓ installed
$ uv run python -c 'from craft_providers.lxd import LXDInstance; LXDInstance(name="u1", project="p1").exists()'
$ sudo snap refresh --channel 6/stable lxd
lxd (6/stable) 6.6-3c9aa6d from Canonical✓ refreshed
$ uv run python -c 'from craft_providers.lxd import LXDInstance; LXDInstance(name="u1", project="p1").exists()'
Traceback (most recent call last):
File "/home/jono/code/craft-providers/craft_providers/lxd/lxc.py", line 917, in list
proc = self._run_lxc(
^^^^^^^^^^^^^^
File "/home/jono/code/craft-providers/craft_providers/lxd/lxc.py", line 206, in _run_lxc
return subprocess.run(
^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['lxc', '--project', 'p1', 'list', 'local:', '--format=yaml']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/jono/code/craft-providers/craft_providers/lxd/lxd_instance.py", line 286, in exists
return self._get_instance_information() is not None
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jono/code/craft-providers/craft_providers/lxd/lxd_instance.py", line 316, in _get_instance_information
instances = self.lxc.list(project=self.project, remote=self.remote)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jono/code/craft-providers/craft_providers/lxd/lxc.py", line 921, in list
raise LXDError(
craft_providers.lxd.errors.LXDError: Failed to list instances for project 'p1'.
* Command that failed: 'lxc --project p1 list local: --format=yaml'
* Command exit code: 1
* Command standard error output: 'Error: Failed to get project: Project not found\n'
```
### part yaml
```shell
```
### Relevant log output
```shell
Traceback (most recent call last):
File "/home/jono/code/craft-providers/craft_providers/lxd/lxc.py", line 917, in list
proc = self._run_lxc(
^^^^^^^^^^^^^^
File "/home/jono/code/craft-providers/craft_providers/lxd/lxc.py", line 206, in _run_lxc
return subprocess.run(
^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['lxc', '--project', 'p1', 'list', 'local:', '--format=yaml']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/jono/code/craft-providers/craft_providers/lxd/lxd_instance.py", line 286, in exists
return self._get_instance_information() is not None
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jono/code/craft-providers/craft_providers/lxd/lxd_instance.py", line 316, in _get_instance_information
instances = self.lxc.list(project=self.project, remote=self.remote)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jono/code/craft-providers/craft_providers/lxd/lxc.py", line 921, in list
raise LXDError(
craft_providers.lxd.errors.LXDError: Failed to list instances for project 'p1'.
* Command that failed: 'lxc --project p1 list local: --format=yaml'
* Command exit code: 1
* Command standard error output: 'Error: Failed to get project: Project not found\n'
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR canonical/craft-providers#874 (commit 48bd685), which changed LXDInstance.exists() to use pylxd and avoid lxc list failures for nonexistent LXD projects. | |
| qwen/qwen3.6-35b-a3b | — | closed resolved | Fixed in #874 by refactoring LXDInstance.exists() to use pylxd instead of lxc list, resolving LXD 6.6 project-not-found errors. |
Update history
| Date | Change |
|---|---|
| created |
Related work
-
Likely Fixed By:
canonical/craft-providers#874
(confidence 100%)
Merged PR 874 explicitly resolves issue 856 through commit 48bd685.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #874 refactor: use pylxd to determine if an instance exists | craft-providers | merged | Merged PR #874 replaced lxc-based existence checks with pylxd, resolving #856's LXD 6.6 missing-project errors; merged as commit 48bd685. | |
| #341 lxd: race condition when running multiple instances of craft-providers | craft-providers | closed | Fixed by merged PR #357, which rechecks LXC project existence after creation fails, preventing concurrent project-creation races (CRAFT-1849). |