Skip to content

fix: handle ill-formed profiles created by older rockcraft - #588

Open
cmatsuoka wants to merge 5 commits into
mainfrom
work/fix-bogus-lxd-profile
Open

fix: handle ill-formed profiles created by older rockcraft#588
cmatsuoka wants to merge 5 commits into
mainfrom
work/fix-bogus-lxd-profile

Conversation

@cmatsuoka

Copy link
Copy Markdown
Collaborator

Older versions of rockcraft may have created a rockcraft lxd project
containing a broken default profile. If this is the case, tell
the user to delete the project and start over.

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • Have you successfully run tox?

Check if the lxd snap is installed by querying the snapd socket
instead of looking for an executable in the path, as lxd can use
auto-installer stubs.

Co-authored-by: Callahan Kovacs <callahan.kovacs@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
@cmatsuoka
cmatsuoka requested review from mr-cal and tigarmo June 24, 2024 20:05
Comment thread craft_providers/lxd/installer.py Outdated
@cmatsuoka
cmatsuoka marked this pull request as draft June 24, 2024 20:13
Older versions of rockcraft may have created a rockcraft lxd project
containing a broken default profile. If this is the case, tell the
user to delete the project and start over.

Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
@cmatsuoka
cmatsuoka force-pushed the work/fix-bogus-lxd-profile branch from d6aaf67 to 8b00682 Compare June 24, 2024 20:27
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
if not devices:
# Project exists but the default profile is ill-formed, tell the user to
# delete the project and start over.
raise LXDError(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately deleting the broken projects ourselves involves deleting everything the project is using first, and this is too risky to implement without better investigation and careful testing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this you be a good scenario to have a test for, aside from that, I generally approve of the appoach

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree that this new check should have a test

@cmatsuoka
cmatsuoka marked this pull request as ready for review June 24, 2024 20:38

@mr-cal mr-cal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this a duplicate of #436?

@tigarmo tigarmo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe there are failing unit tests

@cmatsuoka

Copy link
Copy Markdown
Collaborator Author

Is this a duplicate of #436?

It's a similar check, but performed on the specific project's default profile instead of the default project default profile.

@tigarmo
tigarmo force-pushed the rockcraft branch 2 times, most recently from 27b62e2 to 18ca5f3 Compare July 2, 2024 13:34
Base automatically changed from rockcraft to main July 3, 2024 11:38
@lengau
lengau requested a review from Copilot December 6, 2025 07:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds validation to detect and handle ill-formed LXD profiles that may have been created by older versions of rockcraft. When an empty devices section is detected in the default profile, the user is instructed to delete the project so it can be recreated properly.

Key Changes

  • Added validation logic to check for empty devices in the default profile before launching environments
  • Imported LXD_INSTALL_HELP constant to provide consistent help text in error messages
  • Raises a descriptive LXDError when an ill-formed profile is detected

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

devices = self.lxc.profile_show(
project=self.lxd_project, profile="default", remote=self.lxd_remote
).get("devices")
if not devices:

Copilot AI Dec 6, 2025

Copy link

Choose a reason for hiding this comment

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

The condition if not devices: will be true for both None (key not present) and an empty dict {}. If the devices key exists but is an empty dict, this might be a legitimate state rather than an error. Consider checking specifically for None with if devices is None: or clarifying whether an empty dict should also trigger the error.

Suggested change
if not devices:
if devices == {}:

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +133
devices = self.lxc.profile_show(
project=self.lxd_project, profile="default", remote=self.lxd_remote
).get("devices")

Copilot AI Dec 6, 2025

Copy link

Choose a reason for hiding this comment

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

If profile_show raises an exception (e.g., if the default profile doesn't exist), the error message to the user may be confusing. Consider adding error handling to catch profile lookup failures and provide a clearer message about the missing or inaccessible profile.

Suggested change
devices = self.lxc.profile_show(
project=self.lxd_project, profile="default", remote=self.lxd_remote
).get("devices")
try:
devices = self.lxc.profile_show(
project=self.lxd_project, profile="default", remote=self.lxd_remote
).get("devices")
except Exception as exc:
# Could not access the default profile; provide a clear error message.
raise LXDError(
brief="LXD project is missing or has an inaccessible default profile.",
details=(
f"Could not access the default profile in the LXD project '{self.lxd_project}'.\n"
f"Error: {exc}"
),
resolution=(
f"Delete the '{self.lxd_project}' LXD project, it will be "
"recreated in the next execution.\n" + LXD_INSTALL_HELP
),
)

Copilot uses AI. Check for mistakes.
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.

5 participants