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(snap): check if LXD is actually installed #1984

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def _delete_lxd_instance(instance: dict) -> None:
print(f"Failed to remove LXD instance {instance['name']}.", file=sys.stderr)


def _has_lxd() -> bool:
return subprocess.run(["snap", "list", "lxd"]).returncode == 0


def configure_hook_main():
# Unique valid base instances directory to prevent duplication.
image_slots = {}
Expand All @@ -85,6 +89,10 @@ def configure_hook_main():
print(f"Unsupported snap configuration: {reason}.", file=sys.stderr)
sys.exit(1)

if not _has_lxd():
print("LXD is not installed.", file=sys.stderr)
return

# Remove only base images in LXD related project
try:
lxd_images_json = subprocess.check_output(
Expand Down
8 changes: 8 additions & 0 deletions snap/hooks/remove
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ import sys
PROJECT_NAME = "charmcraft"


def _has_lxd() -> bool:
return subprocess.run(["snap", "list", "lxd"]).returncode == 0


def remove_hook_main():
if not _has_lxd():
print("LXD is not installed.", file=sys.stderr)
return

# Remove all images in LXD related project
try:
lxd_images_json = subprocess.check_output(
Expand Down
Loading