fix: handle ill-formed profiles created by older rockcraft - #588
fix: handle ill-formed profiles created by older rockcraft#588cmatsuoka wants to merge 5 commits into
Conversation
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>
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>
d6aaf67 to
8b00682
Compare
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
this you be a good scenario to have a test for, aside from that, I generally approve of the appoach
There was a problem hiding this comment.
I agree that this new check should have a test
tigarmo
left a comment
There was a problem hiding this comment.
I believe there are failing unit tests
It's a similar check, but performed on the specific project's default profile instead of the default project default profile. |
27b62e2 to
18ca5f3
Compare
There was a problem hiding this comment.
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_HELPconstant to provide consistent help text in error messages - Raises a descriptive
LXDErrorwhen 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: |
There was a problem hiding this comment.
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.
| if not devices: | |
| if devices == {}: |
| devices = self.lxc.profile_show( | ||
| project=self.lxd_project, profile="default", remote=self.lxd_remote | ||
| ).get("devices") |
There was a problem hiding this comment.
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.
| 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 | |
| ), | |
| ) |
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.
tox?