Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion craft_providers/lxd/lxd_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from craft_providers.base import Base
from craft_providers.errors import BaseConfigurationError

from .errors import LXDError, LXDUnstableImageError
from .errors import LXD_INSTALL_HELP, LXDError, LXDUnstableImageError
from .installer import ensure_lxd_is_ready, install, is_installed
from .launcher import launch
from .lxc import LXC
Expand Down Expand Up @@ -126,6 +126,26 @@ def launched_environment(

:raises LXDError: if instance cannot be configured and launched.
"""
projects = self.lxc.project_list(remote=self.lxd_remote)
if self.lxd_project in projects:
devices = self.lxc.profile_show(
project=self.lxd_project, profile="default", remote=self.lxd_remote
).get("devices")
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
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
Collaborator

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
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

brief="LXD project has an ill-formed default profile.",
details=(
f"The default profile in the LXD project '{self.lxd_project}' "
"has an empty devices section."
),
resolution=(
f"Delete the '{self.lxd_project}' LXD project, it will be "
"recreated in the next execution.\n" + LXD_INSTALL_HELP
),
)

if build_base:
logger.warning(
"Deprecated: Parameter 'build_base' is deprecated and should "
Expand Down
Loading